@jsenv/core 25.2.0 → 25.4.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/dist/browser_runtime/asset-manifest.json +2 -2
- package/dist/browser_runtime/{browser_runtime_91c5a3b8.js → browser_runtime_0e3396a1.js} +15 -16
- package/dist/browser_runtime/{browser_runtime_91c5a3b8.js.map → browser_runtime_0e3396a1.js.map} +13 -13
- package/dist/build_manifest.js +5 -5
- package/dist/compile_proxy/asset-manifest.json +2 -2
- package/dist/compile_proxy/compile_proxy.html__inline__20_2334a374.js.map +342 -0
- package/dist/compile_proxy/{compile_proxy_8dfaee51.html → compile_proxy_9f737eaf.html} +357 -398
- package/dist/redirector/asset-manifest.json +2 -2
- package/dist/redirector/redirector.html__inline__12_009c47c7.js.map +348 -0
- package/dist/redirector/{redirector_3e9a97b9.html → redirector_96f74871.html} +378 -421
- package/dist/toolbar/asset-manifest.json +2 -2
- package/dist/toolbar/{toolbar.main_6c1b3d82.js.map → toolbar.main_86335f90.js.map} +82 -115
- package/dist/toolbar/{toolbar_361afb84.html → toolbar_d3a918a4.html} +487 -508
- package/dist/toolbar_injector/asset-manifest.json +2 -2
- package/dist/toolbar_injector/toolbar_injector_978bbd14.js +267 -0
- package/dist/toolbar_injector/toolbar_injector_978bbd14.js.map +119 -0
- package/package.json +19 -14
- package/readme.md +54 -54
- package/src/buildProject.js +31 -26
- package/src/dev_server.js +78 -87
- package/src/execute.js +3 -8
- package/src/internal/browser_launcher/{browser_runtime_report.js → browser_runtime_profile.js} +21 -15
- package/src/internal/browser_launcher/executeHtmlFile.js +22 -14
- package/src/internal/browser_launcher/from_playwright.js +6 -4
- package/src/internal/browser_runtime/browser_runtime.js +12 -14
- package/src/internal/browser_runtime/createBrowserRuntime.js +7 -6
- package/src/internal/browser_utils/fetchAndEvalUsingFetch.js +1 -1
- package/src/internal/browser_utils/fetchJson.js +1 -1
- package/src/internal/browser_utils/{fetch-browser.js → fetch_browser.js} +0 -2
- package/src/internal/building/buildUsingRollup.js +41 -57
- package/src/internal/building/html/parseHtmlRessource.js +2 -1
- package/src/internal/building/rollup_plugin_jsenv.js +28 -8
- package/src/internal/compiling/babel_parse_error.js +9 -0
- package/src/internal/{babel_plugin_transform_import_meta.js → compiling/babel_plugin_transform_import_meta.js} +58 -9
- package/src/internal/compiling/compileFile.js +2 -2
- package/src/internal/compiling/compileHtml.js +1 -1
- package/src/internal/compiling/createCompiledFileService.js +25 -74
- package/src/internal/compiling/js-compilation-service/babelHelper.js +10 -13
- package/src/internal/compiling/js-compilation-service/babel_plugin_babel_helpers_as_jsenv_imports.js +4 -2
- package/src/internal/compiling/js-compilation-service/transformJs.js +153 -23
- package/src/internal/compiling/jsenvCompilerForHtml.js +34 -34
- package/src/internal/compiling/jsenvCompilerForImportmap.js +2 -2
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -4
- package/src/internal/compiling/jsenv_directory/comparison_utils.js +24 -0
- package/src/internal/compiling/{compile-directory/compile-asset.js → jsenv_directory/compile_asset.js} +0 -0
- package/src/internal/compiling/jsenv_directory/compile_context.js +68 -0
- package/src/internal/compiling/jsenv_directory/compile_profile.js +218 -0
- package/src/internal/compiling/{compile-directory/createLockRegistry.js → jsenv_directory/file_lock_registry.js} +0 -0
- package/src/internal/compiling/{compile-directory/createLockRegistry.test.js → jsenv_directory/file_lock_registry.test.js} +2 -1
- package/src/internal/compiling/{compile-directory → jsenv_directory}/fs-optimized-for-cache.js +0 -0
- package/src/internal/compiling/{compile-directory → jsenv_directory}/getOrGenerateCompiledFile.js +2 -2
- package/src/internal/compiling/jsenv_directory/jsenv_directory.js +174 -0
- package/src/internal/compiling/{compile-directory → jsenv_directory}/updateMeta.js +4 -2
- package/src/internal/compiling/{compile-directory → jsenv_directory}/validateCache.js +0 -0
- package/src/internal/compiling/sse_service/sse_service.js +369 -0
- package/src/internal/compiling/startCompileServer.js +156 -804
- package/src/internal/compiling/transformResultToCompilationResult.js +2 -2
- package/src/internal/dev_server/exploring/exploring.js +10 -8
- package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +85 -78
- package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
- package/src/internal/dev_server/toolbar/toolbar.html +40 -16
- package/src/internal/dev_server/toolbar/toolbar.injector.js +11 -17
- package/src/internal/dev_server/toolbar/toolbar.main.js +6 -6
- package/src/internal/executing/executeConcurrently.js +1 -1
- package/src/internal/executing/executePlan.js +2 -3
- package/src/internal/{generateGroupMap → features}/babel_plugins_compatibility.js +8 -8
- package/src/internal/features/browser_feature_detection/browser_feature_detect_dynamic_import.js +20 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_css.js +23 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_json.js +25 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_importmap.js +37 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_new_stylesheet.js +9 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js +14 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detection.js +85 -0
- package/src/internal/{browser_feature_detection → features/browser_feature_detection}/compile_proxy.html +1 -1
- package/src/internal/features/browser_feature_detection/execute_with_script_module.js +24 -0
- package/src/internal/features/features_compat_from_runtime.js +38 -0
- package/src/internal/features/features_compat_from_runtime_support.js +31 -0
- package/src/internal/{generateGroupMap → features}/features_compatibility.js +3 -3
- package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_dynamic_import.mjs +0 -0
- package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_top_level_await.mjs +0 -0
- package/src/internal/{node_feature_detection/nodeSupportsDynamicImport.js → features/node_feature_detection/node_feature_detect_dynamic_import.js} +0 -0
- package/src/internal/{node_feature_detection/nodeSupportsTopLevelAwait.js → features/node_feature_detection/node_feature_detect_top_level_await.js} +0 -0
- package/src/internal/features/node_feature_detection/node_feature_detection.js +66 -0
- package/src/internal/jsenv_remote_directory.js +1 -1
- package/src/internal/node_launcher/createControllableNodeProcess.js +4 -3
- package/src/internal/node_launcher/node_runtime_report.js +15 -9
- package/src/internal/node_runtime/fetchSource.js +2 -4
- package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
- package/src/internal/{dev_server/redirector → redirector}/redirector.html +8 -18
- package/src/internal/{generateGroupMap/jsenvRuntimeSupport.js → runtime_support/jsenv_runtime_support.js} +0 -0
- package/src/internal/{generateGroupMap → runtime_support}/runtime_support.js +0 -0
- package/src/internal/url_conversion.js +12 -17
- package/src/launchNode.js +29 -41
- package/dist/compile_proxy/compile_proxy.html__inline__20_809f35f7.js.map +0 -392
- package/dist/redirector/redirector.html__inline__15_e391410e.js.map +0 -397
- package/dist/toolbar_injector/toolbar_injector_fac1e995.js +0 -973
- package/dist/toolbar_injector/toolbar_injector_fac1e995.js.map +0 -294
- package/src/internal/CONSTANTS.js +0 -11
- package/src/internal/browser_feature_detection/browser_feature_detection.js +0 -274
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +0 -243
- package/src/internal/generateGroupMap/generateGroupMap.js +0 -65
- package/src/internal/generateGroupMap/one_runtime_compat.js +0 -38
- package/src/internal/generateGroupMap/runtime_compat.js +0 -34
- package/src/internal/generateGroupMap/runtime_compat_composition.js +0 -76
- package/src/internal/generateGroupMap/shake_babel_plugin_map.js +0 -21
- package/src/internal/integrity/integrity_algorithms.js +0 -26
- package/src/internal/integrity/integrity_parsing.js +0 -50
- package/src/internal/integrity/integrity_update.js +0 -23
- package/src/internal/integrity/integrity_validation.js +0 -49
- package/src/internal/node_feature_detection/node_feature_detection.js +0 -117
- package/src/internal/node_runtime/detectNode.js +0 -3
- package/src/internal/runtime/computeCompileIdFromGroupId.js +0 -30
- package/src/internal/runtime/resolveGroup.js +0 -13
- package/src/internal/runtime/resolveRuntimeGroup.js +0 -11
|
@@ -4,19 +4,14 @@ import {
|
|
|
4
4
|
resolveDirectoryUrl,
|
|
5
5
|
normalizeStructuredMetaMap,
|
|
6
6
|
urlToMeta,
|
|
7
|
+
urlToRelativeUrl,
|
|
7
8
|
} from "@jsenv/filesystem"
|
|
8
9
|
|
|
9
|
-
import {
|
|
10
|
-
import { shakeBabelPluginMap } from "@jsenv/core/src/internal/generateGroupMap/shake_babel_plugin_map.js"
|
|
10
|
+
import { REDIRECTOR_BUILD_URL } from "@jsenv/core/dist/build_manifest.js"
|
|
11
11
|
import { serverUrlToCompileInfo } from "@jsenv/core/src/internal/url_conversion.js"
|
|
12
|
-
|
|
13
12
|
import { setUrlExtension } from "../url_utils.js"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
COMPILE_ID_BUILD_GLOBAL_FILES,
|
|
17
|
-
COMPILE_ID_BUILD_COMMONJS,
|
|
18
|
-
COMPILE_ID_BUILD_COMMONJS_FILES,
|
|
19
|
-
} from "../CONSTANTS.js"
|
|
13
|
+
|
|
14
|
+
import { shakeBabelPluginMap } from "./jsenv_directory/compile_profile.js"
|
|
20
15
|
import { compileFile } from "./compileFile.js"
|
|
21
16
|
import { compileHtml } from "./jsenvCompilerForHtml.js"
|
|
22
17
|
import { compileImportmap } from "./jsenvCompilerForImportmap.js"
|
|
@@ -39,20 +34,15 @@ export const createCompiledFileService = ({
|
|
|
39
34
|
|
|
40
35
|
projectDirectoryUrl,
|
|
41
36
|
jsenvDirectoryRelativeUrl,
|
|
42
|
-
|
|
37
|
+
jsenvDirectory,
|
|
43
38
|
jsenvRemoteDirectory,
|
|
44
39
|
|
|
45
|
-
runtimeSupport,
|
|
46
40
|
babelPluginMap,
|
|
47
|
-
moduleOutFormat,
|
|
48
|
-
importMetaFormat,
|
|
49
41
|
topLevelAwait,
|
|
50
42
|
prependSystemJs,
|
|
51
|
-
groupMap,
|
|
52
43
|
customCompilers,
|
|
53
44
|
workerUrls,
|
|
54
45
|
serviceWorkerUrls,
|
|
55
|
-
importMapInWebWorkers,
|
|
56
46
|
|
|
57
47
|
jsenvEventSourceClientInjection,
|
|
58
48
|
jsenvToolbarInjection,
|
|
@@ -62,17 +52,6 @@ export const createCompiledFileService = ({
|
|
|
62
52
|
sourcemapMethod,
|
|
63
53
|
sourcemapExcludeSources,
|
|
64
54
|
}) => {
|
|
65
|
-
const compileIdModuleFormats = {}
|
|
66
|
-
Object.keys(groupMap).forEach((groupName) => {
|
|
67
|
-
compileIdModuleFormats[groupName] = canAvoidSystemJs({
|
|
68
|
-
runtimeSupport: groupMap[groupName].minRuntimeVersions,
|
|
69
|
-
workerUrls,
|
|
70
|
-
importMapInWebWorkers,
|
|
71
|
-
})
|
|
72
|
-
? "esmodule"
|
|
73
|
-
: "systemjs"
|
|
74
|
-
})
|
|
75
|
-
|
|
76
55
|
Object.keys(customCompilers).forEach((key) => {
|
|
77
56
|
const value = customCompilers[key]
|
|
78
57
|
if (typeof value !== "function") {
|
|
@@ -88,27 +67,26 @@ export const createCompiledFileService = ({
|
|
|
88
67
|
},
|
|
89
68
|
projectDirectoryUrl,
|
|
90
69
|
)
|
|
91
|
-
|
|
92
70
|
const importmapInfos = {}
|
|
93
|
-
|
|
71
|
+
const redirectorRelativeUrlForProject = urlToRelativeUrl(
|
|
72
|
+
REDIRECTOR_BUILD_URL,
|
|
73
|
+
projectDirectoryUrl,
|
|
74
|
+
)
|
|
94
75
|
return async (request, { pushResponse, redirectRequest }) => {
|
|
95
76
|
const { origin, ressource } = request
|
|
96
77
|
const requestUrl = `${origin}${ressource}`
|
|
97
|
-
|
|
98
78
|
const requestCompileInfo = serverUrlToCompileInfo(requestUrl, {
|
|
99
|
-
outDirectoryRelativeUrl,
|
|
100
79
|
compileServerOrigin: origin,
|
|
80
|
+
jsenvDirectoryRelativeUrl,
|
|
101
81
|
})
|
|
102
|
-
|
|
103
82
|
// not inside compile directory -> nothing to compile
|
|
104
83
|
if (!requestCompileInfo.insideCompileDirectory) {
|
|
105
84
|
return null
|
|
106
85
|
}
|
|
107
|
-
|
|
108
86
|
const { compileId, afterCompileId } = requestCompileInfo
|
|
109
87
|
// serve files inside /.jsenv/* directly without compilation
|
|
110
88
|
// this is just to allow some files to be written inside outDirectory and read directly
|
|
111
|
-
// if asked by the client
|
|
89
|
+
// if asked by the client
|
|
112
90
|
if (!compileId) {
|
|
113
91
|
return fetchFileSystem(
|
|
114
92
|
new URL(request.ressource.slice(1), projectDirectoryUrl),
|
|
@@ -118,29 +96,27 @@ export const createCompiledFileService = ({
|
|
|
118
96
|
},
|
|
119
97
|
)
|
|
120
98
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
...Object.keys(groupMap),
|
|
124
|
-
COMPILE_ID_BUILD_GLOBAL,
|
|
125
|
-
COMPILE_ID_BUILD_GLOBAL_FILES,
|
|
126
|
-
COMPILE_ID_BUILD_COMMONJS,
|
|
127
|
-
COMPILE_ID_BUILD_COMMONJS_FILES,
|
|
128
|
-
]
|
|
129
|
-
if (!allowedCompileIds.includes(compileId)) {
|
|
99
|
+
const compileDirectory = jsenvDirectory.compileDirectories[compileId]
|
|
100
|
+
if (!compileDirectory) {
|
|
130
101
|
return {
|
|
131
|
-
status:
|
|
132
|
-
|
|
102
|
+
status: 307,
|
|
103
|
+
headers: {
|
|
104
|
+
location: `${
|
|
105
|
+
request.origin
|
|
106
|
+
}/${redirectorRelativeUrlForProject}?redirect=${encodeURIComponent(
|
|
107
|
+
afterCompileId,
|
|
108
|
+
)}`,
|
|
109
|
+
},
|
|
133
110
|
}
|
|
134
111
|
}
|
|
135
|
-
|
|
136
112
|
// nothing after compileId, we don't know what to compile (not supposed to happen)
|
|
137
113
|
if (afterCompileId === "") {
|
|
138
114
|
return null
|
|
139
115
|
}
|
|
140
|
-
|
|
116
|
+
const { compileProfile } = compileDirectory
|
|
141
117
|
const originalFileRelativeUrl = afterCompileId
|
|
142
118
|
const originalFileUrl = `${projectDirectoryUrl}${originalFileRelativeUrl}`
|
|
143
|
-
const compileDirectoryRelativeUrl = `${
|
|
119
|
+
const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
|
|
144
120
|
const compileDirectoryUrl = resolveDirectoryUrl(
|
|
145
121
|
compileDirectoryRelativeUrl,
|
|
146
122
|
projectDirectoryUrl,
|
|
@@ -181,24 +157,18 @@ export const createCompiledFileService = ({
|
|
|
181
157
|
jsenvRemoteDirectory,
|
|
182
158
|
compileServerOrigin: request.origin,
|
|
183
159
|
jsenvDirectoryRelativeUrl,
|
|
184
|
-
outDirectoryRelativeUrl,
|
|
185
160
|
url: originalFileUrl,
|
|
186
161
|
compiledUrl: compiledFileUrl,
|
|
187
162
|
request,
|
|
188
163
|
|
|
164
|
+
compileProfile,
|
|
189
165
|
compileId,
|
|
190
166
|
babelPluginMap: shakeBabelPluginMap({
|
|
191
167
|
babelPluginMap,
|
|
192
|
-
|
|
168
|
+
compileProfile,
|
|
193
169
|
}),
|
|
194
|
-
runtimeSupport,
|
|
195
170
|
workerUrls,
|
|
196
171
|
serviceWorkerUrls,
|
|
197
|
-
moduleOutFormat:
|
|
198
|
-
moduleOutFormat === undefined
|
|
199
|
-
? compileIdModuleFormats[compileId]
|
|
200
|
-
: moduleOutFormat,
|
|
201
|
-
importMetaFormat,
|
|
202
172
|
topLevelAwait,
|
|
203
173
|
prependSystemJs,
|
|
204
174
|
|
|
@@ -217,25 +187,6 @@ export const createCompiledFileService = ({
|
|
|
217
187
|
}
|
|
218
188
|
}
|
|
219
189
|
|
|
220
|
-
const canAvoidSystemJs = ({
|
|
221
|
-
runtimeSupport,
|
|
222
|
-
workerUrls,
|
|
223
|
-
importMapInWebWorkers,
|
|
224
|
-
}) => {
|
|
225
|
-
const runtimeCompatMap = createRuntimeCompat({
|
|
226
|
-
featureNames: [
|
|
227
|
-
"module",
|
|
228
|
-
"importmap",
|
|
229
|
-
"import_assertion_type_json",
|
|
230
|
-
"import_assertion_type_css",
|
|
231
|
-
...(workerUrls.length > 0 ? ["worker_type_module"] : []),
|
|
232
|
-
...(importMapInWebWorkers ? ["worker_importmap"] : []),
|
|
233
|
-
],
|
|
234
|
-
runtimeSupport,
|
|
235
|
-
})
|
|
236
|
-
return runtimeCompatMap.missingFeatureNames.length === 0
|
|
237
|
-
}
|
|
238
|
-
|
|
239
190
|
const getCompiler = ({ originalFileUrl, compileMeta }) => {
|
|
240
191
|
// we remove eventual query param from the url
|
|
241
192
|
// Without this a pattern like "**/*.js" would not match "file.js?t=1"
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// https://github.com/babel/babel/blob/99f4f6c3b03c7f3f67cf1b9f1a21b80cfd5b0224/packages/babel-core/src/tools/build-external-helpers.js
|
|
2
2
|
// the list of possible helpers:
|
|
3
3
|
// https://github.com/babel/babel/blob/99f4f6c3b03c7f3f67cf1b9f1a21b80cfd5b0224/packages/babel-helpers/src/helpers.js#L13
|
|
4
|
-
import { fileSystemPathToUrl } from "@jsenv/filesystem"
|
|
5
4
|
import { require } from "../../require.js"
|
|
6
5
|
|
|
7
6
|
const babelHelperNameInsideJsenvCoreArray = [
|
|
@@ -113,13 +112,14 @@ export const babelHelperNameToImportSpecifier = (babelHelperName) => {
|
|
|
113
112
|
return `${babelHelperAbstractScope}${babelHelperName}/${babelHelperName}.js`
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
export const
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
export const babelHelperNameFromUrl = (url) => {
|
|
116
|
+
if (!url.startsWith("file://")) {
|
|
117
|
+
return null
|
|
118
|
+
}
|
|
119
119
|
const babelHelperPrefix = "core/helpers/babel/"
|
|
120
|
-
if (
|
|
121
|
-
const afterBabelHelper =
|
|
122
|
-
|
|
120
|
+
if (url.includes(babelHelperPrefix)) {
|
|
121
|
+
const afterBabelHelper = url.slice(
|
|
122
|
+
url.indexOf(babelHelperPrefix) + babelHelperPrefix.length,
|
|
123
123
|
)
|
|
124
124
|
const babelHelperName = afterBabelHelper.slice(
|
|
125
125
|
0,
|
|
@@ -127,11 +127,9 @@ export const filePathToBabelHelperName = (filePath) => {
|
|
|
127
127
|
)
|
|
128
128
|
return babelHelperName
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
fileUrl.indexOf(babelHelperAbstractScope) +
|
|
134
|
-
babelHelperAbstractScope.length,
|
|
130
|
+
if (url.includes(babelHelperAbstractScope)) {
|
|
131
|
+
const afterBabelHelper = url.slice(
|
|
132
|
+
url.indexOf(babelHelperAbstractScope) + babelHelperAbstractScope.length,
|
|
135
133
|
)
|
|
136
134
|
const babelHelperName = afterBabelHelper.slice(
|
|
137
135
|
0,
|
|
@@ -139,7 +137,6 @@ export const filePathToBabelHelperName = (filePath) => {
|
|
|
139
137
|
)
|
|
140
138
|
return babelHelperName
|
|
141
139
|
}
|
|
142
|
-
|
|
143
140
|
return null
|
|
144
141
|
}
|
|
145
142
|
|
package/src/internal/compiling/js-compilation-service/babel_plugin_babel_helpers_as_jsenv_imports.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { fileSystemPathToUrl } from "@jsenv/filesystem"
|
|
2
|
+
|
|
1
3
|
import { require } from "../../require.js"
|
|
2
4
|
import {
|
|
3
|
-
|
|
5
|
+
babelHelperNameFromUrl,
|
|
4
6
|
babelHelperNameToImportSpecifier,
|
|
5
7
|
} from "./babelHelper.js"
|
|
6
8
|
|
|
@@ -37,7 +39,7 @@ export const babelPluginBabelHelpersAsJsenvImports = (api) => {
|
|
|
37
39
|
const babelHelperImportSpecifier =
|
|
38
40
|
babelHelperNameToImportSpecifier(name)
|
|
39
41
|
|
|
40
|
-
if (
|
|
42
|
+
if (babelHelperNameFromUrl(fileSystemPathToUrl(filePath)) === name) {
|
|
41
43
|
return undefined
|
|
42
44
|
}
|
|
43
45
|
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import { urlToRelativeUrl } from "@jsenv/filesystem"
|
|
1
|
+
import { urlToRelativeUrl, urlToFileSystemPath } from "@jsenv/filesystem"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { require } from "@jsenv/core/src/internal/require.js"
|
|
4
|
+
import { createParseError } from "@jsenv/core/src/internal/compiling/babel_parse_error.js"
|
|
5
|
+
import { babelPluginTransformImportMeta } from "@jsenv/core/src/internal/compiling/babel_plugin_transform_import_meta.js"
|
|
6
|
+
import {
|
|
7
|
+
getMinimalBabelPluginMap,
|
|
8
|
+
babelPluginsFromBabelPluginMap,
|
|
9
|
+
} from "@jsenv/core/src/internal/compiling/babel_plugins.js"
|
|
10
|
+
import { babelPluginProxyExternalImports } from "@jsenv/core/src/internal/compiling/babel_plugin_proxy_external_imports.js"
|
|
11
|
+
import { babelPluginImportMetadata } from "@jsenv/core/src/internal/compiling/babel_plugin_import_metadata.js"
|
|
12
|
+
|
|
13
|
+
import { ansiToHTML } from "./ansiToHTML.js"
|
|
14
|
+
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
15
|
+
import { babelPluginBabelHelpersAsJsenvImports } from "./babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
16
|
+
import { babelPluginSystemJsPrepend } from "./babel_plugin_systemjs_prepend.js"
|
|
17
|
+
import { babelHelperNameFromUrl } from "./babelHelper.js"
|
|
4
18
|
|
|
5
19
|
export const transformJs = async ({
|
|
6
20
|
projectDirectoryUrl,
|
|
@@ -17,6 +31,7 @@ export const transformJs = async ({
|
|
|
17
31
|
sourcemapEnabled = true,
|
|
18
32
|
|
|
19
33
|
map,
|
|
34
|
+
ast,
|
|
20
35
|
code,
|
|
21
36
|
}) => {
|
|
22
37
|
if (typeof projectDirectoryUrl !== "string") {
|
|
@@ -40,29 +55,144 @@ export const transformJs = async ({
|
|
|
40
55
|
`babelHelpersInjectionAsImport can be enabled only when "moduleOutFormat" is "esmodule"`,
|
|
41
56
|
)
|
|
42
57
|
}
|
|
58
|
+
const relativeUrl = url.startsWith(projectDirectoryUrl)
|
|
59
|
+
? urlToRelativeUrl(url, projectDirectoryUrl)
|
|
60
|
+
: undefined
|
|
43
61
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
const inputPath = computeInputPath(url)
|
|
63
|
+
// https://babeljs.io/docs/en/options
|
|
64
|
+
const options = {
|
|
65
|
+
filename: inputPath,
|
|
66
|
+
filenameRelative: relativeUrl,
|
|
67
|
+
inputSourceMap: map,
|
|
68
|
+
configFile: false,
|
|
69
|
+
babelrc: false, // trust only these options, do not read any babelrc config file
|
|
70
|
+
ast: true,
|
|
71
|
+
sourceMaps: sourcemapEnabled,
|
|
72
|
+
sourceFileName: inputPath,
|
|
73
|
+
// https://babeljs.io/docs/en/options#parseropts
|
|
74
|
+
parserOpts: {
|
|
75
|
+
allowAwaitOutsideFunction:
|
|
76
|
+
topLevelAwait === undefined ||
|
|
77
|
+
topLevelAwait === "return" ||
|
|
78
|
+
topLevelAwait === "simple" ||
|
|
79
|
+
topLevelAwait === "ignore",
|
|
80
|
+
},
|
|
81
|
+
generatorOpts: {
|
|
82
|
+
compact: false,
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
const babelHelperName = babelHelperNameFromUrl(url)
|
|
86
|
+
// to prevent typeof circular dependency
|
|
87
|
+
if (babelHelperName === "typeof") {
|
|
88
|
+
const babelPluginMapWithoutTransformTypeOf = { ...babelPluginMap }
|
|
89
|
+
delete babelPluginMapWithoutTransformTypeOf["transform-typeof-symbol"]
|
|
90
|
+
babelPluginMap = babelPluginMapWithoutTransformTypeOf
|
|
91
|
+
}
|
|
92
|
+
if (transformGenerator) {
|
|
93
|
+
babelPluginMap = {
|
|
94
|
+
...babelPluginMap,
|
|
95
|
+
"regenerator-runtime-as-jsenv-import": [
|
|
96
|
+
babelPluginRegeneratorRuntimeAsJsenvImport,
|
|
97
|
+
],
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
babelPluginMap = {
|
|
101
|
+
...getMinimalBabelPluginMap(),
|
|
102
|
+
"transform-import-meta": [
|
|
103
|
+
babelPluginTransformImportMeta,
|
|
104
|
+
{
|
|
105
|
+
importMetaFormat,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
...babelPluginMap,
|
|
109
|
+
...(babelHelpersInjectionAsImport
|
|
110
|
+
? {
|
|
111
|
+
"babel-helpers-as-jsenv-imports": [
|
|
112
|
+
babelPluginBabelHelpersAsJsenvImports,
|
|
113
|
+
],
|
|
114
|
+
}
|
|
115
|
+
: {}),
|
|
116
|
+
...(jsenvRemoteDirectory
|
|
117
|
+
? {
|
|
118
|
+
"proxy-external-imports": [
|
|
119
|
+
babelPluginProxyExternalImports,
|
|
120
|
+
{ jsenvRemoteDirectory },
|
|
121
|
+
],
|
|
122
|
+
}
|
|
123
|
+
: {}),
|
|
124
|
+
"import-metadata": [babelPluginImportMetadata],
|
|
125
|
+
}
|
|
126
|
+
if (moduleOutFormat === "systemjs") {
|
|
127
|
+
const transformModulesSystemJs = require("@babel/plugin-transform-modules-systemjs")
|
|
128
|
+
const proposalDynamicImport = require("@babel/plugin-proposal-dynamic-import")
|
|
129
|
+
babelPluginMap = {
|
|
130
|
+
...babelPluginMap,
|
|
131
|
+
"proposal-dynamic-import": [proposalDynamicImport],
|
|
132
|
+
"transform-modules-systemjs": [transformModulesSystemJs],
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (prependSystemJs) {
|
|
136
|
+
babelPluginMap = {
|
|
137
|
+
...babelPluginMap,
|
|
138
|
+
"systemjs-prepend": [babelPluginSystemJsPrepend],
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const asyncToPromise = babelPluginMap["transform-async-to-promises"]
|
|
143
|
+
if (topLevelAwait && asyncToPromise) {
|
|
144
|
+
asyncToPromise.options.topLevelAwait = topLevelAwait
|
|
145
|
+
}
|
|
146
|
+
const babelTransformReturnValue = await babelTransform({
|
|
147
|
+
ast,
|
|
51
148
|
code,
|
|
52
|
-
|
|
149
|
+
options: {
|
|
150
|
+
...options,
|
|
151
|
+
plugins: babelPluginsFromBabelPluginMap(babelPluginMap),
|
|
152
|
+
},
|
|
153
|
+
})
|
|
154
|
+
code = babelTransformReturnValue.code
|
|
155
|
+
map = babelTransformReturnValue.map
|
|
156
|
+
ast = babelTransformReturnValue.ast
|
|
157
|
+
const { metadata } = babelTransformReturnValue
|
|
158
|
+
return { code, map, metadata, ast }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const computeInputPath = (url) => {
|
|
162
|
+
if (url.startsWith("file://")) {
|
|
163
|
+
return urlToFileSystemPath(url)
|
|
164
|
+
}
|
|
165
|
+
return url
|
|
166
|
+
}
|
|
53
167
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
importMetaFormat,
|
|
168
|
+
const babelTransform = async ({ ast, code, options }) => {
|
|
169
|
+
const { transformAsync, transformFromAstAsync } = await import("@babel/core")
|
|
57
170
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
171
|
+
try {
|
|
172
|
+
if (ast) {
|
|
173
|
+
const result = await transformFromAstAsync(ast, code, options)
|
|
174
|
+
return result
|
|
175
|
+
}
|
|
176
|
+
return await transformAsync(code, options)
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error && error.code === "BABEL_PARSE_ERROR") {
|
|
179
|
+
const message = error.message
|
|
180
|
+
const messageWithoutAnsi = message.replace(ansiRegex, "")
|
|
181
|
+
throw createParseError({
|
|
182
|
+
cause: error,
|
|
183
|
+
message: messageWithoutAnsi,
|
|
184
|
+
messageHTML: ansiToHTML(message),
|
|
185
|
+
filename: options.filename,
|
|
186
|
+
lineNumber: error.loc.line,
|
|
187
|
+
columnNumber: error.loc.column,
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
throw error
|
|
191
|
+
}
|
|
68
192
|
}
|
|
193
|
+
|
|
194
|
+
const pattern = [
|
|
195
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
196
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
|
|
197
|
+
].join("|")
|
|
198
|
+
const ansiRegex = new RegExp(pattern, "g")
|