diff --git a/Makefile b/Makefile index 0acebfe1e8d..8a64db4d5b7 100644 --- a/Makefile +++ b/Makefile @@ -753,7 +753,7 @@ test-tsc: esbuild | github/tsc cp -r github/tsc/src github/tsc/scripts demo/tsc cp github/tsc/lib/*.d.ts demo/tsc/built/local cd demo/tsc && node scripts/processDiagnosticMessages.mjs src/compiler/diagnosticMessages.json - ./esbuild --bundle demo/tsc/src/tsc/tsc.ts --outfile=demo/tsc/built/local/tsc.js --platform=node --target=es2018 + ./esbuild --bundle demo/tsc/src/tsc/tsc.ts --outfile=demo/tsc/built/local/tsc.js --platform=node --target=es2018 -- packages=external echo '{"dependencies":{"@types/node":"20.2.5","@types/microsoft__typescript-etw":"0.1.1","@types/source-map-support":"0.5.6"}}' > demo/tsc/package.json cd demo/tsc && npm i --silent && echo 'Type checking tsc using tsc...' && time -p node ./built/local/tsc.js -p src/compiler @@ -769,7 +769,6 @@ TEST_ROLLUP_REPLACE += "paths": { "package.json": [".\/package.json"] }, TEST_ROLLUP_FLAGS += --bundle TEST_ROLLUP_FLAGS += --external:fsevents TEST_ROLLUP_FLAGS += --outfile=dist/rollup.js -TEST_ROLLUP_FLAGS += --packages=bundle TEST_ROLLUP_FLAGS += --platform=node TEST_ROLLUP_FLAGS += --target=es6 TEST_ROLLUP_FLAGS += src/node-entry.ts diff --git a/pkg/api/api_impl.go b/pkg/api/api_impl.go index 76320e4a887..d2de989e94f 100644 --- a/pkg/api/api_impl.go +++ b/pkg/api/api_impl.go @@ -218,9 +218,7 @@ func validateASCIIOnly(value Charset) bool { func validateExternalPackages(value Packages, platform Platform) bool { switch value { - case PackagesDefault: - return platform == PlatformNode - case PackagesBundle: + case PackagesDefault, PackagesBundle: return false case PackagesExternal: return true diff --git a/scripts/end-to-end-tests.js b/scripts/end-to-end-tests.js index 1b08bd9e36b..7d280807040 100644 --- a/scripts/end-to-end-tests.js +++ b/scripts/end-to-end-tests.js @@ -8108,9 +8108,7 @@ for (const flags of [[], ['--bundle']]) { } }`, }), - - // Check the default behavior of "--platform=node" - test(['in.js', '--outfile=node.js', '--bundle', '--platform=node', '--format=esm'].concat(flags), { + test(['in.js', '--outfile=node.js', '--bundle', '--platform=node', '--packages=external', '--format=esm'].concat(flags), { 'in.js': `import abc from 'pkg'; if (abc !== 'import') throw 'fail'`, 'node_modules/pkg/fail.js': `TEST FAILED`, // This package should not be bundled 'node_modules/pkg/require.cjs': `module.exports = 'require'`, @@ -8125,7 +8123,7 @@ for (const flags of [[], ['--bundle']]) { } }`, }), - test(['in.js', '--outfile=node.js', '--bundle', '--platform=node', '--format=cjs'].concat(flags), { + test(['in.js', '--outfile=node.js', '--bundle', '--platform=node', '--packages=external', '--format=cjs'].concat(flags), { 'in.js': `import abc from 'pkg'; if (abc !== 'require') throw 'fail'`, 'node_modules/pkg/fail.js': `TEST FAILED`, // This package should not be bundled 'node_modules/pkg/require.cjs': `module.exports = 'require'`, @@ -8141,6 +8139,23 @@ for (const flags of [[], ['--bundle']]) { }`, }), + // Check the default behavior of "--platform=node" + test(['in.js', '--outfile=node.js', '--bundle', '--platform=node', '--format=esm'].concat(flags), { + 'in.js': `import abc from 'pkg'; if (abc !== 'module') throw 'fail'`, + 'node_modules/pkg/module.js': `export default 'module'`, + 'node_modules/pkg/require.cjs': `module.exports = 'require'`, + 'node_modules/pkg/import.mjs': `export default 'import'`, + 'node_modules/pkg/package.json': `{ + "exports": { + ".": { + "module": "./module.js", + "import": "./import.mjs", + "require": "./require.cjs" + } + } + }`, + }), + // This is an edge case for extensionless files. The file should be treated // as CommonJS even though package.json says "type": "module" because that // only applies to ".js" files in node, not to all JavaScript files. diff --git a/scripts/test-yarnpnp.js b/scripts/test-yarnpnp.js index 01f4ebd34d5..30ded93400b 100644 --- a/scripts/test-yarnpnp.js +++ b/scripts/test-yarnpnp.js @@ -66,7 +66,6 @@ function runTests() { 'in.mjs', '--bundle', '--log-level=debug', - '--packages=bundle', '--platform=node', '--outfile=out-native.js', ], { cwd: rootDir, stdio: 'inherit' }) @@ -74,12 +73,12 @@ function runTests() { // Test the WebAssembly build esbuild.buildWasmLib(ESBUILD_BINARY_PATH) - run('node ../../npm/esbuild-wasm/bin/esbuild in.mjs --bundle --log-level=debug --packages=bundle --platform=node --outfile=out-wasm.js') + run('node ../../npm/esbuild-wasm/bin/esbuild in.mjs --bundle --log-level=debug --platform=node --outfile=out-wasm.js') run('node out-wasm.js') // Test the WebAssembly build when run through Yarn's file system shim esbuild.buildWasmLib(ESBUILD_BINARY_PATH) - run('yarn node ../../npm/esbuild-wasm/bin/esbuild in.mjs --bundle --log-level=debug --packages=bundle --platform=node --outfile=out-wasm-yarn.js') + run('yarn node ../../npm/esbuild-wasm/bin/esbuild in.mjs --bundle --log-level=debug --platform=node --outfile=out-wasm-yarn.js') run('node out-wasm-yarn.js') }