From 985bbf36a1c094f5dd2592d0f72bcd7788707f03 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 21 Jul 2021 14:25:13 +0200 Subject: [PATCH 01/16] chore: switch to ESM BREAKING CHANGE: built content includes ESM and CJS --- .../{.aegir.js => .aegir.cjs} | 0 packages/ipfs-unixfs-exporter/package.json | 11 ++--- packages/ipfs-unixfs-exporter/src/index.js | 22 +++------ .../src/resolvers/dag-cbor.js | 10 ++-- .../src/resolvers/identity.js | 12 ++--- .../src/resolvers/index.js | 26 +++++----- .../ipfs-unixfs-exporter/src/resolvers/raw.js | 10 ++-- .../resolvers/unixfs-v1/content/directory.js | 4 +- .../src/resolvers/unixfs-v1/content/file.js | 18 +++---- .../content/hamt-sharded-directory.js | 6 +-- .../src/resolvers/unixfs-v1/content/raw.js | 8 ++- .../src/resolvers/unixfs-v1/index.js | 23 +++++---- .../src/utils/extract-data-from-block.js | 6 +-- .../src/utils/find-cid-in-shard.js | 10 ++-- .../src/utils/validate-offset-and-length.js | 6 +-- .../test/exporter-sharded.spec.js | 29 ++++++----- .../test/exporter-subtree.spec.js | 21 ++++---- .../test/exporter.spec.js | 42 ++++++++-------- .../test/helpers/as-async-iterable.js | 4 +- .../test/helpers/block.js | 6 +-- .../test/helpers/collect-leaf-cids.js | 6 +-- .../test/import-export-dir-sharding.spec.js | 25 +++++----- .../test/import-export-nested-dir.spec.js | 21 ++++---- .../test/import-export.spec.js | 21 ++++---- .../test/importer.spec.js | 49 +++++++++---------- .../{.aegir.js => .aegir.cjs} | 0 packages/ipfs-unixfs-importer/package.json | 9 ++-- .../src/chunker/fixed-size.js | 8 +-- .../ipfs-unixfs-importer/src/chunker/index.js | 10 ++-- .../ipfs-unixfs-importer/src/chunker/rabin.js | 12 ++--- .../src/dag-builder/dir.js | 10 ++-- .../src/dag-builder/file/balanced.js | 6 +-- .../src/dag-builder/file/buffer-importer.js | 12 ++--- .../src/dag-builder/file/flat.js | 8 +-- .../src/dag-builder/file/index.js | 32 ++++++------ .../src/dag-builder/file/trickle.js | 8 +-- .../src/dag-builder/index.js | 19 ++++--- .../src/dag-builder/validate-chunks.js | 8 ++- packages/ipfs-unixfs-importer/src/dir-flat.js | 12 ++--- .../ipfs-unixfs-importer/src/dir-sharded.js | 14 +++--- packages/ipfs-unixfs-importer/src/dir.js | 5 +- .../ipfs-unixfs-importer/src/flat-to-shard.js | 16 ++++-- packages/ipfs-unixfs-importer/src/index.js | 18 +++---- packages/ipfs-unixfs-importer/src/options.js | 14 +++--- .../ipfs-unixfs-importer/src/tree-builder.js | 13 +++-- .../ipfs-unixfs-importer/src/utils/persist.js | 10 ++-- .../src/utils/to-path-components.js | 4 +- .../test/benchmark.spec.js | 8 ++- .../test/builder-balanced.spec.js | 11 ++--- .../test/builder-flat.spec.js | 6 +-- .../test/builder-only-hash.spec.js | 14 +++--- .../test/builder-trickle-dag.spec.js | 8 +-- .../ipfs-unixfs-importer/test/builder.spec.js | 25 +++++----- .../test/chunker-custom.spec.js | 18 +++---- .../test/chunker-fixed-size.spec.js | 17 +++---- .../test/chunker-rabin.spec.js | 18 +++---- .../test/hash-parity-with-go-ipfs.spec.js | 17 +++---- .../test/helpers/as-async-iterable.js | 4 +- .../test/helpers/block.js | 10 ++-- .../finite-pseudorandom-byte-stream.js | 6 +-- .../test/helpers/random-byte-stream.js | 4 +- .../ipfs-unixfs/{.aegir.js => .aegir.cjs} | 0 packages/ipfs-unixfs/package.json | 13 +++-- packages/ipfs-unixfs/src/index.js | 23 +++------ packages/ipfs-unixfs/src/unixfs.js | 18 +++---- .../ipfs-unixfs/test/unixfs-format.spec.js | 15 +++--- 66 files changed, 410 insertions(+), 469 deletions(-) rename packages/ipfs-unixfs-exporter/{.aegir.js => .aegir.cjs} (100%) rename packages/ipfs-unixfs-importer/{.aegir.js => .aegir.cjs} (100%) rename packages/ipfs-unixfs/{.aegir.js => .aegir.cjs} (100%) diff --git a/packages/ipfs-unixfs-exporter/.aegir.js b/packages/ipfs-unixfs-exporter/.aegir.cjs similarity index 100% rename from packages/ipfs-unixfs-exporter/.aegir.js rename to packages/ipfs-unixfs-exporter/.aegir.cjs diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index 869fb30b..367628f8 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -4,13 +4,15 @@ "description": "JavaScript implementation of the UnixFs exporter used by IPFS", "leadMaintainer": "Alex Potsides ", "main": "src/index.js", + "type": "module", "browser": { "fs": false }, "scripts": { - "prepare": "aegir build --no-bundle", + "prepare": "aegir build", "test": "aegir test", "build": "aegir build", + "postbuild": "cd dist && npx json -I -f package.json -e 'this.types=\"src/index.d.ts\"'", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s npm run test -t node && nyc report --reporter=html", @@ -36,7 +38,7 @@ "@types/mocha": "^8.2.1", "@types/sinon": "^10.0.0", "abort-controller": "^3.0.0", - "aegir": "^34.0.0", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", "detect-node": "^2.0.4", @@ -45,6 +47,7 @@ "it-all": "^1.0.5", "it-buffer-stream": "^2.0.0", "it-first": "^1.0.6", + "json": "^11.0.0", "merge-options": "^3.0.4", "murmurhash3js-revisited": "^3.0.0", "native-abort-controller": "^1.0.3", @@ -68,10 +71,6 @@ "uint8arrays": "^2.1.7" }, "types": "dist/src/index.d.ts", - "files": [ - "src", - "dist" - ], "eslintConfig": { "extends": "ipfs" } diff --git a/packages/ipfs-unixfs-exporter/src/index.js b/packages/ipfs-unixfs-exporter/src/index.js index bc3bfa91..8cdaf2c8 100644 --- a/packages/ipfs-unixfs-exporter/src/index.js +++ b/packages/ipfs-unixfs-exporter/src/index.js @@ -1,9 +1,7 @@ -'use strict' - -const errCode = require('err-code') -const { CID } = require('multiformats/cid') -const resolve = require('./resolvers') -const last = require('it-last') +import errCode from 'err-code' +import { CID } from 'multiformats/cid' +import resolve from './resolvers/index.js' +import last from 'it-last' /** * @typedef {import('ipfs-unixfs').UnixFS} UnixFS @@ -65,7 +63,7 @@ const cidAndRest = (path) => { * @param {Blockstore} blockstore * @param {ExporterOptions} [options] */ -async function * walkPath (path, blockstore, options = {}) { +export async function * walkPath (path, blockstore, options = {}) { let { cid, toResolve @@ -102,7 +100,7 @@ async function * walkPath (path, blockstore, options = {}) { * @param {Blockstore} blockstore * @param {ExporterOptions} [options] */ -async function exporter (path, blockstore, options = {}) { +export async function exporter (path, blockstore, options = {}) { const result = await last(walkPath(path, blockstore, options)) if (!result) { @@ -117,7 +115,7 @@ async function exporter (path, blockstore, options = {}) { * @param {Blockstore} blockstore * @param {ExporterOptions} [options] */ -async function * recursive (path, blockstore, options = {}) { +export async function * recursive (path, blockstore, options = {}) { const node = await exporter(path, blockstore, options) if (!node) { @@ -151,9 +149,3 @@ async function * recursive (path, blockstore, options = {}) { } } } - -module.exports = { - exporter, - walkPath, - recursive -} diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.js b/packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.js index 6a077d3d..2188f058 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/dag-cbor.js @@ -1,8 +1,6 @@ -'use strict' - -const { CID } = require('multiformats/cid') -const errCode = require('err-code') -const dagCbor = require('@ipld/dag-cbor') +import { CID } from 'multiformats/cid' +import errCode from 'err-code' +import * as dagCbor from '@ipld/dag-cbor' /** * @typedef {import('../types').Resolver} Resolver @@ -72,4 +70,4 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, o } } -module.exports = resolve +export default resolve diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/identity.js b/packages/ipfs-unixfs-exporter/src/resolvers/identity.js index 2c2d015a..ac1c11b5 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/identity.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/identity.js @@ -1,9 +1,7 @@ -'use strict' - -const errCode = require('err-code') -const extractDataFromBlock = require('../utils/extract-data-from-block') -const validateOffsetAndLength = require('../utils/validate-offset-and-length') -const mh = require('multiformats/hashes/digest') +import errCode from 'err-code' +import extractDataFromBlock from '../utils/extract-data-from-block.js' +import validateOffsetAndLength from '../utils/validate-offset-and-length.js' +import * as mh from 'multiformats/hashes/digest' /** * @typedef {import('../types').ExporterOptions} ExporterOptions @@ -52,4 +50,4 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, o } } -module.exports = resolve +export default resolve diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/index.js b/packages/ipfs-unixfs-exporter/src/resolvers/index.js index 1ec5a034..6ae42047 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/index.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/index.js @@ -1,11 +1,15 @@ -'use strict' +import errCode from 'err-code' -const errCode = require('err-code') +import * as dagPb from '@ipld/dag-pb' +import * as dagCbor from '@ipld/dag-cbor' +import * as raw from 'multiformats/codecs/raw' +import { identity } from 'multiformats/hashes/identity' -const dagPb = require('@ipld/dag-pb') -const dagCbor = require('@ipld/dag-cbor') -const raw = require('multiformats/codecs/raw') -const { identity } = require('multiformats/hashes/identity') +// TODO: Lazy Load +import unixFs1Resolver from './unixfs-v1/index.js' +import rawResolver from './raw.js' +import dagCborResolver from './dag-cbor.js' +import identityResolver from './identity.js' /** * @typedef {import('../types').Resolver} Resolver @@ -16,10 +20,10 @@ const { identity } = require('multiformats/hashes/identity') * @type {{ [ key: string ]: Resolver }} */ const resolvers = { - [dagPb.code]: require('./unixfs-v1'), - [raw.code]: require('./raw'), - [dagCbor.code]: require('./dag-cbor'), - [identity.code]: require('./identity') + [dagPb.code]: unixFs1Resolver, + [raw.code]: rawResolver, + [dagCbor.code]: dagCborResolver, + [identity.code]: identityResolver } /** @@ -35,4 +39,4 @@ function resolve (cid, name, path, toResolve, depth, blockstore, options) { return resolver(cid, name, path, toResolve, resolve, depth, blockstore, options) } -module.exports = resolve +export default resolve diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/raw.js b/packages/ipfs-unixfs-exporter/src/resolvers/raw.js index a82e511b..5807d32c 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/raw.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/raw.js @@ -1,8 +1,6 @@ -'use strict' - -const errCode = require('err-code') -const extractDataFromBlock = require('../utils/extract-data-from-block') -const validateOffsetAndLength = require('../utils/validate-offset-and-length') +import errCode from 'err-code' +import extractDataFromBlock from '../utils/extract-data-from-block.js' +import validateOffsetAndLength from '../utils/validate-offset-and-length.js' /** * @typedef {import('../types').ExporterOptions} ExporterOptions @@ -51,4 +49,4 @@ const resolve = async (cid, name, path, toResolve, resolve, depth, blockstore, o } } -module.exports = resolve +export default resolve diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.js b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.js index 9433f0b4..677d39a6 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.js @@ -1,5 +1,3 @@ -'use strict' - /** * @typedef {import('../../../types').ExporterOptions} ExporterOptions * @typedef {import('../../../types').UnixfsV1DirectoryContent} UnixfsV1DirectoryContent @@ -31,4 +29,4 @@ const directoryContent = (cid, node, unixfs, path, resolve, depth, blockstore) = return yieldDirectoryContent } -module.exports = directoryContent +export default directoryContent diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.js b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.js index 2ba6a5ca..6c95e5fd 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/file.js @@ -1,12 +1,10 @@ -'use strict' - -const extractDataFromBlock = require('../../../utils/extract-data-from-block') -const validateOffsetAndLength = require('../../../utils/validate-offset-and-length') -const { UnixFS } = require('ipfs-unixfs') -const errCode = require('err-code') -const dagPb = require('@ipld/dag-pb') -const dagCbor = require('@ipld/dag-cbor') -const raw = require('multiformats/codecs/raw') +import extractDataFromBlock from '../../../utils/extract-data-from-block.js' +import validateOffsetAndLength from '../../../utils/validate-offset-and-length.js' +import { UnixFS } from 'ipfs-unixfs' +import errCode from 'err-code' +import * as dagPb from '@ipld/dag-pb' +import * as dagCbor from '@ipld/dag-cbor' +import * as raw from 'multiformats/codecs/raw' /** * @typedef {import('../../../types').ExporterOptions} ExporterOptions @@ -126,4 +124,4 @@ const fileContent = (cid, node, unixfs, path, resolve, depth, blockstore) => { return yieldFileContent } -module.exports = fileContent +export default fileContent diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js index 93bf11dd..8e3e8664 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.js @@ -1,6 +1,4 @@ -'use strict' - -const { decode } = require('@ipld/dag-pb') +import { decode } from '@ipld/dag-pb' /** * @typedef {import('interface-blockstore').Blockstore} Blockstore @@ -58,4 +56,4 @@ async function * listDirectory (node, path, resolve, depth, blockstore, options) } } -module.exports = hamtShardedDirectoryContent +export default hamtShardedDirectoryContent diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.js b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.js index 95a38870..5c622248 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/raw.js @@ -1,7 +1,5 @@ -'use strict' - -const extractDataFromBlock = require('../../../utils/extract-data-from-block') -const validateOffsetAndLength = require('../../../utils/validate-offset-and-length') +import extractDataFromBlock from '../../../utils/extract-data-from-block.js' +import validateOffsetAndLength from '../../../utils/validate-offset-and-length.js' /** * @typedef {import('../../../types').ExporterOptions} ExporterOptions @@ -33,4 +31,4 @@ const rawContent = (cid, node, unixfs, path, resolve, depth, blockstore) => { return yieldRawContent } -module.exports = rawContent +export default rawContent diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js index 86b70e91..c5d86f04 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js @@ -1,9 +1,12 @@ -'use strict' +import errCode from 'err-code' +import { UnixFS } from 'ipfs-unixfs' +import findShardCid from '../../utils/find-cid-in-shard.js' +import { decode } from '@ipld/dag-pb' -const errCode = require('err-code') -const { UnixFS } = require('ipfs-unixfs') -const findShardCid = require('../../utils/find-cid-in-shard') -const { decode } = require('@ipld/dag-pb') +// TODO Lazy load +import contentFile from './content/file.js' +import contentDirectory from './content/directory.js' +import contentHamtShardedDirectory from './content/hamt-sharded-directory.js' /** * @typedef {import('../../types').Resolve} Resolve @@ -26,10 +29,10 @@ const findLinkCid = (node, name) => { * @type {{ [key: string]: UnixfsV1Resolver }} */ const contentExporters = { - raw: require('./content/file'), - file: require('./content/file'), - directory: require('./content/directory'), - 'hamt-sharded-directory': require('./content/hamt-sharded-directory'), + raw: contentFile, + file: contentFile, + directory: contentDirectory, + 'hamt-sharded-directory': contentHamtShardedDirectory, metadata: (cid, node, unixfs, path, resolve, depth, blockstore) => { return () => [] }, @@ -109,4 +112,4 @@ const unixFsResolver = async (cid, name, path, toResolve, resolve, depth, blocks } } -module.exports = unixFsResolver +export default unixFsResolver diff --git a/packages/ipfs-unixfs-exporter/src/utils/extract-data-from-block.js b/packages/ipfs-unixfs-exporter/src/utils/extract-data-from-block.js index 4de42822..c5d715be 100644 --- a/packages/ipfs-unixfs-exporter/src/utils/extract-data-from-block.js +++ b/packages/ipfs-unixfs-exporter/src/utils/extract-data-from-block.js @@ -1,12 +1,10 @@ -'use strict' - /** * @param {Uint8Array} block * @param {number} blockStart * @param {number} requestedStart * @param {number} requestedEnd */ -module.exports = function extractDataFromBlock (block, blockStart, requestedStart, requestedEnd) { +function extractDataFromBlock (block, blockStart, requestedStart, requestedEnd) { const blockLength = block.length const blockEnd = blockStart + blockLength @@ -28,3 +26,5 @@ module.exports = function extractDataFromBlock (block, blockStart, requestedStar return block } + +export default extractDataFromBlock 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 5c92bdcd..55cad708 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,10 +1,10 @@ 'use strict' -const { Bucket, createHAMT } = require('hamt-sharding') -const { decode } = require('@ipld/dag-pb') +import { Bucket, createHAMT } from 'hamt-sharding' +import { decode } from '@ipld/dag-pb' // @ts-ignore - no types available -const mur = require('murmurhash3js-revisited') -const uint8ArrayFromString = require('uint8arrays/from-string') +import mur from 'murmurhash3js-revisited' +import uint8ArrayFromString from 'uint8arrays/from-string.js' /** * @typedef {import('interface-blockstore').Blockstore} Blockstore @@ -152,4 +152,4 @@ const findShardCid = async (node, name, blockstore, context, options) => { return findShardCid(node, name, blockstore, context, options) } -module.exports = findShardCid +export default findShardCid diff --git a/packages/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.js b/packages/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.js index 1786302f..80e0ffb8 100644 --- a/packages/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.js +++ b/packages/ipfs-unixfs-exporter/src/utils/validate-offset-and-length.js @@ -1,6 +1,4 @@ -'use strict' - -const errCode = require('err-code') +import errCode from 'err-code' /** * @param {number} size @@ -38,4 +36,4 @@ const validateOffsetAndLength = (size, offset, length) => { } } -module.exports = validateOffsetAndLength +export default validateOffsetAndLength diff --git a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js index 91a43275..da48d1bd 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js @@ -1,19 +1,18 @@ /* eslint-env mocha */ -'use strict' - -const { expect } = require('aegir/utils/chai') -const { UnixFS } = require('ipfs-unixfs') -const all = require('it-all') -const last = require('it-last') -const randomBytes = require('it-buffer-stream') -const { exporter, walkPath } = require('../src') -const { importer } = require('ipfs-unixfs-importer') -const dagPb = require('@ipld/dag-pb') -const blockApi = require('./helpers/block') -const uint8ArrayConcat = require('uint8arrays/concat') -const asAsyncIterable = require('./helpers/as-async-iterable') -const { CID } = require('multiformats/cid') -const { sha256 } = require('multiformats/hashes/sha2') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import { UnixFS } from 'ipfs-unixfs' +import all from 'it-all' +import last from 'it-last' +import randomBytes from 'it-buffer-stream' +import { exporter, walkPath } from '../src/index.js' +import { importer } from 'ipfs-unixfs-importer' +import * as dagPb from '@ipld/dag-pb' +import blockApi from './helpers/block.js' +import uint8ArrayConcat from 'uint8arrays/concat.js' +import asAsyncIterable from './helpers/as-async-iterable.js' +import { CID } from 'multiformats/cid' +import { sha256 } from 'multiformats/hashes/sha2' const SHARD_SPLIT_THRESHOLD = 10 diff --git a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js index 6e1c6e00..2803e53d 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js @@ -1,18 +1,17 @@ /* eslint-env mocha */ -'use strict' - -const { expect } = require('aegir/utils/chai') -const { importer } = require('ipfs-unixfs-importer') -const all = require('it-all') -const last = require('it-last') -const blockApi = require('./helpers/block') -const randomBytes = require('it-buffer-stream') -const uint8ArrayConcat = require('uint8arrays/concat') -const asAsyncIterable = require('./helpers/as-async-iterable') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import { importer } from 'ipfs-unixfs-importer' +import all from 'it-all' +import last from 'it-last' +import blockApi from './helpers/block.js' +import randomBytes from 'it-buffer-stream' +import uint8ArrayConcat from 'uint8arrays/concat.js' +import asAsyncIterable from './helpers/as-async-iterable.js' const ONE_MEG = Math.pow(1024, 2) -const { exporter, walkPath } = require('./../src') +import { exporter, walkPath } from './../src/index.js' describe('exporter subtree', () => { const block = blockApi() diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.js b/packages/ipfs-unixfs-exporter/test/exporter.spec.js index 0b8bbcc1..0c0a51d3 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.js @@ -1,26 +1,26 @@ /* eslint-env mocha */ 'use strict' - -const { expect } = require('aegir/utils/chai') -const { UnixFS } = require('ipfs-unixfs') -const { CID } = require('multiformats/cid') -const dagPb = require('@ipld/dag-pb') -const dagCbor = require('@ipld/dag-cbor') -const { sha256 } = require('multiformats/hashes/sha2') -const { identity } = require('multiformats/hashes/identity') -const raw = require('multiformats/codecs/raw') -const { exporter, recursive } = require('../src') -const { importer } = require('ipfs-unixfs-importer') -const all = require('it-all') -const last = require('it-last') -const first = require('it-first') -const randomBytes = require('it-buffer-stream') -const { AbortController } = require('native-abort-controller') -const blockApi = require('./helpers/block') -const uint8ArrayFromString = require('uint8arrays/from-string') -const uint8ArrayToString = require('uint8arrays/to-string') -const uint8ArrayConcat = require('uint8arrays/concat') -const asAsyncIterable = require('./helpers/as-async-iterable') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import { UnixFS } from 'ipfs-unixfs' +import { CID } from 'multiformats/cid' +import * as dagPb from '@ipld/dag-pb' +import * as dagCbor from '@ipld/dag-cbor' +import { sha256 } from 'multiformats/hashes/sha2' +import { identity } from 'multiformats/hashes/identity' +import * as raw from 'multiformats/codecs/raw' +import { exporter, recursive } from '../src/index.js' +import { importer } from 'ipfs-unixfs-importer' +import all from 'it-all' +import last from 'it-last' +import first from 'it-first' +import randomBytes from 'it-buffer-stream' +import { AbortController } from 'native-abort-controller' +import blockApi from './helpers/block.js' +import uint8ArrayFromString from 'uint8arrays/from-string.js' +import uint8ArrayToString from 'uint8arrays/to-string.js' +import uint8ArrayConcat from 'uint8arrays/concat.js' +import asAsyncIterable from './helpers/as-async-iterable.js' const ONE_MEG = Math.pow(1024, 2) diff --git a/packages/ipfs-unixfs-exporter/test/helpers/as-async-iterable.js b/packages/ipfs-unixfs-exporter/test/helpers/as-async-iterable.js index 7aba5df2..23e1cdea 100644 --- a/packages/ipfs-unixfs-exporter/test/helpers/as-async-iterable.js +++ b/packages/ipfs-unixfs-exporter/test/helpers/as-async-iterable.js @@ -1,5 +1,3 @@ -'use strict' - /** * @param {Uint8Array | Uint8Array[]} arr */ @@ -11,4 +9,4 @@ async function * asAsyncIterable (arr) { yield * arr } -module.exports = asAsyncIterable +export default asAsyncIterable diff --git a/packages/ipfs-unixfs-exporter/test/helpers/block.js b/packages/ipfs-unixfs-exporter/test/helpers/block.js index d6aa505c..659bb6b5 100644 --- a/packages/ipfs-unixfs-exporter/test/helpers/block.js +++ b/packages/ipfs-unixfs-exporter/test/helpers/block.js @@ -1,7 +1,5 @@ -'use strict' - /** @type {() => import('interface-blockstore').Blockstore} */ // @ts-expect-error no types for this deep import -const block = require('ipfs-unixfs-importer/test/helpers/block') +import block from 'ipfs-unixfs-importer/test/helpers/block.js' -module.exports = block +export default block diff --git a/packages/ipfs-unixfs-exporter/test/helpers/collect-leaf-cids.js b/packages/ipfs-unixfs-exporter/test/helpers/collect-leaf-cids.js index 259b3133..bc7fe5c7 100644 --- a/packages/ipfs-unixfs-exporter/test/helpers/collect-leaf-cids.js +++ b/packages/ipfs-unixfs-exporter/test/helpers/collect-leaf-cids.js @@ -1,6 +1,4 @@ -'use strict' - -const dagPb = require('@ipld/dag-pb') +import * as dagPb from '@ipld/dag-pb' /** * @typedef {import('@ipld/dag-pb').PBLink} PBLink @@ -10,7 +8,7 @@ const dagPb = require('@ipld/dag-pb') * @param {import('multiformats/cid').CID} cid * @param {import('interface-blockstore').Blockstore} blockstore */ -module.exports = function (cid, blockstore) { +export default function (cid, blockstore) { /** * @param {import('multiformats/cid').CID} cid */ diff --git a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js index b2772159..8f4e07ff 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js @@ -1,17 +1,16 @@ /* eslint-env mocha */ -'use strict' - -const { importer } = require('ipfs-unixfs-importer') -const { exporter } = require('../src') - -const { expect } = require('aegir/utils/chai') -const all = require('it-all') -const last = require('it-last') -const blockApi = require('./helpers/block') -const uint8ArrayFromString = require('uint8arrays/from-string') -const uint8ArrayToString = require('uint8arrays/to-string') -const uint8ArrayConcat = require('uint8arrays/concat') -const asAsyncIterable = require('./helpers/as-async-iterable') +import { importer } from 'ipfs-unixfs-importer' +import { exporter } from '../src/index.js' + +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import all from 'it-all' +import last from 'it-last' +import blockApi from './helpers/block.js' +import uint8ArrayFromString from 'uint8arrays/from-string.js' +import uint8ArrayToString from 'uint8arrays/to-string.js' +import uint8ArrayConcat from 'uint8arrays/concat.js' +import asAsyncIterable from './helpers/as-async-iterable.js' /** * @typedef {import('../src').UnixFSEntry} UnixFSEntry diff --git a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js index c6018e3f..b27e088d 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js @@ -1,15 +1,14 @@ /* eslint-env mocha */ -'use strict' - -const { expect } = require('aegir/utils/chai') -const all = require('it-all') -const { importer } = require('ipfs-unixfs-importer') -const { exporter } = require('../src') -const blockApi = require('./helpers/block') -const uint8ArrayFromString = require('uint8arrays/from-string') -const uint8ArrayToString = require('uint8arrays/to-string') -const uint8ArrayConcat = require('uint8arrays/concat') -const asAsyncIterable = require('./helpers/as-async-iterable') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import all from 'it-all' +import { importer } from 'ipfs-unixfs-importer' +import { exporter } from '../src/index.js' +import blockApi from './helpers/block.js' +import uint8ArrayFromString from 'uint8arrays/from-string.js' +import uint8ArrayToString from 'uint8arrays/to-string.js' +import uint8ArrayConcat from 'uint8arrays/concat.js' +import asAsyncIterable from './helpers/as-async-iterable.js' describe('import and export: directory', () => { const rootHash = 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK' diff --git a/packages/ipfs-unixfs-exporter/test/import-export.spec.js b/packages/ipfs-unixfs-exporter/test/import-export.spec.js index d8571ff0..8ef149dc 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export.spec.js @@ -1,18 +1,17 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 5] */ -'use strict' - -const { expect } = require('aegir/utils/chai') -// @ts-ignore -const loadFixture = require('aegir/utils/fixtures') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' // @ts-ignore -const isNode = require('detect-node') -const bigFile = loadFixture((isNode ? __dirname : 'test') + '/fixtures/1.2MiB.txt') -const blockApi = require('./helpers/block') -const asAsyncIterable = require('./helpers/as-async-iterable') +import loadFixture from 'aegir/utils/fixtures.js' +import blockApi from './helpers/block.js' +import asAsyncIterable from './helpers/as-async-iterable.js' + +import { importer } from 'ipfs-unixfs-importer' +import { exporter } from '../src/index.js' -const { importer } = require('ipfs-unixfs-importer') -const { exporter } = require('../src') +/** @type {Uint8Array} */ +const bigFile = loadFixture(('test') + '/fixtures/1.2MiB.txt') const strategies = [ 'flat', diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.js b/packages/ipfs-unixfs-exporter/test/importer.spec.js index c722d082..b4f41d41 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.js +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.js @@ -1,32 +1,31 @@ /* eslint-env mocha */ -'use strict' - -const { importer } = require('ipfs-unixfs-importer') -const { exporter, recursive } = require('../src') -const extend = require('merge-options') -const { expect } = require('aegir/utils/chai') -const sinon = require('sinon') -const { UnixFS } = require('ipfs-unixfs') -const collectLeafCids = require('./helpers/collect-leaf-cids') -// @ts-ignore -const loadFixture = require('aegir/utils/fixtures') + +import { importer } from 'ipfs-unixfs-importer' +import { exporter, recursive } from '../src/index.js' +import extend from 'merge-options' +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import sinon from 'sinon' +import { UnixFS } from 'ipfs-unixfs' +import collectLeafCids from './helpers/collect-leaf-cids.js' // @ts-ignore -const isNode = require('detect-node') +import loadFixture from 'aegir/utils/fixtures.js' +import all from 'it-all' +import first from 'it-first' +import blockApi from './helpers/block.js' +import uint8ArrayConcat from 'uint8arrays/concat.js' +import uint8ArrayFromString from 'uint8arrays/from-string.js' +import asAsyncIterable from './helpers/as-async-iterable.js' +import last from 'it-last' +import { CID } from 'multiformats/cid' +import { base58btc } from 'multiformats/bases/base58' +import { decode } from '@ipld/dag-pb' +import { parseMtime } from 'ipfs-unixfs' + /** @type {Uint8Array} */ -const bigFile = loadFixture((isNode ? __dirname : 'test') + '/fixtures/1.2MiB.txt') +const bigFile = loadFixture(('test') + '/fixtures/1.2MiB.txt') /** @type {Uint8Array} */ -const smallFile = loadFixture((isNode ? __dirname : 'test') + '/fixtures/200Bytes.txt') -const all = require('it-all') -const first = require('it-first') -const blockApi = require('./helpers/block') -const uint8ArrayConcat = require('uint8arrays/concat') -const uint8ArrayFromString = require('uint8arrays/from-string') -const asAsyncIterable = require('./helpers/as-async-iterable') -const last = require('it-last') -const { CID } = require('multiformats/cid') -const { base58btc } = require('multiformats/bases/base58') -const { decode } = require('@ipld/dag-pb') -const { parseMtime } = require('ipfs-unixfs') +const smallFile = loadFixture(('test') + '/fixtures/200Bytes.txt') /** * @typedef {import('interface-blockstore').Blockstore} Blockstore diff --git a/packages/ipfs-unixfs-importer/.aegir.js b/packages/ipfs-unixfs-importer/.aegir.cjs similarity index 100% rename from packages/ipfs-unixfs-importer/.aegir.js rename to packages/ipfs-unixfs-importer/.aegir.cjs diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 931bf5a0..b278af5a 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -4,6 +4,7 @@ "description": "JavaScript implementation of the UnixFs importer used by IPFS", "leadMaintainer": "Alex Potsides ", "main": "src/index.js", + "type": "module", "browser": { "fs": false }, @@ -11,6 +12,7 @@ "prepare": "aegir build --no-bundle", "test": "aegir test", "build": "aegir build", + "postbuild": "cd dist && npx json -I -f package.json -e 'this.types=\"src/index.d.ts\"'", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s npm run test -t node && nyc report --reporter=html", @@ -34,12 +36,13 @@ "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { "@types/mocha": "^8.2.1", - "aegir": "^34.0.0", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules", "assert": "^2.0.0", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", "events": "^3.3.0", "it-buffer-stream": "^2.0.0", + "json": "^11.0.0", "nyc": "^15.0.0", "readable-stream": "^3.6.0", "rimraf": "^3.0.2", @@ -63,10 +66,6 @@ "uint8arrays": "^2.1.7" }, "types": "dist/src/index.d.ts", - "files": [ - "src", - "dist" - ], "eslintConfig": { "extends": "ipfs" } diff --git a/packages/ipfs-unixfs-importer/src/chunker/fixed-size.js b/packages/ipfs-unixfs-importer/src/chunker/fixed-size.js index 8ef07361..fe537399 100644 --- a/packages/ipfs-unixfs-importer/src/chunker/fixed-size.js +++ b/packages/ipfs-unixfs-importer/src/chunker/fixed-size.js @@ -1,12 +1,10 @@ -'use strict' - // @ts-ignore -const BufferList = require('bl/BufferList') +import BufferList from 'bl/BufferList.js' /** * @type {import('../types').Chunker} */ -module.exports = async function * fixedSizeChunker (source, options) { +async function * fixedSizeChunker (source, options) { let bl = new BufferList() let currentLength = 0 let emitted = false @@ -41,3 +39,5 @@ module.exports = async function * fixedSizeChunker (source, options) { yield bl.slice(0, currentLength) } } + +export default fixedSizeChunker diff --git a/packages/ipfs-unixfs-importer/src/chunker/index.js b/packages/ipfs-unixfs-importer/src/chunker/index.js index b7df2f09..fe97aba3 100644 --- a/packages/ipfs-unixfs-importer/src/chunker/index.js +++ b/packages/ipfs-unixfs-importer/src/chunker/index.js @@ -1,6 +1,8 @@ -'use strict' +import errCode from 'err-code' -const errCode = require('err-code') +// TODO: lazy load +import rabinChunker from './rabin.js' +import fixedSizeChunker from './fixed-size.js' /** * @typedef {import('../types').ImporterOptions} ImporterOptions @@ -11,8 +13,8 @@ const errCode = require('err-code') * @type {{ [key: string]: Chunker }} */ const chunkers = { - fixed: require('../chunker/fixed-size'), - rabin: require('../chunker/rabin') + fixed: fixedSizeChunker, + rabin: rabinChunker } /** diff --git a/packages/ipfs-unixfs-importer/src/chunker/rabin.js b/packages/ipfs-unixfs-importer/src/chunker/rabin.js index 221659a1..539b878d 100644 --- a/packages/ipfs-unixfs-importer/src/chunker/rabin.js +++ b/packages/ipfs-unixfs-importer/src/chunker/rabin.js @@ -1,10 +1,8 @@ -'use strict' - // @ts-ignore -const BufferList = require('bl/BufferList') +import BufferList from 'bl/BufferList.js' // @ts-ignore -const { create } = require('rabin-wasm') -const errcode = require('err-code') +import { create } from 'rabin-wasm' +import errcode from 'err-code' /** * @typedef {object} RabinOptions @@ -18,7 +16,7 @@ const errcode = require('err-code') /** * @type {import('../types').Chunker} */ -module.exports = async function * rabinChunker (source, options) { +async function * rabinChunker (source, options) { let min, max, avg if (options.minChunkSize && options.maxChunkSize && options.avgChunkSize) { @@ -59,6 +57,8 @@ module.exports = async function * rabinChunker (source, options) { } } +export default rabinChunker + /** * @param {AsyncIterable} source * @param {RabinOptions} options diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/dir.js b/packages/ipfs-unixfs-importer/src/dag-builder/dir.js index ac59de32..6ca92097 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/dir.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/dir.js @@ -1,8 +1,6 @@ -'use strict' - -const { UnixFS } = require('ipfs-unixfs') -const persist = require('../utils/persist') -const { encode, prepare } = require('@ipld/dag-pb') +import { UnixFS } from 'ipfs-unixfs' +import persist from '../utils/persist.js' +import { encode, prepare } from '@ipld/dag-pb' /** * @typedef {import('../types').Directory} Directory @@ -30,4 +28,4 @@ const dirBuilder = async (item, blockstore, options) => { } } -module.exports = dirBuilder +export default dirBuilder diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/file/balanced.js b/packages/ipfs-unixfs-importer/src/dag-builder/file/balanced.js index cb0ace2d..5f646715 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/file/balanced.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/file/balanced.js @@ -1,6 +1,4 @@ -'use strict' - -const batch = require('it-batch') +import batch from 'it-batch' /** * @typedef {import('../../types').FileDAGBuilder} FileDAGBuilder @@ -30,4 +28,4 @@ async function reduceToParents (source, reduce, options) { return roots[0] } -module.exports = balanced +export default balanced diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/file/buffer-importer.js b/packages/ipfs-unixfs-importer/src/dag-builder/file/buffer-importer.js index 3b12a5ad..abfcf676 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/file/buffer-importer.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/file/buffer-importer.js @@ -1,9 +1,7 @@ -'use strict' - -const { UnixFS } = require('ipfs-unixfs') -const persist = require('../../utils/persist') -const dagPb = require('@ipld/dag-pb') -const raw = require('multiformats/codecs/raw') +import { UnixFS } from 'ipfs-unixfs' +import persist from '../../utils/persist.js' +import * as dagPb from '@ipld/dag-pb' +import * as raw from 'multiformats/codecs/raw' /** * @typedef {import('../../types').BufferImporter} BufferImporter @@ -52,4 +50,4 @@ async function * bufferImporter (file, block, options) { } } -module.exports = bufferImporter +export default bufferImporter diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/file/flat.js b/packages/ipfs-unixfs-importer/src/dag-builder/file/flat.js index 549bab0e..b7072218 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/file/flat.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/file/flat.js @@ -1,10 +1,10 @@ -'use strict' - -const all = require('it-all') +import all from 'it-all' /** * @type {import('../../types').FileDAGBuilder} */ -module.exports = async function (source, reduce) { +async function flat (source, reduce) { return reduce(await all(source)) } + +export default flat diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js b/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js index 302ef2cd..97392ee7 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js @@ -1,12 +1,16 @@ -'use strict' - -const errCode = require('err-code') -const { UnixFS } = require('ipfs-unixfs') -const persist = require('../../utils/persist') -const { encode, prepare } = require('@ipld/dag-pb') -const parallelBatch = require('it-parallel-batch') -const rawCodec = require('multiformats/codecs/raw') -const dagPb = require('@ipld/dag-pb') +import errCode from 'err-code' +import { UnixFS } from 'ipfs-unixfs' +import persist from '../../utils/persist.js' +import { encode, prepare } from '@ipld/dag-pb' +import parallelBatch from 'it-parallel-batch' +import * as rawCodec from 'multiformats/codecs/raw' +import * as dagPb from '@ipld/dag-pb' + +// TODO: Lazy load +import flatBuilder from './flat.js' +import balancedBuilder from './balanced.js' +import trickleBuilder from './trickle.js' +import bufImporter from './buffer-importer.js' /** * @typedef {import('interface-blockstore').Blockstore} Blockstore @@ -21,9 +25,9 @@ const dagPb = require('@ipld/dag-pb') * @type {{ [key: string]: FileDAGBuilder}} */ const dagBuilders = { - flat: require('./flat'), - balanced: require('./balanced'), - trickle: require('./trickle') + flat: flatBuilder, + balanced: balancedBuilder, + trickle: trickleBuilder } /** @@ -39,7 +43,7 @@ async function * buildFileBatch (file, blockstore, options) { if (typeof options.bufferImporter === 'function') { bufferImporter = options.bufferImporter } else { - bufferImporter = require('./buffer-importer') + bufferImporter = bufImporter } for await (const entry of parallelBatch(bufferImporter(file, blockstore, options), options.blockWriteConcurrency)) { @@ -202,4 +206,4 @@ function fileBuilder (file, block, options) { return dagBuilder(buildFileBatch(file, block, options), reduce(file, block, options), options) } -module.exports = fileBuilder +export default fileBuilder diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/file/trickle.js b/packages/ipfs-unixfs-importer/src/dag-builder/file/trickle.js index 1de9c98c..677cd6d1 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/file/trickle.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/file/trickle.js @@ -1,6 +1,4 @@ -'use strict' - -const batch = require('it-batch') +import batch from 'it-batch' /** * @typedef {import('ipfs-unixfs').UnixFS} UnixFS @@ -14,7 +12,7 @@ const batch = require('it-batch') /** * @type {FileDAGBuilder} */ -module.exports = async function trickleStream (source, reduce, options) { +async function trickleStream (source, reduce, options) { const root = new Root(options.layerRepeat) let iteration = 0 let maxDepth = 1 @@ -47,6 +45,8 @@ module.exports = async function trickleStream (source, reduce, options) { return root.reduce(reduce) } +export default trickleStream + class SubTree { /** * @param {number} maxDepth diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/index.js b/packages/ipfs-unixfs-importer/src/dag-builder/index.js index d52a4939..822a4a72 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/index.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/index.js @@ -1,8 +1,11 @@ -'use strict' +import dirBuilder from './dir.js' +import fileBuilder from './file/index.js' +import errCode from 'err-code' -const dirBuilder = require('./dir') -const fileBuilder = require('./file') -const errCode = require('err-code') +// TODO: dynamic imports +import validateChunks from './validate-chunks.js' +import rabinChunker from '../chunker/rabin.js' +import fixedSizeChunker from '../chunker/fixed-size.js' /** * @typedef {import('../types').File} File @@ -77,9 +80,9 @@ async function * dagBuilder (source, blockstore, options) { if (typeof options.chunker === 'function') { chunker = options.chunker } else if (options.chunker === 'rabin') { - chunker = require('../chunker/rabin') + chunker = rabinChunker } else { - chunker = require('../chunker/fixed-size') + chunker = fixedSizeChunker } /** @@ -90,7 +93,7 @@ async function * dagBuilder (source, blockstore, options) { if (typeof options.chunkValidator === 'function') { chunkValidator = options.chunkValidator } else { - chunkValidator = require('./validate-chunks') + chunkValidator = validateChunks } /** @type {File} */ @@ -117,4 +120,4 @@ async function * dagBuilder (source, blockstore, options) { } } -module.exports = dagBuilder +export default dagBuilder diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js b/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js index 88689a86..c29a9124 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js @@ -1,7 +1,5 @@ -'use strict' - -const errCode = require('err-code') -const uint8ArrayFromString = require('uint8arrays/from-string') +import errCode from 'err-code' +import uint8ArrayFromString from 'uint8arrays/from-string.js' /** * @typedef {import('../types').ChunkValidator} ChunkValidator @@ -28,4 +26,4 @@ async function * validateChunks (source) { } } -module.exports = validateChunks +export default validateChunks diff --git a/packages/ipfs-unixfs-importer/src/dir-flat.js b/packages/ipfs-unixfs-importer/src/dir-flat.js index 501478ac..ad1d12c0 100644 --- a/packages/ipfs-unixfs-importer/src/dir-flat.js +++ b/packages/ipfs-unixfs-importer/src/dir-flat.js @@ -1,9 +1,7 @@ -'use strict' - -const { encode, prepare } = require('@ipld/dag-pb') -const { UnixFS } = require('ipfs-unixfs') -const Dir = require('./dir') -const persist = require('./utils/persist') +import { encode, prepare } from '@ipld/dag-pb' +import { UnixFS } from 'ipfs-unixfs' +import Dir from './dir.js' +import persist from './utils/persist.js' /** * @typedef {import('./types').ImporterOptions} ImporterOptions @@ -128,4 +126,4 @@ class DirFlat extends Dir { } } -module.exports = DirFlat +export default DirFlat diff --git a/packages/ipfs-unixfs-importer/src/dir-sharded.js b/packages/ipfs-unixfs-importer/src/dir-sharded.js index 71bc49c7..b3bc8671 100644 --- a/packages/ipfs-unixfs-importer/src/dir-sharded.js +++ b/packages/ipfs-unixfs-importer/src/dir-sharded.js @@ -1,10 +1,8 @@ -'use strict' - -const { encode, prepare } = require('@ipld/dag-pb') -const { UnixFS } = require('ipfs-unixfs') -const Dir = require('./dir') -const persist = require('./utils/persist') -const { createHAMT, Bucket } = require('hamt-sharding') +import { encode, prepare } from '@ipld/dag-pb' +import { UnixFS } from 'ipfs-unixfs' +import Dir from './dir.js' +import persist from './utils/persist.js' +import { createHAMT, Bucket } from 'hamt-sharding' /** * @typedef {import('./types').ImporterOptions} ImporterOptions @@ -82,7 +80,7 @@ class DirSharded extends Dir { } } -module.exports = DirSharded +export default DirSharded /** * @param {Bucket} bucket diff --git a/packages/ipfs-unixfs-importer/src/dir.js b/packages/ipfs-unixfs-importer/src/dir.js index fd8571b5..cd1b87ac 100644 --- a/packages/ipfs-unixfs-importer/src/dir.js +++ b/packages/ipfs-unixfs-importer/src/dir.js @@ -1,11 +1,10 @@ -'use strict' - /** * @typedef {import('./types').ImporterOptions} ImporterOptions * @typedef {import('./types').ImportResult} ImportResult * @typedef {import('./types').InProgressImportResult} InProgressImportResult * @typedef {import('interface-blockstore').Blockstore} Blockstore * @typedef {import('multiformats/cid').CID} CID + * * @typedef {object} DirProps * @property {boolean} root * @property {boolean} dir @@ -70,4 +69,4 @@ class Dir { async * flush (blockstore) { } } -module.exports = Dir +export default Dir diff --git a/packages/ipfs-unixfs-importer/src/flat-to-shard.js b/packages/ipfs-unixfs-importer/src/flat-to-shard.js index 590cd62c..30f0f184 100644 --- a/packages/ipfs-unixfs-importer/src/flat-to-shard.js +++ b/packages/ipfs-unixfs-importer/src/flat-to-shard.js @@ -1,7 +1,5 @@ -'use strict' - -const DirSharded = require('./dir-sharded') -const DirFlat = require('./dir-flat') +import DirSharded from './dir-sharded.js' +import DirFlat from './dir-flat.js' /** * @typedef {import('./dir')} Dir @@ -15,25 +13,31 @@ const DirFlat = require('./dir-flat') * @param {ImporterOptions} options * @returns {Promise} */ -module.exports = async function flatToShard (child, dir, threshold, options) { +async function flatToShard (child, dir, threshold, options) { let newDir = dir if (dir instanceof DirFlat && dir.directChildrenCount() >= threshold) { + + // @ts-ignore Dir type conflict!? newDir = await convertToShard(dir, options) } + // @ts-ignore Dir type conflict!? const parent = newDir.parent if (parent) { if (newDir !== dir) { if (child) { + // @ts-ignore Dir type conflict!? child.parent = newDir } + // @ts-ignore Dir type conflict!? if (!newDir.parentKey) { throw new Error('No parent key found') } + // @ts-ignore Dir type conflict!? await parent.put(newDir.parentKey, newDir) } @@ -67,3 +71,5 @@ async function convertToShard (oldDir, options) { return newDir } + +export default flatToShard diff --git a/packages/ipfs-unixfs-importer/src/index.js b/packages/ipfs-unixfs-importer/src/index.js index 8d42d754..b5d25f61 100644 --- a/packages/ipfs-unixfs-importer/src/index.js +++ b/packages/ipfs-unixfs-importer/src/index.js @@ -1,7 +1,9 @@ -'use strict' +import parallelBatch from 'it-parallel-batch' +import defaultOptions from './options.js' -const parallelBatch = require('it-parallel-batch') -const defaultOptions = require('./options') +// TODO: Lazy Load +import defaultDagBuilder from './dag-builder/index.js' +import defaultTreeBuilder from './tree-builder.js' /** * @typedef {import('interface-blockstore').Blockstore} Blockstore @@ -26,7 +28,7 @@ const defaultOptions = require('./options') * @param {Blockstore} blockstore * @param {UserImporterOptions} options */ -async function * importer (source, blockstore, options = {}) { +export async function * importer (source, blockstore, options = {}) { const opts = defaultOptions(options) let dagBuilder @@ -34,7 +36,7 @@ async function * importer (source, blockstore, options = {}) { if (typeof options.dagBuilder === 'function') { dagBuilder = options.dagBuilder } else { - dagBuilder = require('./dag-builder') + dagBuilder = defaultDagBuilder } let treeBuilder @@ -42,7 +44,7 @@ async function * importer (source, blockstore, options = {}) { if (typeof options.treeBuilder === 'function') { treeBuilder = options.treeBuilder } else { - treeBuilder = require('./tree-builder') + treeBuilder = defaultTreeBuilder } /** @type {AsyncIterable | Iterable} */ @@ -65,7 +67,3 @@ async function * importer (source, blockstore, options = {}) { } } } - -module.exports = { - importer -} diff --git a/packages/ipfs-unixfs-importer/src/options.js b/packages/ipfs-unixfs-importer/src/options.js index 43bdfb27..21be7927 100644 --- a/packages/ipfs-unixfs-importer/src/options.js +++ b/packages/ipfs-unixfs-importer/src/options.js @@ -1,10 +1,10 @@ -'use strict' - -const mergeOptions = require('merge-options').bind({ ignoreUndefined: true }) -const { sha256 } = require('multiformats/hashes/sha2') +import mergeOptions from 'merge-options' +import { sha256 } from 'multiformats/hashes/sha2' // @ts-ignore - no types available -const mur = require('murmurhash3js-revisited') -const uint8ArrayFromString = require('uint8arrays/from-string') +import mur from 'murmurhash3js-revisited' +import uint8ArrayFromString from 'uint8arrays/from-string.js' + +mergeOptions.bind({ ignoreUndefined: true }) /** * @param {Uint8Array} buf @@ -62,6 +62,6 @@ const defaultOptions = { * @param {UserImporterOptions} options * @returns {ImporterOptions} */ -module.exports = function (options = {}) { +export default (options = {}) => { return mergeOptions(defaultOptions, options) } diff --git a/packages/ipfs-unixfs-importer/src/tree-builder.js b/packages/ipfs-unixfs-importer/src/tree-builder.js index b9321bb7..9f60b2da 100644 --- a/packages/ipfs-unixfs-importer/src/tree-builder.js +++ b/packages/ipfs-unixfs-importer/src/tree-builder.js @@ -1,9 +1,7 @@ -'use strict' - -const DirFlat = require('./dir-flat') -const flatToShard = require('./flat-to-shard') -const Dir = require('./dir') -const toPathComponents = require('./utils/to-path-components') +import DirFlat from './dir-flat.js' +import flatToShard from './flat-to-shard.js' +import Dir from './dir.js' +import toPathComponents from './utils/to-path-components.js' /** * @typedef {import('./types').ImportResult} ImportResult @@ -36,6 +34,7 @@ async function addToTree (elem, tree, options) { if (last) { await parent.put(pathElem, elem) + // @ts-ignore Dir type conflict!? tree = await flatToShard(null, parent, options.shardSplitThreshold, options) } else { let dir = await parent.get(pathElem) @@ -117,4 +116,4 @@ async function * treeBuilder (source, block, options) { } } -module.exports = treeBuilder +export default treeBuilder diff --git a/packages/ipfs-unixfs-importer/src/utils/persist.js b/packages/ipfs-unixfs-importer/src/utils/persist.js index 7e1f4300..fd57316c 100644 --- a/packages/ipfs-unixfs-importer/src/utils/persist.js +++ b/packages/ipfs-unixfs-importer/src/utils/persist.js @@ -1,8 +1,6 @@ -'use strict' - -const { CID } = require('multiformats/cid') -const dagPb = require('@ipld/dag-pb') -const { sha256 } = require('multiformats/hashes/sha2') +import { CID } from 'multiformats/cid' +import * as dagPb from '@ipld/dag-pb' +import { sha256 } from 'multiformats/hashes/sha2' /** * @param {Uint8Array} buffer @@ -38,4 +36,4 @@ const persist = async (buffer, blockstore, options) => { return cid } -module.exports = persist +export default persist diff --git a/packages/ipfs-unixfs-importer/src/utils/to-path-components.js b/packages/ipfs-unixfs-importer/src/utils/to-path-components.js index 5e826272..085a53b6 100644 --- a/packages/ipfs-unixfs-importer/src/utils/to-path-components.js +++ b/packages/ipfs-unixfs-importer/src/utils/to-path-components.js @@ -1,5 +1,3 @@ -'use strict' - const toPathComponents = (path = '') => { // split on / unless escaped with \ return (path @@ -8,4 +6,4 @@ const toPathComponents = (path = '') => { .filter(Boolean) } -module.exports = toPathComponents +export default toPathComponents diff --git a/packages/ipfs-unixfs-importer/test/benchmark.spec.js b/packages/ipfs-unixfs-importer/test/benchmark.spec.js index b787798d..5591d1ab 100644 --- a/packages/ipfs-unixfs-importer/test/benchmark.spec.js +++ b/packages/ipfs-unixfs-importer/test/benchmark.spec.js @@ -1,10 +1,8 @@ /* eslint-env mocha */ -'use strict' +import { importer } from '../src/index.js' -const { importer } = require('../src') - -const bufferStream = require('it-buffer-stream') -const blockApi = require('./helpers/block') +import bufferStream from 'it-buffer-stream' +import blockApi from './helpers/block.js' const REPEATS = 10 const FILE_SIZE = Math.pow(2, 20) * 500 // 500MB diff --git a/packages/ipfs-unixfs-importer/test/builder-balanced.spec.js b/packages/ipfs-unixfs-importer/test/builder-balanced.spec.js index 84c072cf..22904292 100644 --- a/packages/ipfs-unixfs-importer/test/builder-balanced.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder-balanced.spec.js @@ -1,10 +1,9 @@ /* eslint-env mocha */ -'use strict' - -const { expect } = require('aegir/utils/chai') -const builder = require('../src/dag-builder/file/balanced') -const { CID } = require('multiformats/cid') -const defaultOptions = require('../src/options') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import builder from '../src/dag-builder/file/balanced.js' +import { CID } from 'multiformats/cid' +import defaultOptions from '../src/options.js' /** * @typedef {import('../src/types').InProgressImportResult} InProgressImportResult diff --git a/packages/ipfs-unixfs-importer/test/builder-flat.spec.js b/packages/ipfs-unixfs-importer/test/builder-flat.spec.js index cf0d73dc..f571122b 100644 --- a/packages/ipfs-unixfs-importer/test/builder-flat.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder-flat.spec.js @@ -1,8 +1,8 @@ /* eslint-env mocha */ -'use strict' -const { expect } = require('aegir/utils/chai') -const builder = require('../src/dag-builder/file/flat') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import builder from '../src/dag-builder/file/flat.js' /** * @param {*} leaves diff --git a/packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js b/packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js index fff31ffc..8e5e168b 100644 --- a/packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js @@ -1,12 +1,12 @@ /* eslint-env mocha */ -'use strict' -const { expect } = require('aegir/utils/chai') -const builder = require('../src/dag-builder') -const all = require('it-all') -const blockApi = require('./helpers/block') -const defaultOptions = require('../src/options') -const asAsyncIterable = require('./helpers/as-async-iterable') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import builder from '../src/dag-builder/index.js' +import all from 'it-all' +import blockApi from './helpers/block.js' +import defaultOptions from '../src/options.js' +import asAsyncIterable from './helpers/as-async-iterable.js' describe('builder: onlyHash', () => { const block = blockApi() diff --git a/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js b/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js index 64c27d50..7dfdf4a2 100644 --- a/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js @@ -1,9 +1,9 @@ /* eslint-env mocha */ -'use strict' -const { expect } = require('aegir/utils/chai') -const builder = require('../src/dag-builder/file/trickle') -const asAsyncIterable = require('./helpers/as-async-iterable') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import builder from '../src/dag-builder/file/trickle.js' +import asAsyncIterable from './helpers/as-async-iterable.js' /** * @param {number} max diff --git a/packages/ipfs-unixfs-importer/test/builder.spec.js b/packages/ipfs-unixfs-importer/test/builder.spec.js index a77e742a..4c5c8210 100644 --- a/packages/ipfs-unixfs-importer/test/builder.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder.spec.js @@ -1,17 +1,16 @@ /* eslint-env mocha */ -'use strict' - -const { expect } = require('aegir/utils/chai') -const mh = require('multiformats/hashes/digest') -const { sha256, sha512 } = require('multiformats/hashes/sha2') -const { decode } = require('@ipld/dag-pb') -const { UnixFS } = require('ipfs-unixfs') -const builder = require('../src/dag-builder') -const first = require('it-first') -const blockApi = require('./helpers/block') -const uint8ArrayFromString = require('uint8arrays/from-string') -const defaultOptions = require('../src/options') -const asAsyncIterable = require('./helpers/as-async-iterable') +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import * as mh from 'multiformats/hashes/digest' +import { sha256, sha512 } from 'multiformats/hashes/sha2' +import { decode } from '@ipld/dag-pb' +import { UnixFS } from 'ipfs-unixfs' +import builder from '../src/dag-builder/index.js' +import first from 'it-first' +import blockApi from './helpers/block.js' +import uint8ArrayFromString from 'uint8arrays/from-string.js' +import defaultOptions from '../src/options.js' +import asAsyncIterable from './helpers/as-async-iterable.js' describe('builder', () => { const block = blockApi() diff --git a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js index 7844a1d1..ff45977f 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js @@ -1,14 +1,14 @@ /* eslint-env mocha */ -'use strict' +import { importer } from '../src/index.js' +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' -const { importer } = require('../src') -const { expect } = require('aegir/utils/chai') -const rawCodec = require('multiformats/codecs/raw') -const { sha256 } = require('multiformats/hashes/sha2') -const Block = require('multiformats/block') -const blockApi = require('./helpers/block') -const uint8ArrayFromString = require('uint8arrays/from-string') -const { UnixFS } = require('ipfs-unixfs') +import * as rawCodec from 'multiformats/codecs/raw' +import { sha256 } from 'multiformats/hashes/sha2' +import * as Block from 'multiformats/block' +import blockApi from './helpers/block.js' +import uint8ArrayFromString from 'uint8arrays/from-string.js' +import { UnixFS } from 'ipfs-unixfs' const iter = async function * () { yield uint8ArrayFromString('one') diff --git a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js index 3845fd8d..ba6f8939 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js @@ -1,14 +1,13 @@ /* eslint-env mocha */ -'use strict' - -const chunker = require('../src/chunker/fixed-size') -const { expect } = require('aegir/utils/chai') -const all = require('it-all') +import chunker from '../src/chunker/fixed-size.js' +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import all from 'it-all' const rawFile = new Uint8Array(Math.pow(2, 20)) -const uint8ArrayFromString = require('uint8arrays/from-string') -const uint8ArrayConcat = require('uint8arrays/concat') -const defaultOptions = require('../src/options') -const asAsyncIterable = require('./helpers/as-async-iterable') +import uint8ArrayFromString from 'uint8arrays/from-string.js' +import uint8ArrayConcat from 'uint8arrays/concat.js' +import defaultOptions from '../src/options.js' +import asAsyncIterable from './helpers/as-async-iterable.js' describe('chunker: fixed size', function () { this.timeout(30000) diff --git a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js index 3418e2b5..0944f612 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js @@ -1,13 +1,13 @@ /* eslint-env mocha */ -'use strict' - -const chunker = require('../src/chunker/rabin') -const { expect } = require('aegir/utils/chai') -const all = require('it-all') -const uint8ArrayFromString = require('uint8arrays/from-string') -const uint8ArrayConcat = require('uint8arrays/concat') -const asAsyncIterable = require('./helpers/as-async-iterable') -const defaultOptions = require('../src/options') + +import chunker from '../src/chunker/rabin.js' +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import all from 'it-all' +import uint8ArrayFromString from 'uint8arrays/from-string.js' +import uint8ArrayConcat from 'uint8arrays/concat.js' +import asAsyncIterable from './helpers/as-async-iterable.js' +import defaultOptions from '../src/options.js' const rawFile = new Uint8Array(Math.pow(2, 20)).fill(1) diff --git a/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js b/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js index 1271ed8f..dc52e085 100644 --- a/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js +++ b/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js @@ -1,13 +1,12 @@ /* eslint-env mocha */ -'use strict' - -const { importer } = require('../src') - -const { expect } = require('aegir/utils/chai') -const randomByteStream = require('./helpers/finite-pseudorandom-byte-stream') -const first = require('it-first') -const blockApi = require('./helpers/block') -const defaultOptions = require('../src/options') +import { importer } from '../src/index.js' + +// @ts-ignore needs types properly fixed +import { expect } from 'aegir/utils/chai.js' +import randomByteStream from './helpers/finite-pseudorandom-byte-stream.js' +import first from 'it-first' +import blockApi from './helpers/block.js' +import defaultOptions from '../src/options.js' /** @type {('flat' | 'trickle' | 'balanced')[]} */ const strategies = [ diff --git a/packages/ipfs-unixfs-importer/test/helpers/as-async-iterable.js b/packages/ipfs-unixfs-importer/test/helpers/as-async-iterable.js index 7aba5df2..23e1cdea 100644 --- a/packages/ipfs-unixfs-importer/test/helpers/as-async-iterable.js +++ b/packages/ipfs-unixfs-importer/test/helpers/as-async-iterable.js @@ -1,5 +1,3 @@ -'use strict' - /** * @param {Uint8Array | Uint8Array[]} arr */ @@ -11,4 +9,4 @@ async function * asAsyncIterable (arr) { yield * arr } -module.exports = asAsyncIterable +export default asAsyncIterable diff --git a/packages/ipfs-unixfs-importer/test/helpers/block.js b/packages/ipfs-unixfs-importer/test/helpers/block.js index 0703d2c3..a415ed5c 100644 --- a/packages/ipfs-unixfs-importer/test/helpers/block.js +++ b/packages/ipfs-unixfs-importer/test/helpers/block.js @@ -1,8 +1,6 @@ -'use strict' - -const errCode = require('err-code') -const { BlockstoreAdapter } = require('interface-blockstore') -const { base58btc } = require('multiformats/bases/base58') +import errCode from 'err-code' +import { BlockstoreAdapter } from 'interface-blockstore' +import { base58btc } from 'multiformats/bases/base58' /** * @typedef {import('multiformats/cid').CID} CID @@ -47,4 +45,4 @@ function createBlockApi () { return bs } -module.exports = createBlockApi +export default createBlockApi diff --git a/packages/ipfs-unixfs-importer/test/helpers/finite-pseudorandom-byte-stream.js b/packages/ipfs-unixfs-importer/test/helpers/finite-pseudorandom-byte-stream.js index f1e1ee2d..b3fde114 100644 --- a/packages/ipfs-unixfs-importer/test/helpers/finite-pseudorandom-byte-stream.js +++ b/packages/ipfs-unixfs-importer/test/helpers/finite-pseudorandom-byte-stream.js @@ -1,12 +1,10 @@ -'use strict' - const REPEATABLE_CHUNK_SIZE = 300000 /** * @param {number} maxSize * @param {number} seed */ -module.exports = async function * (maxSize, seed) { +async function * stream (maxSize, seed) { const chunks = Math.ceil(maxSize / REPEATABLE_CHUNK_SIZE) let emitted = 0 const buf = new Uint8Array(REPEATABLE_CHUNK_SIZE) @@ -22,6 +20,8 @@ module.exports = async function * (maxSize, seed) { } } +export default stream + /** * @param {number} seed */ diff --git a/packages/ipfs-unixfs-importer/test/helpers/random-byte-stream.js b/packages/ipfs-unixfs-importer/test/helpers/random-byte-stream.js index e147d2ca..dc2963c3 100644 --- a/packages/ipfs-unixfs-importer/test/helpers/random-byte-stream.js +++ b/packages/ipfs-unixfs-importer/test/helpers/random-byte-stream.js @@ -1,5 +1,3 @@ -'use strict' - /** * @param {number} seed */ @@ -20,4 +18,4 @@ function random (seed) { return x - Math.floor(x) } -module.exports = randomByteStream +export default randomByteStream diff --git a/packages/ipfs-unixfs/.aegir.js b/packages/ipfs-unixfs/.aegir.cjs similarity index 100% rename from packages/ipfs-unixfs/.aegir.js rename to packages/ipfs-unixfs/.aegir.cjs diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index 45e867b1..9c53a9eb 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -4,16 +4,18 @@ "description": "JavaScript implementation of IPFS' unixfs (a Unix FileSystem representation on top of a MerkleDAG)", "leadMaintainer": "Alex Potsides ", "main": "src/index.js", + "type": "module", "browser": { "fs": false }, "scripts": { - "prepare": "run-s prepare:*", - "prepare:proto": "pbjs -t static-module -w commonjs -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": "aegir build", + "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", "test": "aegir test", "build": "aegir build", + "postbuild": "cd dist && npx json -I -f package.json -e 'this.types=\"src/index.d.ts\"'", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s aegir test -t node && nyc report --reporter=html", @@ -37,8 +39,9 @@ "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { "@types/mocha": "^8.2.1", - "aegir": "^34.0.0", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules", "copy": "^0.3.2", + "json": "^11.0.0", "mkdirp": "^1.0.4", "npm-run-all": "^4.1.5", "nyc": "^15.0.0", @@ -50,10 +53,6 @@ "protobufjs": "^6.10.2" }, "types": "dist/src/index.d.ts", - "files": [ - "src", - "dist" - ], "eslintConfig": { "extends": "ipfs", "ignorePatterns": [ diff --git a/packages/ipfs-unixfs/src/index.js b/packages/ipfs-unixfs/src/index.js index 974d6cca..c50a27fd 100644 --- a/packages/ipfs-unixfs/src/index.js +++ b/packages/ipfs-unixfs/src/index.js @@ -1,9 +1,6 @@ -'use strict' - -const { - Data: PBData -} = require('./unixfs') -const errcode = require('err-code') +import errcode from 'err-code' +import * as Pb from './unixfs.js' +const PBData = Pb.Data /** * @typedef {import('./types').Mtime} Mtime @@ -30,7 +27,7 @@ const DEFAULT_DIRECTORY_MODE = parseInt('0755', 8) /** * @param {string | number | undefined} [mode] */ -function parseMode (mode) { +export function parseMode (mode) { if (mode == null) { return undefined } @@ -53,7 +50,7 @@ function parseMode (mode) { /** * @param {any} input */ -function parseMtime (input) { +export function parseMtime (input) { if (input == null) { return undefined } @@ -122,7 +119,7 @@ function parseMtime (input) { return mtime } -class Data { +class UnixFS { /** * Decode from protobuf https://github.com/ipfs/specs/blob/master/UNIXFS.md * @@ -137,7 +134,7 @@ class Data { objects: false }) - const data = new Data({ + const data = new UnixFS({ type: types[decoded.Type], data: decoded.Data, blockSizes: decoded.blocksizes, @@ -330,8 +327,4 @@ class Data { } } -module.exports = { - UnixFS: Data, - parseMode, - parseMtime -} +export { UnixFS } diff --git a/packages/ipfs-unixfs/src/unixfs.js b/packages/ipfs-unixfs/src/unixfs.js index 41d33256..a5e8ab9e 100644 --- a/packages/ipfs-unixfs/src/unixfs.js +++ b/packages/ipfs-unixfs/src/unixfs.js @@ -1,15 +1,13 @@ /*eslint-disable*/ -"use strict"; - -var $protobuf = require("protobufjs/minimal"); +import $protobuf from "protobufjs/minimal.js"; // Common aliases -var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; +const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; // Exported root namespace -var $root = $protobuf.roots["ipfs-unixfs"] || ($protobuf.roots["ipfs-unixfs"] = {}); +const $root = $protobuf.roots["ipfs-unixfs"] || ($protobuf.roots["ipfs-unixfs"] = {}); -$root.Data = (function() { +export const Data = $root.Data = (() => { /** * Properties of a Data. @@ -404,7 +402,7 @@ $root.Data = (function() { * @property {number} HAMTShard=5 HAMTShard value */ Data.DataType = (function() { - var valuesById = {}, values = Object.create(valuesById); + const valuesById = {}, values = Object.create(valuesById); values[valuesById[0] = "Raw"] = 0; values[valuesById[1] = "Directory"] = 1; values[valuesById[2] = "File"] = 2; @@ -417,7 +415,7 @@ $root.Data = (function() { return Data; })(); -$root.UnixTime = (function() { +export const UnixTime = $root.UnixTime = (() => { /** * Properties of an UnixTime. @@ -585,7 +583,7 @@ $root.UnixTime = (function() { return UnixTime; })(); -$root.Metadata = (function() { +export const Metadata = $root.Metadata = (() => { /** * Properties of a Metadata. @@ -717,4 +715,4 @@ $root.Metadata = (function() { return Metadata; })(); -module.exports = $root; +export { $root as default }; diff --git a/packages/ipfs-unixfs/test/unixfs-format.spec.js b/packages/ipfs-unixfs/test/unixfs-format.spec.js index 6e3d4bb6..9ab48e4a 100644 --- a/packages/ipfs-unixfs/test/unixfs-format.spec.js +++ b/packages/ipfs-unixfs/test/unixfs-format.spec.js @@ -1,22 +1,21 @@ /* eslint-env mocha */ -'use strict' -const { expect } = require('aegir/utils/chai') +// @ts-ignore needs proper types export for paths +import { expect } from 'aegir/utils/chai.js' /** @type {(path: string) => Uint8Array} */ // @ts-ignore -const loadFixture = require('aegir/utils/fixtures') +import loadFixture from 'aegir/utils/fixtures.js' +import uint8ArrayFromString from 'uint8arrays/from-string.js' -const { UnixFS } = require('../src') +import { UnixFS } from '../src/index.js' +import * as Pb from '../src/unixfs.js' +const PBData = Pb.Data const raw = loadFixture('test/fixtures/raw.unixfs') const directory = loadFixture('test/fixtures/directory.unixfs') const file = loadFixture('test/fixtures/file.txt.unixfs') const symlink = loadFixture('test/fixtures/symlink.txt.unixfs') -const { - Data: PBData -} = require('../src/unixfs') -const uint8ArrayFromString = require('uint8arrays/from-string') describe('unixfs-format', () => { it('defaults to file', () => { From f43870894dbc92b9a396251dc7dcaaf73c8e80e6 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Fri, 23 Jul 2021 13:46:10 +0200 Subject: [PATCH 02/16] chore: lint for esm --- .travis.yml | 5 ----- packages/ipfs-unixfs-exporter/package.json | 9 +++++---- .../ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js | 1 - .../ipfs-unixfs-exporter/test/exporter-subtree.spec.js | 4 ++-- packages/ipfs-unixfs-exporter/test/exporter.spec.js | 2 +- packages/ipfs-unixfs-exporter/test/importer.spec.js | 3 +-- packages/ipfs-unixfs-importer/package.json | 9 +++++---- packages/ipfs-unixfs-importer/src/flat-to-shard.js | 1 - .../ipfs-unixfs-importer/test/chunker-fixed-size.spec.js | 2 +- packages/ipfs-unixfs/package.json | 7 ++++--- 10 files changed, 19 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab015ea4..539a88df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,11 +54,6 @@ jobs: script: - npm run depcheck -- $RUN_SINCE -- -- -p - - stage: check - name: dep-check (unused deps) - script: - - npm run depcheck -- $RUN_SINCE -- -- -- --unused - - stage: test name: chrome addons: diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index 367628f8..1ee41b04 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -12,7 +12,6 @@ "prepare": "aegir build", "test": "aegir test", "build": "aegir build", - "postbuild": "cd dist && npx json -I -f package.json -e 'this.types=\"src/index.d.ts\"'", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s npm run test -t node && nyc report --reporter=html", @@ -38,7 +37,7 @@ "@types/mocha": "^8.2.1", "@types/sinon": "^10.0.0", "abort-controller": "^3.0.0", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", "detect-node": "^2.0.4", @@ -47,7 +46,6 @@ "it-all": "^1.0.5", "it-buffer-stream": "^2.0.0", "it-first": "^1.0.6", - "json": "^11.0.0", "merge-options": "^3.0.4", "murmurhash3js-revisited": "^3.0.0", "native-abort-controller": "^1.0.3", @@ -72,6 +70,9 @@ }, "types": "dist/src/index.d.ts", "eslintConfig": { - "extends": "ipfs" + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + } } } 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 55cad708..d7e4d5b9 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,4 +1,3 @@ -'use strict' import { Bucket, createHAMT } from 'hamt-sharding' import { decode } from '@ipld/dag-pb' diff --git a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js index 2803e53d..fa0fb070 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js @@ -9,10 +9,10 @@ import randomBytes from 'it-buffer-stream' import uint8ArrayConcat from 'uint8arrays/concat.js' import asAsyncIterable from './helpers/as-async-iterable.js' -const ONE_MEG = Math.pow(1024, 2) - import { exporter, walkPath } from './../src/index.js' +const ONE_MEG = Math.pow(1024, 2) + describe('exporter subtree', () => { const block = blockApi() diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.js b/packages/ipfs-unixfs-exporter/test/exporter.spec.js index 0c0a51d3..24f7d9ed 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.js @@ -1,5 +1,5 @@ /* eslint-env mocha */ -'use strict' + // @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import { UnixFS } from 'ipfs-unixfs' diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.js b/packages/ipfs-unixfs-exporter/test/importer.spec.js index b4f41d41..d5b04c94 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.js +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.js @@ -6,7 +6,7 @@ import extend from 'merge-options' // @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import sinon from 'sinon' -import { UnixFS } from 'ipfs-unixfs' +import { UnixFS, parseMtime } from 'ipfs-unixfs' import collectLeafCids from './helpers/collect-leaf-cids.js' // @ts-ignore import loadFixture from 'aegir/utils/fixtures.js' @@ -20,7 +20,6 @@ import last from 'it-last' import { CID } from 'multiformats/cid' import { base58btc } from 'multiformats/bases/base58' import { decode } from '@ipld/dag-pb' -import { parseMtime } from 'ipfs-unixfs' /** @type {Uint8Array} */ const bigFile = loadFixture(('test') + '/fixtures/1.2MiB.txt') diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index b278af5a..1e5d5be8 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -12,7 +12,6 @@ "prepare": "aegir build --no-bundle", "test": "aegir test", "build": "aegir build", - "postbuild": "cd dist && npx json -I -f package.json -e 'this.types=\"src/index.d.ts\"'", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s npm run test -t node && nyc report --reporter=html", @@ -36,13 +35,12 @@ "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { "@types/mocha": "^8.2.1", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up", "assert": "^2.0.0", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", "events": "^3.3.0", "it-buffer-stream": "^2.0.0", - "json": "^11.0.0", "nyc": "^15.0.0", "readable-stream": "^3.6.0", "rimraf": "^3.0.2", @@ -67,6 +65,9 @@ }, "types": "dist/src/index.d.ts", "eslintConfig": { - "extends": "ipfs" + "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + } } } diff --git a/packages/ipfs-unixfs-importer/src/flat-to-shard.js b/packages/ipfs-unixfs-importer/src/flat-to-shard.js index 30f0f184..a0be94c9 100644 --- a/packages/ipfs-unixfs-importer/src/flat-to-shard.js +++ b/packages/ipfs-unixfs-importer/src/flat-to-shard.js @@ -17,7 +17,6 @@ async function flatToShard (child, dir, threshold, options) { let newDir = dir if (dir instanceof DirFlat && dir.directChildrenCount() >= threshold) { - // @ts-ignore Dir type conflict!? newDir = await convertToShard(dir, options) } diff --git a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js index ba6f8939..81b474cf 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js @@ -3,11 +3,11 @@ import chunker from '../src/chunker/fixed-size.js' // @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import all from 'it-all' -const rawFile = new Uint8Array(Math.pow(2, 20)) import uint8ArrayFromString from 'uint8arrays/from-string.js' import uint8ArrayConcat from 'uint8arrays/concat.js' import defaultOptions from '../src/options.js' import asAsyncIterable from './helpers/as-async-iterable.js' +const rawFile = new Uint8Array(Math.pow(2, 20)) describe('chunker: fixed size', function () { this.timeout(30000) diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index 9c53a9eb..6141f63a 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -15,7 +15,6 @@ "prepare:types": "aegir build --no-bundle", "test": "aegir test", "build": "aegir build", - "postbuild": "cd dist && npx json -I -f package.json -e 'this.types=\"src/index.d.ts\"'", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s aegir test -t node && nyc report --reporter=html", @@ -39,9 +38,8 @@ "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { "@types/mocha": "^8.2.1", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up", "copy": "^0.3.2", - "json": "^11.0.0", "mkdirp": "^1.0.4", "npm-run-all": "^4.1.5", "nyc": "^15.0.0", @@ -55,6 +53,9 @@ "types": "dist/src/index.d.ts", "eslintConfig": { "extends": "ipfs", + "parserOptions": { + "sourceType": "module" + }, "ignorePatterns": [ "src/unixfs.d.ts" ] From 733ccac1374d05dfb715af8f968fcd63c3e22cbc Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Fri, 23 Jul 2021 14:34:11 +0200 Subject: [PATCH 03/16] chore: remove chai ignore --- packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js | 1 - packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js | 1 - packages/ipfs-unixfs-exporter/test/exporter.spec.js | 1 - .../test/import-export-dir-sharding.spec.js | 1 - .../ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js | 1 - packages/ipfs-unixfs-exporter/test/import-export.spec.js | 2 -- packages/ipfs-unixfs-exporter/test/importer.spec.js | 2 -- packages/ipfs-unixfs-importer/test/builder-balanced.spec.js | 1 - packages/ipfs-unixfs-importer/test/builder-flat.spec.js | 1 - packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js | 1 - packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js | 1 - packages/ipfs-unixfs-importer/test/builder.spec.js | 1 - packages/ipfs-unixfs-importer/test/chunker-custom.spec.js | 1 - packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js | 1 - packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js | 1 - .../ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js | 1 - packages/ipfs-unixfs/test/unixfs-format.spec.js | 2 -- 17 files changed, 20 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js index da48d1bd..d2952eea 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js @@ -1,5 +1,4 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import { UnixFS } from 'ipfs-unixfs' import all from 'it-all' diff --git a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js index fa0fb070..9a064637 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js @@ -1,5 +1,4 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import { importer } from 'ipfs-unixfs-importer' import all from 'it-all' diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.js b/packages/ipfs-unixfs-exporter/test/exporter.spec.js index 24f7d9ed..f4d7dc2d 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.js @@ -1,6 +1,5 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import { UnixFS } from 'ipfs-unixfs' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js index 8f4e07ff..f30a251a 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js @@ -2,7 +2,6 @@ import { importer } from 'ipfs-unixfs-importer' import { exporter } from '../src/index.js' -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import all from 'it-all' import last from 'it-last' diff --git a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js index b27e088d..c5bb5537 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js @@ -1,5 +1,4 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import all from 'it-all' import { importer } from 'ipfs-unixfs-importer' diff --git a/packages/ipfs-unixfs-exporter/test/import-export.spec.js b/packages/ipfs-unixfs-exporter/test/import-export.spec.js index 8ef149dc..12644ef8 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export.spec.js @@ -1,8 +1,6 @@ /* eslint-env mocha */ /* eslint max-nested-callbacks: ["error", 5] */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' -// @ts-ignore import loadFixture from 'aegir/utils/fixtures.js' import blockApi from './helpers/block.js' import asAsyncIterable from './helpers/as-async-iterable.js' diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.js b/packages/ipfs-unixfs-exporter/test/importer.spec.js index d5b04c94..ee5817ef 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.js +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.js @@ -3,12 +3,10 @@ import { importer } from 'ipfs-unixfs-importer' import { exporter, recursive } from '../src/index.js' import extend from 'merge-options' -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import sinon from 'sinon' import { UnixFS, parseMtime } from 'ipfs-unixfs' import collectLeafCids from './helpers/collect-leaf-cids.js' -// @ts-ignore import loadFixture from 'aegir/utils/fixtures.js' import all from 'it-all' import first from 'it-first' diff --git a/packages/ipfs-unixfs-importer/test/builder-balanced.spec.js b/packages/ipfs-unixfs-importer/test/builder-balanced.spec.js index 22904292..8403ea30 100644 --- a/packages/ipfs-unixfs-importer/test/builder-balanced.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder-balanced.spec.js @@ -1,5 +1,4 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import builder from '../src/dag-builder/file/balanced.js' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-unixfs-importer/test/builder-flat.spec.js b/packages/ipfs-unixfs-importer/test/builder-flat.spec.js index f571122b..032ada55 100644 --- a/packages/ipfs-unixfs-importer/test/builder-flat.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder-flat.spec.js @@ -1,6 +1,5 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import builder from '../src/dag-builder/file/flat.js' diff --git a/packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js b/packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js index 8e5e168b..6891d1be 100644 --- a/packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder-only-hash.spec.js @@ -1,6 +1,5 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import builder from '../src/dag-builder/index.js' import all from 'it-all' diff --git a/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js b/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js index 7dfdf4a2..f0adf6d4 100644 --- a/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder-trickle-dag.spec.js @@ -1,6 +1,5 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import builder from '../src/dag-builder/file/trickle.js' import asAsyncIterable from './helpers/as-async-iterable.js' diff --git a/packages/ipfs-unixfs-importer/test/builder.spec.js b/packages/ipfs-unixfs-importer/test/builder.spec.js index 4c5c8210..37fb6242 100644 --- a/packages/ipfs-unixfs-importer/test/builder.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder.spec.js @@ -1,5 +1,4 @@ /* eslint-env mocha */ -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import * as mh from 'multiformats/hashes/digest' import { sha256, sha512 } from 'multiformats/hashes/sha2' diff --git a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js index ff45977f..becea79c 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js @@ -1,6 +1,5 @@ /* eslint-env mocha */ import { importer } from '../src/index.js' -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import * as rawCodec from 'multiformats/codecs/raw' diff --git a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js index 81b474cf..503f528e 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js @@ -1,6 +1,5 @@ /* eslint-env mocha */ import chunker from '../src/chunker/fixed-size.js' -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import all from 'it-all' import uint8ArrayFromString from 'uint8arrays/from-string.js' diff --git a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js index 0944f612..0f39876f 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js @@ -1,7 +1,6 @@ /* eslint-env mocha */ import chunker from '../src/chunker/rabin.js' -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import all from 'it-all' import uint8ArrayFromString from 'uint8arrays/from-string.js' diff --git a/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js b/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js index dc52e085..3cc2c5f7 100644 --- a/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js +++ b/packages/ipfs-unixfs-importer/test/hash-parity-with-go-ipfs.spec.js @@ -1,7 +1,6 @@ /* eslint-env mocha */ import { importer } from '../src/index.js' -// @ts-ignore needs types properly fixed import { expect } from 'aegir/utils/chai.js' import randomByteStream from './helpers/finite-pseudorandom-byte-stream.js' import first from 'it-first' diff --git a/packages/ipfs-unixfs/test/unixfs-format.spec.js b/packages/ipfs-unixfs/test/unixfs-format.spec.js index 9ab48e4a..b9d23270 100644 --- a/packages/ipfs-unixfs/test/unixfs-format.spec.js +++ b/packages/ipfs-unixfs/test/unixfs-format.spec.js @@ -1,10 +1,8 @@ /* eslint-env mocha */ -// @ts-ignore needs proper types export for paths import { expect } from 'aegir/utils/chai.js' /** @type {(path: string) => Uint8Array} */ -// @ts-ignore import loadFixture from 'aegir/utils/fixtures.js' import uint8ArrayFromString from 'uint8arrays/from-string.js' From 5616c332bd99807099e2a37476e9a5d6ee800f31 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Fri, 23 Jul 2021 16:04:46 +0200 Subject: [PATCH 04/16] chore: re-add dynamic imports and remove added ts ignores --- packages/ipfs-unixfs-exporter/package.json | 2 +- .../src/resolvers/index.js | 30 ++++++++-------- .../src/resolvers/unixfs-v1/index.js | 35 ++++++++++--------- packages/ipfs-unixfs-exporter/tsconfig.json | 1 + .../ipfs-unixfs-importer/src/chunker/index.js | 22 ++++++------ .../src/dag-builder/file/index.js | 29 +++++++-------- .../src/dag-builder/index.js | 11 ++---- packages/ipfs-unixfs-importer/src/dir.js | 1 - .../ipfs-unixfs-importer/src/flat-to-shard.js | 7 +--- packages/ipfs-unixfs-importer/src/index.js | 8 ++--- .../ipfs-unixfs-importer/src/tree-builder.js | 1 - packages/ipfs-unixfs-importer/tsconfig.json | 1 + 12 files changed, 70 insertions(+), 78 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index 1ee41b04..b19c8115 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -9,7 +9,7 @@ "fs": false }, "scripts": { - "prepare": "aegir build", + "prepare": "aegir build --no-bundle", "test": "aegir test", "build": "aegir build", "clean": "rimraf ./dist", diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/index.js b/packages/ipfs-unixfs-exporter/src/resolvers/index.js index 6ae42047..9fcb0fd5 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/index.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/index.js @@ -5,32 +5,34 @@ import * as dagCbor from '@ipld/dag-cbor' import * as raw from 'multiformats/codecs/raw' import { identity } from 'multiformats/hashes/identity' -// TODO: Lazy Load -import unixFs1Resolver from './unixfs-v1/index.js' -import rawResolver from './raw.js' -import dagCborResolver from './dag-cbor.js' -import identityResolver from './identity.js' - /** * @typedef {import('../types').Resolver} Resolver * @typedef {import('../types').Resolve} Resolve */ /** - * @type {{ [ key: string ]: Resolver }} + * @param {number} key + * @returns {Promise} */ -const resolvers = { - [dagPb.code]: unixFs1Resolver, - [raw.code]: rawResolver, - [dagCbor.code]: dagCborResolver, - [identity.code]: identityResolver +const importResolver = async (key) => { + switch (key) { + case dagPb.code: + return (await (import('./unixfs-v1/index.js'))).default + case raw.code: + return (await (import('./raw.js'))).default + case dagCbor.code: + return (await (import('./dag-cbor.js'))).default + case identity.code: + return (await (import('./identity.js'))).default + default: + } } /** * @type {Resolve} */ -function resolve (cid, name, path, toResolve, depth, blockstore, options) { - const resolver = resolvers[cid.code] +async function resolve (cid, name, path, toResolve, depth, blockstore, options) { + const resolver = await importResolver(cid.code) if (!resolver) { throw errCode(new Error(`No resolver for code ${cid.code}`), 'ERR_NO_RESOLVER') diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js index c5d86f04..8d97ed7e 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js @@ -3,11 +3,6 @@ import { UnixFS } from 'ipfs-unixfs' import findShardCid from '../../utils/find-cid-in-shard.js' import { decode } from '@ipld/dag-pb' -// TODO Lazy load -import contentFile from './content/file.js' -import contentDirectory from './content/directory.js' -import contentHamtShardedDirectory from './content/hamt-sharded-directory.js' - /** * @typedef {import('../../types').Resolve} Resolve * @typedef {import('../../types').Resolver} Resolver @@ -26,18 +21,22 @@ const findLinkCid = (node, name) => { } /** - * @type {{ [key: string]: UnixfsV1Resolver }} + * @param {string} key + * @returns {Promise} */ -const contentExporters = { - raw: contentFile, - file: contentFile, - directory: contentDirectory, - 'hamt-sharded-directory': contentHamtShardedDirectory, - metadata: (cid, node, unixfs, path, resolve, depth, blockstore) => { - return () => [] - }, - symlink: (cid, node, unixfs, path, resolve, depth, blockstore) => { - return () => [] +const importContentExporters = async (key) => { + switch (key) { + case 'raw': + case 'file': + return (await (import('./content/file.js'))).default + case 'directory': + return (await (import('./content/directory.js'))).default + case 'hamt-sharded-directory': + return (await (import('./content/hamt-sharded-directory.js'))).default + case 'metadata': + case 'symlink': + return () => () => [] + default: } } @@ -95,6 +94,8 @@ const unixFsResolver = async (cid, name, path, toResolve, resolve, depth, blocks } } + const contentExporter = await importContentExporters(unixfs.type) + return { entry: { type: unixfs.isDirectory() ? 'directory' : 'file', @@ -102,7 +103,7 @@ const unixFsResolver = async (cid, name, path, toResolve, resolve, depth, blocks path, cid, // @ts-ignore - content: contentExporters[unixfs.type](cid, node, unixfs, path, resolve, depth, blockstore), + content: contentExporter(cid, node, unixfs, path, resolve, depth, blockstore), unixfs, depth, node, diff --git a/packages/ipfs-unixfs-exporter/tsconfig.json b/packages/ipfs-unixfs-exporter/tsconfig.json index c6eb8f25..446917f2 100644 --- a/packages/ipfs-unixfs-exporter/tsconfig.json +++ b/packages/ipfs-unixfs-exporter/tsconfig.json @@ -2,6 +2,7 @@ "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { "outDir": "dist", + "module": "es2020", "importsNotUsedAsValues": "preserve" }, "include": [ diff --git a/packages/ipfs-unixfs-importer/src/chunker/index.js b/packages/ipfs-unixfs-importer/src/chunker/index.js index fe97aba3..065644de 100644 --- a/packages/ipfs-unixfs-importer/src/chunker/index.js +++ b/packages/ipfs-unixfs-importer/src/chunker/index.js @@ -1,20 +1,22 @@ import errCode from 'err-code' -// TODO: lazy load -import rabinChunker from './rabin.js' -import fixedSizeChunker from './fixed-size.js' - /** * @typedef {import('../types').ImporterOptions} ImporterOptions * @typedef {import('../types').Chunker} Chunker */ /** - * @type {{ [key: string]: Chunker }} + * @param {string} key + * @returns {Promise} */ -const chunkers = { - fixed: fixedSizeChunker, - rabin: rabinChunker +const importChunkers = async (key) => { + switch (key) { + case 'fixed': + return (await (import('./fixed-size.js'))).default + case 'rabin': + return (await (import('./rabin.js'))).default + default: + } } /** @@ -22,8 +24,8 @@ const chunkers = { * @param {AsyncIterable} source * @param {import('../types').ImporterOptions} options */ -module.exports = (type, source, options) => { - const chunker = chunkers[type] +module.exports = async (type, source, options) => { + const chunker = await importChunkers(type) if (!chunker) { throw errCode(new Error(`Unknkown chunker named ${type}`), 'ERR_UNKNOWN_CHUNKER') diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js b/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js index 97392ee7..bdf31034 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js @@ -6,12 +6,6 @@ import parallelBatch from 'it-parallel-batch' import * as rawCodec from 'multiformats/codecs/raw' import * as dagPb from '@ipld/dag-pb' -// TODO: Lazy load -import flatBuilder from './flat.js' -import balancedBuilder from './balanced.js' -import trickleBuilder from './trickle.js' -import bufImporter from './buffer-importer.js' - /** * @typedef {import('interface-blockstore').Blockstore} Blockstore * @typedef {import('../../types').File} File @@ -22,12 +16,19 @@ import bufImporter from './buffer-importer.js' */ /** - * @type {{ [key: string]: FileDAGBuilder}} + * @param {string} key + * @returns {Promise} */ -const dagBuilders = { - flat: flatBuilder, - balanced: balancedBuilder, - trickle: trickleBuilder +const importDagBuilder = async (key) => { + switch (key) { + case 'flat': + return (await (import('./flat.js'))).default + case 'balanced': + return (await (import('./balanced.js'))).default + case 'trickle': + return (await (import('./trickle.js'))).default + default: + } } /** @@ -43,7 +44,7 @@ async function * buildFileBatch (file, blockstore, options) { if (typeof options.bufferImporter === 'function') { bufferImporter = options.bufferImporter } else { - bufferImporter = bufImporter + bufferImporter = (await (import('./buffer-importer.js'))).default } for await (const entry of parallelBatch(bufferImporter(file, blockstore, options), options.blockWriteConcurrency)) { @@ -196,8 +197,8 @@ const reduce = (file, blockstore, options) => { /** * @type {import('../../types').UnixFSV1DagBuilder} */ -function fileBuilder (file, block, options) { - const dagBuilder = dagBuilders[options.strategy] +async function fileBuilder (file, block, options) { + const dagBuilder = await importDagBuilder(options.strategy) if (!dagBuilder) { throw errCode(new Error(`Unknown importer build strategy name: ${options.strategy}`), 'ERR_BAD_STRATEGY') diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/index.js b/packages/ipfs-unixfs-importer/src/dag-builder/index.js index 822a4a72..f0ad2cb5 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/index.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/index.js @@ -2,11 +2,6 @@ import dirBuilder from './dir.js' import fileBuilder from './file/index.js' import errCode from 'err-code' -// TODO: dynamic imports -import validateChunks from './validate-chunks.js' -import rabinChunker from '../chunker/rabin.js' -import fixedSizeChunker from '../chunker/fixed-size.js' - /** * @typedef {import('../types').File} File * @typedef {import('../types').Directory} Directory @@ -80,9 +75,9 @@ async function * dagBuilder (source, blockstore, options) { if (typeof options.chunker === 'function') { chunker = options.chunker } else if (options.chunker === 'rabin') { - chunker = rabinChunker + chunker = (await (import('../chunker/rabin.js'))).default } else { - chunker = fixedSizeChunker + chunker = (await (import('../chunker/fixed-size.js'))).default } /** @@ -93,7 +88,7 @@ async function * dagBuilder (source, blockstore, options) { if (typeof options.chunkValidator === 'function') { chunkValidator = options.chunkValidator } else { - chunkValidator = validateChunks + chunkValidator = (await (import('./validate-chunks.js'))).default } /** @type {File} */ diff --git a/packages/ipfs-unixfs-importer/src/dir.js b/packages/ipfs-unixfs-importer/src/dir.js index cd1b87ac..19fdb281 100644 --- a/packages/ipfs-unixfs-importer/src/dir.js +++ b/packages/ipfs-unixfs-importer/src/dir.js @@ -19,7 +19,6 @@ */ class Dir { /** - * * @param {DirProps} props * @param {ImporterOptions} options */ diff --git a/packages/ipfs-unixfs-importer/src/flat-to-shard.js b/packages/ipfs-unixfs-importer/src/flat-to-shard.js index a0be94c9..c46f3d3a 100644 --- a/packages/ipfs-unixfs-importer/src/flat-to-shard.js +++ b/packages/ipfs-unixfs-importer/src/flat-to-shard.js @@ -2,7 +2,7 @@ import DirSharded from './dir-sharded.js' import DirFlat from './dir-flat.js' /** - * @typedef {import('./dir')} Dir + * @typedef {import('./dir').default} Dir * @typedef {import('./types').ImporterOptions} ImporterOptions */ @@ -17,26 +17,21 @@ async function flatToShard (child, dir, threshold, options) { let newDir = dir if (dir instanceof DirFlat && dir.directChildrenCount() >= threshold) { - // @ts-ignore Dir type conflict!? newDir = await convertToShard(dir, options) } - // @ts-ignore Dir type conflict!? const parent = newDir.parent if (parent) { if (newDir !== dir) { if (child) { - // @ts-ignore Dir type conflict!? child.parent = newDir } - // @ts-ignore Dir type conflict!? if (!newDir.parentKey) { throw new Error('No parent key found') } - // @ts-ignore Dir type conflict!? await parent.put(newDir.parentKey, newDir) } diff --git a/packages/ipfs-unixfs-importer/src/index.js b/packages/ipfs-unixfs-importer/src/index.js index b5d25f61..cc4d379d 100644 --- a/packages/ipfs-unixfs-importer/src/index.js +++ b/packages/ipfs-unixfs-importer/src/index.js @@ -1,10 +1,6 @@ import parallelBatch from 'it-parallel-batch' import defaultOptions from './options.js' -// TODO: Lazy Load -import defaultDagBuilder from './dag-builder/index.js' -import defaultTreeBuilder from './tree-builder.js' - /** * @typedef {import('interface-blockstore').Blockstore} Blockstore * @typedef {import('./types').ImportCandidate} ImportCandidate @@ -36,7 +32,7 @@ export async function * importer (source, blockstore, options = {}) { if (typeof options.dagBuilder === 'function') { dagBuilder = options.dagBuilder } else { - dagBuilder = defaultDagBuilder + dagBuilder = (await (import('./dag-builder/index.js'))).default } let treeBuilder @@ -44,7 +40,7 @@ export async function * importer (source, blockstore, options = {}) { if (typeof options.treeBuilder === 'function') { treeBuilder = options.treeBuilder } else { - treeBuilder = defaultTreeBuilder + treeBuilder = (await (import('./tree-builder.js'))).default } /** @type {AsyncIterable | Iterable} */ diff --git a/packages/ipfs-unixfs-importer/src/tree-builder.js b/packages/ipfs-unixfs-importer/src/tree-builder.js index 9f60b2da..301ecad0 100644 --- a/packages/ipfs-unixfs-importer/src/tree-builder.js +++ b/packages/ipfs-unixfs-importer/src/tree-builder.js @@ -34,7 +34,6 @@ async function addToTree (elem, tree, options) { if (last) { await parent.put(pathElem, elem) - // @ts-ignore Dir type conflict!? tree = await flatToShard(null, parent, options.shardSplitThreshold, options) } else { let dir = await parent.get(pathElem) diff --git a/packages/ipfs-unixfs-importer/tsconfig.json b/packages/ipfs-unixfs-importer/tsconfig.json index c6eb8f25..446917f2 100644 --- a/packages/ipfs-unixfs-importer/tsconfig.json +++ b/packages/ipfs-unixfs-importer/tsconfig.json @@ -2,6 +2,7 @@ "extends": "aegir/src/config/tsconfig.aegir.json", "compilerOptions": { "outDir": "dist", + "module": "es2020", "importsNotUsedAsValues": "preserve" }, "include": [ From 6b5c08cbdbe9f9c388362003c180adea7306651d Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 29 Jul 2021 10:20:35 +0100 Subject: [PATCH 05/16] chore: update uint8arrays --- packages/ipfs-unixfs-exporter/package.json | 4 ++-- .../ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter.spec.js | 6 +++--- .../test/import-export-dir-sharding.spec.js | 6 +++--- .../test/import-export-nested-dir.spec.js | 6 +++--- packages/ipfs-unixfs-exporter/test/importer.spec.js | 4 ++-- packages/ipfs-unixfs-importer/package.json | 4 ++-- .../ipfs-unixfs-importer/src/dag-builder/validate-chunks.js | 2 +- packages/ipfs-unixfs-importer/src/options.js | 2 +- packages/ipfs-unixfs-importer/test/builder.spec.js | 2 +- packages/ipfs-unixfs-importer/test/chunker-custom.spec.js | 2 +- .../ipfs-unixfs-importer/test/chunker-fixed-size.spec.js | 4 ++-- packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js | 4 ++-- packages/ipfs-unixfs/package.json | 4 ++-- packages/ipfs-unixfs/test/unixfs-format.spec.js | 2 +- 17 files changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index b19c8115..b49185ea 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -37,7 +37,7 @@ "@types/mocha": "^8.2.1", "@types/sinon": "^10.0.0", "abort-controller": "^3.0.0", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", "detect-node": "^2.0.4", @@ -53,7 +53,7 @@ "readable-stream": "^3.6.0", "rimraf": "^3.0.2", "sinon": "^11.1.1", - "uint8arrays": "^2.1.2", + "@vascosantos/uint8arrays": "^3.0.3", "util": "^0.12.3" }, "dependencies": { 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 d7e4d5b9..40a863b8 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 @@ -3,7 +3,7 @@ import { Bucket, createHAMT } from 'hamt-sharding' import { decode } from '@ipld/dag-pb' // @ts-ignore - no types available import mur from 'murmurhash3js-revisited' -import uint8ArrayFromString from 'uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' /** * @typedef {import('interface-blockstore').Blockstore} Blockstore diff --git a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js index d2952eea..c35ac4b2 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js @@ -8,7 +8,7 @@ import { exporter, walkPath } from '../src/index.js' import { importer } from 'ipfs-unixfs-importer' import * as dagPb from '@ipld/dag-pb' import blockApi from './helpers/block.js' -import uint8ArrayConcat from 'uint8arrays/concat.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' import asAsyncIterable from './helpers/as-async-iterable.js' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' diff --git a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js index 9a064637..ead36796 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js @@ -5,7 +5,7 @@ import all from 'it-all' import last from 'it-last' import blockApi from './helpers/block.js' import randomBytes from 'it-buffer-stream' -import uint8ArrayConcat from 'uint8arrays/concat.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' import asAsyncIterable from './helpers/as-async-iterable.js' import { exporter, walkPath } from './../src/index.js' diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.js b/packages/ipfs-unixfs-exporter/test/exporter.spec.js index f4d7dc2d..84ce6009 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.js @@ -16,9 +16,9 @@ import first from 'it-first' import randomBytes from 'it-buffer-stream' import { AbortController } from 'native-abort-controller' import blockApi from './helpers/block.js' -import uint8ArrayFromString from 'uint8arrays/from-string.js' -import uint8ArrayToString from 'uint8arrays/to-string.js' -import uint8ArrayConcat from 'uint8arrays/concat.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string.js' import asAsyncIterable from './helpers/as-async-iterable.js' const ONE_MEG = Math.pow(1024, 2) diff --git a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js index f30a251a..745158ca 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js @@ -6,9 +6,9 @@ import { expect } from 'aegir/utils/chai.js' import all from 'it-all' import last from 'it-last' import blockApi from './helpers/block.js' -import uint8ArrayFromString from 'uint8arrays/from-string.js' -import uint8ArrayToString from 'uint8arrays/to-string.js' -import uint8ArrayConcat from 'uint8arrays/concat.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string.js' import asAsyncIterable from './helpers/as-async-iterable.js' /** diff --git a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js index c5bb5537..1f4f09af 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js @@ -4,9 +4,9 @@ import all from 'it-all' import { importer } from 'ipfs-unixfs-importer' import { exporter } from '../src/index.js' import blockApi from './helpers/block.js' -import uint8ArrayFromString from 'uint8arrays/from-string.js' -import uint8ArrayToString from 'uint8arrays/to-string.js' -import uint8ArrayConcat from 'uint8arrays/concat.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string.js' import asAsyncIterable from './helpers/as-async-iterable.js' describe('import and export: directory', () => { diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.js b/packages/ipfs-unixfs-exporter/test/importer.spec.js index ee5817ef..1ad400b5 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.js +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.js @@ -11,8 +11,8 @@ import loadFixture from 'aegir/utils/fixtures.js' import all from 'it-all' import first from 'it-first' import blockApi from './helpers/block.js' -import uint8ArrayConcat from 'uint8arrays/concat.js' -import uint8ArrayFromString from 'uint8arrays/from-string.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' import asAsyncIterable from './helpers/as-async-iterable.js' import last from 'it-last' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 1e5d5be8..72aa7bbb 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -35,7 +35,7 @@ "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { "@types/mocha": "^8.2.1", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", "assert": "^2.0.0", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", @@ -61,7 +61,7 @@ "multiformats": "^9.4.2", "murmurhash3js-revisited": "^3.0.0", "rabin-wasm": "^0.1.4", - "uint8arrays": "^2.1.7" + "@vascosantos/uint8arrays": "^3.0.3" }, "types": "dist/src/index.d.ts", "eslintConfig": { diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js b/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js index c29a9124..158f0755 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js @@ -1,5 +1,5 @@ import errCode from 'err-code' -import uint8ArrayFromString from 'uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' /** * @typedef {import('../types').ChunkValidator} ChunkValidator diff --git a/packages/ipfs-unixfs-importer/src/options.js b/packages/ipfs-unixfs-importer/src/options.js index 21be7927..9d110d27 100644 --- a/packages/ipfs-unixfs-importer/src/options.js +++ b/packages/ipfs-unixfs-importer/src/options.js @@ -2,7 +2,7 @@ import mergeOptions from 'merge-options' import { sha256 } from 'multiformats/hashes/sha2' // @ts-ignore - no types available import mur from 'murmurhash3js-revisited' -import uint8ArrayFromString from 'uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' mergeOptions.bind({ ignoreUndefined: true }) diff --git a/packages/ipfs-unixfs-importer/test/builder.spec.js b/packages/ipfs-unixfs-importer/test/builder.spec.js index 37fb6242..75941776 100644 --- a/packages/ipfs-unixfs-importer/test/builder.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder.spec.js @@ -7,7 +7,7 @@ import { UnixFS } from 'ipfs-unixfs' import builder from '../src/dag-builder/index.js' import first from 'it-first' import blockApi from './helpers/block.js' -import uint8ArrayFromString from 'uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' import defaultOptions from '../src/options.js' import asAsyncIterable from './helpers/as-async-iterable.js' diff --git a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js index becea79c..9ba3b10b 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js @@ -6,7 +6,7 @@ import * as rawCodec from 'multiformats/codecs/raw' import { sha256 } from 'multiformats/hashes/sha2' import * as Block from 'multiformats/block' import blockApi from './helpers/block.js' -import uint8ArrayFromString from 'uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' import { UnixFS } from 'ipfs-unixfs' const iter = async function * () { diff --git a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js index 503f528e..34b891e2 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js @@ -2,8 +2,8 @@ import chunker from '../src/chunker/fixed-size.js' import { expect } from 'aegir/utils/chai.js' import all from 'it-all' -import uint8ArrayFromString from 'uint8arrays/from-string.js' -import uint8ArrayConcat from 'uint8arrays/concat.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' import defaultOptions from '../src/options.js' import asAsyncIterable from './helpers/as-async-iterable.js' const rawFile = new Uint8Array(Math.pow(2, 20)) diff --git a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js index 0f39876f..c1affe32 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js @@ -3,8 +3,8 @@ import chunker from '../src/chunker/rabin.js' import { expect } from 'aegir/utils/chai.js' import all from 'it-all' -import uint8ArrayFromString from 'uint8arrays/from-string.js' -import uint8ArrayConcat from 'uint8arrays/concat.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' import asAsyncIterable from './helpers/as-async-iterable.js' import defaultOptions from '../src/options.js' diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index 6141f63a..a59a00be 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -38,12 +38,12 @@ "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", "devDependencies": { "@types/mocha": "^8.2.1", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up", + "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", "copy": "^0.3.2", "mkdirp": "^1.0.4", "npm-run-all": "^4.1.5", "nyc": "^15.0.0", - "uint8arrays": "^2.1.2", + "@vascosantos/uint8arrays": "^3.0.3", "util": "^0.12.3" }, "dependencies": { diff --git a/packages/ipfs-unixfs/test/unixfs-format.spec.js b/packages/ipfs-unixfs/test/unixfs-format.spec.js index b9d23270..60b80c70 100644 --- a/packages/ipfs-unixfs/test/unixfs-format.spec.js +++ b/packages/ipfs-unixfs/test/unixfs-format.spec.js @@ -4,7 +4,7 @@ import { expect } from 'aegir/utils/chai.js' /** @type {(path: string) => Uint8Array} */ import loadFixture from 'aegir/utils/fixtures.js' -import uint8ArrayFromString from 'uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' import { UnixFS } from '../src/index.js' import * as Pb from '../src/unixfs.js' From 1ca3b7e483112950065c32d8e0a2f63c43d126e8 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 29 Jul 2021 18:27:13 +0200 Subject: [PATCH 06/16] chore: apply suggestions from code review Co-authored-by: Alex Potsides --- packages/ipfs-unixfs-exporter/test/importer.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.js b/packages/ipfs-unixfs-exporter/test/importer.spec.js index 1ad400b5..b195f8cf 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.js +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.js @@ -20,9 +20,9 @@ import { base58btc } from 'multiformats/bases/base58' import { decode } from '@ipld/dag-pb' /** @type {Uint8Array} */ -const bigFile = loadFixture(('test') + '/fixtures/1.2MiB.txt') +const bigFile = loadFixture('test/fixtures/1.2MiB.txt') /** @type {Uint8Array} */ -const smallFile = loadFixture(('test') + '/fixtures/200Bytes.txt') +const smallFile = loadFixture('test/fixtures/200Bytes.txt') /** * @typedef {import('interface-blockstore').Blockstore} Blockstore From 06956bd8d6867f6566c7b5c48e92ac02537728c6 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 29 Jul 2021 17:36:44 +0100 Subject: [PATCH 07/16] chore: re-add dep check --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 539a88df..ab015ea4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -54,6 +54,11 @@ jobs: script: - npm run depcheck -- $RUN_SINCE -- -- -p + - stage: check + name: dep-check (unused deps) + script: + - npm run depcheck -- $RUN_SINCE -- -- -- --unused + - stage: test name: chrome addons: From bd6a57a01f66f576c70bcb98fd641235ad1a1b0e Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 29 Jul 2021 18:13:17 +0100 Subject: [PATCH 08/16] chore: not dynamic imports flagged --- .../src/resolvers/index.js | 29 +++++++--------- .../src/resolvers/unixfs-v1/index.js | 34 +++++++++---------- .../src/dag-builder/file/index.js | 25 ++++++-------- 3 files changed, 40 insertions(+), 48 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/index.js b/packages/ipfs-unixfs-exporter/src/resolvers/index.js index 9fcb0fd5..73a0b895 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/index.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/index.js @@ -5,34 +5,31 @@ import * as dagCbor from '@ipld/dag-cbor' import * as raw from 'multiformats/codecs/raw' import { identity } from 'multiformats/hashes/identity' +import dagPbResolver from './unixfs-v1/index.js' +import rawResolver from './raw.js' +import dagCborResolver from './dag-cbor.js' +import identifyResolver from './identity.js' + /** * @typedef {import('../types').Resolver} Resolver * @typedef {import('../types').Resolve} Resolve */ /** - * @param {number} key - * @returns {Promise} + * @type {{ [ key: string ]: Resolver }} */ -const importResolver = async (key) => { - switch (key) { - case dagPb.code: - return (await (import('./unixfs-v1/index.js'))).default - case raw.code: - return (await (import('./raw.js'))).default - case dagCbor.code: - return (await (import('./dag-cbor.js'))).default - case identity.code: - return (await (import('./identity.js'))).default - default: - } +const resolvers = { + [dagPb.code]: dagPbResolver, + [raw.code]: rawResolver, + [dagCbor.code]: dagCborResolver, + [identity.code]: identifyResolver } /** * @type {Resolve} */ -async function resolve (cid, name, path, toResolve, depth, blockstore, options) { - const resolver = await importResolver(cid.code) +function resolve (cid, name, path, toResolve, depth, blockstore, options) { + const resolver = resolvers[cid.code] if (!resolver) { throw errCode(new Error(`No resolver for code ${cid.code}`), 'ERR_NO_RESOLVER') diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js index 8d97ed7e..cdb79de3 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/index.js @@ -3,6 +3,10 @@ import { UnixFS } from 'ipfs-unixfs' import findShardCid from '../../utils/find-cid-in-shard.js' import { decode } from '@ipld/dag-pb' +import contentFile from './content/file.js' +import contentDirectory from './content/directory.js' +import contentHamtShardedDirectory from './content/hamt-sharded-directory.js' + /** * @typedef {import('../../types').Resolve} Resolve * @typedef {import('../../types').Resolver} Resolver @@ -21,22 +25,18 @@ const findLinkCid = (node, name) => { } /** - * @param {string} key - * @returns {Promise} + * @type {{ [key: string]: UnixfsV1Resolver }} */ -const importContentExporters = async (key) => { - switch (key) { - case 'raw': - case 'file': - return (await (import('./content/file.js'))).default - case 'directory': - return (await (import('./content/directory.js'))).default - case 'hamt-sharded-directory': - return (await (import('./content/hamt-sharded-directory.js'))).default - case 'metadata': - case 'symlink': - return () => () => [] - default: +const contentExporters = { + raw: contentFile, + file: contentFile, + directory: contentDirectory, + 'hamt-sharded-directory': contentHamtShardedDirectory, + metadata: (cid, node, unixfs, path, resolve, depth, blockstore) => { + return () => [] + }, + symlink: (cid, node, unixfs, path, resolve, depth, blockstore) => { + return () => [] } } @@ -94,8 +94,6 @@ const unixFsResolver = async (cid, name, path, toResolve, resolve, depth, blocks } } - const contentExporter = await importContentExporters(unixfs.type) - return { entry: { type: unixfs.isDirectory() ? 'directory' : 'file', @@ -103,7 +101,7 @@ const unixFsResolver = async (cid, name, path, toResolve, resolve, depth, blocks path, cid, // @ts-ignore - content: contentExporter(cid, node, unixfs, path, resolve, depth, blockstore), + content: contentExporters[unixfs.type](cid, node, unixfs, path, resolve, depth, blockstore), unixfs, depth, node, diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js b/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js index bdf31034..10c3b26e 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/file/index.js @@ -6,6 +6,10 @@ import parallelBatch from 'it-parallel-batch' import * as rawCodec from 'multiformats/codecs/raw' import * as dagPb from '@ipld/dag-pb' +import dagFlat from './flat.js' +import dagBalanced from './balanced.js' +import dagTrickle from './trickle.js' + /** * @typedef {import('interface-blockstore').Blockstore} Blockstore * @typedef {import('../../types').File} File @@ -16,19 +20,12 @@ import * as dagPb from '@ipld/dag-pb' */ /** - * @param {string} key - * @returns {Promise} + * @type {{ [key: string]: FileDAGBuilder}} */ -const importDagBuilder = async (key) => { - switch (key) { - case 'flat': - return (await (import('./flat.js'))).default - case 'balanced': - return (await (import('./balanced.js'))).default - case 'trickle': - return (await (import('./trickle.js'))).default - default: - } +const dagBuilders = { + flat: dagFlat, + balanced: dagBalanced, + trickle: dagTrickle } /** @@ -197,8 +194,8 @@ const reduce = (file, blockstore, options) => { /** * @type {import('../../types').UnixFSV1DagBuilder} */ -async function fileBuilder (file, block, options) { - const dagBuilder = await importDagBuilder(options.strategy) +function fileBuilder (file, block, options) { + const dagBuilder = dagBuilders[options.strategy] if (!dagBuilder) { throw errCode(new Error(`Unknown importer build strategy name: ${options.strategy}`), 'ERR_BAD_STRATEGY') From 85fff58e8f78f8b4802d7948870ce57bc79d3745 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 29 Jul 2021 18:37:50 +0100 Subject: [PATCH 09/16] chore: remove unused deps --- packages/ipfs-unixfs-exporter/package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index b49185ea..c866cca1 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -40,7 +40,6 @@ "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", - "detect-node": "^2.0.4", "events": "^3.3.0", "ipfs-unixfs-importer": "^8.0.1", "it-all": "^1.0.5", @@ -53,7 +52,6 @@ "readable-stream": "^3.6.0", "rimraf": "^3.0.2", "sinon": "^11.1.1", - "@vascosantos/uint8arrays": "^3.0.3", "util": "^0.12.3" }, "dependencies": { @@ -66,7 +64,7 @@ "it-last": "^1.0.5", "multiformats": "^9.4.2", "murmurhash3js-revisited": "^3.0.0", - "uint8arrays": "^2.1.7" + "@vascosantos/uint8arrays": "^3.0.3" }, "types": "dist/src/index.d.ts", "eslintConfig": { From 16347de7af810c6294b9339f45a7e2fddf9e980d Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Thu, 29 Jul 2021 22:48:39 +0100 Subject: [PATCH 10/16] chore: set cjs path for electron --- .travis.yml | 4 +++- packages/ipfs-unixfs-exporter/package.json | 2 +- packages/ipfs-unixfs-importer/package.json | 2 +- packages/ipfs-unixfs/package.json | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ab015ea4..7cf93789 100644 --- a/.travis.yml +++ b/.travis.yml @@ -87,7 +87,9 @@ jobs: name: electron main addons: firefox: latest - script: npm run test -- -- -- -t electron-main + script: + - npm run build + - npm run test -- -- -- -t electron-main -f dist/cjs/node-test/*js - stage: release # only run on changes to master diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index c866cca1..a33c7f19 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -11,7 +11,7 @@ "scripts": { "prepare": "aegir build --no-bundle", "test": "aegir test", - "build": "aegir build", + "build": "aegir build --esm-tests", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s npm run test -t node && nyc report --reporter=html", diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 72aa7bbb..9f6f63eb 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -11,7 +11,7 @@ "scripts": { "prepare": "aegir build --no-bundle", "test": "aegir test", - "build": "aegir build", + "build": "aegir build --esm-tests", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s npm run test -t node && nyc report --reporter=html", diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index a59a00be..0de62866 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -14,7 +14,7 @@ "prepare:proto-types": "pbts -o src/unixfs.d.ts src/unixfs.js", "prepare:types": "aegir build --no-bundle", "test": "aegir test", - "build": "aegir build", + "build": "aegir build --esm-tests", "clean": "rimraf ./dist", "lint": "aegir ts -p check && aegir lint", "coverage": "nyc -s aegir test -t node && nyc report --reporter=html", From c1ab1e6965afcbe4312a40e2279e2a28a1fdeb32 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 11 Aug 2021 12:08:10 +0200 Subject: [PATCH 11/16] chore: add lerna publish config --- package.json | 1 + packages/ipfs-unixfs-exporter/package.json | 5 +- .../test/helpers/block.js | 51 +++++++++++++++++-- packages/ipfs-unixfs-importer/package.json | 5 +- packages/ipfs-unixfs/package.json | 5 +- 5 files changed, 60 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index a0f452c4..b2a8d727 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "JS implementation of the IPFS UnixFS", "scripts": { "reset": "lerna run clean && rimraf packages/*/node_modules node_modules packages/*/package-lock.json package-lock.json", + "postinstall": "lerna link", "test": "lerna run test", "coverage": "lerna run coverage", "prepare": "lerna run prepare", diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index a33c7f19..c27d9b1b 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -9,7 +9,7 @@ "fs": false }, "scripts": { - "prepare": "aegir build --no-bundle", + "prepare": "aegir build --no-bundle --esm-tests", "test": "aegir test", "build": "aegir build --esm-tests", "clean": "rimraf ./dist", @@ -33,6 +33,9 @@ "npm": ">=7.0.0" }, "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", + "publishConfig": { + "directory": "dist" + }, "devDependencies": { "@types/mocha": "^8.2.1", "@types/sinon": "^10.0.0", diff --git a/packages/ipfs-unixfs-exporter/test/helpers/block.js b/packages/ipfs-unixfs-exporter/test/helpers/block.js index 659bb6b5..a415ed5c 100644 --- a/packages/ipfs-unixfs-exporter/test/helpers/block.js +++ b/packages/ipfs-unixfs-exporter/test/helpers/block.js @@ -1,5 +1,48 @@ -/** @type {() => import('interface-blockstore').Blockstore} */ -// @ts-expect-error no types for this deep import -import block from 'ipfs-unixfs-importer/test/helpers/block.js' +import errCode from 'err-code' +import { BlockstoreAdapter } from 'interface-blockstore' +import { base58btc } from 'multiformats/bases/base58' -export default block +/** + * @typedef {import('multiformats/cid').CID} CID + */ + +function createBlockApi () { + class MockBlockstore extends BlockstoreAdapter { + constructor () { + super() + + /** @type {{[key: string]: Uint8Array}} */ + this._blocks = {} + } + + /** + * @param {CID} cid + * @param {Uint8Array} block + * @param {any} [options] + */ + async put (cid, block, options = {}) { + this._blocks[base58btc.encode(cid.multihash.bytes)] = block + } + + /** + * @param {CID} cid + * @param {any} [options] + */ + async get (cid, options = {}) { + const bytes = this._blocks[base58btc.encode(cid.multihash.bytes)] + + if (bytes === undefined) { + throw errCode(new Error(`Could not find data for CID '${cid}'`), 'ERR_NOT_FOUND') + } + + return bytes + } + } + + /** @type {import('interface-blockstore').Blockstore} */ + const bs = new MockBlockstore() + + return bs +} + +export default createBlockApi diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 9f6f63eb..bd6526fa 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -9,7 +9,7 @@ "fs": false }, "scripts": { - "prepare": "aegir build --no-bundle", + "prepare": "aegir build --no-bundle --esm-tests", "test": "aegir test", "build": "aegir build --esm-tests", "clean": "rimraf ./dist", @@ -33,6 +33,9 @@ "npm": ">=7.0.0" }, "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", + "publishConfig": { + "directory": "dist" + }, "devDependencies": { "@types/mocha": "^8.2.1", "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index 0de62866..e8d04f1d 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -9,7 +9,7 @@ "fs": false }, "scripts": { - "prepare": "aegir build", + "prepare": "aegir build --esm-tests", "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", @@ -36,6 +36,9 @@ "npm": ">=7.0.0" }, "homepage": "https://github.com/ipfs/js-ipfs-unixfs#readme", + "publishConfig": { + "directory": "dist" + }, "devDependencies": { "@types/mocha": "^8.2.1", "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", From ad16d468684618100a870e2b13abd901404c41f2 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Wed, 11 Aug 2021 13:21:56 +0200 Subject: [PATCH 12/16] chore: do not require build per change --- .travis.yml | 1 + package.json | 1 - packages/ipfs-unixfs-exporter/package.json | 2 +- packages/ipfs-unixfs-importer/package.json | 2 +- packages/ipfs-unixfs/package.json | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7cf93789..43654a99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -89,6 +89,7 @@ jobs: firefox: latest script: - npm run build + - npx lerna link # use publishConfig.directory - npm run test -- -- -- -t electron-main -f dist/cjs/node-test/*js - stage: release diff --git a/package.json b/package.json index b2a8d727..a0f452c4 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "description": "JS implementation of the IPFS UnixFS", "scripts": { "reset": "lerna run clean && rimraf packages/*/node_modules node_modules packages/*/package-lock.json package-lock.json", - "postinstall": "lerna link", "test": "lerna run test", "coverage": "lerna run coverage", "prepare": "lerna run prepare", diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index c27d9b1b..f1564403 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -9,7 +9,7 @@ "fs": false }, "scripts": { - "prepare": "aegir build --no-bundle --esm-tests", + "prepare": "aegir build --no-bundle", "test": "aegir test", "build": "aegir build --esm-tests", "clean": "rimraf ./dist", diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index bd6526fa..789696ad 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -9,7 +9,7 @@ "fs": false }, "scripts": { - "prepare": "aegir build --no-bundle --esm-tests", + "prepare": "aegir build --no-bundle", "test": "aegir test", "build": "aegir build --esm-tests", "clean": "rimraf ./dist", diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index e8d04f1d..8a91acc1 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -9,7 +9,7 @@ "fs": false }, "scripts": { - "prepare": "aegir build --esm-tests", + "prepare": "aegir build", "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", From 02197396dd7884fe81fce942b36fa0457e9013df Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 16 Aug 2021 11:18:55 +0200 Subject: [PATCH 13/16] chore: use new aegir --- packages/ipfs-unixfs-exporter/package.json | 2 +- packages/ipfs-unixfs-importer/package.json | 2 +- packages/ipfs-unixfs/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index f1564403..0867af2c 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -40,7 +40,7 @@ "@types/mocha": "^8.2.1", "@types/sinon": "^10.0.0", "abort-controller": "^3.0.0", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", + "aegir": "^35.0.1", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", "events": "^3.3.0", diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 789696ad..95131440 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -38,7 +38,7 @@ }, "devDependencies": { "@types/mocha": "^8.2.1", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", + "aegir": "^35.0.1", "assert": "^2.0.0", "copy": "^0.3.2", "crypto-browserify": "^3.12.0", diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index 8a91acc1..154c72e3 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -41,7 +41,7 @@ }, "devDependencies": { "@types/mocha": "^8.2.1", - "aegir": "https://gitpkg.now.sh/ipfs/aegir?feat/build-esm-modules-follow-up-with-dist", + "aegir": "^35.0.1", "copy": "^0.3.2", "mkdirp": "^1.0.4", "npm-run-all": "^4.1.5", From 57ee71d37e195568935aeb10280c07fba4254dee Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 16 Aug 2021 13:34:32 +0200 Subject: [PATCH 14/16] chore: remove extensins from uint8array and use exports as is --- .../ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter.spec.js | 6 +++--- .../test/import-export-dir-sharding.spec.js | 6 +++--- .../test/import-export-nested-dir.spec.js | 6 +++--- packages/ipfs-unixfs-exporter/test/importer.spec.js | 4 ++-- .../ipfs-unixfs-importer/src/dag-builder/validate-chunks.js | 2 +- packages/ipfs-unixfs-importer/src/options.js | 2 +- packages/ipfs-unixfs-importer/test/builder.spec.js | 2 +- packages/ipfs-unixfs-importer/test/chunker-custom.spec.js | 2 +- .../ipfs-unixfs-importer/test/chunker-fixed-size.spec.js | 4 ++-- packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js | 4 ++-- packages/ipfs-unixfs/test/unixfs-format.spec.js | 2 +- 14 files changed, 23 insertions(+), 23 deletions(-) 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 40a863b8..86bd98e6 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 @@ -3,7 +3,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 '@vascosantos/uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' /** * @typedef {import('interface-blockstore').Blockstore} Blockstore diff --git a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js index c35ac4b2..e95e2346 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js @@ -8,7 +8,7 @@ import { exporter, walkPath } from '../src/index.js' import { importer } from 'ipfs-unixfs-importer' import * as dagPb from '@ipld/dag-pb' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' import asAsyncIterable from './helpers/as-async-iterable.js' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' diff --git a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js index ead36796..155139b3 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js @@ -5,7 +5,7 @@ import all from 'it-all' import last from 'it-last' import blockApi from './helpers/block.js' import randomBytes from 'it-buffer-stream' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' import asAsyncIterable from './helpers/as-async-iterable.js' import { exporter, walkPath } from './../src/index.js' diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.js b/packages/ipfs-unixfs-exporter/test/exporter.spec.js index 84ce6009..fa685c03 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.js @@ -16,9 +16,9 @@ import first from 'it-first' import randomBytes from 'it-buffer-stream' import { AbortController } from 'native-abort-controller' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' -import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string' import asAsyncIterable from './helpers/as-async-iterable.js' const ONE_MEG = Math.pow(1024, 2) diff --git a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js index 745158ca..a0290840 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js @@ -6,9 +6,9 @@ import { expect } from 'aegir/utils/chai.js' import all from 'it-all' import last from 'it-last' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' -import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string' import asAsyncIterable from './helpers/as-async-iterable.js' /** diff --git a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js index 1f4f09af..260bf652 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js @@ -4,9 +4,9 @@ import all from 'it-all' import { importer } from 'ipfs-unixfs-importer' import { exporter } from '../src/index.js' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' -import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string' import asAsyncIterable from './helpers/as-async-iterable.js' describe('import and export: directory', () => { diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.js b/packages/ipfs-unixfs-exporter/test/importer.spec.js index b195f8cf..26109227 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.js +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.js @@ -11,8 +11,8 @@ import loadFixture from 'aegir/utils/fixtures.js' import all from 'it-all' import first from 'it-first' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' import asAsyncIterable from './helpers/as-async-iterable.js' import last from 'it-last' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js b/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js index 158f0755..abd849dc 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js @@ -1,5 +1,5 @@ import errCode from 'err-code' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' /** * @typedef {import('../types').ChunkValidator} ChunkValidator diff --git a/packages/ipfs-unixfs-importer/src/options.js b/packages/ipfs-unixfs-importer/src/options.js index 9d110d27..33dbda5f 100644 --- a/packages/ipfs-unixfs-importer/src/options.js +++ b/packages/ipfs-unixfs-importer/src/options.js @@ -2,7 +2,7 @@ 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 '@vascosantos/uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' mergeOptions.bind({ ignoreUndefined: true }) diff --git a/packages/ipfs-unixfs-importer/test/builder.spec.js b/packages/ipfs-unixfs-importer/test/builder.spec.js index 75941776..a0837a5e 100644 --- a/packages/ipfs-unixfs-importer/test/builder.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder.spec.js @@ -7,7 +7,7 @@ import { UnixFS } from 'ipfs-unixfs' import builder from '../src/dag-builder/index.js' import first from 'it-first' import blockApi from './helpers/block.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' import defaultOptions from '../src/options.js' import asAsyncIterable from './helpers/as-async-iterable.js' diff --git a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js index 9ba3b10b..71294685 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js @@ -6,7 +6,7 @@ import * as rawCodec from 'multiformats/codecs/raw' import { sha256 } from 'multiformats/hashes/sha2' import * as Block from 'multiformats/block' import blockApi from './helpers/block.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' import { UnixFS } from 'ipfs-unixfs' const iter = async function * () { diff --git a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js index 34b891e2..81270d60 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js @@ -2,8 +2,8 @@ import chunker from '../src/chunker/fixed-size.js' import { expect } from 'aegir/utils/chai.js' import all from 'it-all' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' import defaultOptions from '../src/options.js' import asAsyncIterable from './helpers/as-async-iterable.js' const rawFile = new Uint8Array(Math.pow(2, 20)) diff --git a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js index c1affe32..7a6b81d0 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js @@ -3,8 +3,8 @@ import chunker from '../src/chunker/rabin.js' import { expect } from 'aegir/utils/chai.js' import all from 'it-all' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' import asAsyncIterable from './helpers/as-async-iterable.js' import defaultOptions from '../src/options.js' diff --git a/packages/ipfs-unixfs/test/unixfs-format.spec.js b/packages/ipfs-unixfs/test/unixfs-format.spec.js index 60b80c70..833d3ca2 100644 --- a/packages/ipfs-unixfs/test/unixfs-format.spec.js +++ b/packages/ipfs-unixfs/test/unixfs-format.spec.js @@ -4,7 +4,7 @@ import { expect } from 'aegir/utils/chai.js' /** @type {(path: string) => Uint8Array} */ import loadFixture from 'aegir/utils/fixtures.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string.js' +import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' import { UnixFS } from '../src/index.js' import * as Pb from '../src/unixfs.js' From 7743fe63ebf464ef2d9541317fc032c1e779f085 Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Mon, 16 Aug 2021 15:09:44 +0200 Subject: [PATCH 15/16] chore: revert uint8arrays fork --- packages/ipfs-unixfs-exporter/package.json | 2 +- .../ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js | 2 +- packages/ipfs-unixfs-exporter/test/exporter.spec.js | 6 +++--- .../test/import-export-dir-sharding.spec.js | 6 +++--- .../test/import-export-nested-dir.spec.js | 6 +++--- packages/ipfs-unixfs-exporter/test/importer.spec.js | 4 ++-- packages/ipfs-unixfs-importer/package.json | 2 +- .../ipfs-unixfs-importer/src/dag-builder/validate-chunks.js | 2 +- packages/ipfs-unixfs-importer/src/options.js | 2 +- packages/ipfs-unixfs-importer/test/builder.spec.js | 2 +- packages/ipfs-unixfs-importer/test/chunker-custom.spec.js | 2 +- .../ipfs-unixfs-importer/test/chunker-fixed-size.spec.js | 4 ++-- packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js | 4 ++-- packages/ipfs-unixfs/package.json | 2 +- packages/ipfs-unixfs/test/unixfs-format.spec.js | 2 +- 17 files changed, 26 insertions(+), 26 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index 0867af2c..8fccac5e 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -67,7 +67,7 @@ "it-last": "^1.0.5", "multiformats": "^9.4.2", "murmurhash3js-revisited": "^3.0.0", - "@vascosantos/uint8arrays": "^3.0.3" + "uint8arrays": "^3.0.0-rc.0" }, "types": "dist/src/index.d.ts", "eslintConfig": { 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 86bd98e6..285a0116 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 @@ -3,7 +3,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 '@vascosantos/uint8arrays/from-string' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' /** * @typedef {import('interface-blockstore').Blockstore} Blockstore diff --git a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js index e95e2346..b4e6bfd9 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.js @@ -8,7 +8,7 @@ import { exporter, walkPath } from '../src/index.js' import { importer } from 'ipfs-unixfs-importer' import * as dagPb from '@ipld/dag-pb' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import asAsyncIterable from './helpers/as-async-iterable.js' import { CID } from 'multiformats/cid' import { sha256 } from 'multiformats/hashes/sha2' diff --git a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js index 155139b3..eb0b99d9 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter-subtree.spec.js @@ -5,7 +5,7 @@ import all from 'it-all' import last from 'it-last' import blockApi from './helpers/block.js' import randomBytes from 'it-buffer-stream' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import asAsyncIterable from './helpers/as-async-iterable.js' import { exporter, walkPath } from './../src/index.js' diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.js b/packages/ipfs-unixfs-exporter/test/exporter.spec.js index fa685c03..b9d45a4a 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.js +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.js @@ -16,9 +16,9 @@ import first from 'it-first' import randomBytes from 'it-buffer-stream' import { AbortController } from 'native-abort-controller' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' -import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import asAsyncIterable from './helpers/as-async-iterable.js' const ONE_MEG = Math.pow(1024, 2) diff --git a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js index a0290840..cb7c309b 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-dir-sharding.spec.js @@ -6,9 +6,9 @@ import { expect } from 'aegir/utils/chai.js' import all from 'it-all' import last from 'it-last' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' -import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import asAsyncIterable from './helpers/as-async-iterable.js' /** diff --git a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js index 260bf652..746e4971 100644 --- a/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js +++ b/packages/ipfs-unixfs-exporter/test/import-export-nested-dir.spec.js @@ -4,9 +4,9 @@ import all from 'it-all' import { importer } from 'ipfs-unixfs-importer' import { exporter } from '../src/index.js' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' -import { toString as uint8ArrayToString } from '@vascosantos/uint8arrays/to-string' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import asAsyncIterable from './helpers/as-async-iterable.js' describe('import and export: directory', () => { diff --git a/packages/ipfs-unixfs-exporter/test/importer.spec.js b/packages/ipfs-unixfs-exporter/test/importer.spec.js index 26109227..ad8126f0 100644 --- a/packages/ipfs-unixfs-exporter/test/importer.spec.js +++ b/packages/ipfs-unixfs-exporter/test/importer.spec.js @@ -11,8 +11,8 @@ import loadFixture from 'aegir/utils/fixtures.js' import all from 'it-all' import first from 'it-first' import blockApi from './helpers/block.js' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import asAsyncIterable from './helpers/as-async-iterable.js' import last from 'it-last' import { CID } from 'multiformats/cid' diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 95131440..9affe886 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -64,7 +64,7 @@ "multiformats": "^9.4.2", "murmurhash3js-revisited": "^3.0.0", "rabin-wasm": "^0.1.4", - "@vascosantos/uint8arrays": "^3.0.3" + "uint8arrays": "^3.0.0-rc.0" }, "types": "dist/src/index.d.ts", "eslintConfig": { diff --git a/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js b/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js index abd849dc..ec5a6f13 100644 --- a/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js +++ b/packages/ipfs-unixfs-importer/src/dag-builder/validate-chunks.js @@ -1,5 +1,5 @@ import errCode from 'err-code' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' /** * @typedef {import('../types').ChunkValidator} ChunkValidator diff --git a/packages/ipfs-unixfs-importer/src/options.js b/packages/ipfs-unixfs-importer/src/options.js index 33dbda5f..de0b0acc 100644 --- a/packages/ipfs-unixfs-importer/src/options.js +++ b/packages/ipfs-unixfs-importer/src/options.js @@ -2,7 +2,7 @@ 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 '@vascosantos/uint8arrays/from-string' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' mergeOptions.bind({ ignoreUndefined: true }) diff --git a/packages/ipfs-unixfs-importer/test/builder.spec.js b/packages/ipfs-unixfs-importer/test/builder.spec.js index a0837a5e..f2ea3370 100644 --- a/packages/ipfs-unixfs-importer/test/builder.spec.js +++ b/packages/ipfs-unixfs-importer/test/builder.spec.js @@ -7,7 +7,7 @@ import { UnixFS } from 'ipfs-unixfs' import builder from '../src/dag-builder/index.js' import first from 'it-first' import blockApi from './helpers/block.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import defaultOptions from '../src/options.js' import asAsyncIterable from './helpers/as-async-iterable.js' diff --git a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js index 71294685..55d6d833 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-custom.spec.js @@ -6,7 +6,7 @@ import * as rawCodec from 'multiformats/codecs/raw' import { sha256 } from 'multiformats/hashes/sha2' import * as Block from 'multiformats/block' import blockApi from './helpers/block.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { UnixFS } from 'ipfs-unixfs' const iter = async function * () { diff --git a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js index 81270d60..ab446a3e 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-fixed-size.spec.js @@ -2,8 +2,8 @@ import chunker from '../src/chunker/fixed-size.js' import { expect } from 'aegir/utils/chai.js' import all from 'it-all' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import defaultOptions from '../src/options.js' import asAsyncIterable from './helpers/as-async-iterable.js' const rawFile = new Uint8Array(Math.pow(2, 20)) diff --git a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js index 7a6b81d0..9b7f09f9 100644 --- a/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js +++ b/packages/ipfs-unixfs-importer/test/chunker-rabin.spec.js @@ -3,8 +3,8 @@ import chunker from '../src/chunker/rabin.js' import { expect } from 'aegir/utils/chai.js' import all from 'it-all' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' -import { concat as uint8ArrayConcat } from '@vascosantos/uint8arrays/concat' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import asAsyncIterable from './helpers/as-async-iterable.js' import defaultOptions from '../src/options.js' diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index 154c72e3..c1c7f5c1 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -46,7 +46,7 @@ "mkdirp": "^1.0.4", "npm-run-all": "^4.1.5", "nyc": "^15.0.0", - "@vascosantos/uint8arrays": "^3.0.3", + "uint8arrays": "^3.0.0-rc.0", "util": "^0.12.3" }, "dependencies": { diff --git a/packages/ipfs-unixfs/test/unixfs-format.spec.js b/packages/ipfs-unixfs/test/unixfs-format.spec.js index 833d3ca2..7714282f 100644 --- a/packages/ipfs-unixfs/test/unixfs-format.spec.js +++ b/packages/ipfs-unixfs/test/unixfs-format.spec.js @@ -4,7 +4,7 @@ import { expect } from 'aegir/utils/chai.js' /** @type {(path: string) => Uint8Array} */ import loadFixture from 'aegir/utils/fixtures.js' -import { fromString as uint8ArrayFromString } from '@vascosantos/uint8arrays/from-string' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { UnixFS } from '../src/index.js' import * as Pb from '../src/unixfs.js' From 752d354173d64498c12301adf77b7265dcaefc3e Mon Sep 17 00:00:00 2001 From: Vasco Santos Date: Tue, 17 Aug 2021 10:21:08 +0200 Subject: [PATCH 16/16] chore: use final uint8arrays --- packages/ipfs-unixfs-exporter/package.json | 2 +- packages/ipfs-unixfs-importer/package.json | 2 +- packages/ipfs-unixfs/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/package.json b/packages/ipfs-unixfs-exporter/package.json index 8fccac5e..ab545187 100644 --- a/packages/ipfs-unixfs-exporter/package.json +++ b/packages/ipfs-unixfs-exporter/package.json @@ -67,7 +67,7 @@ "it-last": "^1.0.5", "multiformats": "^9.4.2", "murmurhash3js-revisited": "^3.0.0", - "uint8arrays": "^3.0.0-rc.0" + "uint8arrays": "^3.0.0" }, "types": "dist/src/index.d.ts", "eslintConfig": { diff --git a/packages/ipfs-unixfs-importer/package.json b/packages/ipfs-unixfs-importer/package.json index 9affe886..fe6e5bf7 100644 --- a/packages/ipfs-unixfs-importer/package.json +++ b/packages/ipfs-unixfs-importer/package.json @@ -64,7 +64,7 @@ "multiformats": "^9.4.2", "murmurhash3js-revisited": "^3.0.0", "rabin-wasm": "^0.1.4", - "uint8arrays": "^3.0.0-rc.0" + "uint8arrays": "^3.0.0" }, "types": "dist/src/index.d.ts", "eslintConfig": { diff --git a/packages/ipfs-unixfs/package.json b/packages/ipfs-unixfs/package.json index c1c7f5c1..852adf9b 100644 --- a/packages/ipfs-unixfs/package.json +++ b/packages/ipfs-unixfs/package.json @@ -46,7 +46,7 @@ "mkdirp": "^1.0.4", "npm-run-all": "^4.1.5", "nyc": "^15.0.0", - "uint8arrays": "^3.0.0-rc.0", + "uint8arrays": "^3.0.0", "util": "^0.12.3" }, "dependencies": {