Skip to content

Commit 4842293

Browse files
authored
fix: remove dynamic imports (#169)
Removes dynamic imports because they dont work well when imports cjs also removes unused file
1 parent eaeae88 commit 4842293

File tree

4 files changed

+12
-41
lines changed

4 files changed

+12
-41
lines changed

packages/ipfs-unixfs-importer/src/chunker/index.js

-35
This file was deleted.

packages/ipfs-unixfs-importer/src/dag-builder/file/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as dagPb from '@ipld/dag-pb'
99
import dagFlat from './flat.js'
1010
import dagBalanced from './balanced.js'
1111
import dagTrickle from './trickle.js'
12+
import bufferImporterFn from './buffer-importer.js'
1213

1314
/**
1415
* @typedef {import('interface-blockstore').Blockstore} Blockstore
@@ -41,7 +42,7 @@ async function * buildFileBatch (file, blockstore, options) {
4142
if (typeof options.bufferImporter === 'function') {
4243
bufferImporter = options.bufferImporter
4344
} else {
44-
bufferImporter = (await (import('./buffer-importer.js'))).default
45+
bufferImporter = bufferImporterFn
4546
}
4647

4748
for await (const entry of parallelBatch(bufferImporter(file, blockstore, options), options.blockWriteConcurrency)) {

packages/ipfs-unixfs-importer/src/dag-builder/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import dirBuilder from './dir.js'
22
import fileBuilder from './file/index.js'
33
import errCode from 'err-code'
4+
import rabin from '../chunker/rabin.js'
5+
import fixedSize from '../chunker/fixed-size.js'
6+
import validateChunks from './validate-chunks.js'
47

58
/**
69
* @typedef {import('../types').File} File
@@ -75,9 +78,9 @@ async function * dagBuilder (source, blockstore, options) {
7578
if (typeof options.chunker === 'function') {
7679
chunker = options.chunker
7780
} else if (options.chunker === 'rabin') {
78-
chunker = (await (import('../chunker/rabin.js'))).default
81+
chunker = rabin
7982
} else {
80-
chunker = (await (import('../chunker/fixed-size.js'))).default
83+
chunker = fixedSize
8184
}
8285

8386
/**
@@ -88,7 +91,7 @@ async function * dagBuilder (source, blockstore, options) {
8891
if (typeof options.chunkValidator === 'function') {
8992
chunkValidator = options.chunkValidator
9093
} else {
91-
chunkValidator = (await (import('./validate-chunks.js'))).default
94+
chunkValidator = validateChunks
9295
}
9396

9497
/** @type {File} */

packages/ipfs-unixfs-importer/src/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import parallelBatch from 'it-parallel-batch'
22
import defaultOptions from './options.js'
3+
import dagBuilderFn from './dag-builder/index.js'
4+
import treeBuilderFn from './tree-builder.js'
35

46
/**
57
* @typedef {import('interface-blockstore').Blockstore} Blockstore
@@ -32,15 +34,15 @@ export async function * importer (source, blockstore, options = {}) {
3234
if (typeof options.dagBuilder === 'function') {
3335
dagBuilder = options.dagBuilder
3436
} else {
35-
dagBuilder = (await (import('./dag-builder/index.js'))).default
37+
dagBuilder = dagBuilderFn
3638
}
3739

3840
let treeBuilder
3941

4042
if (typeof options.treeBuilder === 'function') {
4143
treeBuilder = options.treeBuilder
4244
} else {
43-
treeBuilder = (await (import('./tree-builder.js'))).default
45+
treeBuilder = treeBuilderFn
4446
}
4547

4648
/** @type {AsyncIterable<ImportCandidate> | Iterable<ImportCandidate>} */

0 commit comments

Comments
 (0)