@jsenv/plugin-commonjs 2.0.0 → 2.0.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.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"test": "node --conditions=development ./scripts/test.mjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@jsenv/filesystem": "4.2.
|
|
27
|
+
"@jsenv/filesystem": "4.2.2",
|
|
28
28
|
"@jsenv/log": "3.3.4",
|
|
29
|
-
"@jsenv/url-meta": "8.
|
|
29
|
+
"@jsenv/url-meta": "8.1.0",
|
|
30
30
|
"@jsenv/urls": "1.2.8",
|
|
31
31
|
"@rollup/plugin-commonjs": "24.0.1",
|
|
32
32
|
"@rollup/plugin-json": "6.0.0",
|
package/src/cjs_to_esm.js
CHANGED
|
@@ -4,8 +4,6 @@ import { ensureWindowsDriveLetter } from "@jsenv/filesystem"
|
|
|
4
4
|
import {
|
|
5
5
|
setUrlExtension,
|
|
6
6
|
setUrlFilename,
|
|
7
|
-
urlIsInsideOf,
|
|
8
|
-
moveUrl,
|
|
9
7
|
urlToExtension,
|
|
10
8
|
urlToBasename,
|
|
11
9
|
} from "@jsenv/urls"
|
|
@@ -15,33 +13,26 @@ import { reuseOrCreateCompiledFile } from "./compile_cache/compiled_file_cache.j
|
|
|
15
13
|
export const commonJsToJsModule = ({
|
|
16
14
|
logLevel,
|
|
17
15
|
filesystemCache = true,
|
|
18
|
-
|
|
19
|
-
jsenvInternalDirectoryUrl,
|
|
16
|
+
compileCacheDirectoryUrl,
|
|
20
17
|
sourceFileUrl,
|
|
21
18
|
processEnvNodeEnv,
|
|
22
19
|
...rest
|
|
23
20
|
}) => {
|
|
24
21
|
if (filesystemCache) {
|
|
25
|
-
const compileDirectoryUrl = new URL(
|
|
26
|
-
"cjs_to_esm/",
|
|
27
|
-
jsenvInternalDirectoryUrl,
|
|
28
|
-
)
|
|
29
22
|
const compiledFileUrl = determineCompiledFileUrl({
|
|
30
23
|
url: sourceFileUrl,
|
|
31
|
-
|
|
32
|
-
compileDirectoryUrl,
|
|
24
|
+
compileCacheDirectoryUrl,
|
|
33
25
|
processEnvNodeEnv,
|
|
34
26
|
})
|
|
35
27
|
|
|
36
28
|
return reuseOrCreateCompiledFile({
|
|
37
29
|
logLevel,
|
|
38
|
-
|
|
30
|
+
compileCacheDirectoryUrl,
|
|
39
31
|
sourceFileUrl,
|
|
40
32
|
compiledFileUrl,
|
|
41
33
|
compile: async () => {
|
|
42
34
|
const { content, sourcemap } = await commonJsToJsModuleRaw({
|
|
43
35
|
logLevel,
|
|
44
|
-
rootDirectoryUrl,
|
|
45
36
|
sourceFileUrl,
|
|
46
37
|
processEnvNodeEnv,
|
|
47
38
|
...rest,
|
|
@@ -63,7 +54,6 @@ export const commonJsToJsModule = ({
|
|
|
63
54
|
}
|
|
64
55
|
return commonJsToJsModuleRaw({
|
|
65
56
|
logLevel,
|
|
66
|
-
rootDirectoryUrl,
|
|
67
57
|
sourceFileUrl,
|
|
68
58
|
...rest,
|
|
69
59
|
})
|
|
@@ -107,23 +97,15 @@ const extractCompileAssets = ({
|
|
|
107
97
|
|
|
108
98
|
const determineCompiledFileUrl = ({
|
|
109
99
|
url,
|
|
110
|
-
|
|
111
|
-
compileDirectoryUrl,
|
|
100
|
+
compileCacheDirectoryUrl,
|
|
112
101
|
processEnvNodeEnv,
|
|
113
102
|
}) => {
|
|
114
|
-
if (!urlIsInsideOf(url, rootDirectoryUrl)) {
|
|
115
|
-
const fsRootUrl = ensureWindowsDriveLetter("file:///", url)
|
|
116
|
-
url = `${rootDirectoryUrl}@fs/${url.slice(fsRootUrl.length)}`
|
|
117
|
-
}
|
|
118
103
|
if (processEnvNodeEnv) {
|
|
119
104
|
const basename = urlToBasename(url)
|
|
120
105
|
const extension = urlToExtension(url)
|
|
121
106
|
url = setUrlFilename(url, `${basename}.${processEnvNodeEnv}${extension}`)
|
|
122
107
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
to: compileDirectoryUrl,
|
|
127
|
-
preferAbsolute: true,
|
|
128
|
-
})
|
|
108
|
+
const fsRootUrl = ensureWindowsDriveLetter("file:///", url)
|
|
109
|
+
url = `${compileCacheDirectoryUrl}@fs/${url.slice(fsRootUrl.length)}`
|
|
110
|
+
return url
|
|
129
111
|
}
|
|
@@ -13,7 +13,7 @@ const { lockForResource } = createLockRegistry()
|
|
|
13
13
|
|
|
14
14
|
export const reuseOrCreateCompiledFile = async ({
|
|
15
15
|
logLevel,
|
|
16
|
-
|
|
16
|
+
compileCacheDirectoryUrl,
|
|
17
17
|
sourceFileUrl,
|
|
18
18
|
compiledFileUrl,
|
|
19
19
|
compileCacheStrategy,
|
|
@@ -21,7 +21,7 @@ export const reuseOrCreateCompiledFile = async ({
|
|
|
21
21
|
compile,
|
|
22
22
|
}) => {
|
|
23
23
|
const logger = createLogger({ logLevel })
|
|
24
|
-
await
|
|
24
|
+
await initCompileCacheDirectory({ logger, compileCacheDirectoryUrl })
|
|
25
25
|
sourceFileUrl = assertAndNormalizeFileUrl(sourceFileUrl)
|
|
26
26
|
if (typeof compile !== "function") {
|
|
27
27
|
throw new TypeError(`compile must be a function, got ${compile}`)
|
|
@@ -107,15 +107,18 @@ export const reuseOrCreateCompiledFile = async ({
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
const initalized = {}
|
|
110
|
-
const
|
|
111
|
-
|
|
110
|
+
const initCompileCacheDirectory = async ({
|
|
111
|
+
logger,
|
|
112
|
+
compileCacheDirectoryUrl,
|
|
113
|
+
}) => {
|
|
114
|
+
if (initalized[compileCacheDirectoryUrl]) {
|
|
112
115
|
return
|
|
113
116
|
}
|
|
114
|
-
initalized[
|
|
115
|
-
logger.debug(`check compile directory at ${
|
|
117
|
+
initalized[compileCacheDirectoryUrl] = true
|
|
118
|
+
logger.debug(`check compile directory at ${compileCacheDirectoryUrl}`)
|
|
116
119
|
const compileContextJsonFileUrl = new URL(
|
|
117
120
|
"./__compile_context__.json",
|
|
118
|
-
|
|
121
|
+
compileCacheDirectoryUrl,
|
|
119
122
|
)
|
|
120
123
|
const version = JSON.parse(
|
|
121
124
|
readFileSync(new URL("../../package.json", import.meta.url)),
|
|
@@ -132,7 +135,7 @@ const initCompileDirectory = async ({ logger, compileDirectoryUrl }) => {
|
|
|
132
135
|
} else {
|
|
133
136
|
logger.debug(`${UNICODE.INFO} create an empty directory`)
|
|
134
137
|
}
|
|
135
|
-
await ensureEmptyDirectory(
|
|
138
|
+
await ensureEmptyDirectory(compileCacheDirectoryUrl)
|
|
136
139
|
writeFileSync(
|
|
137
140
|
compileContextJsonFileUrl,
|
|
138
141
|
JSON.stringify({ version }, null, " "),
|
|
@@ -4,6 +4,8 @@ import { defaultLookupPackageScope } from "@jsenv/node-esm-resolution"
|
|
|
4
4
|
|
|
5
5
|
import { commonJsToJsModule } from "./cjs_to_esm.js"
|
|
6
6
|
|
|
7
|
+
const compileCacheDirectoryUrl = new URL("../.cache/", import.meta.url)
|
|
8
|
+
|
|
7
9
|
export const jsenvPluginCommonJs = ({
|
|
8
10
|
name = "jsenv:commonjs",
|
|
9
11
|
logLevel,
|
|
@@ -75,8 +77,7 @@ export const jsenvPluginCommonJs = ({
|
|
|
75
77
|
)
|
|
76
78
|
const { content, sourcemap, isValid } = await commonJsToJsModule({
|
|
77
79
|
logLevel,
|
|
78
|
-
|
|
79
|
-
jsenvInternalDirectoryUrl: context.jsenvInternalDirectoryUrl,
|
|
80
|
+
compileCacheDirectoryUrl,
|
|
80
81
|
sourceFileUrl: commonJsUrlInfo.url,
|
|
81
82
|
browsers: !nodeRuntimeEnabled,
|
|
82
83
|
processEnvNodeEnv: context.dev ? "development" : "production",
|