@jsenv/core 21.1.0 → 22.0.3
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/dist/.DS_Store +0 -0
- package/dist/jsenv_browser_system.js.map +16 -16
- package/{LICENSE → license} +0 -0
- package/main.js +0 -1
- package/package.json +50 -45
- package/readme.md +74 -51
- package/src/buildProject.js +1 -2
- package/src/commonJsToJavaScriptModule.js +88 -39
- package/src/executeTestPlan.js +2 -0
- package/src/internal/building/createJsenvRollupPlugin.js +2 -2
- package/src/internal/compiling/babel_plugins.js +44 -0
- package/src/internal/compiling/createCompiledFileService.js +14 -9
- package/src/internal/compiling/html_source_file_service.js +1 -1
- package/src/internal/compiling/js-compilation-service/babelHelper.js +10 -2
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +39 -40
- package/src/internal/compiling/js-compilation-service/transformBabelHelperToImportBabelPlugin.js +3 -0
- package/src/internal/compiling/jsenvCompilerForImportmap.js +2 -1
- package/src/internal/compiling/load_babel_plugin_map_from_file.js +49 -0
- package/src/internal/compiling/rollup_plugin_commonjs_named_exports.js +186 -0
- package/src/internal/compiling/startCompileServer.js +79 -4
- package/src/internal/executing/coverage/relativeUrlToEmptyCoverage.js +21 -13
- package/src/internal/executing/executePlan.js +8 -10
- package/src/internal/generateGroupMap/generateGroupMap.js +0 -12
- package/src/internal/generateGroupMap/jsenvBabelPluginCompatMap.js +3 -0
- package/src/internal/import-resolution/import-resolver-importmap.js +1 -1
- package/src/internal/import-resolution/import-resolver-node.js +1 -1
- package/src/internal/runtime/createBrowserRuntime/createBrowserRuntime.js +1 -1
- package/src/internal/runtime/createNodeRuntime/createNodeSystem.js +6 -2
- package/src/internal/minimalBabelPluginArray.js +0 -16
- package/src/jsenvBabelPluginMap.js +0 -76
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// https://github.com/snowpackjs/snowpack/blob/main/esinstall/src/rollup-plugins/rollup-plugin-wrap-install-targets.ts
|
|
2
|
+
|
|
3
|
+
import { readFileSync } from "node:fs"
|
|
4
|
+
import { fileURLToPath } from "node:url"
|
|
5
|
+
import { VM as VM2 } from "vm2"
|
|
6
|
+
import isValidIdentifier from "is-valid-identifier"
|
|
7
|
+
import resolve from "resolve"
|
|
8
|
+
import { init, parse } from "cjs-module-lexer"
|
|
9
|
+
import { fileSystemPathToUrl } from "@jsenv/filesystem"
|
|
10
|
+
|
|
11
|
+
export const rollupPluginCommonJsNamedExports = ({ logger }) => {
|
|
12
|
+
const inputSummaries = {}
|
|
13
|
+
const cjsScannedNamedExports = {}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
async buildStart({ input }) {
|
|
17
|
+
await init()
|
|
18
|
+
|
|
19
|
+
Object.keys(input).forEach((key) => {
|
|
20
|
+
const inputFilePath = input[key]
|
|
21
|
+
const inputFileUrl = fileSystemPathToUrl(inputFilePath)
|
|
22
|
+
inputSummaries[inputFileUrl] = {
|
|
23
|
+
all: false,
|
|
24
|
+
default: false,
|
|
25
|
+
namespace: false,
|
|
26
|
+
named: [],
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const cjsExports =
|
|
30
|
+
detectStaticExports({ logger, fileUrl: inputFileUrl }) ||
|
|
31
|
+
detectExportsUsingSandboxedRuntime({ logger, fileUrl: inputFileUrl })
|
|
32
|
+
|
|
33
|
+
if (cjsExports && cjsExports.length) {
|
|
34
|
+
cjsScannedNamedExports[inputFileUrl] = cjsExports
|
|
35
|
+
}
|
|
36
|
+
input[key] = `jsenv:${inputFileUrl}`
|
|
37
|
+
})
|
|
38
|
+
},
|
|
39
|
+
resolveId(source) {
|
|
40
|
+
if (source.startsWith("jsenv:")) {
|
|
41
|
+
return source
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return null
|
|
45
|
+
},
|
|
46
|
+
load(id) {
|
|
47
|
+
if (!id.startsWith("jsenv:")) {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const inputFileUrl = id.substring("jsenv:".length)
|
|
52
|
+
const inputSummary = inputSummaries[inputFileUrl]
|
|
53
|
+
let uniqueNamedExports = inputSummary.named
|
|
54
|
+
const scannedNamedExports = cjsScannedNamedExports[inputFileUrl]
|
|
55
|
+
if (scannedNamedExports) {
|
|
56
|
+
uniqueNamedExports = scannedNamedExports || []
|
|
57
|
+
inputSummary.default = true
|
|
58
|
+
}
|
|
59
|
+
const codeForExports = generateCodeForExports({
|
|
60
|
+
uniqueNamedExports,
|
|
61
|
+
inputSummary,
|
|
62
|
+
inputFileUrl,
|
|
63
|
+
})
|
|
64
|
+
return codeForExports
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Attempt #1: Static analysis: Lower Fidelity, but faster.
|
|
71
|
+
* Do our best job to statically scan a file for named exports. This uses "cjs-module-lexer", the
|
|
72
|
+
* same CJS export scanner that Node.js uses internally. Very fast, but only works on some modules,
|
|
73
|
+
* depending on how they were build/written/compiled.
|
|
74
|
+
*/
|
|
75
|
+
const detectStaticExports = ({ logger, fileUrl, visited = new Set() }) => {
|
|
76
|
+
const isMainEntrypoint = visited.size === 0
|
|
77
|
+
// Prevent infinite loops via circular dependencies.
|
|
78
|
+
if (visited.has(fileUrl)) {
|
|
79
|
+
return []
|
|
80
|
+
}
|
|
81
|
+
visited.add(fileUrl)
|
|
82
|
+
|
|
83
|
+
const fileContents = readFileSync(new URL(fileUrl), "utf8")
|
|
84
|
+
try {
|
|
85
|
+
const { exports, reexports } = parse(fileContents)
|
|
86
|
+
// If re-exports were detected (`exports.foo = require(...)`) then resolve them here.
|
|
87
|
+
let resolvedReexports = []
|
|
88
|
+
if (reexports.length > 0) {
|
|
89
|
+
reexports.forEach((reexport) => {
|
|
90
|
+
const reExportedFilePath = resolve.sync(reexport, {
|
|
91
|
+
basedir: fileURLToPath(new URL("./", fileUrl)),
|
|
92
|
+
})
|
|
93
|
+
const reExportedFileUrl = fileSystemPathToUrl(reExportedFilePath)
|
|
94
|
+
const staticExports = detectStaticExports({
|
|
95
|
+
logger,
|
|
96
|
+
fileUrl: reExportedFileUrl,
|
|
97
|
+
visited,
|
|
98
|
+
})
|
|
99
|
+
if (staticExports) {
|
|
100
|
+
resolvedReexports = [...resolvedReexports, ...staticExports]
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
const resolvedExports = Array.from(
|
|
105
|
+
new Set([...exports, ...resolvedReexports]),
|
|
106
|
+
).filter(isValidNamedExport)
|
|
107
|
+
|
|
108
|
+
if (isMainEntrypoint && resolvedExports.length === 0) {
|
|
109
|
+
return undefined
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return resolvedExports
|
|
113
|
+
} catch (err) {
|
|
114
|
+
// Safe to ignore, this is usually due to the file not being CJS.
|
|
115
|
+
logger.debug(`detectStaticExports ${fileUrl}: ${err.message}`)
|
|
116
|
+
return undefined
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Attempt #2b - Sandboxed runtime analysis: More powerful, but slower.
|
|
122
|
+
* This will only work on UMD and very simple CJS files (require not supported).
|
|
123
|
+
* Uses VM2 to run safely sandbox untrusted code (no access no Node.js primitives, just JS).
|
|
124
|
+
* If nothing was detected, return undefined.
|
|
125
|
+
*/
|
|
126
|
+
const detectExportsUsingSandboxedRuntime = ({ logger, fileUrl }) => {
|
|
127
|
+
try {
|
|
128
|
+
const fileContents = readFileSync(new URL(fileUrl), "utf8")
|
|
129
|
+
const vm = new VM2({ wasm: false, fixAsync: false })
|
|
130
|
+
const vmResult = vm.run(wrapCodeToRunInVm(fileContents))
|
|
131
|
+
const exportsResult = Object.keys(vmResult)
|
|
132
|
+
logger.debug(
|
|
133
|
+
`detectExportsUsingSandboxedRuntime success ${fileUrl}: ${exportsResult}`,
|
|
134
|
+
)
|
|
135
|
+
return exportsResult.filter((identifier) => isValidIdentifier(identifier))
|
|
136
|
+
} catch (err) {
|
|
137
|
+
logger.debug(
|
|
138
|
+
`detectExportsUsingSandboxedRuntime error ${fileUrl}: ${err.message}`,
|
|
139
|
+
)
|
|
140
|
+
return undefined
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const isValidNamedExport = (name) =>
|
|
145
|
+
name !== "default" && name !== "__esModule" && isValidIdentifier(name)
|
|
146
|
+
|
|
147
|
+
const wrapCodeToRunInVm = (code) => {
|
|
148
|
+
return `const exports = {};
|
|
149
|
+
const module = { exports };
|
|
150
|
+
${code};;
|
|
151
|
+
module.exports;`
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const generateCodeForExports = ({
|
|
155
|
+
uniqueNamedExports,
|
|
156
|
+
inputSummary,
|
|
157
|
+
inputFileUrl,
|
|
158
|
+
}) => {
|
|
159
|
+
const from =
|
|
160
|
+
process.platform === "win32"
|
|
161
|
+
? inputFileUrl.slice("file:///".length)
|
|
162
|
+
: inputFileUrl.slice("file://".length)
|
|
163
|
+
const lines = [
|
|
164
|
+
...(inputSummary.namespace ? [stringifyNamespaceReExport({ from })] : []),
|
|
165
|
+
...(inputSummary.default ? [stringifyDefaultReExport({ from })] : []),
|
|
166
|
+
stringifyNamedReExports({
|
|
167
|
+
namedExports: uniqueNamedExports,
|
|
168
|
+
from,
|
|
169
|
+
}),
|
|
170
|
+
]
|
|
171
|
+
return lines.join(`
|
|
172
|
+
`)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const stringifyNamespaceReExport = ({ from }) => {
|
|
176
|
+
return `export * from "${from}";`
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const stringifyDefaultReExport = ({ from }) => {
|
|
180
|
+
return `import __jsenv_default_import__ from "${from}";
|
|
181
|
+
export default __jsenv_default_import__;`
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const stringifyNamedReExports = ({ namedExports, from }) => {
|
|
185
|
+
return `export { ${namedExports.join(",")} } from "${from}";`
|
|
186
|
+
}
|
|
@@ -28,7 +28,11 @@ import {
|
|
|
28
28
|
urlToBasename,
|
|
29
29
|
} from "@jsenv/filesystem"
|
|
30
30
|
|
|
31
|
-
import {
|
|
31
|
+
import { loadBabelPluginMapFromFile } from "./load_babel_plugin_map_from_file.js"
|
|
32
|
+
import {
|
|
33
|
+
extractSyntaxBabelPluginMap,
|
|
34
|
+
babelPluginNamesToRemoveFromBest,
|
|
35
|
+
} from "./babel_plugins.js"
|
|
32
36
|
import { generateGroupMap } from "../generateGroupMap/generateGroupMap.js"
|
|
33
37
|
import { createCallbackList } from "../createCallbackList.js"
|
|
34
38
|
import {
|
|
@@ -71,7 +75,8 @@ export const startCompileServer = async ({
|
|
|
71
75
|
replaceGlobalFilename = false,
|
|
72
76
|
replaceGlobalDirname = false,
|
|
73
77
|
replaceMap = {},
|
|
74
|
-
babelPluginMap
|
|
78
|
+
babelPluginMap,
|
|
79
|
+
babelConfigFileUrl,
|
|
75
80
|
customCompilers = {},
|
|
76
81
|
|
|
77
82
|
// options related to the server itself
|
|
@@ -126,11 +131,59 @@ export const startCompileServer = async ({
|
|
|
126
131
|
)
|
|
127
132
|
|
|
128
133
|
const logger = createLogger({ logLevel: compileServerLogLevel })
|
|
134
|
+
|
|
135
|
+
const babelPluginMapFromFile = await loadBabelPluginMapFromFile({
|
|
136
|
+
projectDirectoryUrl,
|
|
137
|
+
babelConfigFileUrl,
|
|
138
|
+
})
|
|
139
|
+
babelPluginMap = {
|
|
140
|
+
...babelPluginMapFromFile,
|
|
141
|
+
...babelPluginMap,
|
|
142
|
+
}
|
|
143
|
+
Object.keys(babelPluginMap).forEach((key) => {
|
|
144
|
+
if (
|
|
145
|
+
key === "transform-modules-commonjs" ||
|
|
146
|
+
key === "transform-modules-amd" ||
|
|
147
|
+
key === "transform-modules-systemjs"
|
|
148
|
+
) {
|
|
149
|
+
const declaredInFile = Boolean(babelPluginMapFromFile[key])
|
|
150
|
+
logger.warn(
|
|
151
|
+
createDetailedMessage(
|
|
152
|
+
`WARNING: "${key}" babel plugin should not be enabled, it will be ignored`,
|
|
153
|
+
{
|
|
154
|
+
suggestion: declaredInFile
|
|
155
|
+
? `To get rid of this warning, remove "${key}" from babel config file. Either with "modules": false in @babel/preset-env or removing "@babel/${key}" from plugins`
|
|
156
|
+
: `To get rid of this warning, remove "${key}" from babelPluginMap parameter`,
|
|
157
|
+
},
|
|
158
|
+
),
|
|
159
|
+
)
|
|
160
|
+
delete babelPluginMap[key]
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
const { babelSyntaxPluginMap, babelPluginMapWithoutSyntax } =
|
|
165
|
+
extractSyntaxBabelPluginMap(babelPluginMap)
|
|
129
166
|
const compileServerGroupMap = generateGroupMap({
|
|
130
|
-
babelPluginMap,
|
|
167
|
+
babelPluginMap: babelPluginMapWithoutSyntax,
|
|
131
168
|
runtimeSupport,
|
|
132
169
|
})
|
|
133
170
|
|
|
171
|
+
const { best } = compileServerGroupMap
|
|
172
|
+
if (best) {
|
|
173
|
+
// here it's just that @babel/preset-env is a bit aggressive in the list of babel plugins
|
|
174
|
+
// that it enables
|
|
175
|
+
// we don't want to end up transforming code that could run without any compile step
|
|
176
|
+
// ideally we should maintain our own babel preset list
|
|
177
|
+
// (would just be the jsenvBabelPluginMap)
|
|
178
|
+
// so that we have the correct list of babel plugins
|
|
179
|
+
// and we are not forced to remove some of them
|
|
180
|
+
// we should also fix the node system not working anymore
|
|
181
|
+
best.babelPluginRequiredNameArray =
|
|
182
|
+
best.babelPluginRequiredNameArray.filter((babelPluginName) => {
|
|
183
|
+
return !babelPluginNamesToRemoveFromBest.includes(babelPluginName)
|
|
184
|
+
})
|
|
185
|
+
}
|
|
186
|
+
|
|
134
187
|
babelPluginMap = {
|
|
135
188
|
"transform-replace-expressions": [
|
|
136
189
|
babelPluginReplaceExpressions,
|
|
@@ -149,6 +202,7 @@ export const startCompileServer = async ({
|
|
|
149
202
|
allowConflictingReplacements: true,
|
|
150
203
|
},
|
|
151
204
|
],
|
|
205
|
+
...babelSyntaxPluginMap,
|
|
152
206
|
...babelPluginMap,
|
|
153
207
|
}
|
|
154
208
|
|
|
@@ -201,6 +255,7 @@ export const startCompileServer = async ({
|
|
|
201
255
|
compileServerGroupMap,
|
|
202
256
|
env,
|
|
203
257
|
inlineImportMapIntoHTML,
|
|
258
|
+
babelPluginMap,
|
|
204
259
|
customCompilers,
|
|
205
260
|
})
|
|
206
261
|
if (compileServerCanWriteOnFilesystem) {
|
|
@@ -335,6 +390,7 @@ export const startCompileServer = async ({
|
|
|
335
390
|
outDirectoryRelativeUrl,
|
|
336
391
|
...compileServer,
|
|
337
392
|
compileServerGroupMap,
|
|
393
|
+
babelPluginMap,
|
|
338
394
|
}
|
|
339
395
|
}
|
|
340
396
|
|
|
@@ -893,7 +949,7 @@ const createOutJSONFiles = ({
|
|
|
893
949
|
const customCompilerPatterns = Object.keys(customCompilers)
|
|
894
950
|
const outDirectoryMeta = {
|
|
895
951
|
jsenvCorePackageVersion,
|
|
896
|
-
babelPluginMap,
|
|
952
|
+
babelPluginMap: babelPluginMapAsData(babelPluginMap),
|
|
897
953
|
compileServerGroupMap,
|
|
898
954
|
replaceProcessEnvNodeEnv,
|
|
899
955
|
processEnvNodeEnv,
|
|
@@ -927,6 +983,25 @@ const createOutJSONFiles = ({
|
|
|
927
983
|
return outJSONFiles
|
|
928
984
|
}
|
|
929
985
|
|
|
986
|
+
const babelPluginMapAsData = (babelPluginMap) => {
|
|
987
|
+
const data = {}
|
|
988
|
+
Object.keys(babelPluginMap).forEach((key) => {
|
|
989
|
+
const value = babelPluginMap[key]
|
|
990
|
+
if (Array.isArray(value)) {
|
|
991
|
+
data[key] = value
|
|
992
|
+
return
|
|
993
|
+
}
|
|
994
|
+
if (typeof value === "object") {
|
|
995
|
+
data[key] = {
|
|
996
|
+
options: value.options,
|
|
997
|
+
}
|
|
998
|
+
return
|
|
999
|
+
}
|
|
1000
|
+
data[key] = value
|
|
1001
|
+
})
|
|
1002
|
+
return data
|
|
1003
|
+
}
|
|
1004
|
+
|
|
930
1005
|
const createOutFilesService = async ({
|
|
931
1006
|
logger,
|
|
932
1007
|
projectDirectoryUrl,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { createOperation } from "@jsenv/cancellation"
|
|
2
2
|
import { resolveUrl, urlToFileSystemPath, readFile } from "@jsenv/filesystem"
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
babelPluginsFromBabelPluginMap,
|
|
6
|
+
getMinimalBabelPluginMap,
|
|
7
|
+
} from "@jsenv/core/src/internal/compiling/babel_plugins.js"
|
|
8
|
+
|
|
5
9
|
import { babelPluginInstrument } from "./babel-plugin-instrument.js"
|
|
6
10
|
import { createEmptyCoverage } from "./createEmptyCoverage.js"
|
|
7
11
|
|
|
@@ -17,28 +21,32 @@ export const relativeUrlToEmptyCoverage = async (
|
|
|
17
21
|
start: () => readFile(fileUrl),
|
|
18
22
|
})
|
|
19
23
|
|
|
20
|
-
const plugins = [...getMinimalBabelPluginArray()]
|
|
21
|
-
Object.keys(babelPluginMap).forEach((babelPluginName) => {
|
|
22
|
-
if (babelPluginName !== "transform-instrument") {
|
|
23
|
-
plugins.push(babelPluginMap[babelPluginName])
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
plugins.push([babelPluginInstrument, { projectDirectoryUrl }])
|
|
27
|
-
|
|
28
24
|
try {
|
|
29
25
|
const { metadata } = await createOperation({
|
|
30
26
|
cancellationToken,
|
|
31
|
-
start: () =>
|
|
32
|
-
|
|
27
|
+
start: async () => {
|
|
28
|
+
babelPluginMap = {
|
|
29
|
+
...getMinimalBabelPluginMap(),
|
|
30
|
+
...babelPluginMap,
|
|
31
|
+
"transform-instrument": [
|
|
32
|
+
babelPluginInstrument,
|
|
33
|
+
{ projectDirectoryUrl },
|
|
34
|
+
],
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { metadata } = await transformAsync(source, {
|
|
33
38
|
filename: urlToFileSystemPath(fileUrl),
|
|
34
39
|
filenameRelative: relativeUrl,
|
|
35
40
|
configFile: false,
|
|
36
41
|
babelrc: false,
|
|
42
|
+
ast: true,
|
|
37
43
|
parserOpts: {
|
|
38
44
|
allowAwaitOutsideFunction: true,
|
|
39
45
|
},
|
|
40
|
-
plugins,
|
|
41
|
-
})
|
|
46
|
+
plugins: babelPluginsFromBabelPluginMap(babelPluginMap),
|
|
47
|
+
})
|
|
48
|
+
return { metadata }
|
|
49
|
+
},
|
|
42
50
|
})
|
|
43
51
|
|
|
44
52
|
const { coverage } = metadata
|
|
@@ -39,6 +39,7 @@ export const executePlan = async (
|
|
|
39
39
|
compileServerCanReadFromFilesystem,
|
|
40
40
|
compileServerCanWriteOnFilesystem,
|
|
41
41
|
babelPluginMap,
|
|
42
|
+
babelConfigFileUrl,
|
|
42
43
|
customCompilers,
|
|
43
44
|
runtimeSupport,
|
|
44
45
|
} = {},
|
|
@@ -53,11 +54,7 @@ export const executePlan = async (
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
const {
|
|
57
|
-
origin: compileServerOrigin,
|
|
58
|
-
outDirectoryRelativeUrl,
|
|
59
|
-
stop,
|
|
60
|
-
} = await startCompileServer({
|
|
57
|
+
const compileServer = await startCompileServer({
|
|
61
58
|
cancellationToken,
|
|
62
59
|
compileServerLogLevel,
|
|
63
60
|
|
|
@@ -78,6 +75,7 @@ export const executePlan = async (
|
|
|
78
75
|
compileServerCanWriteOnFilesystem,
|
|
79
76
|
keepProcessAlive: true, // to be sure it stays alive
|
|
80
77
|
babelPluginMap,
|
|
78
|
+
babelConfigFileUrl,
|
|
81
79
|
customCompilers,
|
|
82
80
|
runtimeSupport,
|
|
83
81
|
})
|
|
@@ -85,7 +83,7 @@ export const executePlan = async (
|
|
|
85
83
|
const executionSteps = await generateExecutionSteps(
|
|
86
84
|
{
|
|
87
85
|
...plan,
|
|
88
|
-
[outDirectoryRelativeUrl]: null,
|
|
86
|
+
[compileServer.outDirectoryRelativeUrl]: null,
|
|
89
87
|
},
|
|
90
88
|
{
|
|
91
89
|
cancellationToken,
|
|
@@ -99,14 +97,14 @@ export const executePlan = async (
|
|
|
99
97
|
cancellationToken,
|
|
100
98
|
|
|
101
99
|
projectDirectoryUrl,
|
|
102
|
-
compileServerOrigin,
|
|
103
|
-
outDirectoryRelativeUrl,
|
|
100
|
+
compileServerOrigin: compileServer.origin,
|
|
101
|
+
outDirectoryRelativeUrl: compileServer.outDirectoryRelativeUrl,
|
|
104
102
|
|
|
105
103
|
// not sure we actually have to pass import params to executeConcurrently
|
|
106
104
|
importResolutionMethod,
|
|
107
105
|
importDefaultExtension,
|
|
108
106
|
|
|
109
|
-
babelPluginMap,
|
|
107
|
+
babelPluginMap: compileServer.babelPluginMap,
|
|
110
108
|
|
|
111
109
|
defaultMsAllocatedPerExecution,
|
|
112
110
|
concurrencyLimit,
|
|
@@ -122,7 +120,7 @@ export const executePlan = async (
|
|
|
122
120
|
coverageV8MergeConflictIsExpected,
|
|
123
121
|
})
|
|
124
122
|
|
|
125
|
-
stop("all execution done")
|
|
123
|
+
compileServer.stop("all execution done")
|
|
126
124
|
|
|
127
125
|
return {
|
|
128
126
|
planSummary: result.summary,
|
|
@@ -61,7 +61,6 @@ export const generateGroupMap = ({
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const runtimeNames = Object.keys(runtimeSupport)
|
|
64
|
-
babelPluginMap = withoutSyntaxPlugins(babelPluginMap)
|
|
65
64
|
|
|
66
65
|
const groupWithoutFeature = {
|
|
67
66
|
babelPluginRequiredNameArray: Object.keys(babelPluginMap),
|
|
@@ -89,14 +88,3 @@ export const generateGroupMap = ({
|
|
|
89
88
|
[COMPILE_ID_OTHERWISE]: groupWithoutFeature,
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
|
-
|
|
93
|
-
export const withoutSyntaxPlugins = (babelPluginMap) => {
|
|
94
|
-
const babelPluginMapWithoutSyntaxPlugins = {}
|
|
95
|
-
Object.keys(babelPluginMap).forEach((key) => {
|
|
96
|
-
if (key.startsWith("syntax-")) {
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
babelPluginMapWithoutSyntaxPlugins[key] = babelPluginMap[key]
|
|
100
|
-
})
|
|
101
|
-
return babelPluginMapWithoutSyntaxPlugins
|
|
102
|
-
}
|
|
@@ -427,3 +427,6 @@ export const jsenvBabelPluginCompatMap = {
|
|
|
427
427
|
// so that async is not transpiled when supported
|
|
428
428
|
jsenvBabelPluginCompatMap["transform-async-to-promises"] =
|
|
429
429
|
jsenvBabelPluginCompatMap["transform-async-to-generator"]
|
|
430
|
+
|
|
431
|
+
jsenvBabelPluginCompatMap["regenerator-transform"] =
|
|
432
|
+
jsenvBabelPluginCompatMap["transform-regenerator"]
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createDetailedMessage } from "@jsenv/logger"
|
|
2
|
-
import { resolveImport } from "@jsenv/
|
|
2
|
+
import { resolveImport } from "@jsenv/importmap/src/resolveImport.js"
|
|
3
3
|
|
|
4
4
|
import { tryToFindProjectRelativeUrl } from "@jsenv/core/src/internal/runtime/module-registration.js"
|
|
5
5
|
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
urlToRelativeUrl,
|
|
6
6
|
readFile,
|
|
7
7
|
} from "@jsenv/filesystem"
|
|
8
|
-
import { isSpecifierForNodeCoreModule } from "@jsenv/
|
|
8
|
+
import { isSpecifierForNodeCoreModule } from "@jsenv/importmap/src/isSpecifierForNodeCoreModule.js"
|
|
9
9
|
|
|
10
10
|
import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js"
|
|
11
11
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeImportMap } from "@jsenv/
|
|
1
|
+
import { normalizeImportMap } from "@jsenv/importmap/src/normalizeImportMap.js"
|
|
2
2
|
|
|
3
3
|
import { unevalException } from "../../unevalException.js"
|
|
4
4
|
// do not use memoize from @jsenv/filesystem to avoid pulling @jsenv/filesystem code into the browser build
|
|
@@ -5,7 +5,8 @@ We could use https://nodejs.org/api/esm.html#esm_loaders once it gets stable
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { urlToFileSystemPath, resolveUrl } from "@jsenv/filesystem"
|
|
8
|
-
import { isSpecifierForNodeCoreModule } from "@jsenv/
|
|
8
|
+
import { isSpecifierForNodeCoreModule } from "@jsenv/importmap/src/isSpecifierForNodeCoreModule.js"
|
|
9
|
+
|
|
9
10
|
import { createImportResolverForNode } from "@jsenv/core/src/internal/import-resolution/import-resolver-node.js"
|
|
10
11
|
import { require } from "../../require.js"
|
|
11
12
|
import "../s.js"
|
|
@@ -45,8 +46,11 @@ export const createNodeSystem = async ({
|
|
|
45
46
|
if (isSpecifierForNodeCoreModule(url)) {
|
|
46
47
|
return fromFunctionReturningNamespace(
|
|
47
48
|
() => {
|
|
49
|
+
const coreNodeModuleSpecifier = url.startsWith("node:")
|
|
50
|
+
? url.slice("node:".length)
|
|
51
|
+
: url
|
|
48
52
|
// eslint-disable-next-line import/no-dynamic-require
|
|
49
|
-
const moduleExportsForNativeNodeModule = require(
|
|
53
|
+
const moduleExportsForNativeNodeModule = require(coreNodeModuleSpecifier)
|
|
50
54
|
return moduleExportsToModuleNamespace(
|
|
51
55
|
moduleExportsForNativeNodeModule,
|
|
52
56
|
)
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
minimalBabelPluginArray exists so that jsenv support latest js syntax by default.
|
|
4
|
-
Otherwise users have to explicitely enable those syntax when they use it.
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { require } from "./require.js"
|
|
9
|
-
|
|
10
|
-
export const getMinimalBabelPluginArray = () => {
|
|
11
|
-
const syntaxDynamicImport = require("@babel/plugin-syntax-dynamic-import")
|
|
12
|
-
const syntaxImportMeta = require("@babel/plugin-syntax-import-meta")
|
|
13
|
-
const syntaxNumericSeparator = require("@babel/plugin-syntax-numeric-separator")
|
|
14
|
-
|
|
15
|
-
return [syntaxDynamicImport, syntaxImportMeta, syntaxNumericSeparator]
|
|
16
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/max-dependencies */
|
|
2
|
-
|
|
3
|
-
import { require } from "./internal/require.js"
|
|
4
|
-
|
|
5
|
-
const proposalJSONStrings = require("@babel/plugin-proposal-json-strings")
|
|
6
|
-
const proposalNumericSeparator = require("@babel/plugin-proposal-numeric-separator")
|
|
7
|
-
const proposalObjectRestSpread = require("@babel/plugin-proposal-object-rest-spread")
|
|
8
|
-
const proposalOptionalCatchBinding = require("@babel/plugin-proposal-optional-catch-binding")
|
|
9
|
-
const proposalOptionalChaining = require("@babel/plugin-proposal-optional-chaining")
|
|
10
|
-
const proposalUnicodePropertyRegex = require("@babel/plugin-proposal-unicode-property-regex")
|
|
11
|
-
const syntaxObjectRestSpread = require("@babel/plugin-syntax-object-rest-spread")
|
|
12
|
-
const syntaxOptionalCatchBinding = require("@babel/plugin-syntax-optional-catch-binding")
|
|
13
|
-
const transformArrowFunction = require("@babel/plugin-transform-arrow-functions")
|
|
14
|
-
const transformAsyncToPromises = require("babel-plugin-transform-async-to-promises")
|
|
15
|
-
const transformBlockScopedFunctions = require("@babel/plugin-transform-block-scoped-functions")
|
|
16
|
-
const transformBlockScoping = require("@babel/plugin-transform-block-scoping")
|
|
17
|
-
const transformClasses = require("@babel/plugin-transform-classes")
|
|
18
|
-
const transformComputedProperties = require("@babel/plugin-transform-computed-properties")
|
|
19
|
-
const transformDestructuring = require("@babel/plugin-transform-destructuring")
|
|
20
|
-
const transformDotAllRegex = require("@babel/plugin-transform-dotall-regex")
|
|
21
|
-
const transformDuplicateKeys = require("@babel/plugin-transform-duplicate-keys")
|
|
22
|
-
const transformExponentiationOperator = require("@babel/plugin-transform-exponentiation-operator")
|
|
23
|
-
const transformForOf = require("@babel/plugin-transform-for-of")
|
|
24
|
-
const transformFunctionName = require("@babel/plugin-transform-function-name")
|
|
25
|
-
const transformLiterals = require("@babel/plugin-transform-literals")
|
|
26
|
-
const transformNewTarget = require("@babel/plugin-transform-new-target")
|
|
27
|
-
const transformObjectSuper = require("@babel/plugin-transform-object-super")
|
|
28
|
-
const transformParameters = require("@babel/plugin-transform-parameters")
|
|
29
|
-
const transformRegenerator = require("@babel/plugin-transform-regenerator")
|
|
30
|
-
const transformShorthandProperties = require("@babel/plugin-transform-shorthand-properties")
|
|
31
|
-
const transformSpread = require("@babel/plugin-transform-spread")
|
|
32
|
-
const transformStickyRegex = require("@babel/plugin-transform-sticky-regex")
|
|
33
|
-
const transformTemplateLiterals = require("@babel/plugin-transform-template-literals")
|
|
34
|
-
const transformTypeOfSymbol = require("@babel/plugin-transform-typeof-symbol")
|
|
35
|
-
const transformUnicodeRegex = require("@babel/plugin-transform-unicode-regex")
|
|
36
|
-
|
|
37
|
-
export const jsenvBabelPluginMap = {
|
|
38
|
-
"proposal-numeric-separator": [proposalNumericSeparator],
|
|
39
|
-
"proposal-json-strings": [proposalJSONStrings],
|
|
40
|
-
"proposal-object-rest-spread": [proposalObjectRestSpread],
|
|
41
|
-
"proposal-optional-catch-binding": [proposalOptionalCatchBinding],
|
|
42
|
-
"proposal-optional-chaining": [proposalOptionalChaining],
|
|
43
|
-
"proposal-unicode-property-regex": [proposalUnicodePropertyRegex],
|
|
44
|
-
"syntax-object-rest-spread": [syntaxObjectRestSpread],
|
|
45
|
-
"syntax-optional-catch-binding": [syntaxOptionalCatchBinding],
|
|
46
|
-
"transform-async-to-promises": [transformAsyncToPromises],
|
|
47
|
-
"transform-arrow-functions": [transformArrowFunction],
|
|
48
|
-
"transform-block-scoped-functions": [transformBlockScopedFunctions],
|
|
49
|
-
"transform-block-scoping": [transformBlockScoping],
|
|
50
|
-
"transform-classes": [transformClasses],
|
|
51
|
-
"transform-computed-properties": [transformComputedProperties],
|
|
52
|
-
"transform-destructuring": [transformDestructuring],
|
|
53
|
-
"transform-dotall-regex": [transformDotAllRegex],
|
|
54
|
-
"transform-duplicate-keys": [transformDuplicateKeys],
|
|
55
|
-
"transform-exponentiation-operator": [transformExponentiationOperator],
|
|
56
|
-
"transform-for-of": [transformForOf],
|
|
57
|
-
"transform-function-name": [transformFunctionName],
|
|
58
|
-
"transform-literals": [transformLiterals],
|
|
59
|
-
"transform-new-target": [transformNewTarget],
|
|
60
|
-
"transform-object-super": [transformObjectSuper],
|
|
61
|
-
"transform-parameters": [transformParameters],
|
|
62
|
-
"transform-regenerator": [
|
|
63
|
-
transformRegenerator,
|
|
64
|
-
{
|
|
65
|
-
asyncGenerators: true,
|
|
66
|
-
generators: true,
|
|
67
|
-
async: false,
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
"transform-shorthand-properties": [transformShorthandProperties],
|
|
71
|
-
"transform-spread": [transformSpread],
|
|
72
|
-
"transform-sticky-regex": [transformStickyRegex],
|
|
73
|
-
"transform-template-literals": [transformTemplateLiterals],
|
|
74
|
-
"transform-typeof-symbol": [transformTypeOfSymbol],
|
|
75
|
-
"transform-unicode-regex": [transformUnicodeRegex],
|
|
76
|
-
}
|