@jsenv/core 25.3.0 → 25.4.3

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 (108) 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_f4285042.js.map +343 -0
  7. package/dist/compile_proxy/{compile_proxy_8dfaee51.html → compile_proxy_ab528227.html} +358 -397
  8. package/dist/redirector/asset-manifest.json +2 -2
  9. package/dist/redirector/redirector.html__inline__12_404b8295.js.map +349 -0
  10. package/dist/redirector/{redirector_3e9a97b9.html → redirector_6df2620a.html} +369 -407
  11. package/dist/toolbar/asset-manifest.json +2 -2
  12. package/dist/toolbar/toolbar.main_279b3a68.js.map +764 -0
  13. package/dist/toolbar/{toolbar_361afb84.html → toolbar_0a91ca3b.html} +1509 -1583
  14. package/dist/toolbar_injector/asset-manifest.json +2 -2
  15. package/dist/toolbar_injector/{toolbar_injector_fac1e995.js → toolbar_injector_34f6ad8e.js} +18 -15
  16. package/dist/toolbar_injector/{toolbar_injector_fac1e995.js.map → toolbar_injector_34f6ad8e.js.map} +15 -15
  17. package/package.json +10 -10
  18. package/src/buildProject.js +31 -26
  19. package/src/dev_server.js +111 -92
  20. package/src/execute.js +3 -8
  21. package/src/importUsingChildProcess.js +1 -0
  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/rollup_plugin_jsenv.js +28 -8
  32. package/src/internal/compiling/babel_parse_error.js +9 -0
  33. package/src/internal/{babel_plugin_transform_import_meta.js → compiling/babel_plugin_transform_import_meta.js} +53 -36
  34. package/src/internal/compiling/compileFile.js +2 -2
  35. package/src/internal/compiling/compileHtml.js +1 -1
  36. package/src/internal/compiling/createCompiledFileService.js +25 -74
  37. package/src/internal/compiling/js-compilation-service/transformJs.js +151 -23
  38. package/src/internal/compiling/jsenvCompilerForHtml.js +38 -43
  39. package/src/internal/compiling/jsenvCompilerForImportmap.js +2 -2
  40. package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -4
  41. package/src/internal/compiling/jsenv_directory/comparison_utils.js +24 -0
  42. package/src/internal/compiling/{compile-directory/compile-asset.js → jsenv_directory/compile_asset.js} +0 -0
  43. package/src/internal/compiling/jsenv_directory/compile_context.js +68 -0
  44. package/src/internal/compiling/jsenv_directory/compile_profile.js +218 -0
  45. package/src/internal/compiling/{compile-directory/createLockRegistry.js → jsenv_directory/file_lock_registry.js} +0 -0
  46. package/src/internal/compiling/{compile-directory/createLockRegistry.test.js → jsenv_directory/file_lock_registry.test.js} +2 -1
  47. package/src/internal/compiling/{compile-directory → jsenv_directory}/fs-optimized-for-cache.js +0 -0
  48. package/src/internal/compiling/{compile-directory → jsenv_directory}/getOrGenerateCompiledFile.js +2 -2
  49. package/src/internal/compiling/jsenv_directory/jsenv_directory.js +174 -0
  50. package/src/internal/compiling/{compile-directory → jsenv_directory}/updateMeta.js +1 -1
  51. package/src/internal/compiling/{compile-directory → jsenv_directory}/validateCache.js +0 -0
  52. package/src/internal/compiling/sse_service/sse_service.js +369 -0
  53. package/src/internal/compiling/startCompileServer.js +157 -804
  54. package/src/internal/compiling/transformResultToCompilationResult.js +2 -2
  55. package/src/internal/dev_server/exploring/exploring.js +10 -8
  56. package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +92 -78
  57. package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
  58. package/src/internal/dev_server/toolbar/toolbar.html +46 -16
  59. package/src/internal/dev_server/toolbar/toolbar.injector.js +17 -15
  60. package/src/internal/dev_server/toolbar/toolbar.main.js +12 -16
  61. package/src/internal/executing/executeConcurrently.js +1 -1
  62. package/src/internal/executing/executePlan.js +2 -3
  63. package/src/internal/{generateGroupMap → features}/babel_plugins_compatibility.js +8 -8
  64. package/src/internal/features/browser_feature_detection/browser_feature_detect_dynamic_import.js +20 -0
  65. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_css.js +23 -0
  66. package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_json.js +25 -0
  67. package/src/internal/features/browser_feature_detection/browser_feature_detect_importmap.js +37 -0
  68. package/src/internal/features/browser_feature_detection/browser_feature_detect_new_stylesheet.js +9 -0
  69. package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js +14 -0
  70. package/src/internal/features/browser_feature_detection/browser_feature_detection.js +89 -0
  71. package/src/internal/{browser_feature_detection → features/browser_feature_detection}/compile_proxy.html +1 -1
  72. package/src/internal/features/browser_feature_detection/execute_with_script_module.js +24 -0
  73. package/src/internal/features/features_compat_from_runtime.js +38 -0
  74. package/src/internal/features/features_compat_from_runtime_support.js +31 -0
  75. package/src/internal/{generateGroupMap → features}/features_compatibility.js +3 -3
  76. package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_dynamic_import.mjs +0 -0
  77. package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_top_level_await.mjs +0 -0
  78. package/src/internal/{node_feature_detection/nodeSupportsDynamicImport.js → features/node_feature_detection/node_feature_detect_dynamic_import.js} +0 -0
  79. package/src/internal/{node_feature_detection/nodeSupportsTopLevelAwait.js → features/node_feature_detection/node_feature_detect_top_level_await.js} +0 -0
  80. package/src/internal/features/node_feature_detection/node_feature_detection.js +66 -0
  81. package/src/internal/import-resolution/importmap_default.js +2 -17
  82. package/src/internal/node_launcher/createControllableNodeProcess.js +4 -6
  83. package/src/internal/node_launcher/node_runtime_report.js +15 -9
  84. package/src/internal/node_runtime/fetchSource.js +2 -4
  85. package/src/internal/node_runtime/nodeControllableFile.mjs +1 -5
  86. package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
  87. package/src/internal/redirector/redirector.html +40 -0
  88. package/src/internal/{generateGroupMap/jsenvRuntimeSupport.js → runtime_support/jsenv_runtime_support.js} +0 -0
  89. package/src/internal/{generateGroupMap → runtime_support}/runtime_support.js +0 -0
  90. package/src/internal/url_conversion.js +12 -17
  91. package/src/launchNode.js +29 -41
  92. package/dist/compile_proxy/compile_proxy.html__inline__20_809f35f7.js.map +0 -392
  93. package/dist/redirector/redirector.html__inline__15_e391410e.js.map +0 -397
  94. package/dist/toolbar/toolbar.main_6c1b3d82.js.map +0 -802
  95. package/src/internal/CONSTANTS.js +0 -11
  96. package/src/internal/browser_feature_detection/browser_feature_detection.js +0 -274
  97. package/src/internal/compiling/js-compilation-service/jsenvTransform.js +0 -242
  98. package/src/internal/dev_server/redirector/redirector.html +0 -48
  99. package/src/internal/generateGroupMap/generateGroupMap.js +0 -65
  100. package/src/internal/generateGroupMap/one_runtime_compat.js +0 -38
  101. package/src/internal/generateGroupMap/runtime_compat.js +0 -34
  102. package/src/internal/generateGroupMap/runtime_compat_composition.js +0 -76
  103. package/src/internal/generateGroupMap/shake_babel_plugin_map.js +0 -21
  104. package/src/internal/node_feature_detection/node_feature_detection.js +0 -117
  105. package/src/internal/node_runtime/detectNode.js +0 -3
  106. package/src/internal/runtime/computeCompileIdFromGroupId.js +0 -30
  107. package/src/internal/runtime/resolveGroup.js +0 -13
  108. package/src/internal/runtime/resolveRuntimeGroup.js +0 -11
