@jsenv/plugin-commonjs 2.10.14 → 2.11.1
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 +4 -5
- package/src/cjs_to_esm_raw.js +0 -17
- package/src/jsenv_plugin_commonjs.js +55 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-commonjs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/jsenv/core",
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
"/src/"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@jsenv/filesystem": "4.15.
|
|
22
|
+
"@jsenv/filesystem": "4.15.6",
|
|
23
23
|
"@jsenv/humanize": "1.6.0",
|
|
24
|
-
"@jsenv/node-esm-resolution": "1.2.
|
|
24
|
+
"@jsenv/node-esm-resolution": "1.2.7",
|
|
25
25
|
"@jsenv/url-meta": "8.5.7",
|
|
26
|
-
"@jsenv/urls": "2.9.
|
|
26
|
+
"@jsenv/urls": "2.9.1",
|
|
27
27
|
"@rollup/plugin-commonjs": "28.0.3",
|
|
28
28
|
"@rollup/plugin-json": "6.1.0",
|
|
29
29
|
"@rollup/plugin-node-resolve": "16.0.1",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
"is-valid-identifier": "2.0.2",
|
|
33
33
|
"resolve": "1.22.10",
|
|
34
34
|
"rollup": "4.40.1",
|
|
35
|
-
"rollup-plugin-node-globals": "1.4.0",
|
|
36
35
|
"rollup-plugin-polyfill-node": "0.13.0"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
package/src/cjs_to_esm_raw.js
CHANGED
|
@@ -11,8 +11,6 @@ export const commonJsToJsModuleRaw = async ({
|
|
|
11
11
|
replaceGlobalFilename = browsers,
|
|
12
12
|
replaceGlobalDirname = browsers,
|
|
13
13
|
replaceProcessEnvNodeEnv = browsers,
|
|
14
|
-
replaceProcess = browsers,
|
|
15
|
-
replaceBuffer = browsers,
|
|
16
14
|
processEnvNodeEnv = process.env.NODE_ENV,
|
|
17
15
|
replaceMap = {},
|
|
18
16
|
convertBuiltinsToBrowser = browsers,
|
|
@@ -82,10 +80,6 @@ export const commonJsToJsModuleRaw = async ({
|
|
|
82
80
|
requireReturnsDefault: "auto",
|
|
83
81
|
});
|
|
84
82
|
|
|
85
|
-
const { default: createNodeGlobalRollupPlugin } = await import(
|
|
86
|
-
"rollup-plugin-node-globals"
|
|
87
|
-
);
|
|
88
|
-
|
|
89
83
|
const commonJsNamedExportsRollupPlugin = rollupPluginCommonJsNamedExports({
|
|
90
84
|
logger,
|
|
91
85
|
});
|
|
@@ -111,17 +105,6 @@ export const commonJsToJsModuleRaw = async ({
|
|
|
111
105
|
replaceRollupPlugin,
|
|
112
106
|
commonJsRollupPlugin,
|
|
113
107
|
commonJsNamedExportsRollupPlugin,
|
|
114
|
-
...(replaceProcess || replaceBuffer
|
|
115
|
-
? [
|
|
116
|
-
createNodeGlobalRollupPlugin({
|
|
117
|
-
global: false, // handled by replaceMap
|
|
118
|
-
dirname: false, // handled by replaceMap
|
|
119
|
-
filename: false, // handled by replaceMap
|
|
120
|
-
process: replaceProcess,
|
|
121
|
-
buffer: replaceBuffer,
|
|
122
|
-
}),
|
|
123
|
-
]
|
|
124
|
-
: []),
|
|
125
108
|
...(convertBuiltinsToBrowser
|
|
126
109
|
? [
|
|
127
110
|
rollupPluginNodePolyfills({
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
// for reference this is how Node.js detect module format https://github.com/nodejs/node/blob/a446e3bdc96b0f263fd363ce89b9c739b066240f/lib/internal/modules/esm/get_format.js#L1
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
applyNodeEsmResolution,
|
|
4
|
+
defaultLookupPackageScope,
|
|
5
|
+
} from "@jsenv/node-esm-resolution";
|
|
3
6
|
import { URL_META } from "@jsenv/url-meta";
|
|
4
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
injectQueryParams,
|
|
9
|
+
pathnameToExtension,
|
|
10
|
+
urlToBasename,
|
|
11
|
+
urlToExtension,
|
|
12
|
+
} from "@jsenv/urls";
|
|
5
13
|
import { commonJsToJsModule } from "./cjs_to_esm.js";
|
|
6
14
|
|
|
7
15
|
const compileCacheDirectoryUrlDefault = new URL("../.cache/", import.meta.url);
|
|
@@ -38,10 +46,23 @@ export const jsenvPluginCommonJs = ({
|
|
|
38
46
|
let associations;
|
|
39
47
|
let nodeRuntimeEnabled;
|
|
40
48
|
|
|
49
|
+
const packageConditionsConfig = {};
|
|
50
|
+
const onIncludedUrl = (url) => {
|
|
51
|
+
url = String(url);
|
|
52
|
+
if (url.endsWith(".map")) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
packageConditionsConfig[url] = ["node", "import", "require"];
|
|
56
|
+
};
|
|
57
|
+
|
|
41
58
|
return {
|
|
42
59
|
name,
|
|
43
60
|
appliesDuring: "*",
|
|
44
|
-
init: (
|
|
61
|
+
init: (kitchenContext) => {
|
|
62
|
+
const { rootDirectoryUrl, outDirectoryUrl, runtimeCompat } =
|
|
63
|
+
kitchenContext;
|
|
64
|
+
kitchenContext.packageConditionsConfig = packageConditionsConfig;
|
|
65
|
+
|
|
45
66
|
associations = URL_META.resolveAssociations(
|
|
46
67
|
{
|
|
47
68
|
commonjs: {
|
|
@@ -49,7 +70,37 @@ export const jsenvPluginCommonJs = ({
|
|
|
49
70
|
"/**/*.map": false,
|
|
50
71
|
},
|
|
51
72
|
},
|
|
52
|
-
|
|
73
|
+
(pattern) => {
|
|
74
|
+
if (!isBareSpecifier(pattern)) {
|
|
75
|
+
const url = new URL(pattern, rootDirectoryUrl);
|
|
76
|
+
onIncludedUrl(url);
|
|
77
|
+
return url;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
if (!pattern.endsWith("/") && !pathnameToExtension(pattern)) {
|
|
81
|
+
pattern = `${pattern}/`;
|
|
82
|
+
}
|
|
83
|
+
if (pattern.endsWith("/")) {
|
|
84
|
+
// avoid package path not exported
|
|
85
|
+
const { packageDirectoryUrl } = applyNodeEsmResolution({
|
|
86
|
+
specifier: pattern.slice(0, -1),
|
|
87
|
+
parentUrl: rootDirectoryUrl,
|
|
88
|
+
});
|
|
89
|
+
onIncludedUrl(packageDirectoryUrl);
|
|
90
|
+
return packageDirectoryUrl;
|
|
91
|
+
}
|
|
92
|
+
const { url } = applyNodeEsmResolution({
|
|
93
|
+
specifier: pattern,
|
|
94
|
+
parentUrl: rootDirectoryUrl,
|
|
95
|
+
});
|
|
96
|
+
onIncludedUrl(url);
|
|
97
|
+
return url;
|
|
98
|
+
} catch {
|
|
99
|
+
const url = new URL(pattern, rootDirectoryUrl);
|
|
100
|
+
onIncludedUrl(url);
|
|
101
|
+
return url;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
53
104
|
);
|
|
54
105
|
nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
55
106
|
if (compileCacheDirectoryUrl === undefined) {
|