@jsenv/plugin-commonjs 2.3.1 → 2.4.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 +1 -1
- package/src/jsenv_plugin_commonjs.js +28 -6
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { URL_META } from "@jsenv/url-meta";
|
|
2
|
-
import { injectQueryParams, urlToExtension } from "@jsenv/urls";
|
|
2
|
+
import { injectQueryParams, urlToExtension, urlToBasename } from "@jsenv/urls";
|
|
3
3
|
import { defaultLookupPackageScope } from "@jsenv/node-esm-resolution";
|
|
4
4
|
|
|
5
5
|
import { commonJsToJsModule } from "./cjs_to_esm.js";
|
|
@@ -15,11 +15,16 @@ export const jsenvPluginCommonJs = ({
|
|
|
15
15
|
}) => {
|
|
16
16
|
const markAsJsModuleProxy = (reference) => {
|
|
17
17
|
reference.expectedType = "js_module";
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
)
|
|
18
|
+
const onwerUrlExtension = urlToExtension(reference.ownerUrlInfo.url);
|
|
19
|
+
const referenceUrlExtension = urlToExtension(reference.url);
|
|
20
|
+
if (referenceUrlExtension !== onwerUrlExtension) {
|
|
21
|
+
const packageFileUrl = defaultLookupPackageScope(reference.url);
|
|
22
|
+
if (packageFileUrl) {
|
|
23
|
+
const basename = isBareSpecifier(reference.specifier)
|
|
24
|
+
? reference.specifier
|
|
25
|
+
: urlToBasename(reference.url);
|
|
26
|
+
reference.filename = `${basename}${onwerUrlExtension}`;
|
|
27
|
+
}
|
|
23
28
|
}
|
|
24
29
|
};
|
|
25
30
|
const turnIntoJsModuleProxy = (reference) => {
|
|
@@ -108,3 +113,20 @@ export const jsenvPluginCommonJs = ({
|
|
|
108
113
|
},
|
|
109
114
|
};
|
|
110
115
|
};
|
|
116
|
+
|
|
117
|
+
const isBareSpecifier = (specifier) => {
|
|
118
|
+
if (
|
|
119
|
+
specifier[0] === "/" ||
|
|
120
|
+
specifier.startsWith("./") ||
|
|
121
|
+
specifier.startsWith("../")
|
|
122
|
+
) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
// eslint-disable-next-line no-new
|
|
127
|
+
new URL(specifier);
|
|
128
|
+
return false;
|
|
129
|
+
} catch (e) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
};
|