@jsenv/plugin-commonjs 2.1.1 → 2.3.0
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 +6 -6
- package/src/jsenv_plugin_commonjs.js +17 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-commonjs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@jsenv/filesystem": "4.2.
|
|
27
|
+
"@jsenv/filesystem": "4.2.4",
|
|
28
28
|
"@jsenv/log": "3.4.0",
|
|
29
29
|
"@jsenv/url-meta": "8.1.0",
|
|
30
|
-
"@jsenv/urls": "2.
|
|
31
|
-
"@rollup/plugin-commonjs": "25.0.
|
|
30
|
+
"@jsenv/urls": "2.1.0",
|
|
31
|
+
"@rollup/plugin-commonjs": "25.0.2",
|
|
32
32
|
"@rollup/plugin-json": "6.0.0",
|
|
33
33
|
"@rollup/plugin-node-resolve": "15.1.0",
|
|
34
34
|
"@rollup/plugin-replace": "5.0.2",
|
|
35
|
-
"cjs-module-lexer": "1.2.
|
|
35
|
+
"cjs-module-lexer": "1.2.3",
|
|
36
36
|
"is-valid-identifier": "2.0.2",
|
|
37
37
|
"resolve": "1.22.2",
|
|
38
|
-
"rollup": "3.
|
|
38
|
+
"rollup": "3.26.2",
|
|
39
39
|
"rollup-plugin-node-globals": "1.4.0",
|
|
40
40
|
"rollup-plugin-polyfill-node": "0.12.0",
|
|
41
41
|
"vm2": "3.9.19"
|
|
@@ -4,19 +4,21 @@ import { defaultLookupPackageScope } from "@jsenv/node-esm-resolution";
|
|
|
4
4
|
|
|
5
5
|
import { commonJsToJsModule } from "./cjs_to_esm.js";
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const compileCacheDirectoryUrlDefault = new URL("../.cache/", import.meta.url);
|
|
8
8
|
|
|
9
9
|
export const jsenvPluginCommonJs = ({
|
|
10
10
|
name = "jsenv:commonjs",
|
|
11
11
|
logLevel,
|
|
12
12
|
include,
|
|
13
|
+
compileCacheDirectoryUrl = compileCacheDirectoryUrlDefault,
|
|
14
|
+
dev,
|
|
13
15
|
}) => {
|
|
14
16
|
const markAsJsModuleProxy = (reference) => {
|
|
15
17
|
reference.expectedType = "js_module";
|
|
16
18
|
const packageFileUrl = defaultLookupPackageScope(reference.url);
|
|
17
19
|
if (packageFileUrl) {
|
|
18
20
|
reference.filename = `${reference.specifier}${urlToExtension(
|
|
19
|
-
reference.
|
|
21
|
+
reference.ownerUrlInfo.url,
|
|
20
22
|
)}`;
|
|
21
23
|
}
|
|
22
24
|
};
|
|
@@ -56,31 +58,29 @@ export const jsenvPluginCommonJs = ({
|
|
|
56
58
|
reference.data.commonjs = commonjs;
|
|
57
59
|
return turnIntoJsModuleProxy(reference);
|
|
58
60
|
},
|
|
59
|
-
fetchUrlContent: async (urlInfo
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
context,
|
|
64
|
-
searchParam: "cjs_as_js_module",
|
|
61
|
+
fetchUrlContent: async (urlInfo) => {
|
|
62
|
+
const commonJsUrlInfo = urlInfo.getWithoutSearchParam(
|
|
63
|
+
"cjs_as_js_module",
|
|
64
|
+
{
|
|
65
65
|
// during this fetch we don't want to alter the original file
|
|
66
66
|
// so we consider it as text
|
|
67
67
|
expectedType: "text",
|
|
68
|
-
}
|
|
69
|
-
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
if (!commonJsUrlInfo) {
|
|
70
71
|
return null;
|
|
71
72
|
}
|
|
72
|
-
await
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"node",
|
|
77
|
-
);
|
|
73
|
+
await commonJsUrlInfo.fetchContent();
|
|
74
|
+
const nodeRuntimeEnabled = Object.keys(
|
|
75
|
+
urlInfo.context.runtimeCompat,
|
|
76
|
+
).includes("node");
|
|
78
77
|
const { content, sourcemap, isValid } = await commonJsToJsModule({
|
|
79
78
|
logLevel,
|
|
80
79
|
compileCacheDirectoryUrl,
|
|
81
80
|
sourceFileUrl: commonJsUrlInfo.url,
|
|
82
81
|
browsers: !nodeRuntimeEnabled,
|
|
83
|
-
processEnvNodeEnv:
|
|
82
|
+
processEnvNodeEnv:
|
|
83
|
+
dev || urlInfo.context.dev ? "development" : "production",
|
|
84
84
|
...urlInfo.data.commonjs,
|
|
85
85
|
});
|
|
86
86
|
if (isValid) {
|