@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
@@ -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
- }
@@ -1,76 +0,0 @@
1
- import { findHighestVersion } from "../semantic_versioning/index.js"
2
-
3
- export const composeMinRuntimeVersions = (
4
- firstMinRuntimeVersions,
5
- secondMinRuntimeVersions,
6
- ) => {
7
- const composed = {}
8
- Object.keys(firstMinRuntimeVersions).forEach((runtimeName) => {
9
- const firstRuntimeVersion = String(firstMinRuntimeVersions[runtimeName])
10
- composed[runtimeName] = firstRuntimeVersion
11
- })
12
- Object.keys(secondMinRuntimeVersions).forEach((runtimeName) => {
13
- const firstRuntimeVersion = composed[runtimeName]
14
- const secondRuntimeVersion = String(secondMinRuntimeVersions[runtimeName])
15
- composed[runtimeName] = firstRuntimeVersion
16
- ? findHighestVersion(firstRuntimeVersion, secondRuntimeVersion)
17
- : secondRuntimeVersion
18
- })
19
- return sortObjectKeys(composed)
20
- }
21
-
22
- const sortObjectKeys = (object) => {
23
- const sorted = {}
24
- Object.keys(object)
25
- .sort()
26
- .forEach((key) => {
27
- sorted[key] = object[key]
28
- })
29
- return sorted
30
- }
31
-
32
- // export const composeRuntimeCompat = (...runtimeCompats) => {
33
- // return runtimeCompats.reduce(runtimeCompatComposer, {
34
- // missingFeatureNames: [],
35
- // runtimeCompatMap: {},
36
- // })
37
- // }
38
-
39
- // const compositionMappingToStrictReducer = (compositionMapping) => {
40
- // const propertyComposeStrict = (key, previous, current) => {
41
- // const propertyExistInCurrent = key in current
42
- // if (!propertyExistInCurrent) return previous[key]
43
-
44
- // const propertyExistInPrevious = key in previous
45
- // if (!propertyExistInPrevious) return current[key]
46
-
47
- // const composeProperty = compositionMapping[key]
48
- // return composeProperty(previous[key], current[key])
49
- // }
50
-
51
- // return (previous, current) => {
52
- // if (typeof current !== "object" || current === null) return previous
53
-
54
- // const composed = {}
55
- // Object.keys(compositionMapping).forEach((key) => {
56
- // composed[key] = propertyComposeStrict(key, previous, current)
57
- // })
58
- // return composed
59
- // }
60
- // }
61
-
62
- // const runtimeCompatComposer = compositionMappingToStrictReducer({
63
- // missingFeatureNames: (
64
- // babelPluginNamesPrevious,
65
- // babelPluginNamesCurrent,
66
- // ) => {
67
- // return arrayWithoutDuplicate([
68
- // ...babelPluginNamesPrevious,
69
- // ...babelPluginNamesCurrent,
70
- // ]).sort()
71
- // },
72
- // minRuntimeVersions: composeMinRuntimeVersions,
73
- // })
74
-
75
- // const arrayWithoutDuplicate = (array) =>
76
- // array.filter((value, index) => array.indexOf(value) === index)
@@ -1,21 +0,0 @@
1
- export const shakeBabelPluginMap = ({
2
- babelPluginMap,
3
- missingFeatureNames,
4
- }) => {
5
- const babelPluginMapForGroup = {}
6
- missingFeatureNames.forEach((featureName) => {
7
- const babelPlugin = babelPluginMap[featureName]
8
- if (babelPlugin) {
9
- babelPluginMapForGroup[featureName] = babelPlugin
10
- }
11
- })
12
- Object.keys(babelPluginMap).forEach((key) => {
13
- if (key.startsWith("syntax-")) {
14
- babelPluginMapForGroup[key] = babelPluginMap[key]
15
- }
16
- if (key === "transform-replace-expressions") {
17
- babelPluginMapForGroup[key] = babelPluginMap[key]
18
- }
19
- })
20
- return babelPluginMapForGroup
21
- }
@@ -1,117 +0,0 @@
1
- import { resolveGroup } from "@jsenv/core/src/internal/runtime/resolveGroup.js"
2
- import { detectNode } from "@jsenv/core/src/internal/node_runtime/detectNode.js"
3
- import { computeCompileIdFromGroupId } from "@jsenv/core/src/internal/runtime/computeCompileIdFromGroupId.js"
4
- import { nodeSupportsDynamicImport } from "@jsenv/core/src/internal/node_feature_detection/nodeSupportsDynamicImport.js"
5
- import { nodeSupportsTopLevelAwait } from "@jsenv/core/src/internal/node_feature_detection/nodeSupportsTopLevelAwait.js"
6
- import { fetchSource } from "@jsenv/core/src/internal/node_runtime/fetchSource.js"
7
-
8
- export const scanNodeRuntimeFeatures = async ({
9
- compileServerOrigin,
10
- outDirectoryRelativeUrl,
11
- coverageHandledFromOutside = false,
12
- }) => {
13
- const outDirectoryServerUrl = `${compileServerOrigin}/${outDirectoryRelativeUrl}`
14
- const {
15
- importDefaultExtension,
16
- customCompilerPatterns,
17
- compileServerGroupMap,
18
- } = await importJson(
19
- new URL("__compile_server_meta__.json", outDirectoryServerUrl),
20
- )
21
-
22
- const node = detectNode()
23
- const compileId = computeCompileIdFromGroupId({
24
- groupId: resolveGroup(node, compileServerGroupMap),
25
- groupMap: compileServerGroupMap,
26
- })
27
- const groupInfo = compileServerGroupMap[compileId]
28
-
29
- const featuresReport = {
30
- dynamicImport: undefined,
31
- topLevelAwait: undefined,
32
- }
33
- await detectSupportedFeatures({
34
- featuresReport,
35
- failFastOnFeatureDetection: true,
36
- })
37
- const missingFeatureNames = adjustMissingFeatureNames(groupInfo, {
38
- featuresReport,
39
- coverageHandledFromOutside,
40
- })
41
-
42
- const canAvoidCompilation =
43
- // node native resolution will not auto add extension
44
- !importDefaultExtension &&
45
- customCompilerPatterns.length === 0 &&
46
- missingFeatureNames.length === 0 &&
47
- featuresReport.dynamicImport &&
48
- featuresReport.topLevelAwait
49
-
50
- return {
51
- canAvoidCompilation,
52
- featuresReport,
53
- missingFeatureNames,
54
- compileId,
55
- importDefaultExtension,
56
- node,
57
- }
58
- }
59
-
60
- const detectSupportedFeatures = async ({
61
- featuresReport,
62
- failFastOnFeatureDetection,
63
- }) => {
64
- const dynamicImport = await nodeSupportsDynamicImport()
65
- featuresReport.dynamicImport = dynamicImport
66
- if (failFastOnFeatureDetection && !dynamicImport) {
67
- return
68
- }
69
-
70
- const topLevelAwait = await nodeSupportsTopLevelAwait()
71
- featuresReport.topLevelAwait = topLevelAwait
72
- if (failFastOnFeatureDetection && !topLevelAwait) {
73
- return
74
- }
75
- }
76
-
77
- const importJson = async (url) => {
78
- const response = await fetchSource(url)
79
- const status = response.status
80
- if (status !== 200) {
81
- throw new Error(`unexpected response status for ${url}, got ${status}`)
82
- }
83
- const object = await response.json()
84
- return object
85
- }
86
-
87
- const adjustMissingFeatureNames = (
88
- groupInfo,
89
- { coverageHandledFromOutside },
90
- ) => {
91
- const { missingFeatureNames } = groupInfo
92
- const missingFeatureNamesCopy = missingFeatureNames.slice()
93
- const markAsSupported = (name) => {
94
- const index = missingFeatureNamesCopy.indexOf(name)
95
- if (index > -1) {
96
- missingFeatureNamesCopy.splice(index, 1)
97
- }
98
- }
99
- if (coverageHandledFromOutside) {
100
- markAsSupported("transform-instrument")
101
- }
102
- // Jsenv enable some features because they are standard and we can expect code to use them.
103
- // At the time of writing this, these features are not available in latest Node.js.
104
- // Some feature are also browser specific.
105
- // To avoid compiling code for Node.js these feaure are marked as supported.
106
- // It means code written to be execute in Node.js should not use these features
107
- // because jsenv ignore them (it won't try to "polyfill" them)
108
- markAsSupported("module")
109
- markAsSupported("importmap")
110
- markAsSupported("transform-import-assertions")
111
- markAsSupported("import_assertion_type_json")
112
- markAsSupported("import_assertion_type_css")
113
- markAsSupported("new-stylesheet-as-jsenv-import")
114
- markAsSupported("worker_type_module")
115
- markAsSupported("worker_importmap")
116
- return missingFeatureNamesCopy
117
- }
@@ -1,3 +0,0 @@
1
- export const detectNode = () => {
2
- return { name: "node", version: process.version.slice(1) }
3
- }
@@ -1,30 +0,0 @@
1
- import { createDetailedMessage } from "@jsenv/logger"
2
-
3
- import { COMPILE_ID_OTHERWISE } from "../CONSTANTS.js"
4
-
5
- export const computeCompileIdFromGroupId = ({ groupId, groupMap }) => {
6
- if (typeof groupId === "undefined") {
7
- if (COMPILE_ID_OTHERWISE in groupMap) {
8
- return COMPILE_ID_OTHERWISE
9
- }
10
-
11
- const keys = Object.keys(groupMap)
12
- if (keys.length === 1) {
13
- return keys[0]
14
- }
15
-
16
- throw new Error(createUnexpectedGroupIdMessage({ groupMap }))
17
- }
18
-
19
- if (groupId in groupMap === false) {
20
- throw new Error(createUnexpectedGroupIdMessage({ groupId, groupMap }))
21
- }
22
-
23
- return groupId
24
- }
25
-
26
- const createUnexpectedGroupIdMessage = ({ compileId, groupMap }) =>
27
- createDetailedMessage(`unexpected groupId.`, {
28
- ["expected compiled id"]: Object.keys(groupMap),
29
- ["received compile id"]: compileId,
30
- })
@@ -1,13 +0,0 @@
1
- import { findHighestVersion } from "../semantic_versioning/index.js"
2
-
3
- export const resolveGroup = ({ name, version }, groupMap) => {
4
- return Object.keys(groupMap).find((compileIdCandidate) => {
5
- const { minRuntimeVersions } = groupMap[compileIdCandidate]
6
- const versionForGroup = minRuntimeVersions[name]
7
- if (!versionForGroup) {
8
- return false
9
- }
10
- const highestVersion = findHighestVersion(version, versionForGroup)
11
- return highestVersion === version
12
- })
13
- }
@@ -1,11 +0,0 @@
1
- /* eslint-env browser, node */
2
- import { detectBrowser } from "../browser_detection/browser_detection.js"
3
- import { detectNode } from "../node_runtime/detectNode.js"
4
- import { resolveGroup } from "./resolveGroup.js"
5
-
6
- export const resolveRuntimeGroup = (groupMap) => {
7
- if (typeof window === "object") return resolveGroup(detectBrowser(), groupMap)
8
- if (typeof process === "object") return resolveGroup(detectNode(), groupMap)
9
- // we should certainly throw with unknown runtime
10
- return null
11
- }