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 2 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 @@ -56,7 +56,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 @@ -1374,10 +1374,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 @@ -1395,7 +1398,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 @@ -1416,7 +1419,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 @@ -1432,7 +1435,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 @@ -1451,7 +1454,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 @@ -1473,7 +1476,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 @@ -1494,7 +1497,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 @@ -1514,7 +1517,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 @@ -1535,7 +1538,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