diff --git a/.gitignore b/.gitignore index 5691469f..953d9319 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ node_modules lib dist +types diff --git a/.travis.yml b/.travis.yml index 43654a99..5ac5ceaf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 diff --git a/package.json b/package.json index a5d029b0..02fd243d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/ipfs-unixfs-exporter/.aegir.cjs b/packages/ipfs-unixfs-exporter/.aegir.cjs index 139ce023..7c48d0be 100644 --- a/packages/ipfs-unixfs-exporter/.aegir.cjs +++ b/packages/ipfs-unixfs-exporter/.aegir.cjs @@ -32,5 +32,8 @@ module.exports = { buildConfig } } + }, + ts: { + copyTo: 'types' } } diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index 480c334a..d3447c34 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -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", @@ -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", @@ -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": { diff --git a/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js b/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js index 285a0116..6945690c 100644 --- a/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js +++ b/packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js @@ -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 @@ -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() } /** diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.js b/packages/ipfs-unixfs-exporter/test/importer.spec.js index 74efa7da..28dd168b 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.js +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.js @@ -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 @@ -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 diff --git a/packages/ipfs-unixfs-exporter/tsconfig.json b/packages/ipfs-unixfs-exporter/tsconfig.json index 446917f2..c490e3c1 100644 --- a/packages/ipfs-unixfs-exporter/tsconfig.json +++ b/packages/ipfs-unixfs-exporter/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "dist", + "outDir": "types", "module": "es2020", "importsNotUsedAsValues": "preserve" }, @@ -16,6 +16,9 @@ "references": [ { "path": "../ipfs-unixfs" + }, + { + "path": "../ipfs-unixfs-importer" } ] } diff --git a/packages/ipfs-unixfs-importer/.aegir.cjs b/packages/ipfs-unixfs-importer/.aegir.cjs index fbe2f018..6abe4ea8 100644 --- a/packages/ipfs-unixfs-importer/.aegir.cjs +++ b/packages/ipfs-unixfs-importer/.aegir.cjs @@ -32,5 +32,8 @@ module.exports = { buildConfig } } + }, + ts: { + copyTo: 'types' } } diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 57979cd6..69940433 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -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", @@ -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", @@ -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": { diff --git a/packages/ipfs-unixfs-importer/src/options.js b/packages/ipfs-unixfs-importer/src/options.js index de0b0acc..39efd91e 100644 --- a/packages/ipfs-unixfs-importer/src/options.js +++ b/packages/ipfs-unixfs-importer/src/options.js @@ -1,8 +1,6 @@ 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 }) @@ -10,7 +8,7 @@ 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.. diff --git a/packages/ipfs-unixfs-importer/tsconfig.json b/packages/ipfs-unixfs-importer/tsconfig.json index 446917f2..c69a39ac 100644 --- a/packages/ipfs-unixfs-importer/tsconfig.json +++ b/packages/ipfs-unixfs-importer/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "dist", + "outDir": "types", "module": "es2020", "importsNotUsedAsValues": "preserve" }, diff --git a/packages/ipfs-unixfs/.aegir.cjs b/packages/ipfs-unixfs/.aegir.cjs index 7297ccbd..6622ba0a 100644 --- a/packages/ipfs-unixfs/.aegir.cjs +++ b/packages/ipfs-unixfs/.aegir.cjs @@ -4,5 +4,8 @@ module.exports = { build: { bundlesizeMax: '11KB' + }, + ts: { + copyTo: 'types' } } diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index 89dd8fe6..9039489e 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -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", @@ -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": { diff --git a/packages/ipfs-unixfs/tsconfig.json b/packages/ipfs-unixfs/tsconfig.json index f06b4656..7c8a6394 100644 --- a/packages/ipfs-unixfs/tsconfig.json +++ b/packages/ipfs-unixfs/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { - "outDir": "dist" + "outDir": "types" }, "include": [ "src",