@jsenv/plugin-commonjs 2.8.29 → 2.9.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/plugin-commonjs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"/src/"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@jsenv/filesystem": "4.10.
|
|
24
|
+
"@jsenv/filesystem": "4.10.12",
|
|
25
25
|
"@jsenv/humanize": "1.2.8",
|
|
26
26
|
"@jsenv/url-meta": "8.5.2",
|
|
27
|
-
"@jsenv/urls": "2.5.
|
|
27
|
+
"@jsenv/urls": "2.5.3",
|
|
28
28
|
"@rollup/plugin-commonjs": "28.0.1",
|
|
29
29
|
"@rollup/plugin-json": "6.1.0",
|
|
30
30
|
"@rollup/plugin-node-resolve": "15.3.0",
|
package/src/cjs_to_esm_raw.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createLogger } from "@jsenv/humanize";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { urlToFileSystemPath } from "@jsenv/urls";
|
|
4
3
|
import { rollupPluginCommonJsNamedExports } from "./rollup_plugin_commonjs_named_exports.js";
|
|
5
4
|
|
|
6
5
|
export const commonJsToJsModuleRaw = async ({
|
|
@@ -28,7 +27,7 @@ export const commonJsToJsModuleRaw = async ({
|
|
|
28
27
|
`compatible only with file:// protocol, got ${sourceFileUrl}`,
|
|
29
28
|
);
|
|
30
29
|
}
|
|
31
|
-
const sourceFilePath =
|
|
30
|
+
const sourceFilePath = urlToFileSystemPath(sourceFileUrl);
|
|
32
31
|
|
|
33
32
|
const { nodeResolve } = await import("@rollup/plugin-node-resolve");
|
|
34
33
|
const nodeResolveRollupPlugin = nodeResolve({
|
|
@@ -160,7 +159,7 @@ export const commonJsToJsModuleRaw = async ({
|
|
|
160
159
|
sourcemap: true,
|
|
161
160
|
sourcemapExcludeSources,
|
|
162
161
|
exports: "named",
|
|
163
|
-
dir:
|
|
162
|
+
dir: urlToFileSystemPath(abstractDirUrl),
|
|
164
163
|
sourcemapPathTransform: (relativePath) => {
|
|
165
164
|
const sourceUrl = new URL(relativePath, abstractDirUrl).href;
|
|
166
165
|
return sourceUrl;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { bufferToEtag, writeFileSync } from "@jsenv/filesystem";
|
|
2
|
-
import { urlToRelativeUrl } from "@jsenv/urls";
|
|
2
|
+
import { urlToFileSystemPath, urlToRelativeUrl } from "@jsenv/urls";
|
|
3
3
|
import { existsSync, utimesSync } from "node:fs";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
4
|
|
|
6
5
|
export const updateCompileCache = ({
|
|
7
6
|
logger,
|
|
@@ -38,7 +37,9 @@ cache will be reused even if one of the source file is modified
|
|
|
38
37
|
${filesRemoved.join(`\n`)}`);
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
logger.debug(
|
|
40
|
+
logger.debug(
|
|
41
|
+
`write compiled file at ${urlToFileSystemPath(compiledFileUrl)}`,
|
|
42
|
+
);
|
|
42
43
|
writeFileSync(compiledFileUrl, content, {
|
|
43
44
|
fileLikelyNotFound: isNew,
|
|
44
45
|
});
|
|
@@ -50,7 +51,9 @@ ${filesRemoved.join(`\n`)}`);
|
|
|
50
51
|
|
|
51
52
|
const assetInfos = {};
|
|
52
53
|
Object.keys(assets).forEach((assetUrl) => {
|
|
53
|
-
logger.debug(
|
|
54
|
+
logger.debug(
|
|
55
|
+
`write compiled file asset at ${urlToFileSystemPath(assetUrl)}`,
|
|
56
|
+
);
|
|
54
57
|
const asset = assets[assetUrl];
|
|
55
58
|
writeFileSync(assetUrl, asset.content, {
|
|
56
59
|
fileLikelyNotFound: isNew,
|
|
@@ -82,7 +85,7 @@ ${filesRemoved.join(`\n`)}`);
|
|
|
82
85
|
};
|
|
83
86
|
}
|
|
84
87
|
logger.debug(
|
|
85
|
-
`write compiled file info at ${
|
|
88
|
+
`write compiled file info at ${urlToFileSystemPath(compileInfoFileUrl)}`,
|
|
86
89
|
);
|
|
87
90
|
writeFileSync(
|
|
88
91
|
compileInfoFileUrl,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { bufferToEtag } from "@jsenv/filesystem";
|
|
2
|
-
import { readFileSync
|
|
1
|
+
import { bufferToEtag, readEntryStatSync } from "@jsenv/filesystem";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
3
|
|
|
4
4
|
export const validateCompileCache = ({
|
|
5
5
|
compiledFileUrl,
|
|
@@ -94,7 +94,7 @@ const validateCompiledFile = ({
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
if (compileCacheStrategy === "mtime" && lastModificationTime) {
|
|
97
|
-
const stats =
|
|
97
|
+
const stats = readEntryStatSync(new URL(compiledFileUrl));
|
|
98
98
|
const mtime = Math.floor(stats.mtimeMs);
|
|
99
99
|
validity.data.mtime = mtime;
|
|
100
100
|
let ifModifiedSinceDate;
|
|
@@ -78,17 +78,13 @@ export const jsenvPluginCommonJs = ({
|
|
|
78
78
|
return turnIntoJsModuleProxy(reference);
|
|
79
79
|
},
|
|
80
80
|
fetchUrlContent: async (urlInfo) => {
|
|
81
|
-
const commonJsUrlInfo = urlInfo.getWithoutSearchParam(
|
|
82
|
-
"cjs_as_js_module",
|
|
83
|
-
{
|
|
84
|
-
// during this fetch we don't want to alter the original file
|
|
85
|
-
// so we consider it as text
|
|
86
|
-
expectedType: "text",
|
|
87
|
-
},
|
|
88
|
-
);
|
|
81
|
+
const commonJsUrlInfo = urlInfo.getWithoutSearchParam("cjs_as_js_module");
|
|
89
82
|
if (!commonJsUrlInfo) {
|
|
90
83
|
return null;
|
|
91
84
|
}
|
|
85
|
+
// during this fetch we don't want to alter the original file
|
|
86
|
+
// so we consider it as text
|
|
87
|
+
commonJsUrlInfo.type = "text";
|
|
92
88
|
await commonJsUrlInfo.cook();
|
|
93
89
|
const nodeRuntimeEnabled = Object.keys(
|
|
94
90
|
urlInfo.context.runtimeCompat,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// https://github.com/snowpackjs/snowpack/blob/main/esinstall/src/rollup-plugins/rollup-plugin-wrap-install-targets.ts
|
|
2
2
|
|
|
3
|
+
import { urlToFileSystemPath } from "@jsenv/urls";
|
|
3
4
|
import { init, parse } from "cjs-module-lexer";
|
|
4
5
|
import isValidIdentifier from "is-valid-identifier";
|
|
5
6
|
import { readFileSync } from "node:fs";
|
|
6
7
|
import path from "node:path";
|
|
7
|
-
import {
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
8
9
|
import { Worker } from "node:worker_threads";
|
|
9
10
|
import resolve from "resolve";
|
|
10
11
|
|
|
@@ -101,7 +102,7 @@ const detectStaticExports = ({ logger, filePath, visited = new Set() }) => {
|
|
|
101
102
|
if (reexports.length > 0) {
|
|
102
103
|
reexports.forEach((reexport) => {
|
|
103
104
|
const reExportedFilePath = resolve.sync(reexport, {
|
|
104
|
-
basedir:
|
|
105
|
+
basedir: urlToFileSystemPath(new URL("./", pathToFileURL(filePath))),
|
|
105
106
|
});
|
|
106
107
|
const staticExports = detectStaticExports({
|
|
107
108
|
logger,
|