@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
@@ -36,7 +36,7 @@ import {
36
36
  visitHtmlAst,
37
37
  addHtmlNodeAttribute,
38
38
  } from "./compileHtml.js"
39
- import { generateCompilationAssetUrl } from "./compile-directory/compile-asset.js"
39
+ import { generateCompilationAssetUrl } from "./jsenv_directory/compile_asset.js"
40
40
 
41
41
  export const compileHtml = async ({
42
42
  // cancellationToken,
@@ -46,12 +46,11 @@ export const compileHtml = async ({
46
46
  projectDirectoryUrl,
47
47
  jsenvRemoteDirectory,
48
48
  compileServerOrigin,
49
- outDirectoryRelativeUrl,
49
+ jsenvDirectoryRelativeUrl,
50
50
 
51
+ compileProfile,
51
52
  compileId,
52
53
  babelPluginMap,
53
- moduleOutFormat,
54
- importMetaFormat,
55
54
  topLevelAwait,
56
55
  jsenvScriptInjection = true,
57
56
  jsenvEventSourceClientInjection,
@@ -61,7 +60,7 @@ export const compileHtml = async ({
61
60
  sourcemapMethod,
62
61
  code,
63
62
  }) => {
64
- const compileDirectoryUrl = `${projectDirectoryUrl}${outDirectoryRelativeUrl}${compileId}/`
63
+ const compileDirectoryUrl = `${projectDirectoryUrl}${jsenvDirectoryRelativeUrl}${compileId}/`
65
64
  const browserRuntimeBuildUrlRelativeToProject = urlToRelativeUrl(
66
65
  BROWSER_RUNTIME_BUILD_URL,
67
66
  projectDirectoryUrl,
@@ -133,7 +132,7 @@ export const compileHtml = async ({
133
132
  specifier,
134
133
  })
135
134
  }
136
- if (moduleOutFormat !== "esmodule") {
135
+ if (compileProfile.moduleOutFormat !== "esmodule") {
137
136
  const ressourceHints = collectRessourceHints(htmlAst)
138
137
  await visitRessourceHints({
139
138
  ressourceHints,
@@ -141,13 +140,15 @@ export const compileHtml = async ({
141
140
  })
142
141
  }
143
142
  await visitImportmapScript({
144
- htmlAst,
145
143
  logger,
146
144
  url,
147
145
  compiledUrl,
148
146
  projectDirectoryUrl,
149
147
  compileDirectoryUrl,
150
- moduleOutFormat,
148
+
149
+ compileProfile,
150
+
151
+ htmlAst,
151
152
  scripts,
152
153
  addHtmlMutation,
153
154
  addHtmlSourceFile,
@@ -161,9 +162,8 @@ export const compileHtml = async ({
161
162
  url,
162
163
  compiledUrl,
163
164
 
165
+ compileProfile,
164
166
  babelPluginMap,
165
- moduleOutFormat,
166
- importMetaFormat,
167
167
  topLevelAwait,
168
168
  sourcemapMethod,
169
169
 
@@ -246,13 +246,15 @@ const visitRessourceHints = async ({ ressourceHints, addHtmlMutation }) => {
246
246
  }
247
247
 
248
248
  const visitImportmapScript = async ({
249
- htmlAst,
250
249
  logger,
251
250
  url,
252
251
  compiledUrl,
253
252
  projectDirectoryUrl,
254
253
  compileDirectoryUrl,
255
- moduleOutFormat,
254
+
255
+ compileProfile,
256
+
257
+ htmlAst,
256
258
  scripts,
257
259
  addHtmlMutation,
258
260
  addHtmlSourceFile,
@@ -280,7 +282,7 @@ const visitImportmapScript = async ({
280
282
  scriptInjections: [
281
283
  {
282
284
  type:
283
- moduleOutFormat === "systemjs"
285
+ compileProfile.moduleOutFormat === "systemjs"
284
286
  ? "systemjs-importmap"
285
287
  : "importmap",
286
288
  text: defaultImportMapAsText,
@@ -330,7 +332,7 @@ const visitImportmapScript = async ({
330
332
  addHtmlMutation(() => {
331
333
  removeHtmlNodeAttribute(firstImportmapScript, srcAttribute)
332
334
  setHtmlNodeText(firstImportmapScript, importmapAsText)
333
- if (moduleOutFormat === "systemjs") {
335
+ if (compileProfile.moduleOutFormat === "systemjs") {
334
336
  const typeAttribute = getHtmlNodeAttributeByName(
335
337
  firstImportmapScript,
336
338
  "type",
@@ -357,7 +359,7 @@ const visitImportmapScript = async ({
357
359
  addHtmlMutation(() => {
358
360
  removeHtmlNodeAttribute(firstImportmapScript, srcAttribute)
359
361
  setHtmlNodeText(firstImportmapScript, importmapAsText)
360
- if (moduleOutFormat === "systemjs") {
362
+ if (compileProfile.moduleOutFormat === "systemjs") {
361
363
  const typeAttribute = getHtmlNodeAttributeByName(
362
364
  firstImportmapScript,
363
365
  "type",
@@ -371,14 +373,13 @@ const visitImportmapScript = async ({
371
373
  const visitScripts = async ({
372
374
  logger,
373
375
  projectDirectoryUrl,
374
- compileServerOrigin,
375
376
  jsenvRemoteDirectory,
377
+ compileServerOrigin,
376
378
  url,
377
379
  compiledUrl,
378
380
 
381
+ compileProfile,
379
382
  babelPluginMap,
380
- moduleOutFormat,
381
- importMetaFormat,
382
383
  topLevelAwait,
383
384
  sourcemapMethod,
384
385
 
@@ -398,7 +399,7 @@ const visitScripts = async ({
398
399
  if (type === "module") {
399
400
  if (src) {
400
401
  addHtmlMutation(() => {
401
- if (moduleOutFormat === "systemjs") {
402
+ if (compileProfile.moduleOutFormat === "systemjs") {
402
403
  removeHtmlNodeAttribute(script, typeAttribute)
403
404
  }
404
405
  if (integrityAttribute) {
@@ -406,7 +407,7 @@ const visitScripts = async ({
406
407
  }
407
408
  removeHtmlNodeAttribute(script, srcAttribute)
408
409
  const jsenvMethod =
409
- moduleOutFormat === "systemjs"
410
+ compileProfile.moduleOutFormat === "systemjs"
410
411
  ? "executeFileUsingSystemJs"
411
412
  : "executeFileUsingDynamicImport"
412
413
  let specifier
@@ -427,7 +428,6 @@ const visitScripts = async ({
427
428
  })
428
429
  return
429
430
  }
430
-
431
431
  const scriptId = getIdForInlineHtmlNode(script, scripts)
432
432
  const inlineScriptName = `${scriptId}.js`
433
433
  const scriptOriginalUrl = resolveUrl(inlineScriptName, url)
@@ -443,9 +443,8 @@ const visitScripts = async ({
443
443
  compiledUrl: scriptCompiledUrl,
444
444
 
445
445
  type: "module",
446
+ compileProfile,
446
447
  babelPluginMap,
447
- moduleOutFormat,
448
- importMetaFormat,
449
448
  topLevelAwait,
450
449
 
451
450
  sourcemapMethod,
@@ -454,12 +453,12 @@ const visitScripts = async ({
454
453
  })
455
454
  const specifier = `./${urlToRelativeUrl(scriptCompiledUrl, compiledUrl)}`
456
455
  addHtmlMutation(() => {
457
- if (moduleOutFormat === "systemjs") {
456
+ if (compileProfile.moduleOutFormat === "systemjs") {
458
457
  removeHtmlNodeAttribute(script, typeAttribute)
459
458
  }
460
459
  removeHtmlNodeAttribute(script, srcAttribute)
461
460
  const jsenvMethod =
462
- moduleOutFormat === "systemjs"
461
+ compileProfile.moduleOutFormat === "systemjs"
463
462
  ? "executeFileUsingSystemJs"
464
463
  : "executeFileUsingDynamicImport"
465
464
  setHtmlNodeText(
@@ -491,7 +490,10 @@ const visitScripts = async ({
491
490
  if (fileIsInsideJsenvDistDirectory) {
492
491
  return
493
492
  }
494
-
493
+ const isRemoteUrl = jsenvRemoteDirectory.isRemoteUrl(src)
494
+ if (isRemoteUrl && jsenvRemoteDirectory.isPreservedUrl(src)) {
495
+ return
496
+ }
495
497
  const scriptCompiledUrl = generateCompilationAssetUrl(
496
498
  compiledUrl,
497
499
  urlToFilename(scriptOriginalUrl),
@@ -501,6 +503,7 @@ const visitScripts = async ({
501
503
  // the transformation here and not in compile server
502
504
  // (because compile server would think it's a module script
503
505
  // and add things like systemjs)
506
+ // we could take into account the integrity her
504
507
  const scriptResponse = await fetchUrl(scriptOriginalUrl)
505
508
  if (scriptResponse.status !== 200) {
506
509
  logger.warn(
@@ -528,9 +531,8 @@ const visitScripts = async ({
528
531
  compiledUrl: scriptCompiledUrl,
529
532
 
530
533
  type: "classic",
534
+ compileProfile,
531
535
  babelPluginMap,
532
- moduleOutFormat,
533
- importMetaFormat,
534
536
  topLevelAwait,
535
537
 
536
538
  sourcemapMethod,
@@ -563,9 +565,8 @@ const visitScripts = async ({
563
565
  compiledUrl: scriptCompiledUrl,
564
566
 
565
567
  type: "classic",
568
+ compileProfile,
566
569
  babelPluginMap,
567
- moduleOutFormat,
568
- importMetaFormat,
569
570
  topLevelAwait,
570
571
 
571
572
  code: textNode.value,
@@ -588,9 +589,8 @@ const transformHtmlScript = async ({
588
589
  compiledUrl,
589
590
 
590
591
  type,
592
+ compileProfile,
591
593
  babelPluginMap,
592
- moduleOutFormat,
593
- importMetaFormat,
594
594
  topLevelAwait,
595
595
 
596
596
  code,
@@ -605,8 +605,8 @@ const transformHtmlScript = async ({
605
605
  compiledUrl,
606
606
 
607
607
  babelPluginMap,
608
- moduleOutFormat: type === "module" ? moduleOutFormat : "global",
609
- importMetaFormat,
608
+ moduleOutFormat:
609
+ type === "module" ? compileProfile.moduleOutFormat : "global",
610
610
  topLevelAwait: type === "module" ? topLevelAwait : false,
611
611
  babelHelpersInjectionAsImport: type === "module" ? undefined : false,
612
612
 
@@ -7,12 +7,12 @@ export const compileImportmap = async ({
7
7
  url,
8
8
  compiledUrl,
9
9
  projectDirectoryUrl,
10
- outDirectoryRelativeUrl,
10
+ jsenvDirectoryRelativeUrl,
11
11
  compileId,
12
12
  }) => {
13
13
  const jsenvImportmap = getDefaultImportmap(compiledUrl, {
14
14
  projectDirectoryUrl,
15
- compileDirectoryUrl: `${projectDirectoryUrl}${outDirectoryRelativeUrl}${compileId}/`,
15
+ compileDirectoryUrl: `${projectDirectoryUrl}${jsenvDirectoryRelativeUrl}${compileId}/`,
16
16
  })
17
17
  const projectImportmap = JSON.parse(code)
18
18
  const importmap = composeTwoImportMaps(jsenvImportmap, projectImportmap)
@@ -9,11 +9,10 @@ export const compileJavascript = async ({
9
9
  url,
10
10
  compiledUrl,
11
11
 
12
+ compileProfile,
12
13
  babelPluginMap,
13
14
  workerUrls,
14
15
  serviceWorkerUrls,
15
- moduleOutFormat,
16
- importMetaFormat,
17
16
  topLevelAwait,
18
17
  prependSystemJs,
19
18
 
@@ -33,8 +32,7 @@ export const compileJavascript = async ({
33
32
  compiledUrl,
34
33
 
35
34
  babelPluginMap,
36
- moduleOutFormat,
37
- importMetaFormat,
35
+ moduleOutFormat: compileProfile.moduleOutFormat,
38
36
  topLevelAwait,
39
37
  prependSystemJs,
40
38
 
@@ -0,0 +1,24 @@
1
+ export const sameValueInTwoObjects = (object, secondObject) => {
2
+ const objectKeys = Object.keys(object)
3
+ const secondObjectKeys = Object.keys(secondObject)
4
+ if (!sameValuesInTwoArrays(objectKeys, secondObjectKeys)) {
5
+ return false
6
+ }
7
+ return objectKeys.every((key) => {
8
+ const objectKeyValue = object[key]
9
+ const secondObjectKeyValue = secondObject[key]
10
+ if (
11
+ typeof objectKeyValue === "object" &&
12
+ objectKeyValue !== null &&
13
+ typeof secondObjectKeyValue === "object" &&
14
+ secondObjectKeyValue !== null
15
+ ) {
16
+ return sameValueInTwoObjects(objectKeyValue, secondObjectKeyValue)
17
+ }
18
+ return objectKeyValue === secondObjectKeyValue
19
+ })
20
+ }
21
+
22
+ export const sameValuesInTwoArrays = (array, secondArray) => {
23
+ return array.every((value) => secondArray.includes(value))
24
+ }
@@ -0,0 +1,68 @@
1
+ import { resolveUrl, readFile } from "@jsenv/filesystem"
2
+
3
+ import {
4
+ TOOLBAR_INJECTOR_BUILD_URL,
5
+ EVENT_SOURCE_CLIENT_BUILD_URL,
6
+ BROWSER_RUNTIME_BUILD_URL,
7
+ } from "@jsenv/core/dist/build_manifest.js"
8
+ import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js"
9
+
10
+ import {
11
+ sameValuesInTwoArrays,
12
+ sameValueInTwoObjects,
13
+ } from "./comparison_utils.js"
14
+
15
+ const COMPARERS = {
16
+ preservedUrls: sameValueInTwoObjects,
17
+ workers: sameValuesInTwoArrays,
18
+ serviceWorkers: sameValuesInTwoArrays,
19
+ replaceProcessEnvNodeEnv: (a, b) => a === b,
20
+ inlineImportMapIntoHTML: (a, b) => a === b,
21
+
22
+ jsenvCorePackageVersion: (a, b) => a === b,
23
+ TOOLBAR_INJECTOR_BUILD_URL: (a, b) => a === b,
24
+ EVENT_SOURCE_CLIENT_BUILD_URL: (a, b) => a === b,
25
+ BROWSER_RUNTIME_BUILD_URL: (a, b) => a === b,
26
+ }
27
+
28
+ export const compareCompileContexts = (
29
+ compileContext,
30
+ secondCompileContext,
31
+ ) => {
32
+ return Object.keys(COMPARERS).every((key) => {
33
+ return COMPARERS[key](compileContext[key], secondCompileContext[key])
34
+ })
35
+ }
36
+
37
+ export const createCompileContext = async ({
38
+ preservedUrls,
39
+ workers,
40
+ serviceWorkers,
41
+ replaceProcessEnvNodeEnv,
42
+ inlineImportMapIntoHTML,
43
+ }) => {
44
+ return {
45
+ preservedUrls,
46
+ workers,
47
+ serviceWorkers,
48
+ replaceProcessEnvNodeEnv,
49
+ inlineImportMapIntoHTML,
50
+
51
+ // when "jsenvCorePackageVersion" is different, it means compile logic may have changed
52
+ jsenvCorePackageVersion: await readJsenvCoreVersionFromPackageFile(),
53
+ TOOLBAR_INJECTOR_BUILD_URL,
54
+ EVENT_SOURCE_CLIENT_BUILD_URL,
55
+ BROWSER_RUNTIME_BUILD_URL,
56
+ }
57
+ }
58
+
59
+ const readJsenvCoreVersionFromPackageFile = async () => {
60
+ const jsenvCorePackageFileUrl = resolveUrl(
61
+ "./package.json",
62
+ jsenvCoreDirectoryUrl,
63
+ )
64
+ const jsenvCoreVersion = await readFile(jsenvCorePackageFileUrl, {
65
+ as: "json",
66
+ }).version
67
+ return jsenvCoreVersion
68
+ }
@@ -0,0 +1,218 @@
1
+ import { featuresCompatFromRuntime } from "@jsenv/core/src/internal/features/features_compat_from_runtime.js"
2
+ import { featuresCompatFromRuntimeSupport } from "@jsenv/core/src/internal/features/features_compat_from_runtime_support.js"
3
+
4
+ import { sameValueInTwoObjects } from "./comparison_utils.js"
5
+
6
+ const COMPARERS = {
7
+ missingFeatures: sameValueInTwoObjects,
8
+ preservedUrls: sameValueInTwoObjects,
9
+ moduleOutFormat: (a, b) => a === b,
10
+ sourcemapMethod: (a, b) => a === b,
11
+ sourcemapExcludeSources: (a, b) => a === b,
12
+ jsenvEventSourceClientInjection: (a, b) => a === b,
13
+ jsenvToolbarInjection: (a, b) => a === b,
14
+ }
15
+
16
+ export const createCompileProfile = ({
17
+ importDefaultExtension,
18
+ preservedUrls,
19
+ customCompilers,
20
+ babelPluginMapWithoutSyntax,
21
+ workerUrls,
22
+ importMapInWebWorkers,
23
+ moduleOutFormat,
24
+ sourcemapMethod,
25
+ sourcemapExcludeSources,
26
+ jsenvEventSourceClientInjection,
27
+ jsenvToolbarInjection,
28
+
29
+ runtimeReport,
30
+ }) => {
31
+ const { env = {} } = runtimeReport
32
+
33
+ const features = {}
34
+ if (importDefaultExtension) {
35
+ features["import_default_extension"] = true
36
+ }
37
+ const customCompilerPatterns = Object.keys(customCompilers)
38
+ if (customCompilerPatterns.length > 0) {
39
+ features["custom_compiler_patterns"] = customCompilerPatterns
40
+ }
41
+ Object.keys(babelPluginMapWithoutSyntax).forEach((babelPluginName) => {
42
+ // if we need to be compatible only with node
43
+ // ignore "new-stylesheet-as-jsenv-import" and "transform-import-assertions"
44
+ // (we consider they won't be used in the code we are about to execute)
45
+ if (env.node && !env.browser) {
46
+ if (
47
+ babelPluginName === "new-stylesheet-as-jsenv-import" ||
48
+ babelPluginName === "transform-import-assertions"
49
+ ) {
50
+ return
51
+ }
52
+ }
53
+ features[babelPluginName] = babelPluginValueAsJSON(
54
+ babelPluginMapWithoutSyntax[babelPluginName],
55
+ )
56
+ })
57
+
58
+ if (env.browser) {
59
+ Object.assign(features, {
60
+ script_type_module: true,
61
+ import_dynamic: true,
62
+ top_level_await: true,
63
+ importmap: true,
64
+ import_assertion_type_json: true,
65
+ import_assertion_type_css: true,
66
+ })
67
+ }
68
+ if (env.browser && workerUrls.length > 0) {
69
+ features["worker_type_module"] = true
70
+ }
71
+ if (env.browser && importMapInWebWorkers) {
72
+ features["worker_importmap"] = true
73
+ }
74
+ const featureNames = Object.keys(features)
75
+
76
+ const supportedFeatureNames = []
77
+ const { featuresReport = {} } = runtimeReport
78
+ Object.keys(featuresReport).forEach((featureName) => {
79
+ if (featuresReport[featureName]) {
80
+ supportedFeatureNames.push(featureName)
81
+ }
82
+ })
83
+ const { name, version } = runtimeReport
84
+ if (name && version) {
85
+ const { availableFeatureNames } = featuresCompatFromRuntime({
86
+ runtimeName: name,
87
+ runtimeVersion: version,
88
+ featureNames,
89
+ })
90
+ availableFeatureNames.forEach((featureName) => {
91
+ const runtimeReportResult = featuresReport[featureName]
92
+ if (runtimeReportResult === undefined) {
93
+ supportedFeatureNames.push(featureName)
94
+ }
95
+ })
96
+ }
97
+ const { runtimeSupport } = runtimeReport
98
+ if (runtimeSupport) {
99
+ const { availableFeatureNames } = featuresCompatFromRuntimeSupport({
100
+ runtimeSupport,
101
+ featureNames,
102
+ })
103
+ availableFeatureNames.forEach((featureName) => {
104
+ const runtimeReportResult = featuresReport[featureName]
105
+ if (runtimeReportResult === undefined) {
106
+ supportedFeatureNames.push(featureName)
107
+ }
108
+ })
109
+ }
110
+ Object.keys(featureEffects).forEach((featureName) => {
111
+ if (featuresReport[featureName]) {
112
+ featureEffects[featureName]({
113
+ supportedFeatureNames,
114
+ })
115
+ }
116
+ })
117
+
118
+ const missingFeatures = {}
119
+ if (!runtimeReport.forceSource) {
120
+ featureNames.forEach((featureName) => {
121
+ const supported = supportedFeatureNames.includes(featureName)
122
+ if (supported) {
123
+ return
124
+ }
125
+ missingFeatures[featureName] = features[featureName]
126
+ })
127
+ if (moduleOutFormat === undefined) {
128
+ if (runtimeReport.moduleOutFormat) {
129
+ moduleOutFormat = runtimeReport.moduleOutFormat
130
+ if (moduleOutFormat !== "esmodule") {
131
+ missingFeatures["module_format"] = moduleOutFormat
132
+ }
133
+ } else {
134
+ const systemJsIsRequired =
135
+ featuresRelatedToSystemJs.some((featureName) => {
136
+ return Boolean(missingFeatures[featureName])
137
+ }) || !featuresReport["import_http"]
138
+ moduleOutFormat = systemJsIsRequired ? "systemjs" : "esmodule"
139
+ }
140
+ }
141
+ if (runtimeReport.forceCompilation) {
142
+ missingFeatures["compilation_forced"] = true
143
+ }
144
+ }
145
+ return {
146
+ missingFeatures,
147
+ preservedUrls,
148
+ moduleOutFormat,
149
+ sourcemapMethod,
150
+ sourcemapExcludeSources,
151
+ jsenvEventSourceClientInjection,
152
+ jsenvToolbarInjection,
153
+ }
154
+ }
155
+
156
+ const featuresRelatedToSystemJs = [
157
+ "script_type_module",
158
+ "import_dynamic",
159
+ "top_level_await",
160
+ "importmap",
161
+ "import_assertion_type_json",
162
+ "import_assertion_type_css",
163
+ "worker_type_module",
164
+ "worker_importmap",
165
+ ]
166
+
167
+ const featureEffects = {
168
+ coverage_js: ({ supportedFeatureNames }) => {
169
+ supportedFeatureNames.push("transform-instrument")
170
+ },
171
+ new_stylesheet: ({ supportedFeatureNames }) => {
172
+ supportedFeatureNames.push("new-stylesheet-as-jsenv-import")
173
+ },
174
+ }
175
+
176
+ export const compareCompileProfiles = (
177
+ compileProfile,
178
+ secondCompileProfile,
179
+ ) => {
180
+ return Object.keys(COMPARERS).every((key) => {
181
+ return COMPARERS[key](compileProfile[key], secondCompileProfile[key])
182
+ })
183
+ }
184
+
185
+ export const shakeBabelPluginMap = ({ babelPluginMap, compileProfile }) => {
186
+ const babelPluginMapShaked = {}
187
+ const { missingFeatures } = compileProfile
188
+ Object.keys(babelPluginMap).forEach((babelPluginName) => {
189
+ if (missingFeatures[babelPluginName]) {
190
+ babelPluginMapShaked[babelPluginName] = babelPluginMap[babelPluginName]
191
+ }
192
+ })
193
+ Object.keys(babelPluginMap).forEach((key) => {
194
+ if (key.startsWith("syntax-")) {
195
+ babelPluginMapShaked[key] = babelPluginMap[key]
196
+ }
197
+ if (key === "transform-replace-expressions") {
198
+ babelPluginMapShaked[key] = babelPluginMap[key]
199
+ }
200
+ })
201
+ return babelPluginMapShaked
202
+ }
203
+
204
+ const babelPluginValueAsJSON = (babelPluginValue) => {
205
+ if (Array.isArray(babelPluginValue)) {
206
+ if (babelPluginValue.length === 1) {
207
+ return true
208
+ }
209
+ if (babelPluginValue.length === 2) {
210
+ return babelPluginValue[1]
211
+ }
212
+ return true
213
+ }
214
+ if (typeof babelPluginValue === "object") {
215
+ return babelPluginValue.options
216
+ }
217
+ return true
218
+ }
@@ -1,5 +1,6 @@
1
1
  import { assert } from "@jsenv/assert"
2
- import { createLockRegistry } from "./createLockRegistry.js"
2
+
3
+ import { createLockRegistry } from "./file_lock_registry.js"
3
4
 
4
5
  // a second lock on same ressource await first one to be unlocked
5
6
  {
@@ -3,8 +3,8 @@ import { urlToFileSystemPath, readFile } from "@jsenv/filesystem"
3
3
  import { createDetailedMessage } from "@jsenv/logger"
4
4
 
5
5
  import { validateCache } from "./validateCache.js"
6
- import { getMetaJsonFileUrl } from "./compile-asset.js"
7
- import { createLockRegistry } from "./createLockRegistry.js"
6
+ import { getMetaJsonFileUrl } from "./compile_asset.js"
7
+ import { createLockRegistry } from "./file_lock_registry.js"
8
8
 
9
9
  const { lockForRessource } = createLockRegistry()
10
10