Skip to content

Commit

Permalink
fix: remove dynamic imports (#169)
Browse files Browse the repository at this point in the history
Removes dynamic imports because they dont work well when imports cjs
also removes unused file
  • Loading branch information
hugomrdias authored Aug 27, 2021
1 parent eaeae88 commit 4842293
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 41 deletions.
35 changes: 0 additions & 35 deletions packages/ipfs-unixfs-importer/src/chunker/index.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/ipfs-unixfs-importer/src/dag-builder/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as dagPb from '@ipld/dag-pb'
import dagFlat from './flat.js'
import dagBalanced from './balanced.js'
import dagTrickle from './trickle.js'
import bufferImporterFn from './buffer-importer.js'

/**
* @typedef {import('interface-blockstore').Blockstore} Blockstore
Expand Down Expand Up @@ -41,7 +42,7 @@ async function * buildFileBatch (file, blockstore, options) {
if (typeof options.bufferImporter === 'function') {
bufferImporter = options.bufferImporter
} else {
bufferImporter = (await (import('./buffer-importer.js'))).default
bufferImporter = bufferImporterFn
}

for await (const entry of parallelBatch(bufferImporter(file, blockstore, options), options.blockWriteConcurrency)) {
Expand Down
9 changes: 6 additions & 3 deletions packages/ipfs-unixfs-importer/src/dag-builder/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import dirBuilder from './dir.js'
import fileBuilder from './file/index.js'
import errCode from 'err-code'
import rabin from '../chunker/rabin.js'
import fixedSize from '../chunker/fixed-size.js'
import validateChunks from './validate-chunks.js'

/**
* @typedef {import('../types').File} File
Expand Down Expand Up @@ -75,9 +78,9 @@ async function * dagBuilder (source, blockstore, options) {
if (typeof options.chunker === 'function') {
chunker = options.chunker
} else if (options.chunker === 'rabin') {
chunker = (await (import('../chunker/rabin.js'))).default
chunker = rabin
} else {
chunker = (await (import('../chunker/fixed-size.js'))).default
chunker = fixedSize
}

/**
Expand All @@ -88,7 +91,7 @@ async function * dagBuilder (source, blockstore, options) {
if (typeof options.chunkValidator === 'function') {
chunkValidator = options.chunkValidator
} else {
chunkValidator = (await (import('./validate-chunks.js'))).default
chunkValidator = validateChunks
}

/** @type {File} */
Expand Down
6 changes: 4 additions & 2 deletions packages/ipfs-unixfs-importer/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import parallelBatch from 'it-parallel-batch'
import defaultOptions from './options.js'
import dagBuilderFn from './dag-builder/index.js'
import treeBuilderFn from './tree-builder.js'

/**
* @typedef {import('interface-blockstore').Blockstore} Blockstore
Expand Down Expand Up @@ -32,15 +34,15 @@ export async function * importer (source, blockstore, options = {}) {
if (typeof options.dagBuilder === 'function') {
dagBuilder = options.dagBuilder
} else {
dagBuilder = (await (import('./dag-builder/index.js'))).default
dagBuilder = dagBuilderFn
}

let treeBuilder

if (typeof options.treeBuilder === 'function') {
treeBuilder = options.treeBuilder
} else {
treeBuilder = (await (import('./tree-builder.js'))).default
treeBuilder = treeBuilderFn
}

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

0 comments on commit 4842293

Please sign in to comment.