@jsenv/plugin-commonjs 2.9.16 → 2.10.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/plugin-commonjs",
3
- "version": "2.9.16",
3
+ "version": "2.10.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -21,15 +21,15 @@
21
21
  "/src/"
22
22
  ],
23
23
  "dependencies": {
24
- "@jsenv/filesystem": "4.13.4",
25
- "@jsenv/humanize": "1.2.8",
26
- "@jsenv/url-meta": "8.5.3",
27
- "@jsenv/urls": "2.6.0",
24
+ "@jsenv/filesystem": "4.14.0",
25
+ "@jsenv/humanize": "1.3.0",
26
+ "@jsenv/url-meta": "8.5.4",
27
+ "@jsenv/urls": "2.6.1",
28
28
  "@rollup/plugin-commonjs": "28.0.2",
29
29
  "@rollup/plugin-json": "6.1.0",
30
30
  "@rollup/plugin-node-resolve": "16.0.0",
31
31
  "@rollup/plugin-replace": "6.0.2",
32
- "cjs-module-lexer": "1.4.1",
32
+ "cjs-module-lexer": "2.1.0",
33
33
  "is-valid-identifier": "2.0.2",
34
34
  "resolve": "1.22.10",
35
35
  "rollup": "4.31.0",
@@ -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,