@jsenv/core 25.3.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 (105) 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 +12 -11
  18. package/src/buildProject.js +31 -26
  19. package/src/dev_server.js +76 -87
  20. package/src/execute.js +3 -8
  21. package/src/internal/browser_launcher/{browser_runtime_report.js → browser_runtime_profile.js} +21 -15
  22. package/src/internal/browser_launcher/executeHtmlFile.js +22 -14
  23. package/src/internal/browser_launcher/from_playwright.js +6 -4
  24. package/src/internal/browser_runtime/browser_runtime.js +12 -14
  25. package/src/internal/browser_runtime/createBrowserRuntime.js +7 -6
  26. package/src/internal/browser_utils/fetchAndEvalUsingFetch.js +1 -1
  27. package/src/internal/browser_utils/fetchJson.js +1 -1
  28. package/src/internal/browser_utils/{fetch-browser.js → fetch_browser.js} +0 -2
  29. package/src/internal/building/buildUsingRollup.js +41 -57
  30. package/src/internal/building/rollup_plugin_jsenv.js +28 -8
  31. package/src/internal/compiling/babel_parse_error.js +9 -0
  32. package/src/internal/{babel_plugin_transform_import_meta.js → compiling/babel_plugin_transform_import_meta.js} +58 -9
  33. package/src/internal/compiling/compileFile.js +2 -2
  34. package/src/internal/compiling/compileHtml.js +1 -1
  35. package/src/internal/compiling/createCompiledFileService.js +25 -74
  36. package/src/internal/compiling/js-compilation-service/transformJs.js +153 -23
  37. package/src/internal/compiling/jsenvCompilerForHtml.js +29 -32
  38. package/src/internal/compiling/jsenvCompilerForImportmap.js +2 -2
  39. package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -4
  40. package/src/internal/compiling/jsenv_directory/comparison_utils.js +24 -0
  41. package/src/internal/compiling/{compile-directory/compile-asset.js → jsenv_directory/compile_asset.js} +0 -0
  42. package/src/internal/compiling/jsenv_directory/compile_context.js +68 -0
  43. package/src/internal/compiling/jsenv_directory/compile_profile.js +218 -0
  44. package/src/internal/compiling/{compile-directory/createLockRegistry.js → jsenv_directory/file_lock_registry.js} +0 -0
  45. package/src/internal/compiling/{compile-directory/createLockRegistry.test.js → jsenv_directory/file_lock_registry.test.js} +2 -1
  46. package/src/internal/compiling/{compile-directory → jsenv_directory}/fs-optimized-for-cache.js +0 -0
  47. package/src/internal/compiling/{compile-directory → jsenv_directory}/getOrGenerateCompiledFile.js +2 -2
  48. package/src/internal/compiling/jsenv_directory/jsenv_directory.js +174 -0
  49. package/src/internal/compiling/{compile-directory → jsenv_directory}/updateMeta.js +1 -1
  50. package/src/internal/compiling/{compile-directory → jsenv_directory}/validateCache.js +0 -0
  51. package/src/internal/compiling/sse_service/sse_service.js +369 -0
  52. package/src/internal/compiling/startCompileServer.js +156 -804
  53. package/src/internal/compiling/transformResultToCompilationResult.js +2 -2
  54. package/src/internal/dev_server/exploring/exploring.js +10 -8
  55. package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +85 -78
  56. package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
  57. package/src/internal/dev_server/toolbar/toolbar.html +40 -16
  58. package/src/internal/dev_server/toolbar/toolbar.injector.js +11 -17
  59. package/src/internal/dev_server/toolbar/toolbar.main.js +6 -6
  60. package/src/internal/executing/executeConcurrently.js +1 -1
  61. package/src/internal/executing/executePlan.js +2 -3
  62. package/src/internal/{generateGroupMap → features}/babel_plugins_compatibility.js +8 -8
  63. package/src/internal/features/browser_feature_detection/browser_feature_detect_dynamic_import.js +20 -0
  64. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_css.js +23 -0
  65. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_json.js +25 -0
  66. package/src/internal/features/browser_feature_detection/browser_feature_detect_importmap.js +37 -0
  67. package/src/internal/features/browser_feature_detection/browser_feature_detect_new_stylesheet.js +9 -0
  68. package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js +14 -0
  69. package/src/internal/features/browser_feature_detection/browser_feature_detection.js +85 -0
  70. package/src/internal/{browser_feature_detection → features/browser_feature_detection}/compile_proxy.html +1 -1
  71. package/src/internal/features/browser_feature_detection/execute_with_script_module.js +24 -0
  72. package/src/internal/features/features_compat_from_runtime.js +38 -0
  73. package/src/internal/features/features_compat_from_runtime_support.js +31 -0
  74. package/src/internal/{generateGroupMap → features}/features_compatibility.js +3 -3
  75. package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_dynamic_import.mjs +0 -0
  76. package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_top_level_await.mjs +0 -0
  77. package/src/internal/{node_feature_detection/nodeSupportsDynamicImport.js → features/node_feature_detection/node_feature_detect_dynamic_import.js} +0 -0
  78. package/src/internal/{node_feature_detection/nodeSupportsTopLevelAwait.js → features/node_feature_detection/node_feature_detect_top_level_await.js} +0 -0
  79. package/src/internal/features/node_feature_detection/node_feature_detection.js +66 -0
  80. package/src/internal/node_launcher/createControllableNodeProcess.js +4 -3
  81. package/src/internal/node_launcher/node_runtime_report.js +15 -9
  82. package/src/internal/node_runtime/fetchSource.js +2 -4
  83. package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
  84. package/src/internal/{dev_server/redirector → redirector}/redirector.html +8 -18
  85. package/src/internal/{generateGroupMap/jsenvRuntimeSupport.js → runtime_support/jsenv_runtime_support.js} +0 -0
  86. package/src/internal/{generateGroupMap → runtime_support}/runtime_support.js +0 -0
  87. package/src/internal/url_conversion.js +12 -17
  88. package/src/launchNode.js +29 -41
  89. package/dist/compile_proxy/compile_proxy.html__inline__20_809f35f7.js.map +0 -392
  90. package/dist/redirector/redirector.html__inline__15_e391410e.js.map +0 -397
  91. package/dist/toolbar_injector/toolbar_injector_fac1e995.js +0 -973
  92. package/dist/toolbar_injector/toolbar_injector_fac1e995.js.map +0 -294
  93. package/src/internal/CONSTANTS.js +0 -11
  94. package/src/internal/browser_feature_detection/browser_feature_detection.js +0 -274
  95. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +0 -242
  96. package/src/internal/generateGroupMap/generateGroupMap.js +0 -65
  97. package/src/internal/generateGroupMap/one_runtime_compat.js +0 -38
  98. package/src/internal/generateGroupMap/runtime_compat.js +0 -34
  99. package/src/internal/generateGroupMap/runtime_compat_composition.js +0 -76
  100. package/src/internal/generateGroupMap/shake_babel_plugin_map.js +0 -21
  101. package/src/internal/node_feature_detection/node_feature_detection.js +0 -117
  102. package/src/internal/node_runtime/detectNode.js +0 -3
  103. package/src/internal/runtime/computeCompileIdFromGroupId.js +0 -30
  104. package/src/internal/runtime/resolveGroup.js +0 -13
  105. package/src/internal/runtime/resolveRuntimeGroup.js +0 -11
