@jsenv/plugin-commonjs 2.9.17 → 2.10.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 +10 -9
- package/src/jsenv_plugin_commonjs.js +13 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-commonjs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,19 +20,20 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"/src/"
|
|
22
22
|
],
|
|
23
|
+
"sideEffects": false,
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@jsenv/filesystem": "4.
|
|
25
|
-
"@jsenv/humanize": "1.
|
|
26
|
-
"@jsenv/url-meta": "8.5.
|
|
27
|
-
"@jsenv/urls": "2.6.
|
|
28
|
-
"@rollup/plugin-commonjs": "28.0.
|
|
25
|
+
"@jsenv/filesystem": "4.14.1",
|
|
26
|
+
"@jsenv/humanize": "1.3.1",
|
|
27
|
+
"@jsenv/url-meta": "8.5.4",
|
|
28
|
+
"@jsenv/urls": "2.6.2",
|
|
29
|
+
"@rollup/plugin-commonjs": "28.0.3",
|
|
29
30
|
"@rollup/plugin-json": "6.1.0",
|
|
30
|
-
"@rollup/plugin-node-resolve": "16.0.
|
|
31
|
+
"@rollup/plugin-node-resolve": "16.0.1",
|
|
31
32
|
"@rollup/plugin-replace": "6.0.2",
|
|
32
|
-
"cjs-module-lexer": "1.
|
|
33
|
+
"cjs-module-lexer": "2.1.0",
|
|
33
34
|
"is-valid-identifier": "2.0.2",
|
|
34
35
|
"resolve": "1.22.10",
|
|
35
|
-
"rollup": "4.
|
|
36
|
+
"rollup": "4.35.0",
|
|
36
37
|
"rollup-plugin-node-globals": "1.4.0",
|
|
37
38
|
"rollup-plugin-polyfill-node": "0.13.0"
|
|
38
39
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
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
|
|
1
2
|
import { defaultLookupPackageScope } from "@jsenv/node-esm-resolution";
|
|
2
3
|
import { URL_META } from "@jsenv/url-meta";
|
|
3
4
|
import { injectQueryParams, urlToBasename, urlToExtension } from "@jsenv/urls";
|
|
@@ -11,7 +12,7 @@ export const jsenvPluginCommonJs = ({
|
|
|
11
12
|
include,
|
|
12
13
|
compileCacheDirectoryUrl,
|
|
13
14
|
dev,
|
|
14
|
-
}) => {
|
|
15
|
+
} = {}) => {
|
|
15
16
|
const markAsJsModuleProxy = (reference) => {
|
|
16
17
|
reference.expectedType = "js_module";
|
|
17
18
|
const onwerUrlExtension = urlToExtension(reference.ownerUrlInfo.url);
|
|
@@ -35,11 +36,12 @@ export const jsenvPluginCommonJs = ({
|
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
let associations;
|
|
39
|
+
let nodeRuntimeEnabled;
|
|
38
40
|
|
|
39
41
|
return {
|
|
40
42
|
name,
|
|
41
43
|
appliesDuring: "*",
|
|
42
|
-
init: ({ rootDirectoryUrl }) => {
|
|
44
|
+
init: ({ rootDirectoryUrl, outDirectoryUrl, runtimeCompat }) => {
|
|
43
45
|
associations = URL_META.resolveAssociations(
|
|
44
46
|
{
|
|
45
47
|
commonjs: {
|
|
@@ -49,6 +51,15 @@ export const jsenvPluginCommonJs = ({
|
|
|
49
51
|
},
|
|
50
52
|
rootDirectoryUrl,
|
|
51
53
|
);
|
|
54
|
+
nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
|
|
55
|
+
if (compileCacheDirectoryUrl === undefined) {
|
|
56
|
+
if (outDirectoryUrl) {
|
|
57
|
+
compileCacheDirectoryUrl = new URL("./cjs_to_esm/", outDirectoryUrl)
|
|
58
|
+
.href;
|
|
59
|
+
} else {
|
|
60
|
+
compileCacheDirectoryUrl = compileCacheDirectoryUrlDefault;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
52
63
|
},
|
|
53
64
|
redirectReference: (reference) => {
|
|
54
65
|
if (reference.type === "sourcemap_comment") {
|
|
@@ -86,19 +97,6 @@ export const jsenvPluginCommonJs = ({
|
|
|
86
97
|
// so we consider it as text
|
|
87
98
|
commonJsUrlInfo.type = "text";
|
|
88
99
|
await commonJsUrlInfo.cook();
|
|
89
|
-
const nodeRuntimeEnabled = Object.keys(
|
|
90
|
-
urlInfo.context.runtimeCompat,
|
|
91
|
-
).includes("node");
|
|
92
|
-
if (compileCacheDirectoryUrl === undefined) {
|
|
93
|
-
if (urlInfo.context.outDirectoryUrl) {
|
|
94
|
-
compileCacheDirectoryUrl = new URL(
|
|
95
|
-
"./cjs_to_esm/",
|
|
96
|
-
urlInfo.context.outDirectoryUrl,
|
|
97
|
-
).href;
|
|
98
|
-
} else {
|
|
99
|
-
compileCacheDirectoryUrl = compileCacheDirectoryUrlDefault;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
100
|
const { content, sourcemap, isValid } = await commonJsToJsModule({
|
|
103
101
|
logLevel,
|
|
104
102
|
compileCacheDirectoryUrl,
|