Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

feat: change default value of processDynamicNodeImports #603

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtimes/node/bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const bundleJsFile = async function ({
basePath,
includedPaths: dynamicImportsIncludedPaths,
moduleNames: nodeModulesWithDynamicImports,
processImports: config.processDynamicNodeImports === true,
processImports: config.processDynamicNodeImports !== false,
srcDir,
}),
]
Expand Down
23 changes: 13 additions & 10 deletions tests/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1424,10 +1424,13 @@ test('Returns an empty list of modules with dynamic imports if the modules are m
t.is(files[0].nodeModulesWithDynamicImports.length, 0)
})

test('Leaves dynamic imports untouched when the `processDynamicNodeImports` configuration property is not `true`', async (t) => {
test('Leaves dynamic imports untouched when the `processDynamicNodeImports` configuration property is `false`', async (t) => {
const fixtureName = 'node-module-dynamic-import-template-literal'
const { tmpDir } = await zipNode(t, fixtureName, {
opts: { basePath: join(FIXTURES_DIR, fixtureName), config: { '*': { nodeBundler: ESBUILD } } },
opts: {
basePath: join(FIXTURES_DIR, fixtureName),
config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: false } },
},
})
const functionSource = await pReadFile(`${tmpDir}/function.js`, 'utf8')

Expand All @@ -1445,7 +1448,7 @@ test('Adds a runtime shim and includes the files needed for dynamic imports usin
const { files, tmpDir } = await zipNode(t, fixtureName, {
opts: {
basePath: join(FIXTURES_DIR, fixtureName),
config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
config: { '*': { nodeBundler: ESBUILD } },
},
})

Expand All @@ -1466,7 +1469,7 @@ test('Leaves dynamic imports untouched when the files required to resolve the ex
const { tmpDir } = await zipNode(t, fixtureName, {
opts: {
basePath: join(FIXTURES_DIR, fixtureName),
config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
config: { '*': { nodeBundler: ESBUILD } },
},
})
const functionSource = await pReadFile(`${tmpDir}/function.js`, 'utf8')
Expand All @@ -1482,7 +1485,7 @@ test('Adds a runtime shim and includes the files needed for dynamic imports usin
const { tmpDir } = await zipNode(t, fixtureName, {
opts: {
basePath: join(FIXTURES_DIR, fixtureName),
config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
config: { '*': { nodeBundler: ESBUILD } },
},
})

Expand All @@ -1501,7 +1504,7 @@ test('The dynamic import runtime shim handles files in nested directories', asyn
const { tmpDir } = await zipNode(t, fixtureName, {
opts: {
basePath: join(FIXTURES_DIR, fixtureName),
config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
config: { '*': { nodeBundler: ESBUILD } },
},
})

Expand All @@ -1523,7 +1526,7 @@ test('The dynamic import runtime shim handles files in nested directories when u
opts: {
archiveFormat: 'none',
basePath: join(FIXTURES_DIR, fixtureName),
config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
config: { '*': { nodeBundler: ESBUILD } },
},
})

Expand All @@ -1544,7 +1547,7 @@ test('Negated files in `included_files` are excluded from the bundle even if the
const { tmpDir } = await zipNode(t, fixtureName, {
opts: {
basePath: join(FIXTURES_DIR, fixtureName),
config: { '*': { includedFiles: ['!lang/en.*'], nodeBundler: ESBUILD, processDynamicNodeImports: true } },
config: { '*': { includedFiles: ['!lang/en.*'], nodeBundler: ESBUILD } },
},
})

Expand All @@ -1564,7 +1567,7 @@ test('Creates dynamic import shims for functions with the same name and same shi
length: FUNCTION_COUNT,
opts: {
basePath: join(FIXTURES_DIR, fixtureName),
config: { '*': { nodeBundler: ESBUILD, processDynamicNodeImports: true } },
config: { '*': { nodeBundler: ESBUILD } },
},
})

Expand All @@ -1585,7 +1588,7 @@ test('Creates dynamic import shims for functions using `zipFunction`', async (t)
const fixtureDir = join(FIXTURES_DIR, 'node-module-dynamic-import-2')
const result = await zipFunction(join(fixtureDir, 'function.js'), tmpDir, {
basePath: fixtureDir,
config: { '*': { nodeBundler: 'esbuild', processDynamicNodeImports: true } },
config: { '*': { nodeBundler: 'esbuild' } },
})

await unzipFiles([result])
Expand Down