@@ -9,82 +9,60 @@ import {
9
9
  import { createDetailedMessage } from "@jsenv/logger"
10
10
 
11
11
  import { humanizeUrl } from "@jsenv/core/src/internal/building/url_trace.js"
12
- import {
13
- isNodePartOfSupportedRuntimes,
14
- isBrowserPartOfSupportedRuntimes,
15
- } from "@jsenv/core/src/internal/generateGroupMap/runtime_support.js"
16
- import { createRuntimeCompat } from "@jsenv/core/src/internal/generateGroupMap/runtime_compat.js"
12
+
17
13
  import { createRollupPlugins } from "./rollup_plugin_jsenv.js"
18
14
 
19
15
  export const buildUsingRollup = async ({
20
16
  buildOperation,
21
17
  logger,
22
18
 
23
- projectDirectoryUrl,
24
19
  entryPoints,
25
- compileServerOrigin,
26
- compileDirectoryRelativeUrl,
27
- jsenvDirectoryRelativeUrl,
20
+ projectDirectoryUrl,
28
21
  buildDirectoryUrl,
29
22
  buildDirectoryClean,
30
- assetManifestFile = false,
23
+ assetManifestFile,
31
24
  assetManifestFileRelativeUrl,
32
- sourcemapExcludeSources,
33
- writeOnFileSystem,
34
-
35
- format,
36
- systemJsUrl,
37
- globalName,
38
- globals,
39
- babelPluginMap,
40
- runtimeSupport,
41
25
 
42
26
  urlMappings,
43
27
  importResolutionMethod,
44
28
  importMapFileRelativeUrl,
45
29
  importDefaultExtension,
46
30
  externalImportSpecifiers,
47
- importPaths,
48
31
  preservedUrls,
32
+ importPaths,
33
+
34
+ format,
35
+ systemJsUrl,
36
+ globalName,
37
+ globals,
49
38
  workers,
50
39
  serviceWorkers,
51
40
  serviceWorkerFinalizer,
52
41
  classicWorkers,
53
42
  classicServiceWorkers,
54
43
 
44
+ node,
45
+ browser,
46
+ compileServer,
47
+ compileProfile,
48
+ compileId,
49
+
55
50
  urlVersioning,
56
51
  lineBreakNormalization,
57
- jsConcatenation,
58
- cssConcatenation,
59
52
  useImportMapToMaximizeCacheReuse,
60
53
  preserveEntrySignatures,
61
54
  treeshake,
55
+ jsConcatenation,
56
+ cssConcatenation,
62
57
 
63
58
  minify,
59
+ minifyHtmlOptions,
64
60
  minifyJsOptions,
65
61
  minifyCssOptions,
66
- minifyHtmlOptions,
67
- }) => {
68
- const node = isNodePartOfSupportedRuntimes(runtimeSupport)
69
- const browser = isBrowserPartOfSupportedRuntimes(runtimeSupport)
70
-
71
- const runtimeCompatMap = createRuntimeCompat({
72
- runtimeSupport,
73
- featureNames: ["import_assertion_type_json", "import_assertion_type_css"],
74
- })
75
- const importAssertionsSupport = {
76
- json:
77
- format === "esmodule" &&
78
- !runtimeCompatMap.missingFeatureNames.includes(
79
- "import_assertion_type_json",
80
- ),
81
- css:
82
- format === "esmodule" &&
83
- !runtimeCompatMap.missingFeatureNames.includes(
84
- "import_assertion_type_json",
85
- ),
86
- }
87
62
 
63
+ writeOnFileSystem,
64
+ sourcemapExcludeSources,
65
+ }) => {
88
66
  const {
89
67
  rollupPlugins,
90
68
  getLastErrorMessage,
@@ -97,18 +75,10 @@ export const buildUsingRollup = async ({
97
75
 
98
76
  projectDirectoryUrl,
99
77
  entryPoints,
100
- compileServerOrigin,
101
- compileDirectoryRelativeUrl,
102
- jsenvDirectoryRelativeUrl,
103
78
  buildDirectoryUrl,
104
79
 
105
80
  format,
106
81
  systemJsUrl,
107
- babelPluginMap,
108
- node,
109
- browser,
110
- importAssertionsSupport,
111
-
112
82
  urlMappings,
113
83
  importResolutionMethod,
114
84
  importMapFileRelativeUrl,
@@ -122,6 +92,12 @@ export const buildUsingRollup = async ({
122
92
  classicWorkers,
123
93
  classicServiceWorkers,
124
94
 
95
+ node,
96
+ browser,
97
+ compileServer,
98
+ compileProfile,
99
+ compileId,
100
+
125
101
  urlVersioning,
126
102
  lineBreakNormalization,
127
103
  jsConcatenation,
@@ -140,7 +116,7 @@ export const buildUsingRollup = async ({
140
116
  logger,
141
117
 
142
118
  rollupPlugins,
143
- babelPluginMap,
119
+ compileProfile,
144
120
  format,
145
121
  globals,
146
122
  globalName,
@@ -246,7 +222,7 @@ const useRollup = async ({
246
222
  buildOperation,
247
223
  logger,
248
224
  rollupPlugins,
249
- babelPluginMap,
225
+ compileProfile,
250
226
  format,
251
227
  globals,
252
228
  globalName,
@@ -319,10 +295,18 @@ const useRollup = async ({
319
295
  // experimentalTopLevelAwait: true,
320
296
  // https://rollupjs.org/guide/en/#outputgeneratedcode
321
297
  generatedCode: {
322
- arrowFunctions: !babelPluginMap["transform-arrow-functions"],
323
- constBindings: !babelPluginMap["transform-block-scoping"],
324
- objectShorthand: !babelPluginMap["transform-shorthand-properties"],
325
- reservedNamesAsProps: !babelPluginMap["transform-reserved-words"],
298
+ arrowFunctions:
299
+ compileProfile &&
300
+ !compileProfile.missingFeatures["transform-arrow-functions"],
301
+ constBindings:
302
+ compileProfile &&
303
+ !compileProfile.missingFeatures["transform-block-scoping"],
304
+ objectShorthand:
305
+ compileProfile &&
306
+ !compileProfile.missingFeatures["transform-shorthand-properties"],
307
+ reservedNamesAsProps:
308
+ compileProfile &&
309
+ !compileProfile.missingFeatures["transform-reserved-words"],
326
310
  },
327
311
  // https://rollupjs.org/guide/en#output-dir
328
312
  dir: urlToFileSystemPath(buildDirectoryUrl),
@@ -32,6 +32,7 @@ import { createImportResolverForImportmap } from "@jsenv/core/src/internal/impor
32
32
  import { getDefaultImportmap } from "@jsenv/core/src/internal/import-resolution/importmap_default.js"
33
33
  import { createJsenvRemoteDirectory } from "@jsenv/core/src/internal/jsenv_remote_directory.js"
34
34
  import { setUrlSearchParamsDescriptor } from "@jsenv/core/src/internal/url_utils.js"
35
+ import { shakeBabelPluginMap } from "@jsenv/core/src/internal/compiling/jsenv_directory/compile_profile.js"
35
36
 
36
37
  import {
37
38
  formatBuildStartLog,
@@ -56,9 +57,6 @@ export const createRollupPlugins = async ({
56
57
 
57
58
  projectDirectoryUrl,
58
59
  entryPoints,
59
- compileServerOrigin,
60
- compileDirectoryRelativeUrl,
61
- jsenvDirectoryRelativeUrl,
62
60
  buildDirectoryUrl,
63
61
 
64
62
  urlMappings,
@@ -73,12 +71,13 @@ export const createRollupPlugins = async ({
73
71
  serviceWorkerFinalizer,
74
72
  classicWorkers,
75
73
  classicServiceWorkers,
76
-
77
74
  format,
78
75
  systemJsUrl,
79
- babelPluginMap,
76
+
80
77
  node,
81
- importAssertionsSupport,
78
+ compileServer,
79
+ compileProfile,
80
+ compileId,
82
81
 
83
82
  urlVersioning,
84
83
  lineBreakNormalization,
@@ -91,6 +90,29 @@ export const createRollupPlugins = async ({
91
90
  minifyCssOptions,
92
91
  minifyHtmlOptions,
93
92
  }) => {
93
+ const compileServerOrigin = compileServer.origin
94
+ // For now the compilation is forced during build because this plugin
95
+ // was coded assuming build always requires to be compiled.
96
+ // Ideally jsenv should also be able to build a project using source files
97
+ // and in that case compileProfile and compileId are null
98
+ // the babel plugin map is useless (we can just fetch the source file directly)
99
+ const jsenvDirectoryRelativeUrl = compileServer.jsenvDirectoryRelativeUrl
100
+ const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
101
+ const babelPluginMap = shakeBabelPluginMap({
102
+ babelPluginMap: compileServer.babelPluginMap,
103
+ compileProfile,
104
+ })
105
+ const importAssertionsSupport = {
106
+ json:
107
+ format === "esmodule" &&
108
+ compileProfile &&
109
+ !compileProfile.missingFeatures["import_assertion_type_json"],
110
+ css:
111
+ format === "esmodule" &&
112
+ compileProfile &&
113
+ !compileProfile.missingFeatures["import_assertion_type_css"],
114
+ }
115
+
94
116
  const jsenvRemoteDirectory = createJsenvRemoteDirectory({
95
117
  projectDirectoryUrl,
96
118
  jsenvDirectoryRelativeUrl,
@@ -433,7 +455,6 @@ export const createRollupPlugins = async ({
433
455
  asCompiledServerUrl(importMapInfoFromHtml.htmlUrl),
434
456
  )
435
457
  importMapUrl = applyUrlMappings(importMapUrl)
436
-
437
458
  if (!urlIsInsideOf(importMapUrl, compileDirectoryServerUrl)) {
438
459
  logger.warn(
439
460
  formatImportmapOutsideCompileDirectory({
@@ -442,7 +463,6 @@ export const createRollupPlugins = async ({
442
463
  }),
443
464
  )
444
465
  }
445
-
446
466
  fetchImportMap = () => {
447
467
  return fetchImportMapFromUrl(
448
468
  importMapUrl,
@@ -0,0 +1,9 @@
1
+ export const createParseError = ({ message, cause, ...data }) => {
2
+ const parseError = new Error(message, { cause })
3
+ parseError.code = "PARSE_ERROR"
4
+ parseError.data = {
5
+ message,
6
+ ...data,
7
+ }
8
+ return parseError
9
+ }
@@ -4,23 +4,75 @@
4
4
 
5
5
  import { require } from "@jsenv/core/src/internal/require.js"
6
6
 
7
- export const babelPluginTransformImportMeta = (api, pluginOptions) => {
7
+ import { createParseError } from "./babel_parse_error.js"
8
+
9
+ export const babelPluginTransformImportMeta = (api, { importMetaFormat }) => {
8
10
  const {
9
11
  addNamespace,
10
12
  addDefault,
11
13
  addNamed,
12
14
  } = require("@babel/helper-module-imports")
13
15
  const { parseExpression } = require("@babel/parser")
14
-
15
- const { replaceImportMeta } = pluginOptions
16
-
17
16
  let babelState
18
17
  const jsValueToAst = (jsValue) => {
19
18
  const valueAst = parseExpression(jsValue, babelState.opts)
20
19
  return valueAst
21
20
  }
21
+ const visitImportMetaProperty = ({
22
+ importMetaPropertyName,
23
+ replaceWithImport,
24
+ replaceWithValue,
25
+ }) => {
26
+ if (importMetaPropertyName === "url") {
27
+ if (importMetaFormat === "esmodule") {
28
+ // keep native version
29
+ return
30
+ }
31
+ if (importMetaFormat === "systemjs") {
32
+ // systemjs will handle it
33
+ return
34
+ }
35
+ if (importMetaFormat === "commonjs") {
36
+ replaceWithImport({
37
+ from: `@jsenv/core/helpers/import-meta/import-meta-url-commonjs.js`,
38
+ })
39
+ return
40
+ }
41
+ if (importMetaFormat === "global") {
42
+ replaceWithImport({
43
+ from: `@jsenv/core/helpers/import-meta/import-meta-url-global.js`,
44
+ })
45
+ return
46
+ }
47
+ return
48
+ }
49
+ if (importMetaPropertyName === "resolve") {
50
+ if (importMetaFormat === "esmodule") {
51
+ // keep native version
52
+ return
53
+ }
54
+ if (importMetaFormat === "systemjs") {
55
+ // systemjs will handle it
56
+ return
57
+ }
58
+ if (importMetaFormat === "commonjs") {
59
+ throw createParseError({
60
+ message: `import.meta.resolve() not supported with commonjs format`,
61
+ })
62
+ }
63
+ if (importMetaFormat === "global") {
64
+ throw createParseError({
65
+ message: `import.meta.resolve() not supported with global format`,
66
+ })
67
+ }
68
+ return
69
+ }
70
+ replaceWithValue(undefined)
71
+ }
22
72
 
23
73
  return {
74
+ name: "transform-import-meta",
75
+
24
76
  pre: (state) => {
25
77
  babelState = state
26
78
  },
@@ -53,7 +105,6 @@ export const babelPluginTransformImportMeta = (api, pluginOptions) => {
53
105
  visitor: {
54
106
  Program(programPath) {
55
107
  const metaPropertyPathMap = {}
56
-
57
108
  programPath.traverse({
58
109
  MemberExpression(path) {
59
110
  const { node } = path
@@ -61,12 +112,10 @@ export const babelPluginTransformImportMeta = (api, pluginOptions) => {
61
112
  if (object.type !== "MetaProperty") {
62
113
  return
63
114
  }
64
-
65
115
  const { property: objectProperty } = object
66
116
  if (objectProperty.name !== "meta") {
67
117
  return
68
118
  }
69
-
70
119
  const { property } = node
71
120
  const { name } = property
72
121
  if (name in metaPropertyPathMap) {
@@ -76,9 +125,9 @@ export const babelPluginTransformImportMeta = (api, pluginOptions) => {
76
125
  }
77
126
  },
78
127
  })
79
-
80
128
  Object.keys(metaPropertyPathMap).forEach((importMetaPropertyName) => {
81
- replaceImportMeta(importMetaPropertyName, {
129
+ visitImportMetaProperty({
130
+ importMetaPropertyName,
82
131
  replaceWithImport: ({ namespace, name, from, nameHint }) => {
83
132
  let importAst
84
133
  if (namespace) {
@@ -7,8 +7,8 @@ import {
7
7
  } from "@jsenv/filesystem"
8
8
  import { convertFileSystemErrorToResponseProperties } from "@jsenv/server/src/internal/convertFileSystemErrorToResponseProperties.js"
9
9
 
10
- import { getOrGenerateCompiledFile } from "./compile-directory/getOrGenerateCompiledFile.js"
11
- import { updateMeta } from "./compile-directory/updateMeta.js"
10
+ import { getOrGenerateCompiledFile } from "./jsenv_directory/getOrGenerateCompiledFile.js"
11
+ import { updateMeta } from "./jsenv_directory/updateMeta.js"
12
12
 
13
13
  export const compileFile = async ({
14
14
  logger,
@@ -313,7 +313,7 @@ export const collectHtmlDependenciesFromAst = (htmlAst) => {
313
313
  const srcsetAttribute = getHtmlNodeAttributeByName(htmlNode, "srcset")
314
314
  if (srcsetAttribute) {
315
315
  const srcsetParts = parseSrcset(srcsetAttribute.value)
316
- srcsetParts.forEeach(({ specifier }) => {
316
+ srcsetParts.forEach(({ specifier }) => {
317
317
  dependencies.push({
318
318
  htmlNode,
319
319
  attribute: srcsetAttribute,
@@ -4,19 +4,14 @@ import {
4
4
  resolveDirectoryUrl,
5
5
  normalizeStructuredMetaMap,
6
6
  urlToMeta,
7
+ urlToRelativeUrl,
7
8
  } from "@jsenv/filesystem"
8
9
 
9
- import { createRuntimeCompat } from "@jsenv/core/src/internal/generateGroupMap/runtime_compat.js"
10
- import { shakeBabelPluginMap } from "@jsenv/core/src/internal/generateGroupMap/shake_babel_plugin_map.js"
10
+ import { REDIRECTOR_BUILD_URL } from "@jsenv/core/dist/build_manifest.js"
11
11
  import { serverUrlToCompileInfo } from "@jsenv/core/src/internal/url_conversion.js"
12
-
13
12
  import { setUrlExtension } from "../url_utils.js"
14
- import {
15
- COMPILE_ID_BUILD_GLOBAL,
16
- COMPILE_ID_BUILD_GLOBAL_FILES,
17
- COMPILE_ID_BUILD_COMMONJS,
18
- COMPILE_ID_BUILD_COMMONJS_FILES,
19
- } from "../CONSTANTS.js"
13
+
14
+ import { shakeBabelPluginMap } from "./jsenv_directory/compile_profile.js"
20
15
  import { compileFile } from "./compileFile.js"
21
16
  import { compileHtml } from "./jsenvCompilerForHtml.js"
22
17
  import { compileImportmap } from "./jsenvCompilerForImportmap.js"
@@ -39,20 +34,15 @@ export const createCompiledFileService = ({
39
34
 
40
35
  projectDirectoryUrl,
41
36
  jsenvDirectoryRelativeUrl,
42
- outDirectoryRelativeUrl,
37
+ jsenvDirectory,
43
38
  jsenvRemoteDirectory,
44
39
 
45
- runtimeSupport,
46
40
  babelPluginMap,
47
- moduleOutFormat,
48
- importMetaFormat,
49
41
  topLevelAwait,
50
42
  prependSystemJs,
51
- groupMap,
52
43
  customCompilers,
53
44
  workerUrls,
54
45
  serviceWorkerUrls,
55
- importMapInWebWorkers,
56
46
 
57
47
  jsenvEventSourceClientInjection,
58
48
  jsenvToolbarInjection,
@@ -62,17 +52,6 @@ export const createCompiledFileService = ({
62
52
  sourcemapMethod,
63
53
  sourcemapExcludeSources,
64
54
  }) => {
65
- const compileIdModuleFormats = {}
66
- Object.keys(groupMap).forEach((groupName) => {
67
- compileIdModuleFormats[groupName] = canAvoidSystemJs({
68
- runtimeSupport: groupMap[groupName].minRuntimeVersions,
69
- workerUrls,
70
- importMapInWebWorkers,
71
- })
72
- ? "esmodule"
73
- : "systemjs"
74
- })
75
-
76
55
  Object.keys(customCompilers).forEach((key) => {
77
56
  const value = customCompilers[key]
78
57
  if (typeof value !== "function") {
@@ -88,27 +67,26 @@ export const createCompiledFileService = ({
88
67
  },
89
68
  projectDirectoryUrl,
90
69
  )
91
-
92
70
  const importmapInfos = {}
93
-
71
+ const redirectorRelativeUrlForProject = urlToRelativeUrl(
72
+ REDIRECTOR_BUILD_URL,
73
+ projectDirectoryUrl,
74
+ )
94
75
  return async (request, { pushResponse, redirectRequest }) => {
95
76
  const { origin, ressource } = request
96
77
  const requestUrl = `${origin}${ressource}`
97
-
98
78
  const requestCompileInfo = serverUrlToCompileInfo(requestUrl, {
99
- outDirectoryRelativeUrl,
100
79
  compileServerOrigin: origin,
80
+ jsenvDirectoryRelativeUrl,
101
81
  })
102
-
103
82
  // not inside compile directory -> nothing to compile
104
83
  if (!requestCompileInfo.insideCompileDirectory) {
105
84
  return null
106
85
  }
107
-
108
86
  const { compileId, afterCompileId } = requestCompileInfo
109
87
  // serve files inside /.jsenv/* directly without compilation
110
88
  // this is just to allow some files to be written inside outDirectory and read directly
111
- // if asked by the client (such __compile_server_meta__.json)
89
+ // if asked by the client
112
90
  if (!compileId) {
113
91
  return fetchFileSystem(
114
92
  new URL(request.ressource.slice(1), projectDirectoryUrl),
@@ -118,29 +96,27 @@ export const createCompiledFileService = ({
118
96
  },
119
97
  )
120
98
  }
121
-
122
- const allowedCompileIds = [
123
- ...Object.keys(groupMap),
124
- COMPILE_ID_BUILD_GLOBAL,
125
- COMPILE_ID_BUILD_GLOBAL_FILES,
126
- COMPILE_ID_BUILD_COMMONJS,
127
- COMPILE_ID_BUILD_COMMONJS_FILES,
128
- ]
129
- if (!allowedCompileIds.includes(compileId)) {
99
+ const compileDirectory = jsenvDirectory.compileDirectories[compileId]
100
+ if (!compileDirectory) {
130
101
  return {
131
- status: 400,
132
- statusText: `compileId must be one of ${allowedCompileIds}, received ${compileId}`,
102
+ status: 307,
103
+ headers: {
104
+ location: `${
105
+ request.origin
106
+ }/${redirectorRelativeUrlForProject}?redirect=${encodeURIComponent(
107
+ afterCompileId,
108
+ )}`,
109
+ },
133
110
  }
134
111
  }
135
-
136
112
  // nothing after compileId, we don't know what to compile (not supposed to happen)
137
113
  if (afterCompileId === "") {
138
114
  return null
139
115
  }
140
-
116
+ const { compileProfile } = compileDirectory
141
117
  const originalFileRelativeUrl = afterCompileId
142
118
  const originalFileUrl = `${projectDirectoryUrl}${originalFileRelativeUrl}`
143
- const compileDirectoryRelativeUrl = `${outDirectoryRelativeUrl}${compileId}/`
119
+ const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
144
120
  const compileDirectoryUrl = resolveDirectoryUrl(
145
121
  compileDirectoryRelativeUrl,
146
122
  projectDirectoryUrl,
@@ -181,24 +157,18 @@ export const createCompiledFileService = ({
181
157
  jsenvRemoteDirectory,
182
158
  compileServerOrigin: request.origin,
183
159
  jsenvDirectoryRelativeUrl,
184
- outDirectoryRelativeUrl,
185
160
  url: originalFileUrl,
186
161
  compiledUrl: compiledFileUrl,
187
162
  request,
188
163
 
164
+ compileProfile,
189
165
  compileId,
190
166
  babelPluginMap: shakeBabelPluginMap({
191
167
  babelPluginMap,
192
- missingFeatureNames: groupMap[compileId].missingFeatureNames,
168
+ compileProfile,
193
169
  }),
194
- runtimeSupport,
195
170
  workerUrls,
196
171
  serviceWorkerUrls,
197
- moduleOutFormat:
198
- moduleOutFormat === undefined
199
- ? compileIdModuleFormats[compileId]
200
- : moduleOutFormat,
201
- importMetaFormat,
202
172
  topLevelAwait,
203
173
  prependSystemJs,
204
174
 
@@ -217,25 +187,6 @@ export const createCompiledFileService = ({
217
187
  }
218
188
  }
219
189
 
220
- const canAvoidSystemJs = ({
221
- runtimeSupport,
222
- workerUrls,
223
- importMapInWebWorkers,
224
- }) => {
225
- const runtimeCompatMap = createRuntimeCompat({
226
- featureNames: [
227
- "module",
228
- "importmap",
229
- "import_assertion_type_json",
230
- "import_assertion_type_css",
231
- ...(workerUrls.length > 0 ? ["worker_type_module"] : []),
232
- ...(importMapInWebWorkers ? ["worker_importmap"] : []),
233
- ],
234
- runtimeSupport,
235
- })
236
- return runtimeCompatMap.missingFeatureNames.length === 0
237
- }
238
-
239
190
  const getCompiler = ({ originalFileUrl, compileMeta }) => {
240
191
  // we remove eventual query param from the url
241
192
  // Without this a pattern like "**/*.js" would not match "file.js?t=1"