@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.
Files changed (114) hide show
  1. package/dist/browser_runtime/asset-manifest.json +2 -2
  2. package/dist/browser_runtime/{browser_runtime_91c5a3b8.js → browser_runtime_0e3396a1.js} +15 -16
  3. package/dist/browser_runtime/{browser_runtime_91c5a3b8.js.map → browser_runtime_0e3396a1.js.map} +13 -13
  4. package/dist/build_manifest.js +5 -5
  5. package/dist/compile_proxy/asset-manifest.json +2 -2
  6. package/dist/compile_proxy/compile_proxy.html__inline__20_2334a374.js.map +342 -0
  7. package/dist/compile_proxy/{compile_proxy_8dfaee51.html → compile_proxy_9f737eaf.html} +357 -398
  8. package/dist/redirector/asset-manifest.json +2 -2
  9. package/dist/redirector/redirector.html__inline__12_009c47c7.js.map +348 -0
  10. package/dist/redirector/{redirector_3e9a97b9.html → redirector_96f74871.html} +378 -421
  11. package/dist/toolbar/asset-manifest.json +2 -2
  12. package/dist/toolbar/{toolbar.main_6c1b3d82.js.map → toolbar.main_86335f90.js.map} +82 -115
  13. package/dist/toolbar/{toolbar_361afb84.html → toolbar_d3a918a4.html} +487 -508
  14. package/dist/toolbar_injector/asset-manifest.json +2 -2
  15. package/dist/toolbar_injector/toolbar_injector_978bbd14.js +267 -0
  16. package/dist/toolbar_injector/toolbar_injector_978bbd14.js.map +119 -0
  17. package/package.json +19 -14
  18. package/readme.md +54 -54
  19. package/src/buildProject.js +31 -26
  20. package/src/dev_server.js +78 -87
  21. package/src/execute.js +3 -8
  22. package/src/internal/browser_launcher/{browser_runtime_report.js → browser_runtime_profile.js} +21 -15
  23. package/src/internal/browser_launcher/executeHtmlFile.js +22 -14
  24. package/src/internal/browser_launcher/from_playwright.js +6 -4
  25. package/src/internal/browser_runtime/browser_runtime.js +12 -14
  26. package/src/internal/browser_runtime/createBrowserRuntime.js +7 -6
  27. package/src/internal/browser_utils/fetchAndEvalUsingFetch.js +1 -1
  28. package/src/internal/browser_utils/fetchJson.js +1 -1
  29. package/src/internal/browser_utils/{fetch-browser.js → fetch_browser.js} +0 -2
  30. package/src/internal/building/buildUsingRollup.js +41 -57
  31. package/src/internal/building/html/parseHtmlRessource.js +2 -1
  32. package/src/internal/building/rollup_plugin_jsenv.js +28 -8
  33. package/src/internal/compiling/babel_parse_error.js +9 -0
  34. package/src/internal/{babel_plugin_transform_import_meta.js → compiling/babel_plugin_transform_import_meta.js} +58 -9
  35. package/src/internal/compiling/compileFile.js +2 -2
  36. package/src/internal/compiling/compileHtml.js +1 -1
  37. package/src/internal/compiling/createCompiledFileService.js +25 -74
  38. package/src/internal/compiling/js-compilation-service/babelHelper.js +10 -13
  39. package/src/internal/compiling/js-compilation-service/babel_plugin_babel_helpers_as_jsenv_imports.js +4 -2
  40. package/src/internal/compiling/js-compilation-service/transformJs.js +153 -23
  41. package/src/internal/compiling/jsenvCompilerForHtml.js +34 -34
  42. package/src/internal/compiling/jsenvCompilerForImportmap.js +2 -2
  43. package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -4
  44. package/src/internal/compiling/jsenv_directory/comparison_utils.js +24 -0
  45. package/src/internal/compiling/{compile-directory/compile-asset.js → jsenv_directory/compile_asset.js} +0 -0
  46. package/src/internal/compiling/jsenv_directory/compile_context.js +68 -0
  47. package/src/internal/compiling/jsenv_directory/compile_profile.js +218 -0
  48. package/src/internal/compiling/{compile-directory/createLockRegistry.js → jsenv_directory/file_lock_registry.js} +0 -0
  49. package/src/internal/compiling/{compile-directory/createLockRegistry.test.js → jsenv_directory/file_lock_registry.test.js} +2 -1
  50. package/src/internal/compiling/{compile-directory → jsenv_directory}/fs-optimized-for-cache.js +0 -0
  51. package/src/internal/compiling/{compile-directory → jsenv_directory}/getOrGenerateCompiledFile.js +2 -2
  52. package/src/internal/compiling/jsenv_directory/jsenv_directory.js +174 -0
  53. package/src/internal/compiling/{compile-directory → jsenv_directory}/updateMeta.js +4 -2
  54. package/src/internal/compiling/{compile-directory → jsenv_directory}/validateCache.js +0 -0
  55. package/src/internal/compiling/sse_service/sse_service.js +369 -0
  56. package/src/internal/compiling/startCompileServer.js +156 -804
  57. package/src/internal/compiling/transformResultToCompilationResult.js +2 -2
  58. package/src/internal/dev_server/exploring/exploring.js +10 -8
  59. package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +85 -78
  60. package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
  61. package/src/internal/dev_server/toolbar/toolbar.html +40 -16
  62. package/src/internal/dev_server/toolbar/toolbar.injector.js +11 -17
  63. package/src/internal/dev_server/toolbar/toolbar.main.js +6 -6
  64. package/src/internal/executing/executeConcurrently.js +1 -1
  65. package/src/internal/executing/executePlan.js +2 -3
  66. package/src/internal/{generateGroupMap → features}/babel_plugins_compatibility.js +8 -8
  67. package/src/internal/features/browser_feature_detection/browser_feature_detect_dynamic_import.js +20 -0
  68. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_css.js +23 -0
  69. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_json.js +25 -0
  70. package/src/internal/features/browser_feature_detection/browser_feature_detect_importmap.js +37 -0
  71. package/src/internal/features/browser_feature_detection/browser_feature_detect_new_stylesheet.js +9 -0
  72. package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js +14 -0
  73. package/src/internal/features/browser_feature_detection/browser_feature_detection.js +85 -0
  74. package/src/internal/{browser_feature_detection → features/browser_feature_detection}/compile_proxy.html +1 -1
  75. package/src/internal/features/browser_feature_detection/execute_with_script_module.js +24 -0
  76. package/src/internal/features/features_compat_from_runtime.js +38 -0
  77. package/src/internal/features/features_compat_from_runtime_support.js +31 -0
  78. package/src/internal/{generateGroupMap → features}/features_compatibility.js +3 -3
  79. package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_dynamic_import.mjs +0 -0
  80. package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_top_level_await.mjs +0 -0
  81. package/src/internal/{node_feature_detection/nodeSupportsDynamicImport.js → features/node_feature_detection/node_feature_detect_dynamic_import.js} +0 -0
  82. package/src/internal/{node_feature_detection/nodeSupportsTopLevelAwait.js → features/node_feature_detection/node_feature_detect_top_level_await.js} +0 -0
  83. package/src/internal/features/node_feature_detection/node_feature_detection.js +66 -0
  84. package/src/internal/jsenv_remote_directory.js +1 -1
  85. package/src/internal/node_launcher/createControllableNodeProcess.js +4 -3
  86. package/src/internal/node_launcher/node_runtime_report.js +15 -9
  87. package/src/internal/node_runtime/fetchSource.js +2 -4
  88. package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
  89. package/src/internal/{dev_server/redirector → redirector}/redirector.html +8 -18
  90. package/src/internal/{generateGroupMap/jsenvRuntimeSupport.js → runtime_support/jsenv_runtime_support.js} +0 -0
  91. package/src/internal/{generateGroupMap → runtime_support}/runtime_support.js +0 -0
  92. package/src/internal/url_conversion.js +12 -17
  93. package/src/launchNode.js +29 -41
  94. package/dist/compile_proxy/compile_proxy.html__inline__20_809f35f7.js.map +0 -392
  95. package/dist/redirector/redirector.html__inline__15_e391410e.js.map +0 -397
  96. package/dist/toolbar_injector/toolbar_injector_fac1e995.js +0 -973
  97. package/dist/toolbar_injector/toolbar_injector_fac1e995.js.map +0 -294
  98. package/src/internal/CONSTANTS.js +0 -11
  99. package/src/internal/browser_feature_detection/browser_feature_detection.js +0 -274
  100. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +0 -243
  101. package/src/internal/generateGroupMap/generateGroupMap.js +0 -65
  102. package/src/internal/generateGroupMap/one_runtime_compat.js +0 -38
  103. package/src/internal/generateGroupMap/runtime_compat.js +0 -34
  104. package/src/internal/generateGroupMap/runtime_compat_composition.js +0 -76
  105. package/src/internal/generateGroupMap/shake_babel_plugin_map.js +0 -21
  106. package/src/internal/integrity/integrity_algorithms.js +0 -26
  107. package/src/internal/integrity/integrity_parsing.js +0 -50
  108. package/src/internal/integrity/integrity_update.js +0 -23
  109. package/src/internal/integrity/integrity_validation.js +0 -49
  110. package/src/internal/node_feature_detection/node_feature_detection.js +0 -117
  111. package/src/internal/node_runtime/detectNode.js +0 -3
  112. package/src/internal/runtime/computeCompileIdFromGroupId.js +0 -30
  113. package/src/internal/runtime/resolveGroup.js +0 -13
  114. package/src/internal/runtime/resolveRuntimeGroup.js +0 -11