@@ -3,7 +3,7 @@
3
3
  import { normalizeImportMap } from "@jsenv/importmap/src/normalizeImportMap.js"
4
4
 
5
5
  // do not use memoize from @jsenv/filesystem to avoid pulling @jsenv/filesystem code into the browser build
6
- import { fetchUrl } from "../browser_utils/fetch-browser.js"
6
+ import { fetchUrl } from "../browser_utils/fetch_browser.js"
7
7
  import { createImportResolverForImportmap } from "../import-resolution/import-resolver-importmap.js"
8
8
  import { memoize } from "../memoize.js"
9
9
  import { measureAsyncFnPerf } from "../perf_browser.js"
@@ -15,7 +15,7 @@ const memoizedCreateBrowserSystem = memoize(createBrowserSystem)
15
15
 
16
16
  export const createBrowserRuntime = async ({
17
17
  compileServerOrigin,
18
- outDirectoryRelativeUrl,
18
+ jsenvDirectoryRelativeUrl,
19
19
  compileId,
20
20
  }) => {
21
21
  const fetchSource = (url, { contentTypeExpected }) => {
@@ -33,10 +33,11 @@ export const createBrowserRuntime = async ({
33
33
  return json
34
34
  }
35
35
 
36
- const outDirectoryUrl = `${compileServerOrigin}/${outDirectoryRelativeUrl}`
37
- const envUrl = String(new URL("env.json", outDirectoryUrl))
38
- const { importDefaultExtension } = await fetchJson(envUrl)
39
- const compileDirectoryRelativeUrl = `${outDirectoryRelativeUrl}${compileId}/`
36
+ const compileServerMetaUrl = String(
37
+ new URL("__jsenv_compile_profile__", `${compileServerOrigin}/`),
38
+ )
39
+ const { importDefaultExtension } = await fetchJson(compileServerMetaUrl)
40
+ const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
40
41
  // if there is an importmap in the document we use it instead of fetching.
41
42
  // systemjs style with systemjs-importmap
42
43
  const importmapScript = document.querySelector(
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { createDetailedMessage } from "@jsenv/logger"
4
4
 
5
- import { fetchUrl } from "./fetch-browser.js"
5
+ import { fetchUrl } from "./fetch_browser.js"
6
6
 
7
7
  export const fetchAndEvalUsingFetch = async (url) => {
8
8
  const response = await fetchUrl(url)
@@ -1,4 +1,4 @@
1
- import { fetchUrl } from "./fetch-browser.js"
1
+ import { fetchUrl } from "./fetch_browser.js"
2
2
 
3
3
  export const fetchJson = async (url, options = {}) => {
4
4
  const response = await fetchUrl(url, options)
@@ -1,5 +1,3 @@
1
- /* eslint-env browser */
2
-
3
1
  import { fetchUsingXHR } from "./fetchUsingXHR.js"
4
2
 
5
3
  const fetchNative = async (url, { mode = "cors", ...options } = {}) => {
@@ -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,56 +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
- const { parseExpression } = require("@babel/parser")
14
-
15
- const { replaceImportMeta } = pluginOptions
16
-
17
15
  let babelState
18
16
  const jsValueToAst = (jsValue) => {
19
- const valueAst = parseExpression(jsValue, babelState.opts)
17
+ const { parseExpression } = require("@babel/parser")
18
+ const valueAst = parseExpression(jsValue, babelState.parserOpts)
20
19
  return valueAst
21
20
  }
21
+ const visitImportMetaProperty = ({
22
+ importMetaPropertyName,
23
+ replaceWithImport,
24
+ replaceWithValue,
25
+ }) => {
26
+ if (importMetaFormat === "esmodule") {
27
+ // keep native version
28
+ return
29
+ }
30
+ if (importMetaFormat === "systemjs") {
31
+ // systemjs will handle it
32
+ return
33
+ }
34
+ if (importMetaFormat === "commonjs") {
35
+ if (importMetaPropertyName === "url") {
36
+ replaceWithImport({
37
+ from: `@jsenv/core/helpers/import-meta/import-meta-url-commonjs.js`,
38
+ })
39
+ return
40
+ }
41
+ if (importMetaPropertyName === "resolve") {
42
+ throw createParseError({
43
+ message: `import.meta.resolve() not supported with commonjs format`,
44
+ })
45
+ }
46
+ replaceWithValue(undefined)
47
+ return
48
+ }
49
+ if (importMetaFormat === "global") {
50
+ if (importMetaPropertyName === "url") {
51
+ replaceWithImport({
52
+ from: `@jsenv/core/helpers/import-meta/import-meta-url-global.js`,
53
+ })
54
+ return
55
+ }
56
+ if (importMetaPropertyName === "resolve") {
57
+ throw createParseError({
58
+ message: `import.meta.resolve() not supported with global format`,
59
+ })
60
+ }
61
+ replaceWithValue(undefined)
62
+ return
63
+ }
64
+ }
22
65
 
23
66
  return {
67
+ name: "transform-import-meta",
68
+
24
69
  pre: (state) => {
25
70
  babelState = state
26
71
  },
27
72
 
28
- // visitor: {
29
- // Program(programPath) {
30
- // const paths = []
31
- // programPath.traverse({
32
- // MetaProperty(metaPropertyPath) {
33
- // const metaPropertyNode = metaPropertyPath.node
34
- // if (!metaPropertyNode.meta) {
35
- // return
36
- // }
37
- // if (metaPropertyNode.meta.name !== "import") {
38
- // return
39
- // }
40
- // if (metaPropertyNode.property.name !== "meta") {
41
- // return
42
- // }
43
- // paths.push(metaPropertyPath)
44
- // },
45
- // })
46
-
47
- // const importAst = addNamespace(programPath, importMetaSpecifier)
48
- // paths.forEach((path) => {
49
- // path.replaceWith(importAst)
50
- // })
51
- // },
52
-
53
73
  visitor: {
54
74
  Program(programPath) {
55
75
  const metaPropertyPathMap = {}
56
-
57
76
  programPath.traverse({
58
77
  MemberExpression(path) {
59
78
  const { node } = path
@@ -61,12 +80,10 @@ export const babelPluginTransformImportMeta = (api, pluginOptions) => {
61
80
  if (object.type !== "MetaProperty") {
62
81
  return
63
82
  }
64
-
65
83
  const { property: objectProperty } = object
66
84
  if (objectProperty.name !== "meta") {
67
85
  return
68
86
  }
69
-
70
87
  const { property } = node
71
88
  const { name } = property
72
89
  if (name in metaPropertyPathMap) {
@@ -76,9 +93,9 @@ export const babelPluginTransformImportMeta = (api, pluginOptions) => {
76
93
  }
77
94
  },
78
95
  })
79
-
80
96
  Object.keys(metaPropertyPathMap).forEach((importMetaPropertyName) => {
81
- replaceImportMeta(importMetaPropertyName, {
97
+ visitImportMetaProperty({
98
+ importMetaPropertyName,
82
99
  replaceWithImport: ({ namespace, name, from, nameHint }) => {
83
100
  let importAst
84
101
  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"