@jsenv/core 25.3.0-alpha.0 → 25.4.2
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_f4285042.js.map +343 -0
- package/dist/compile_proxy/{compile_proxy_8dfaee51.html → compile_proxy_ab528227.html} +358 -397
- package/dist/redirector/asset-manifest.json +2 -2
- package/dist/redirector/redirector.html__inline__12_404b8295.js.map +349 -0
- package/dist/redirector/{redirector_3e9a97b9.html → redirector_6df2620a.html} +369 -407
- package/dist/toolbar/asset-manifest.json +2 -2
- package/dist/toolbar/toolbar.main_279b3a68.js.map +764 -0
- package/dist/toolbar/{toolbar_361afb84.html → toolbar_0a91ca3b.html} +1509 -1583
- package/dist/toolbar_injector/asset-manifest.json +2 -2
- package/dist/toolbar_injector/{toolbar_injector_fac1e995.js → toolbar_injector_34f6ad8e.js} +18 -15
- package/dist/toolbar_injector/{toolbar_injector_fac1e995.js.map → toolbar_injector_34f6ad8e.js.map} +15 -15
- package/package.json +10 -10
- package/src/buildProject.js +31 -26
- package/src/dev_server.js +111 -92
- package/src/execute.js +3 -8
- package/src/importUsingChildProcess.js +1 -0
- 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/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} +53 -36
- 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/transformJs.js +151 -23
- package/src/internal/compiling/jsenvCompilerForHtml.js +29 -32
- 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 +1 -1
- 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 +157 -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 +92 -78
- package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
- package/src/internal/dev_server/toolbar/toolbar.html +46 -16
- package/src/internal/dev_server/toolbar/toolbar.injector.js +17 -15
- package/src/internal/dev_server/toolbar/toolbar.main.js +12 -16
- 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 +89 -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/node_launcher/createControllableNodeProcess.js +4 -6
- 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/nodeControllableFile.mjs +1 -5
- package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
- package/src/internal/redirector/redirector.html +40 -0
- 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/toolbar.main_6c1b3d82.js.map +0 -802
- 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 -242
- package/src/internal/dev_server/redirector/redirector.html +0 -48
- 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/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
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const COMPILE_ID_BEST = "best"
|
|
2
|
-
|
|
3
|
-
export const COMPILE_ID_OTHERWISE = "otherwise"
|
|
4
|
-
|
|
5
|
-
export const COMPILE_ID_BUILD_GLOBAL = "build-global"
|
|
6
|
-
|
|
7
|
-
export const COMPILE_ID_BUILD_GLOBAL_FILES = "build-global-files"
|
|
8
|
-
|
|
9
|
-
export const COMPILE_ID_BUILD_COMMONJS = "build-commonjs"
|
|
10
|
-
|
|
11
|
-
export const COMPILE_ID_BUILD_COMMONJS_FILES = "build-commonjs-files"
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
|
|
3
|
-
import { computeCompileIdFromGroupId } from "../runtime/computeCompileIdFromGroupId.js"
|
|
4
|
-
import { resolveGroup } from "../runtime/resolveGroup.js"
|
|
5
|
-
import { fetchJson } from "../browser_utils/fetchJson.js"
|
|
6
|
-
import { detectBrowser } from "../browser_detection/browser_detection.js"
|
|
7
|
-
|
|
8
|
-
export const scanBrowserRuntimeFeatures = async ({
|
|
9
|
-
coverageHandledFromOutside = false,
|
|
10
|
-
failFastOnFeatureDetection = false,
|
|
11
|
-
} = {}) => {
|
|
12
|
-
const {
|
|
13
|
-
outDirectoryRelativeUrl,
|
|
14
|
-
inlineImportMapIntoHTML,
|
|
15
|
-
customCompilerPatterns,
|
|
16
|
-
compileServerGroupMap,
|
|
17
|
-
} = await fetchJson("/.jsenv/__compile_server_meta__.json")
|
|
18
|
-
|
|
19
|
-
const browser = detectBrowser()
|
|
20
|
-
const compileId = computeCompileIdFromGroupId({
|
|
21
|
-
groupId: resolveGroup(browser, compileServerGroupMap),
|
|
22
|
-
groupMap: compileServerGroupMap,
|
|
23
|
-
})
|
|
24
|
-
const groupInfo = compileServerGroupMap[compileId]
|
|
25
|
-
|
|
26
|
-
const featuresReport = {
|
|
27
|
-
importmap: undefined,
|
|
28
|
-
dynamicImport: undefined,
|
|
29
|
-
topLevelAwait: undefined,
|
|
30
|
-
jsonImportAssertions: undefined,
|
|
31
|
-
cssImportAssertions: undefined,
|
|
32
|
-
newStylesheet: undefined,
|
|
33
|
-
}
|
|
34
|
-
await detectSupportedFeatures({
|
|
35
|
-
featuresReport,
|
|
36
|
-
failFastOnFeatureDetection,
|
|
37
|
-
inlineImportMapIntoHTML,
|
|
38
|
-
})
|
|
39
|
-
const missingFeatureNames = await adjustMissingFeatureNames(groupInfo, {
|
|
40
|
-
featuresReport,
|
|
41
|
-
coverageHandledFromOutside,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const canAvoidCompilation =
|
|
45
|
-
customCompilerPatterns.length === 0 &&
|
|
46
|
-
missingFeatureNames.length === 0 &&
|
|
47
|
-
featuresReport.importmap &&
|
|
48
|
-
featuresReport.dynamicImport &&
|
|
49
|
-
featuresReport.topLevelAwait
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
canAvoidCompilation,
|
|
53
|
-
featuresReport,
|
|
54
|
-
customCompilerPatterns,
|
|
55
|
-
missingFeatureNames,
|
|
56
|
-
inlineImportMapIntoHTML,
|
|
57
|
-
outDirectoryRelativeUrl,
|
|
58
|
-
compileId,
|
|
59
|
-
browser,
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const adjustMissingFeatureNames = async (
|
|
64
|
-
groupInfo,
|
|
65
|
-
{ featuresReport, coverageHandledFromOutside },
|
|
66
|
-
) => {
|
|
67
|
-
const { missingFeatureNames } = groupInfo
|
|
68
|
-
const missingFeatureNamesCopy = missingFeatureNames.slice()
|
|
69
|
-
const markAsSupported = (name) => {
|
|
70
|
-
const index = missingFeatureNamesCopy.indexOf(name)
|
|
71
|
-
if (index > -1) {
|
|
72
|
-
missingFeatureNamesCopy.splice(index, 1)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// When instrumentation CAN be handed by playwright
|
|
76
|
-
// https://playwright.dev/docs/api/class-chromiumcoverage#chromiumcoveragestartjscoverageoptions
|
|
77
|
-
// coverageHandledFromOutside is true and "transform-instrument" becomes non mandatory
|
|
78
|
-
if (coverageHandledFromOutside) {
|
|
79
|
-
markAsSupported("transform-instrument")
|
|
80
|
-
}
|
|
81
|
-
if (missingFeatureNames.includes("transform-import-assertions")) {
|
|
82
|
-
const jsonImportAssertions = await supportsJsonImportAssertions()
|
|
83
|
-
featuresReport.jsonImportAssertions = jsonImportAssertions
|
|
84
|
-
|
|
85
|
-
const cssImportAssertions = await supportsCssImportAssertions()
|
|
86
|
-
featuresReport.cssImportAssertions = cssImportAssertions
|
|
87
|
-
|
|
88
|
-
if (jsonImportAssertions && cssImportAssertions) {
|
|
89
|
-
markAsSupported("transform-import-assertions")
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (missingFeatureNames.includes("new-stylesheet-as-jsenv-import")) {
|
|
93
|
-
const newStylesheet = supportsNewStylesheet()
|
|
94
|
-
featuresReport.newStylesheet = newStylesheet
|
|
95
|
-
markAsSupported("new-stylesheet-as-jsenv-import")
|
|
96
|
-
}
|
|
97
|
-
return missingFeatureNamesCopy
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const detectSupportedFeatures = async ({
|
|
101
|
-
featuresReport,
|
|
102
|
-
failFastOnFeatureDetection,
|
|
103
|
-
inlineImportMapIntoHTML,
|
|
104
|
-
}) => {
|
|
105
|
-
// start testing importmap support first and not in paralell
|
|
106
|
-
// so that there is not module script loaded beore importmap is injected
|
|
107
|
-
// it would log an error in chrome console and return undefined
|
|
108
|
-
const importmap = await supportsImportmap({
|
|
109
|
-
// chrome supports inline but not remote importmap
|
|
110
|
-
// https://github.com/WICG/import-maps/issues/235
|
|
111
|
-
|
|
112
|
-
// at this stage we won't know if the html file will use
|
|
113
|
-
// an importmap or not and if that importmap is inline or specified with an src
|
|
114
|
-
// so we should test if browser support local and remote importmap.
|
|
115
|
-
// But there exploring server can inline importmap by transforming html
|
|
116
|
-
// and in that case we can test only the local importmap support
|
|
117
|
-
// so we test importmap support and the remote one
|
|
118
|
-
remote: !inlineImportMapIntoHTML,
|
|
119
|
-
})
|
|
120
|
-
featuresReport.importmap = importmap
|
|
121
|
-
if (!importmap && failFastOnFeatureDetection) {
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const dynamicImport = await supportsDynamicImport()
|
|
126
|
-
featuresReport.dynamicImport = dynamicImport
|
|
127
|
-
if (!dynamicImport && failFastOnFeatureDetection) {
|
|
128
|
-
return
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const topLevelAwait = await supportsTopLevelAwait()
|
|
132
|
-
featuresReport.topLevelAwait = topLevelAwait
|
|
133
|
-
if (!topLevelAwait && failFastOnFeatureDetection) {
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const supportsImportmap = async ({ remote = true } = {}) => {
|
|
139
|
-
const specifier = asBase64Url(`export default false`)
|
|
140
|
-
const importMap = {
|
|
141
|
-
imports: {
|
|
142
|
-
[specifier]: asBase64Url(`export default true`),
|
|
143
|
-
},
|
|
144
|
-
}
|
|
145
|
-
const importmapScript = document.createElement("script")
|
|
146
|
-
const importmapString = JSON.stringify(importMap, null, " ")
|
|
147
|
-
importmapScript.type = "importmap"
|
|
148
|
-
if (remote) {
|
|
149
|
-
importmapScript.src = `data:application/json;base64,${window.btoa(
|
|
150
|
-
importmapString,
|
|
151
|
-
)}`
|
|
152
|
-
} else {
|
|
153
|
-
importmapScript.textContent = importmapString
|
|
154
|
-
}
|
|
155
|
-
document.body.appendChild(importmapScript)
|
|
156
|
-
|
|
157
|
-
try {
|
|
158
|
-
await executeWithScriptModuleInjection(
|
|
159
|
-
`import supported from "${specifier}"; window.__jsenv_runtime_test_importmap__ = supported`,
|
|
160
|
-
)
|
|
161
|
-
document.body.removeChild(importmapScript)
|
|
162
|
-
return window.__jsenv_runtime_test_importmap__
|
|
163
|
-
} catch (e) {
|
|
164
|
-
document.body.removeChild(importmapScript)
|
|
165
|
-
return false
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const supportsDynamicImport = async () => {
|
|
170
|
-
const moduleSource = asBase64Url(`export default 42`)
|
|
171
|
-
try {
|
|
172
|
-
await executeWithScriptModuleInjection(
|
|
173
|
-
`window.__jsenv_runtime_test_dynamic_import__ = import(${JSON.stringify(
|
|
174
|
-
moduleSource,
|
|
175
|
-
)})`,
|
|
176
|
-
)
|
|
177
|
-
const namespace = await window.__jsenv_runtime_test_dynamic_import__
|
|
178
|
-
return namespace.default === 42
|
|
179
|
-
} catch (e) {
|
|
180
|
-
return false
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const supportsNewStylesheet = () => {
|
|
185
|
-
try {
|
|
186
|
-
// eslint-disable-next-line no-new
|
|
187
|
-
new CSSStyleSheet()
|
|
188
|
-
return true
|
|
189
|
-
} catch (e) {
|
|
190
|
-
return false
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const supportsTopLevelAwait = async () => {
|
|
195
|
-
try {
|
|
196
|
-
await executeWithScriptModuleInjection(
|
|
197
|
-
`window.__jsenv_runtime_test_top_level_await__ = await Promise.resolve(42)`,
|
|
198
|
-
)
|
|
199
|
-
return window.__jsenv_runtime_test_top_level_await__ === 42
|
|
200
|
-
} catch (e) {
|
|
201
|
-
return false
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// to execute in a browser devtools
|
|
206
|
-
// const featuresReport = {}
|
|
207
|
-
// await detectSupportedFeatures({ featuresReport, inlineImportMapIntoHTML: true })
|
|
208
|
-
// console.log(featuresReport)
|
|
209
|
-
|
|
210
|
-
const supportsJsonImportAssertions = async () => {
|
|
211
|
-
const jsonBase64Url = asBase64Url("42", "application/json")
|
|
212
|
-
const moduleSource = asBase64Url(
|
|
213
|
-
`import data from "${jsonBase64Url}" assert { type: "json" }
|
|
214
|
-
export default data`,
|
|
215
|
-
)
|
|
216
|
-
try {
|
|
217
|
-
await executeWithScriptModuleInjection(
|
|
218
|
-
`window.__jsenv_runtime_test_json_import_assertion__ = import(${JSON.stringify(
|
|
219
|
-
moduleSource,
|
|
220
|
-
)})`,
|
|
221
|
-
)
|
|
222
|
-
const namespace = await window.__jsenv_runtime_test_json_import_assertion__
|
|
223
|
-
return namespace.default === 42
|
|
224
|
-
} catch (e) {
|
|
225
|
-
return false
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const supportsCssImportAssertions = async () => {
|
|
230
|
-
const cssBase64Url = asBase64Url("p { color: red; }", "text/css")
|
|
231
|
-
const moduleSource = asBase64Url(
|
|
232
|
-
`import css from "${cssBase64Url}" assert { type: "css" }
|
|
233
|
-
export default css`,
|
|
234
|
-
)
|
|
235
|
-
try {
|
|
236
|
-
await executeWithScriptModuleInjection(
|
|
237
|
-
`window.__jsenv_runtime_test_css_import_assertion__ = import(${JSON.stringify(
|
|
238
|
-
moduleSource,
|
|
239
|
-
)})`,
|
|
240
|
-
)
|
|
241
|
-
const namespace = await window.__jsenv_runtime_test_css_import_assertion__
|
|
242
|
-
return namespace.default instanceof CSSStyleSheet
|
|
243
|
-
} catch (e) {
|
|
244
|
-
return false
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const executeWithScriptModuleInjection = (code) => {
|
|
249
|
-
const scriptModule = document.createElement("script")
|
|
250
|
-
scriptModule.type = "module"
|
|
251
|
-
|
|
252
|
-
const loadPromise = new Promise((resolve, reject) => {
|
|
253
|
-
scriptModule.onload = () => {
|
|
254
|
-
document.body.removeChild(scriptModule)
|
|
255
|
-
resolve()
|
|
256
|
-
}
|
|
257
|
-
scriptModule.onerror = () => {
|
|
258
|
-
document.body.removeChild(scriptModule)
|
|
259
|
-
reject()
|
|
260
|
-
}
|
|
261
|
-
document.body.appendChild(scriptModule)
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
scriptModule.src = asBase64Url(code)
|
|
265
|
-
|
|
266
|
-
return loadPromise
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
const asBase64Url = (text, mimeType = "application/javascript") => {
|
|
270
|
-
return `data:${mimeType};base64,${window.btoa(text)}`
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// const cssImportAssertions = await supportsCssImportAssertions()
|
|
274
|
-
// console.log({ cssImportAssertions })
|
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import { urlToFileSystemPath } from "@jsenv/filesystem"
|
|
2
|
-
|
|
3
|
-
import { require } from "@jsenv/core/src/internal/require.js"
|
|
4
|
-
import { babelPluginTransformImportMeta } from "@jsenv/core/src/internal/babel_plugin_transform_import_meta.js"
|
|
5
|
-
import {
|
|
6
|
-
getMinimalBabelPluginMap,
|
|
7
|
-
babelPluginsFromBabelPluginMap,
|
|
8
|
-
} from "@jsenv/core/src/internal/compiling/babel_plugins.js"
|
|
9
|
-
import { babelPluginProxyExternalImports } from "@jsenv/core/src/internal/compiling/babel_plugin_proxy_external_imports.js"
|
|
10
|
-
import { babelPluginImportMetadata } from "@jsenv/core/src/internal/compiling/babel_plugin_import_metadata.js"
|
|
11
|
-
|
|
12
|
-
import { ansiToHTML } from "./ansiToHTML.js"
|
|
13
|
-
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
14
|
-
import { babelPluginBabelHelpersAsJsenvImports } from "./babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
15
|
-
import { babelPluginSystemJsPrepend } from "./babel_plugin_systemjs_prepend.js"
|
|
16
|
-
import { babelHelperNameFromUrl } from "./babelHelper.js"
|
|
17
|
-
|
|
18
|
-
export const jsenvTransform = async ({
|
|
19
|
-
jsenvRemoteDirectory,
|
|
20
|
-
url,
|
|
21
|
-
relativeUrl, // optional
|
|
22
|
-
|
|
23
|
-
babelPluginMap,
|
|
24
|
-
moduleOutFormat,
|
|
25
|
-
importMetaFormat = moduleOutFormat,
|
|
26
|
-
topLevelAwait,
|
|
27
|
-
babelHelpersInjectionAsImport,
|
|
28
|
-
prependSystemJs,
|
|
29
|
-
transformGenerator,
|
|
30
|
-
regeneratorRuntimeImportPath,
|
|
31
|
-
|
|
32
|
-
sourcemapEnabled,
|
|
33
|
-
ast, // optional
|
|
34
|
-
map, // optional
|
|
35
|
-
code,
|
|
36
|
-
}) => {
|
|
37
|
-
const transformModulesSystemJs = require("@babel/plugin-transform-modules-systemjs")
|
|
38
|
-
const proposalDynamicImport = require("@babel/plugin-proposal-dynamic-import")
|
|
39
|
-
const inputPath = computeInputPath(url)
|
|
40
|
-
|
|
41
|
-
// https://babeljs.io/docs/en/options
|
|
42
|
-
const options = {
|
|
43
|
-
filename: inputPath,
|
|
44
|
-
filenameRelative: relativeUrl,
|
|
45
|
-
inputSourceMap: map,
|
|
46
|
-
configFile: false,
|
|
47
|
-
babelrc: false, // trust only these options, do not read any babelrc config file
|
|
48
|
-
ast: true,
|
|
49
|
-
sourceMaps: sourcemapEnabled,
|
|
50
|
-
sourceFileName: inputPath,
|
|
51
|
-
// https://babeljs.io/docs/en/options#parseropts
|
|
52
|
-
parserOpts: {
|
|
53
|
-
allowAwaitOutsideFunction:
|
|
54
|
-
topLevelAwait === undefined ||
|
|
55
|
-
topLevelAwait === "return" ||
|
|
56
|
-
topLevelAwait === "simple" ||
|
|
57
|
-
topLevelAwait === "ignore",
|
|
58
|
-
},
|
|
59
|
-
generatorOpts: {
|
|
60
|
-
compact: false,
|
|
61
|
-
},
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const babelHelperName = babelHelperNameFromUrl(url)
|
|
65
|
-
// to prevent typeof circular dependency
|
|
66
|
-
if (babelHelperName === "typeof") {
|
|
67
|
-
const babelPluginMapWithoutTransformTypeOf = { ...babelPluginMap }
|
|
68
|
-
delete babelPluginMapWithoutTransformTypeOf["transform-typeof-symbol"]
|
|
69
|
-
babelPluginMap = babelPluginMapWithoutTransformTypeOf
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (transformGenerator) {
|
|
73
|
-
babelPluginMap = {
|
|
74
|
-
...babelPluginMap,
|
|
75
|
-
"regenerator-runtime-as-jsenv-import": [
|
|
76
|
-
babelPluginRegeneratorRuntimeAsJsenvImport,
|
|
77
|
-
{
|
|
78
|
-
regeneratorRuntimeImportPath,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
babelPluginMap = {
|
|
84
|
-
...getMinimalBabelPluginMap(),
|
|
85
|
-
"transform-import-meta": [
|
|
86
|
-
babelPluginTransformImportMeta,
|
|
87
|
-
{
|
|
88
|
-
replaceImportMeta: (
|
|
89
|
-
metaPropertyName,
|
|
90
|
-
{ replaceWithImport, replaceWithValue },
|
|
91
|
-
) => {
|
|
92
|
-
if (metaPropertyName === "url") {
|
|
93
|
-
if (importMetaFormat === "esmodule") {
|
|
94
|
-
// keep native version
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
if (importMetaFormat === "systemjs") {
|
|
98
|
-
// systemjs will handle it
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
if (importMetaFormat === "commonjs") {
|
|
102
|
-
replaceWithImport({
|
|
103
|
-
from: `@jsenv/core/helpers/import-meta/import-meta-url-commonjs.js`,
|
|
104
|
-
})
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
if (importMetaFormat === "global") {
|
|
108
|
-
replaceWithImport({
|
|
109
|
-
from: `@jsenv/core/helpers/import-meta/import-meta-url-global.js`,
|
|
110
|
-
})
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
return
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (metaPropertyName === "resolve") {
|
|
117
|
-
if (importMetaFormat === "esmodule") {
|
|
118
|
-
// keep native version
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
if (importMetaFormat === "systemjs") {
|
|
122
|
-
// systemjs will handle it
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
if (importMetaFormat === "commonjs") {
|
|
126
|
-
throw createParseError({
|
|
127
|
-
message: `import.meta.resolve() not supported with commonjs format`,
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
if (importMetaFormat === "global") {
|
|
131
|
-
throw createParseError({
|
|
132
|
-
message: `import.meta.resolve() not supported with global format`,
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
return
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
replaceWithValue(undefined)
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
...babelPluginMap,
|
|
143
|
-
...(babelHelpersInjectionAsImport
|
|
144
|
-
? {
|
|
145
|
-
"babel-helpers-as-jsenv-imports": [
|
|
146
|
-
babelPluginBabelHelpersAsJsenvImports,
|
|
147
|
-
],
|
|
148
|
-
}
|
|
149
|
-
: {}),
|
|
150
|
-
...(jsenvRemoteDirectory
|
|
151
|
-
? {
|
|
152
|
-
"proxy-external-imports": [
|
|
153
|
-
babelPluginProxyExternalImports,
|
|
154
|
-
{ jsenvRemoteDirectory },
|
|
155
|
-
],
|
|
156
|
-
}
|
|
157
|
-
: {}),
|
|
158
|
-
"import-metadata": [babelPluginImportMetadata],
|
|
159
|
-
}
|
|
160
|
-
if (moduleOutFormat === "systemjs") {
|
|
161
|
-
babelPluginMap = {
|
|
162
|
-
...babelPluginMap,
|
|
163
|
-
"proposal-dynamic-import": [proposalDynamicImport],
|
|
164
|
-
"transform-modules-systemjs": [transformModulesSystemJs],
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (prependSystemJs) {
|
|
168
|
-
babelPluginMap = {
|
|
169
|
-
...babelPluginMap,
|
|
170
|
-
"systemjs-prepend": [babelPluginSystemJsPrepend],
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const asyncToPromise = babelPluginMap["transform-async-to-promises"]
|
|
175
|
-
if (topLevelAwait && asyncToPromise) {
|
|
176
|
-
asyncToPromise.options.topLevelAwait = topLevelAwait
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const babelTransformReturnValue = await babelTransform({
|
|
180
|
-
ast,
|
|
181
|
-
code,
|
|
182
|
-
options: {
|
|
183
|
-
...options,
|
|
184
|
-
plugins: babelPluginsFromBabelPluginMap(babelPluginMap),
|
|
185
|
-
},
|
|
186
|
-
})
|
|
187
|
-
code = babelTransformReturnValue.code
|
|
188
|
-
map = babelTransformReturnValue.map
|
|
189
|
-
ast = babelTransformReturnValue.ast
|
|
190
|
-
const { metadata } = babelTransformReturnValue
|
|
191
|
-
return { code, map, metadata, ast }
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const computeInputPath = (url) => {
|
|
195
|
-
if (url.startsWith("file://")) {
|
|
196
|
-
return urlToFileSystemPath(url)
|
|
197
|
-
}
|
|
198
|
-
return url
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const babelTransform = async ({ ast, code, options }) => {
|
|
202
|
-
const { transformAsync, transformFromAstAsync } = await import("@babel/core")
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
if (ast) {
|
|
206
|
-
const result = await transformFromAstAsync(ast, code, options)
|
|
207
|
-
return result
|
|
208
|
-
}
|
|
209
|
-
return await transformAsync(code, options)
|
|
210
|
-
} catch (error) {
|
|
211
|
-
if (error && error.code === "BABEL_PARSE_ERROR") {
|
|
212
|
-
const message = error.message
|
|
213
|
-
const messageWithoutAnsi = message.replace(ansiRegex, "")
|
|
214
|
-
throw createParseError({
|
|
215
|
-
cause: error,
|
|
216
|
-
message: messageWithoutAnsi,
|
|
217
|
-
messageHTML: ansiToHTML(message),
|
|
218
|
-
filename: options.filename,
|
|
219
|
-
lineNumber: error.loc.line,
|
|
220
|
-
columnNumber: error.loc.column,
|
|
221
|
-
})
|
|
222
|
-
}
|
|
223
|
-
throw error
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const pattern = [
|
|
228
|
-
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
229
|
-
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
|
|
230
|
-
].join("|")
|
|
231
|
-
const ansiRegex = new RegExp(pattern, "g")
|
|
232
|
-
|
|
233
|
-
const createParseError = ({ message, cause, ...data }) => {
|
|
234
|
-
const parseError = new Error(message, { cause })
|
|
235
|
-
parseError.code = "PARSE_ERROR"
|
|
236
|
-
parseError.data = {
|
|
237
|
-
message,
|
|
238
|
-
...data,
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return parseError
|
|
242
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>Jsenv redirector</title>
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
-
<meta charset="utf-8" />
|
|
7
|
-
<link rel="icon" href="data:," />
|
|
8
|
-
</head>
|
|
9
|
-
|
|
10
|
-
<body>
|
|
11
|
-
<script
|
|
12
|
-
type="importmap"
|
|
13
|
-
src="../../../../node_resolution.importmap"
|
|
14
|
-
></script>
|
|
15
|
-
<script type="module">
|
|
16
|
-
import { scanBrowserRuntimeFeatures } from "../../browser_feature_detection/browser_feature_detection.js"
|
|
17
|
-
|
|
18
|
-
const redirect = async () => {
|
|
19
|
-
const redirectTarget = new URLSearchParams(window.location.search).get(
|
|
20
|
-
"redirect",
|
|
21
|
-
)
|
|
22
|
-
const browserRuntimeFeaturesReport = await scanBrowserRuntimeFeatures({
|
|
23
|
-
failFastOnFeatureDetection: true,
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
const href = `${getDirectoryUrl(
|
|
27
|
-
browserRuntimeFeaturesReport,
|
|
28
|
-
)}${redirectTarget}`
|
|
29
|
-
// It's IMPORTANT to use location.replace and NOT location.href = url
|
|
30
|
-
// otherwise it would break the back button
|
|
31
|
-
window.location.replace(href)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const getDirectoryUrl = ({
|
|
35
|
-
canAvoidCompilation,
|
|
36
|
-
outDirectoryRelativeUrl,
|
|
37
|
-
compileId,
|
|
38
|
-
}) => {
|
|
39
|
-
if (canAvoidCompilation) {
|
|
40
|
-
return `/`
|
|
41
|
-
}
|
|
42
|
-
return `/${outDirectoryRelativeUrl}${compileId}/`
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
redirect()
|
|
46
|
-
</script>
|
|
47
|
-
</body>
|
|
48
|
-
</html>
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|
|
3
|
-
# featureCompatMap legend
|
|
4
|
-
|
|
5
|
-
featureName
|
|
6
|
-
│
|
|
7
|
-
{ ┌──────────┴────────────┐
|
|
8
|
-
"transform-block-scoping": {─┐
|
|
9
|
-
"chrome": "10", │
|
|
10
|
-
"safari": "3.0", minRuntimeVersions
|
|
11
|
-
"firefox": "5.1" │
|
|
12
|
-
}────┼─────────┼───────────────┘
|
|
13
|
-
} │ └─────┐
|
|
14
|
-
runtimeName runtimeVersion
|
|
15
|
-
|
|
16
|
-
# group legend
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
"best": {
|
|
20
|
-
"missingFeatureNames" : [
|
|
21
|
-
"transform-block-scoping",
|
|
22
|
-
],
|
|
23
|
-
"minRuntimeVersions": {
|
|
24
|
-
"chrome": "10",
|
|
25
|
-
"firefox": "6"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
Take chars below to update legends
|
|
31
|
-
─│┌┐└┘├┤┴┬
|
|
32
|
-
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
import { COMPILE_ID_OTHERWISE, COMPILE_ID_BEST } from "../CONSTANTS.js"
|
|
36
|
-
import { createRuntimeCompat } from "./runtime_compat.js"
|
|
37
|
-
|
|
38
|
-
export const generateGroupMap = ({ featureNames, runtimeSupport }) => {
|
|
39
|
-
if (!Array.isArray(featureNames)) {
|
|
40
|
-
throw new TypeError(`featureNames must be an array, got ${featureNames}`)
|
|
41
|
-
}
|
|
42
|
-
if (typeof runtimeSupport !== "object") {
|
|
43
|
-
throw new TypeError(
|
|
44
|
-
`runtimeSupport must be an object, got ${runtimeSupport}`,
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
const runtimeNames = Object.keys(runtimeSupport)
|
|
48
|
-
const groupWithoutFeature = {
|
|
49
|
-
missingFeatureNames: featureNames,
|
|
50
|
-
minRuntimeVersions: {},
|
|
51
|
-
}
|
|
52
|
-
if (runtimeNames.length === 0) {
|
|
53
|
-
return {
|
|
54
|
-
[COMPILE_ID_OTHERWISE]: groupWithoutFeature,
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const runtimeCompat = createRuntimeCompat({
|
|
58
|
-
runtimeSupport,
|
|
59
|
-
featureNames,
|
|
60
|
-
})
|
|
61
|
-
return {
|
|
62
|
-
[COMPILE_ID_BEST]: runtimeCompat,
|
|
63
|
-
[COMPILE_ID_OTHERWISE]: groupWithoutFeature,
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { findHighestVersion } from "../semantic_versioning/index.js"
|
|
2
|
-
|
|
3
|
-
export const createOneRuntimeCompat = ({
|
|
4
|
-
runtimeName,
|
|
5
|
-
runtimeVersion,
|
|
6
|
-
featureNames,
|
|
7
|
-
featuresCompatMap,
|
|
8
|
-
}) => {
|
|
9
|
-
const missingFeatureNames = []
|
|
10
|
-
// will be the first runtime version compatible with all features not listed in
|
|
11
|
-
// missingFeatureNames
|
|
12
|
-
let minRuntimeVersion
|
|
13
|
-
featureNames.forEach((featureName) => {
|
|
14
|
-
const featureCompat = featuresCompatMap[featureName] || {}
|
|
15
|
-
const runtimeVersionCompatible = featureCompat[runtimeName] || "Infinity"
|
|
16
|
-
|
|
17
|
-
const highestVersion = findHighestVersion(
|
|
18
|
-
runtimeVersion,
|
|
19
|
-
runtimeVersionCompatible,
|
|
20
|
-
)
|
|
21
|
-
const compatible = highestVersion === runtimeVersion
|
|
22
|
-
if (!compatible) {
|
|
23
|
-
missingFeatureNames.push(featureName)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (compatible && runtimeVersionCompatible !== "Infinity") {
|
|
27
|
-
// there is a version from which runtime becomes compatible with this feature
|
|
28
|
-
minRuntimeVersion = findHighestVersion(
|
|
29
|
-
minRuntimeVersion || "0.0.0",
|
|
30
|
-
runtimeVersionCompatible,
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
return {
|
|
35
|
-
missingFeatureNames,
|
|
36
|
-
minRuntimeVersion: minRuntimeVersion || runtimeVersion,
|
|
37
|
-
}
|
|
38
|
-
}
|