Skip to content

Commit

Permalink
fix: force esbuild target in zisi (#681)
Browse files Browse the repository at this point in the history
* fix: force esbuild target in zisi

* refactor: reduce esbuild log limit

* refactor: increase esbuild log limit in zisi
  • Loading branch information
eduardoboucas committed Sep 29, 2021
1 parent 12a08ba commit 6e74a0a
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/runtimes/node/list_imports.js
Expand Up @@ -4,6 +4,11 @@ const { tmpName } = require('tmp-promise')

const { safeUnlink } = require('../../utils/fs')

// Maximum number of log messages that an esbuild instance will produce. This
// limit is important to avoid out-of-memory errors due to too much data being
// sent in the Go<>Node IPC channel.
const ESBUILD_LOG_LIMIT = 10

const getListImportsPlugin = ({ imports, path }) => ({
name: 'list-imports',
setup(build) {
Expand Down Expand Up @@ -35,11 +40,14 @@ const listImports = async ({ path }) => {

try {
await esbuild.build({
entryPoints: [path],
bundle: true,
entryPoints: [path],
logLevel: 'error',
logLimit: ESBUILD_LOG_LIMIT,
outfile: targetPath,
platform: 'node',
plugins: [getListImportsPlugin({ imports, path })],
target: 'esnext',
})
} finally {
await safeUnlink(targetPath)
Expand Down
@@ -0,0 +1,3 @@
const { stack } = require('@netlify/mock-package/stack')

module.exports = { stack }

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,7 @@
{
"name": "local-node-module-destructure-require",
"version": "1.0.0",
"dependencies": {
"@netlify/mock-package": "1.0.0"
}
}
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"target": "ES5"
}
}
15 changes: 15 additions & 0 deletions tests/main.js
Expand Up @@ -173,6 +173,21 @@ testBundlers('Can require deep paths in node modules', [ESBUILD, ESBUILD_ZISI, D
}
})

testBundlers(
'Can require Node modules with destructuring expressions',
[ESBUILD, ESBUILD_ZISI, DEFAULT],
async (bundler, t) => {
await zipNode(t, `local-node-module-destructure-require`, {
opts: { config: { '*': { nodeBundler: bundler } } },
})

// TO DO: Remove when `parseWithEsbuild` feature flag is decommissioned.
await zipNode(t, `local-node-module-destructure-require`, {
opts: { config: { '*': { nodeBundler: bundler } }, featureFlags: { parseWithEsbuild: true } },
})
},
)

testBundlers('Can require scoped node modules', [ESBUILD, ESBUILD_ZISI, DEFAULT], async (bundler, t) => {
await zipNode(t, 'node-module-scope', { opts: { config: { '*': { nodeBundler: bundler } } } })
})
Expand Down

1 comment on commit 6e74a0a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 10.9s

largeDepsZisi: 58.6s

Please sign in to comment.