Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: publish with types in package.json #166

Merged
merged 4 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ node_modules

lib
dist
types
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ before_install:
# allow windows to run scripts with node 14 and npm 7 (may not be necessary when node 14 is no longer lts)
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then npm config set script-shell c:/PROGRA~1/Git/bin/bash.exe ; fi

before_script: npm run build
script: npx nyc -s npm run test -- -- -- -t node --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

Expand Down Expand Up @@ -85,10 +86,7 @@ jobs:

- stage: test
name: electron main
addons:
firefox: latest
script:
- npm run build
script:
- npx lerna link # use publishConfig.directory
- npm run test -- -- -- -t electron-main -f dist/cjs/node-test/*js

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"update-contributors": "aegir release --lint=false --test=false --bump=false --build=false --changelog=false --commit=false --tag=false --push=false --ghrelease=false --docs=false --publish=false"
},
"devDependencies": {
"lerna": "^3.22.1",
"json": "^11.0.0"
"lerna": "^3.22.1"
},
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions packages/ipfs-unixfs-exporter/.aegir.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ module.exports = {
buildConfig
}
}
},
ts: {
copyTo: 'types'
}
}
10 changes: 5 additions & 5 deletions packages/ipfs-unixfs-exporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"fs": false
},
"scripts": {
"prepare": "aegir build --no-bundle",
"prepare": "aegir build --no-bundle && cp -R types dist",
"pretest": "aegir build --esm-tests",
"test": "aegir test",
"build": "aegir build --esm-tests",
"build": "aegir build && cp -R types dist",
"preleaseOnly": "npx json -I -f dist/package.json -e this.types='\"src/index.d.ts\"'",
"clean": "rimraf ./dist",
"lint": "aegir ts -p check && aegir lint",
Expand Down Expand Up @@ -50,7 +51,6 @@
"it-buffer-stream": "^2.0.0",
"it-first": "^1.0.6",
"merge-options": "^3.0.4",
"murmurhash3js-revisited": "^3.0.0",
"native-abort-controller": "^1.0.3",
"nyc": "^15.0.0",
"readable-stream": "^3.6.0",
Expand All @@ -61,16 +61,16 @@
"dependencies": {
"@ipld/dag-cbor": "^6.0.4",
"@ipld/dag-pb": "^2.0.2",
"@multiformats/murmur3": "^1.0.3",
"err-code": "^3.0.1",
"hamt-sharding": "^2.0.0",
"interface-blockstore": "^1.0.0",
"ipfs-unixfs": "^6.0.2",
"it-last": "^1.0.5",
"multiformats": "^9.4.2",
"murmurhash3js-revisited": "^3.0.0",
"uint8arrays": "^3.0.0"
},
"types": "dist/src/index.d.ts",
"types": "types/src/index.d.ts",
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
Expand Down
12 changes: 8 additions & 4 deletions packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import { Bucket, createHAMT } from 'hamt-sharding'
import { decode } from '@ipld/dag-pb'
// @ts-ignore - no types available
import mur from 'murmurhash3js-revisited'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { murmur3128 } from '@multiformats/murmur3'

/**
* @typedef {import('interface-blockstore').Blockstore} Blockstore
Expand All @@ -18,7 +16,13 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
* @param {Uint8Array} buf
*/
const hashFn = async function (buf) {
return uint8ArrayFromString(mur.x64.hash128(buf), 'base16').slice(0, 8).reverse()
return (await murmur3128.encode(buf))
// Murmur3 outputs 128 bit but, accidentally, IPFS Go's
// implementation only uses the first 64, so we must do the same
// for parity..
.slice(0, 8)
// Invert buffer because that's how Go impl does it
.reverse()
}

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/ipfs-unixfs-exporter/test/importer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,6 @@ describe('configuration', () => {
path: 'path',
content: asAsyncIterable(uint8ArrayFromString('content'))
}], block, {
/** @type {import('ipfs-unixfs-importer').ChunkValidator} */
chunkValidator: async function * (source) { // eslint-disable-line require-await
validated = true

Expand All @@ -1106,7 +1105,6 @@ describe('configuration', () => {
}
}
},
/** @type {import('ipfs-unixfs-importer').Chunker} */
chunker: async function * (source) { // eslint-disable-line require-await
chunked = true
yield * source
Expand Down
5 changes: 4 additions & 1 deletion packages/ipfs-unixfs-exporter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist",
"outDir": "types",
"module": "es2020",
"importsNotUsedAsValues": "preserve"
},
Expand All @@ -16,6 +16,9 @@
"references": [
{
"path": "../ipfs-unixfs"
},
{
"path": "../ipfs-unixfs-importer"
}
]
}
3 changes: 3 additions & 0 deletions packages/ipfs-unixfs-importer/.aegir.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,8 @@ module.exports = {
buildConfig
}
}
},
ts: {
copyTo: 'types'
}
}
9 changes: 5 additions & 4 deletions packages/ipfs-unixfs-importer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"fs": false
},
"scripts": {
"prepare": "aegir build --no-bundle",
"prepare": "aegir build --no-bundle && cp -R types dist",
"pretest": "aegir build --esm-tests",
"test": "aegir test",
"build": "aegir build --esm-tests",
"build": "aegir build && cp -R types dist",
"preleaseOnly": "npx json -I -f dist/package.json -e this.types='\"src/index.d.ts\"'",
"clean": "rimraf ./dist",
"lint": "aegir ts -p check && aegir lint",
Expand Down Expand Up @@ -52,6 +53,7 @@
},
"dependencies": {
"@ipld/dag-pb": "^2.0.2",
"@multiformats/murmur3": "^1.0.3",
"bl": "^5.0.0",
"err-code": "^3.0.1",
"hamt-sharding": "^2.0.0",
Expand All @@ -63,11 +65,10 @@
"it-parallel-batch": "^1.0.9",
"merge-options": "^3.0.4",
"multiformats": "^9.4.2",
"murmurhash3js-revisited": "^3.0.0",
"rabin-wasm": "^0.1.4",
"uint8arrays": "^3.0.0"
},
"types": "dist/src/index.d.ts",
"types": "types/src/index.d.ts",
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
Expand Down
6 changes: 2 additions & 4 deletions packages/ipfs-unixfs-importer/src/options.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import mergeOptions from 'merge-options'
import { sha256 } from 'multiformats/hashes/sha2'
// @ts-ignore - no types available
import mur from 'murmurhash3js-revisited'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { murmur3128 } from '@multiformats/murmur3'

