@jsenv/plugin-commonjs 2.11.18 → 2.11.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cjs_to_esm_raw.js +11 -0
package/package.json
CHANGED
package/src/cjs_to_esm_raw.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createLogger } from "@jsenv/humanize";
|
|
2
2
|
import { urlToFileSystemPath } from "@jsenv/urls";
|
|
3
|
+
import { isBuiltin } from "node:module";
|
|
3
4
|
import { rollupPluginCommonJsNamedExports } from "./rollup_plugin_commonjs_named_exports.js";
|
|
4
5
|
|
|
5
6
|
export const commonJsToJsModuleRaw = async ({
|
|
@@ -92,6 +93,16 @@ export const commonJsToJsModuleRaw = async ({
|
|
|
92
93
|
if (specifier.startsWith("node:")) {
|
|
93
94
|
return { id: specifier, external: true };
|
|
94
95
|
}
|
|
96
|
+
// Keep node builtins external when targeting node. A bare builtin
|
|
97
|
+
// (e.g. `require("util")` inside ws) must NOT be resolved into a
|
|
98
|
+
// userland package of the same name (a `util` polyfill hoisted into
|
|
99
|
+
// node_modules) — Node resolves the builtin, and that polyfill lacks
|
|
100
|
+
// Node-only APIs like util.types, so bundling it breaks at runtime.
|
|
101
|
+
// When converting builtins to browser equivalents this must stay off,
|
|
102
|
+
// so the polyfill plugin can do its job.
|
|
103
|
+
if (!convertBuiltinsToBrowser && isBuiltin(specifier)) {
|
|
104
|
+
return { id: `node:${specifier}`, external: true };
|
|
105
|
+
}
|
|
95
106
|
return null;
|
|
96
107
|
},
|
|
97
108
|
},
|