@@ -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,243 +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 { filePathToBabelHelperName } 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
-
40
- const inputPath = computeInputPath(url)
41
-
42
- // https://babeljs.io/docs/en/options
43
- const options = {
44
- filename: inputPath,
45
- filenameRelative: relativeUrl,
46
- inputSourceMap: map,
47
- configFile: false,
48
- babelrc: false, // trust only these options, do not read any babelrc config file
49
- ast: true,
50
- sourceMaps: sourcemapEnabled,
51
- sourceFileName: inputPath,
52
- // https://babeljs.io/docs/en/options#parseropts
53
- parserOpts: {
54
- allowAwaitOutsideFunction:
55
- topLevelAwait === undefined ||
56
- topLevelAwait === "return" ||
57
- topLevelAwait === "simple" ||
58
- topLevelAwait === "ignore",
59
- },
60
- generatorOpts: {
61
- compact: false,
62
- },
63
- }
64
-
65
- const babelHelperName = filePathToBabelHelperName(inputPath)
66
- // to prevent typeof circular dependency
67
- if (babelHelperName === "typeof") {
68
- const babelPluginMapWithoutTransformTypeOf = { ...babelPluginMap }
69
- delete babelPluginMapWithoutTransformTypeOf["transform-typeof-symbol"]
70
- babelPluginMap = babelPluginMapWithoutTransformTypeOf
71
- }
72
-
73
- if (transformGenerator) {
74
- babelPluginMap = {
75
- ...babelPluginMap,
76
- "regenerator-runtime-as-jsenv-import": [
77
- babelPluginRegeneratorRuntimeAsJsenvImport,
78
- {
79
- regeneratorRuntimeImportPath,
80
- },
81
- ],
82
- }
83
- }
84
- babelPluginMap = {
85
- ...getMinimalBabelPluginMap(),
86
- "transform-import-meta": [
87
- babelPluginTransformImportMeta,
88
- {
89
- replaceImportMeta: (
90
- metaPropertyName,
91
- { replaceWithImport, replaceWithValue },
92
- ) => {
93
- if (metaPropertyName === "url") {
94
- if (importMetaFormat === "esmodule") {
95
- // keep native version
96
- return
97
- }
98
- if (importMetaFormat === "systemjs") {
99
- // systemjs will handle it
100
- return
101
- }
102
- if (importMetaFormat === "commonjs") {
103
- replaceWithImport({
104
- from: `@jsenv/core/helpers/import-meta/import-meta-url-commonjs.js`,
105
- })
106
- return
107
- }
108
- if (importMetaFormat === "global") {
109
- replaceWithImport({
110
- from: `@jsenv/core/helpers/import-meta/import-meta-url-global.js`,
111
- })
112
- return
113
- }
114
- return
115
- }
116
-
117
- if (metaPropertyName === "resolve") {
118
- if (importMetaFormat === "esmodule") {
119
- // keep native version
120
- return
121
- }
122
- if (importMetaFormat === "systemjs") {
123
- // systemjs will handle it
124
- return
125
- }
126
- if (importMetaFormat === "commonjs") {
127
- throw createParseError({
128
- message: `import.meta.resolve() not supported with commonjs format`,
129
- })
130
- }
131
- if (importMetaFormat === "global") {
132
- throw createParseError({
133
- message: `import.meta.resolve() not supported with global format`,
134
- })
135
- }
136
- return
137
- }
138
-
139
- replaceWithValue(undefined)
140
- },
141
- },
142
- ],
143
- ...babelPluginMap,
144
- ...(babelHelpersInjectionAsImport
145
- ? {
146
- "babel-helpers-as-jsenv-imports": [
147
- babelPluginBabelHelpersAsJsenvImports,
148
- ],
149
- }
150
- : {}),
151
- ...(jsenvRemoteDirectory
152
- ? {
153
- "proxy-external-imports": [
154
- babelPluginProxyExternalImports,
155
- { jsenvRemoteDirectory },
156
- ],
157
- }
158
- : {}),
159
- "import-metadata": [babelPluginImportMetadata],
160
- }
161
- if (moduleOutFormat === "systemjs") {
162
- babelPluginMap = {
163
- ...babelPluginMap,
164
- "proposal-dynamic-import": [proposalDynamicImport],
165
- "transform-modules-systemjs": [transformModulesSystemJs],
166
- }
167
- }
168
- if (prependSystemJs) {
169
- babelPluginMap = {
170
- ...babelPluginMap,
171
- "systemjs-prepend": [babelPluginSystemJsPrepend],
172
- }
173
- }
174
-
175
- const asyncToPromise = babelPluginMap["transform-async-to-promises"]
176
- if (topLevelAwait && asyncToPromise) {
177
- asyncToPromise.options.topLevelAwait = topLevelAwait
178
- }
179
-
180
- const babelTransformReturnValue = await babelTransform({
181
- ast,
182
- code,
183
- options: {
184
- ...options,
185
- plugins: babelPluginsFromBabelPluginMap(babelPluginMap),
186
- },
187
- })
188
- code = babelTransformReturnValue.code
189
- map = babelTransformReturnValue.map
190
- ast = babelTransformReturnValue.ast
191
- const { metadata } = babelTransformReturnValue
192
- return { code, map, metadata, ast }
193
- }
194
-
195
- const computeInputPath = (url) => {
196
- if (url.startsWith("file://")) {
197
- return urlToFileSystemPath(url)
198
- }
199
- return url
200
- }
201
-
202
- const babelTransform = async ({ ast, code, options }) => {
203
- const { transformAsync, transformFromAstAsync } = await import("@babel/core")
204
-
205
- try {
206
- if (ast) {
207
- const result = await transformFromAstAsync(ast, code, options)
208
- return result
209
- }
210
- return await transformAsync(code, options)
211
- } catch (error) {
212
- if (error && error.code === "BABEL_PARSE_ERROR") {
213
- const message = error.message
214
- const messageWithoutAnsi = message.replace(ansiRegex, "")
215
- throw createParseError({
216
- cause: error,
217
- message: messageWithoutAnsi,
218
- messageHTML: ansiToHTML(message),
219
- filename: options.filename,
220
- lineNumber: error.loc.line,
221
- columnNumber: error.loc.column,
222
- })
223
- }
224
- throw error
225
- }
226
- }
227
-
228
- const pattern = [
229
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
230
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
231
- ].join("|")
232
- const ansiRegex = new RegExp(pattern, "g")
233
-
234
- const createParseError = ({ message, cause, ...data }) => {
235
- const parseError = new Error(message, { cause })
236
- parseError.code = "PARSE_ERROR"
237
- parseError.data = {
238
- message,
239
- ...data,
240
- }
241
-
242
- return parseError
243
- }
@@ -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
- }
@@ -1,34 +0,0 @@
1
- import { featuresCompatMap } from "./features_compatibility.js"
2
- import { createOneRuntimeCompat } from "./one_runtime_compat.js"
3
-
4
- export const createRuntimeCompat = ({ runtimeSupport, featureNames }) => {
5
- const minRuntimeVersions = {}
6
- const missingFeatureNames = []
7
- const runtimeNames = Object.keys(runtimeSupport)
8
- if (runtimeNames.length === 0) {
9
- // when runtimes are unknown, everything is required
10
- missingFeatureNames.push(...featureNames)
11
- } else {
12
- runtimeNames.forEach((runtimeName) => {
13
- const runtimeVersion = runtimeSupport[runtimeName]
14
- const oneRuntimeCompat = createOneRuntimeCompat({
15
- runtimeName,
16
- runtimeVersion,
17
- featureNames,
18
- featuresCompatMap,
19
- })
20
-
21
- minRuntimeVersions[runtimeName] = oneRuntimeCompat.minRuntimeVersion
22
- oneRuntimeCompat.missingFeatureNames.forEach((missingFeatureName) => {
23
- if (!missingFeatureNames.includes(missingFeatureName)) {
24
- missingFeatureNames.push(missingFeatureName)
25
- }
26
- })
27
- })
28
- }
29
-
30
- return {
31
- missingFeatureNames,
32
- minRuntimeVersions,
33
- }
34
- }