mergeOptions.bind({ ignoreUndefined: true })

/**
* @param {Uint8Array} buf
*/
async function hamtHashFn (buf) {
return uint8ArrayFromString(mur.x64.hash128(buf), 'base16')
return (await murmur3128.encode(buf))
// Murmur3 outputs 128 bit but, accidentally, IPFS Go's
// implementation only uses the first 64, so we must do the same
// for parity..
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-unixfs-importer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist",
"outDir": "types",
"module": "es2020",
"importsNotUsedAsValues": "preserve"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/ipfs-unixfs/.aegir.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
module.exports = {
build: {
bundlesizeMax: '11KB'
},
ts: {
copyTo: 'types'
}
}
9 changes: 4 additions & 5 deletions packages/ipfs-unixfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
"fs": false
},
"scripts": {
"prepare": "aegir build",
"prepare": "aegir build --no-bundle && cp -R types dist",
"prepare:proto": "pbjs -t static-module -w es6 -r ipfs-unixfs --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/unixfs.js ./src/unixfs.proto",
"prepare:proto-types": "pbts -o src/unixfs.d.ts src/unixfs.js",
"prepare:types": "aegir build --no-bundle",
"pretest": "aegir build --esm-tests",
"test": "aegir test",
"build": "aegir build --esm-tests",
"preleaseOnly": "npx json -I -f dist/package.json -e this.types='\"src/index.d.ts\"'",
"build": "aegir build && cp -R types dist",
"clean": "rimraf ./dist",
"lint": "aegir ts -p check && aegir lint",
"coverage": "nyc -s aegir test -t node && nyc report --reporter=html",
Expand Down Expand Up @@ -54,7 +53,7 @@
"err-code": "^3.0.1",
"protobufjs": "^6.10.2"
},
"types": "dist/src/index.d.ts",
"types": "types/src/index.d.ts",
"eslintConfig": {
"extends": "ipfs",
"parserOptions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-unixfs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist"
"outDir": "types"
},
"include": [
"src",
Expand Down