@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.
- package/dist/browser_runtime/asset-manifest.json +2 -2
- package/dist/browser_runtime/{browser_runtime_91c5a3b8.js → browser_runtime_0e3396a1.js} +15 -16
- package/dist/browser_runtime/{browser_runtime_91c5a3b8.js.map → browser_runtime_0e3396a1.js.map} +13 -13
- package/dist/build_manifest.js +5 -5
- package/dist/compile_proxy/asset-manifest.json +2 -2
- package/dist/compile_proxy/compile_proxy.html__inline__20_2334a374.js.map +342 -0
- package/dist/compile_proxy/{compile_proxy_8dfaee51.html → compile_proxy_9f737eaf.html} +357 -398
- package/dist/redirector/asset-manifest.json +2 -2
- package/dist/redirector/redirector.html__inline__12_009c47c7.js.map +348 -0
- package/dist/redirector/{redirector_3e9a97b9.html → redirector_96f74871.html} +378 -421
- package/dist/toolbar/asset-manifest.json +2 -2
- package/dist/toolbar/{toolbar.main_6c1b3d82.js.map → toolbar.main_86335f90.js.map} +82 -115
- package/dist/toolbar/{toolbar_361afb84.html → toolbar_d3a918a4.html} +487 -508
- package/dist/toolbar_injector/asset-manifest.json +2 -2
- package/dist/toolbar_injector/toolbar_injector_978bbd14.js +267 -0
- package/dist/toolbar_injector/toolbar_injector_978bbd14.js.map +119 -0
- package/package.json +19 -14
- package/readme.md +54 -54
- package/src/buildProject.js +31 -26
- package/src/dev_server.js +78 -87
- package/src/execute.js +3 -8
- package/src/internal/browser_launcher/{browser_runtime_report.js → browser_runtime_profile.js} +21 -15
- package/src/internal/browser_launcher/executeHtmlFile.js +22 -14
- package/src/internal/browser_launcher/from_playwright.js +6 -4
- package/src/internal/browser_runtime/browser_runtime.js +12 -14
- package/src/internal/browser_runtime/createBrowserRuntime.js +7 -6
- package/src/internal/browser_utils/fetchAndEvalUsingFetch.js +1 -1
- package/src/internal/browser_utils/fetchJson.js +1 -1
- package/src/internal/browser_utils/{fetch-browser.js → fetch_browser.js} +0 -2
- package/src/internal/building/buildUsingRollup.js +41 -57
- package/src/internal/building/html/parseHtmlRessource.js +2 -1
- package/src/internal/building/rollup_plugin_jsenv.js +28 -8
- package/src/internal/compiling/babel_parse_error.js +9 -0
- package/src/internal/{babel_plugin_transform_import_meta.js → compiling/babel_plugin_transform_import_meta.js} +58 -9
- package/src/internal/compiling/compileFile.js +2 -2
- package/src/internal/compiling/compileHtml.js +1 -1
- package/src/internal/compiling/createCompiledFileService.js +25 -74
- package/src/internal/compiling/js-compilation-service/babelHelper.js +10 -13
- package/src/internal/compiling/js-compilation-service/babel_plugin_babel_helpers_as_jsenv_imports.js +4 -2
- package/src/internal/compiling/js-compilation-service/transformJs.js +153 -23
- package/src/internal/compiling/jsenvCompilerForHtml.js +34 -34
- package/src/internal/compiling/jsenvCompilerForImportmap.js +2 -2
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +2 -4
- package/src/internal/compiling/jsenv_directory/comparison_utils.js +24 -0
- package/src/internal/compiling/{compile-directory/compile-asset.js → jsenv_directory/compile_asset.js} +0 -0
- package/src/internal/compiling/jsenv_directory/compile_context.js +68 -0
- package/src/internal/compiling/jsenv_directory/compile_profile.js +218 -0
- package/src/internal/compiling/{compile-directory/createLockRegistry.js → jsenv_directory/file_lock_registry.js} +0 -0
- package/src/internal/compiling/{compile-directory/createLockRegistry.test.js → jsenv_directory/file_lock_registry.test.js} +2 -1
- package/src/internal/compiling/{compile-directory → jsenv_directory}/fs-optimized-for-cache.js +0 -0
- package/src/internal/compiling/{compile-directory → jsenv_directory}/getOrGenerateCompiledFile.js +2 -2
- package/src/internal/compiling/jsenv_directory/jsenv_directory.js +174 -0
- package/src/internal/compiling/{compile-directory → jsenv_directory}/updateMeta.js +4 -2
- package/src/internal/compiling/{compile-directory → jsenv_directory}/validateCache.js +0 -0
- package/src/internal/compiling/sse_service/sse_service.js +369 -0
- package/src/internal/compiling/startCompileServer.js +156 -804
- package/src/internal/compiling/transformResultToCompilationResult.js +2 -2
- package/src/internal/dev_server/exploring/exploring.js +10 -8
- package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +85 -78
- package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
- package/src/internal/dev_server/toolbar/toolbar.html +40 -16
- package/src/internal/dev_server/toolbar/toolbar.injector.js +11 -17
- package/src/internal/dev_server/toolbar/toolbar.main.js +6 -6
- package/src/internal/executing/executeConcurrently.js +1 -1
- package/src/internal/executing/executePlan.js +2 -3
- package/src/internal/{generateGroupMap → features}/babel_plugins_compatibility.js +8 -8
- package/src/internal/features/browser_feature_detection/browser_feature_detect_dynamic_import.js +20 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_css.js +23 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_import_assertions_json.js +25 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_importmap.js +37 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_new_stylesheet.js +9 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js +14 -0
- package/src/internal/features/browser_feature_detection/browser_feature_detection.js +85 -0
- package/src/internal/{browser_feature_detection → features/browser_feature_detection}/compile_proxy.html +1 -1
- package/src/internal/features/browser_feature_detection/execute_with_script_module.js +24 -0
- package/src/internal/features/features_compat_from_runtime.js +38 -0
- package/src/internal/features/features_compat_from_runtime_support.js +31 -0
- package/src/internal/{generateGroupMap → features}/features_compatibility.js +3 -3
- package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_dynamic_import.mjs +0 -0
- package/src/internal/{node_feature_detection → features/node_feature_detection}/feature_detect_top_level_await.mjs +0 -0
- package/src/internal/{node_feature_detection/nodeSupportsDynamicImport.js → features/node_feature_detection/node_feature_detect_dynamic_import.js} +0 -0
- package/src/internal/{node_feature_detection/nodeSupportsTopLevelAwait.js → features/node_feature_detection/node_feature_detect_top_level_await.js} +0 -0
- package/src/internal/features/node_feature_detection/node_feature_detection.js +66 -0
- package/src/internal/jsenv_remote_directory.js +1 -1
- package/src/internal/node_launcher/createControllableNodeProcess.js +4 -3
- package/src/internal/node_launcher/node_runtime_report.js +15 -9
- package/src/internal/node_runtime/fetchSource.js +2 -4
- package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
- package/src/internal/{dev_server/redirector → redirector}/redirector.html +8 -18
- package/src/internal/{generateGroupMap/jsenvRuntimeSupport.js → runtime_support/jsenv_runtime_support.js} +0 -0
- package/src/internal/{generateGroupMap → runtime_support}/runtime_support.js +0 -0
- package/src/internal/url_conversion.js +12 -17
- package/src/launchNode.js +29 -41
- package/dist/compile_proxy/compile_proxy.html__inline__20_809f35f7.js.map +0 -392
- package/dist/redirector/redirector.html__inline__15_e391410e.js.map +0 -397
- package/dist/toolbar_injector/toolbar_injector_fac1e995.js +0 -973
- package/dist/toolbar_injector/toolbar_injector_fac1e995.js.map +0 -294
- package/src/internal/CONSTANTS.js +0 -11
- package/src/internal/browser_feature_detection/browser_feature_detection.js +0 -274
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +0 -243
- package/src/internal/generateGroupMap/generateGroupMap.js +0 -65
- package/src/internal/generateGroupMap/one_runtime_compat.js +0 -38
- package/src/internal/generateGroupMap/runtime_compat.js +0 -34
- package/src/internal/generateGroupMap/runtime_compat_composition.js +0 -76
- package/src/internal/generateGroupMap/shake_babel_plugin_map.js +0 -21
- package/src/internal/integrity/integrity_algorithms.js +0 -26
- package/src/internal/integrity/integrity_parsing.js +0 -50
- package/src/internal/integrity/integrity_update.js +0 -23
- package/src/internal/integrity/integrity_validation.js +0 -49
- package/src/internal/node_feature_detection/node_feature_detection.js +0 -117
- package/src/internal/node_runtime/detectNode.js +0 -3
- package/src/internal/runtime/computeCompileIdFromGroupId.js +0 -30
- package/src/internal/runtime/resolveGroup.js +0 -13
- package/src/internal/runtime/resolveRuntimeGroup.js +0 -11
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asBase64Url,
|
|
3
|
+
executeWithScriptModuleInjection,
|
|
4
|
+
} from "./execute_with_script_module.js"
|
|
5
|
+
|
|
6
|
+
export const supportsJsonImportAssertions = async () => {
|
|
7
|
+
const jsonBase64Url = asBase64Url("42", "application/json")
|
|
8
|
+
const moduleSource = asBase64Url(
|
|
9
|
+
`import data from "${jsonBase64Url}" assert { type: "json" }
|
|
10
|
+
export default data`,
|
|
11
|
+
)
|
|
12
|
+
try {
|
|
13
|
+
await executeWithScriptModuleInjection(
|
|
14
|
+
`window.__jsenv_runtime_test_json_import_assertion__ = import(${JSON.stringify(
|
|
15
|
+
moduleSource,
|
|
16
|
+
)})`,
|
|
17
|
+
)
|
|
18
|
+
const namespace = await window.__jsenv_runtime_test_json_import_assertion__
|
|
19
|
+
const supported = namespace.default === 42
|
|
20
|
+
delete window.__jsenv_runtime_test_json_import_assertion__
|
|
21
|
+
return supported
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asBase64Url,
|
|
3
|
+
executeWithScriptModuleInjection,
|
|
4
|
+
} from "./execute_with_script_module.js"
|
|
5
|
+
|
|
6
|
+
export const supportsImportmap = async ({ remote = true } = {}) => {
|
|
7
|
+
const specifier = asBase64Url(`export default false`)
|
|
8
|
+
const importMap = {
|
|
9
|
+
imports: {
|
|
10
|
+
[specifier]: asBase64Url(`export default true`),
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
const importmapScript = document.createElement("script")
|
|
14
|
+
const importmapString = JSON.stringify(importMap, null, " ")
|
|
15
|
+
importmapScript.type = "importmap"
|
|
16
|
+
if (remote) {
|
|
17
|
+
importmapScript.src = `data:application/json;base64,${window.btoa(
|
|
18
|
+
importmapString,
|
|
19
|
+
)}`
|
|
20
|
+
} else {
|
|
21
|
+
importmapScript.textContent = importmapString
|
|
22
|
+
}
|
|
23
|
+
document.body.appendChild(importmapScript)
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
await executeWithScriptModuleInjection(
|
|
27
|
+
`import supported from "${specifier}"; window.__jsenv_runtime_test_importmap__ = supported`,
|
|
28
|
+
)
|
|
29
|
+
document.body.removeChild(importmapScript)
|
|
30
|
+
const supported = window.__jsenv_runtime_test_importmap__
|
|
31
|
+
delete window.__jsenv_runtime_test_importmap__
|
|
32
|
+
return supported
|
|
33
|
+
} catch (e) {
|
|
34
|
+
document.body.removeChild(importmapScript)
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
}
|
package/src/internal/features/browser_feature_detection/browser_feature_detect_top_level_await.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { executeWithScriptModuleInjection } from "./execute_with_script_module.js"
|
|
2
|
+
|
|
3
|
+
export const supportsTopLevelAwait = async () => {
|
|
4
|
+
try {
|
|
5
|
+
await executeWithScriptModuleInjection(
|
|
6
|
+
`window.__jsenv_runtime_test_top_level_await__ = await Promise.resolve(42)`,
|
|
7
|
+
)
|
|
8
|
+
const supported = window.__jsenv_runtime_test_top_level_await__ === 42
|
|
9
|
+
delete window.__jsenv_runtime_test_top_level_await__
|
|
10
|
+
return supported
|
|
11
|
+
} catch (e) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { fetchJson } from "../../browser_utils/fetchJson.js"
|
|
2
|
+
import { detectBrowser } from "../../browser_detection/browser_detection.js"
|
|
3
|
+
|
|
4
|
+
import { supportsImportmap } from "./browser_feature_detect_importmap.js"
|
|
5
|
+
import { supportsDynamicImport } from "./browser_feature_detect_dynamic_import.js"
|
|
6
|
+
import { supportsTopLevelAwait } from "./browser_feature_detect_top_level_await.js"
|
|
7
|
+
import { supportsJsonImportAssertions } from "./browser_feature_detect_import_assertions_json.js"
|
|
8
|
+
import { supportsCssImportAssertions } from "./browser_feature_detect_import_assertions_css.js"
|
|
9
|
+
import { supportsNewStylesheet } from "./browser_feature_detect_new_stylesheet.js"
|
|
10
|
+
|
|
11
|
+
export const scanBrowserRuntimeFeatures = async ({
|
|
12
|
+
coverageHandledFromOutside = false,
|
|
13
|
+
forceCompilation = false,
|
|
14
|
+
forceSource = false,
|
|
15
|
+
} = {}) => {
|
|
16
|
+
const jsenvCompileProfileUrl = "/__jsenv_compile_profile__"
|
|
17
|
+
const { jsenvDirectoryRelativeUrl, inlineImportMapIntoHTML } =
|
|
18
|
+
await fetchJson(jsenvCompileProfileUrl)
|
|
19
|
+
const { name, version } = detectBrowser()
|
|
20
|
+
const featuresReport = await detectSupportedFeatures({
|
|
21
|
+
coverageHandledFromOutside,
|
|
22
|
+
inlineImportMapIntoHTML,
|
|
23
|
+
})
|
|
24
|
+
const runtimeReport = {
|
|
25
|
+
env: { browser: true },
|
|
26
|
+
name,
|
|
27
|
+
version,
|
|
28
|
+
featuresReport,
|
|
29
|
+
forceSource,
|
|
30
|
+
forceCompilation,
|
|
31
|
+
}
|
|
32
|
+
const { compileProfile, compileId } = await fetchJson(
|
|
33
|
+
jsenvCompileProfileUrl,
|
|
34
|
+
{
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"content-type": "application/json",
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify(runtimeReport),
|
|
40
|
+
},
|
|
41
|
+
)
|
|
42
|
+
return {
|
|
43
|
+
jsenvDirectoryRelativeUrl,
|
|
44
|
+
inlineImportMapIntoHTML,
|
|
45
|
+
compileProfile,
|
|
46
|
+
compileId,
|
|
47
|
+
runtimeReport,
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const detectSupportedFeatures = async ({
|
|
52
|
+
coverageHandledFromOutside,
|
|
53
|
+
inlineImportMapIntoHTML,
|
|
54
|
+
}) => {
|
|
55
|
+
const featuresReport = {}
|
|
56
|
+
featuresReport["import_http"] = true
|
|
57
|
+
featuresReport["coverage_js"] = coverageHandledFromOutside
|
|
58
|
+
// new CSSStyleSheet
|
|
59
|
+
featuresReport["new_stylesheet"] = supportsNewStylesheet()
|
|
60
|
+
// importmap
|
|
61
|
+
// start testing importmap support first and not in paralell
|
|
62
|
+
// so that there is not module script loaded beore importmap is injected
|
|
63
|
+
// it would log an error in chrome console and return undefined
|
|
64
|
+
featuresReport.importmap = await supportsImportmap({
|
|
65
|
+
// chrome supports inline but not remote importmap
|
|
66
|
+
// https://github.com/WICG/import-maps/issues/235
|
|
67
|
+
// at this stage we won't know if the html file will use
|
|
68
|
+
// an importmap or not and if that importmap is inline or specified with an src
|
|
69
|
+
// so we should test if browser support local and remote importmap.
|
|
70
|
+
// But there exploring server can inline importmap by transforming html
|
|
71
|
+
// and in that case we can test only the local importmap support
|
|
72
|
+
// so we test importmap support and the remote one
|
|
73
|
+
remote: !inlineImportMapIntoHTML,
|
|
74
|
+
})
|
|
75
|
+
// dynamic import
|
|
76
|
+
featuresReport["import_dynamic"] = await supportsDynamicImport()
|
|
77
|
+
// top level await
|
|
78
|
+
featuresReport["top_level_await"] = await supportsTopLevelAwait()
|
|
79
|
+
// import assertions
|
|
80
|
+
featuresReport["import_assertion_type_json"] =
|
|
81
|
+
await supportsJsonImportAssertions()
|
|
82
|
+
featuresReport["import_assertion_type_css"] =
|
|
83
|
+
await supportsCssImportAssertions()
|
|
84
|
+
return featuresReport
|
|
85
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const executeWithScriptModuleInjection = (code) => {
|
|
2
|
+
const scriptModule = document.createElement("script")
|
|
3
|
+
scriptModule.type = "module"
|
|
4
|
+
|
|
5
|
+
const loadPromise = new Promise((resolve, reject) => {
|
|
6
|
+
scriptModule.onload = () => {
|
|
7
|
+
document.body.removeChild(scriptModule)
|
|
8
|
+
resolve()
|
|
9
|
+
}
|
|
10
|
+
scriptModule.onerror = () => {
|
|
11
|
+
document.body.removeChild(scriptModule)
|
|
12
|
+
reject()
|
|
13
|
+
}
|
|
14
|
+
document.body.appendChild(scriptModule)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
scriptModule.src = asBase64Url(code)
|
|
18
|
+
|
|
19
|
+
return loadPromise
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const asBase64Url = (text, mimeType = "application/javascript") => {
|
|
23
|
+
return `data:${mimeType};base64,${window.btoa(text)}`
|
|
24
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { findHighestVersion } from "@jsenv/core/src/internal/semantic_versioning/index.js"
|
|
2
|
+
|
|
3
|
+
import { featuresCompatMap } from "./features_compatibility.js"
|
|
4
|
+
|
|
5
|
+
export const featuresCompatFromRuntime = ({
|
|
6
|
+
runtimeName,
|
|
7
|
+
runtimeVersion,
|
|
8
|
+
featureNames,
|
|
9
|
+
}) => {
|
|
10
|
+
const availableFeatureNames = []
|
|
11
|
+
// "minRuntimeVersion" is the first version where all
|
|
12
|
+
// features in "availableFeatureNames" where available
|
|
13
|
+
// can be lower or equal to "runtimeVersion"
|
|
14
|
+
let minRuntimeVersion
|
|
15
|
+
featureNames.forEach((featureName) => {
|
|
16
|
+
const featureCompat = featuresCompatMap[featureName] || {}
|
|
17
|
+
const runtimeVersionCompatible = featureCompat[runtimeName] || "Infinity"
|
|
18
|
+
const highestVersion = findHighestVersion(
|
|
19
|
+
runtimeVersion,
|
|
20
|
+
runtimeVersionCompatible,
|
|
21
|
+
)
|
|
22
|
+
const compatible = highestVersion === runtimeVersion
|
|
23
|
+
if (compatible) {
|
|
24
|
+
availableFeatureNames.push(featureName)
|
|
25
|
+
if (runtimeVersionCompatible !== "Infinity") {
|
|
26
|
+
// there is a version from which runtime becomes compatible with this feature
|
|
27
|
+
minRuntimeVersion = findHighestVersion(
|
|
28
|
+
minRuntimeVersion || "0.0.0",
|
|
29
|
+
runtimeVersionCompatible,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
return {
|
|
35
|
+
availableFeatureNames,
|
|
36
|
+
minRuntimeVersion: minRuntimeVersion || runtimeVersion,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { featuresCompatFromRuntime } from "./features_compat_from_runtime.js"
|
|
2
|
+
|
|
3
|
+
export const featuresCompatFromRuntimeSupport = ({
|
|
4
|
+
runtimeSupport,
|
|
5
|
+
featureNames,
|
|
6
|
+
}) => {
|
|
7
|
+
const availableFeatureNames = []
|
|
8
|
+
const minRuntimeVersions = {}
|
|
9
|
+
const runtimeNames = Object.keys(runtimeSupport)
|
|
10
|
+
runtimeNames.forEach((runtimeName) => {
|
|
11
|
+
const runtimeVersion = runtimeSupport[runtimeName]
|
|
12
|
+
const runtimeFeaturesCompat = featuresCompatFromRuntime({
|
|
13
|
+
runtimeName,
|
|
14
|
+
runtimeVersion,
|
|
15
|
+
featureNames,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
minRuntimeVersions[runtimeName] = runtimeFeaturesCompat.minRuntimeVersion
|
|
19
|
+
runtimeFeaturesCompat.availableFeatureNames.forEach(
|
|
20
|
+
(availableFeatureName) => {
|
|
21
|
+
if (!availableFeatureNames.includes(availableFeatureName)) {
|
|
22
|
+
availableFeatureNames.push(availableFeatureName)
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
)
|
|
26
|
+
})
|
|
27
|
+
return {
|
|
28
|
+
availableFeatureNames,
|
|
29
|
+
minRuntimeVersions,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { babelPluginCompatMap } from "./babel_plugins_compatibility.js"
|
|
2
2
|
|
|
3
3
|
export const featuresCompatMap = {
|
|
4
|
-
|
|
4
|
+
script_type_module: {
|
|
5
5
|
edge: "16",
|
|
6
6
|
firefox: "60",
|
|
7
7
|
chrome: "61",
|
|
@@ -33,5 +33,5 @@ export const featuresCompatMap = {
|
|
|
33
33
|
android: "80",
|
|
34
34
|
},
|
|
35
35
|
worker_importmap: {},
|
|
36
|
-
...
|
|
36
|
+
...babelPluginCompatMap,
|
|
37
37
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { fetchSource } from "@jsenv/core/src/internal/node_runtime/fetchSource.js"
|
|
2
|
+
|
|
3
|
+
import { nodeSupportsDynamicImport } from "./node_feature_detect_dynamic_import.js"
|
|
4
|
+
import { nodeSupportsTopLevelAwait } from "./node_feature_detect_top_level_await.js"
|
|
5
|
+
|
|
6
|
+
export const scanNodeRuntimeFeatures = async ({
|
|
7
|
+
compileServerOrigin,
|
|
8
|
+
moduleOutFormat,
|
|
9
|
+
forceSource,
|
|
10
|
+
forceCompilation,
|
|
11
|
+
coverageHandledFromOutside,
|
|
12
|
+
}) => {
|
|
13
|
+
const jsenvCompileProfileServerUrl = new URL(
|
|
14
|
+
"__jsenv_compile_profile__",
|
|
15
|
+
compileServerOrigin,
|
|
16
|
+
).href
|
|
17
|
+
const { compileContext } = await fetchJson(jsenvCompileProfileServerUrl)
|
|
18
|
+
const featuresReport = await detectSupportedFeatures({
|
|
19
|
+
compileContext,
|
|
20
|
+
coverageHandledFromOutside,
|
|
21
|
+
})
|
|
22
|
+
const runtimeReport = {
|
|
23
|
+
env: { node: true },
|
|
24
|
+
name: "node",
|
|
25
|
+
version: process.version.slice(1),
|
|
26
|
+
featuresReport,
|
|
27
|
+
moduleOutFormat,
|
|
28
|
+
forceSource,
|
|
29
|
+
forceCompilation,
|
|
30
|
+
}
|
|
31
|
+
const { compileProfile, compileId } = await fetchJson(
|
|
32
|
+
jsenvCompileProfileServerUrl,
|
|
33
|
+
{
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
"content-type": "application/json",
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify(runtimeReport),
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
return {
|
|
42
|
+
compileProfile,
|
|
43
|
+
compileId,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const detectSupportedFeatures = async ({ coverageHandledFromOutside }) => {
|
|
48
|
+
const featuresReport = {}
|
|
49
|
+
// Node.js do not support http(s) imports, this information is important
|
|
50
|
+
// so that we know we cannot use dynamic import
|
|
51
|
+
featuresReport["import_http"] = false
|
|
52
|
+
featuresReport["coverage_js"] = coverageHandledFromOutside
|
|
53
|
+
featuresReport["import_dynamic"] = await nodeSupportsDynamicImport()
|
|
54
|
+
featuresReport["top_level_await"] = await nodeSupportsTopLevelAwait()
|
|
55
|
+
return featuresReport
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const fetchJson = async (url, options) => {
|
|
59
|
+
const response = await fetchSource(url, options)
|
|
60
|
+
const status = response.status
|
|
61
|
+
if (status !== 200) {
|
|
62
|
+
throw new Error(`unexpected response status for ${url}, got ${status}`)
|
|
63
|
+
}
|
|
64
|
+
const object = await response.json()
|
|
65
|
+
return object
|
|
66
|
+
}
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
urlToMeta,
|
|
7
7
|
writeFile,
|
|
8
8
|
} from "@jsenv/filesystem"
|
|
9
|
+
import { validateResponseIntegrity } from "@jsenv/integrity"
|
|
9
10
|
|
|
10
11
|
import { fetchUrl } from "@jsenv/core/src/internal/fetchUrl.js"
|
|
11
|
-
import { validateResponseIntegrity } from "@jsenv/core/src/internal/integrity/integrity_validation.js"
|
|
12
12
|
|
|
13
13
|
import { originDirectoryConverter } from "./origin_directory_converter.js"
|
|
14
14
|
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { fork } from "node:child_process"
|
|
2
|
-
import { uneval } from "@jsenv/uneval"
|
|
3
|
-
import { createLogger, createDetailedMessage } from "@jsenv/logger"
|
|
4
2
|
import { urlToFileSystemPath, assertFilePresence } from "@jsenv/filesystem"
|
|
3
|
+
import { createLogger, createDetailedMessage } from "@jsenv/logger"
|
|
5
4
|
import {
|
|
6
5
|
Abort,
|
|
7
6
|
raceCallbacks,
|
|
8
7
|
createCallbackList,
|
|
9
8
|
createCallbackListNotifiedOnce,
|
|
10
9
|
} from "@jsenv/abort"
|
|
10
|
+
import { uneval } from "@jsenv/uneval"
|
|
11
|
+
|
|
12
|
+
import { nodeSupportsDynamicImport } from "@jsenv/core/src/internal/features/node_feature_detection/node_feature_detect_dynamic_import.js"
|
|
11
13
|
|
|
12
|
-
import { nodeSupportsDynamicImport } from "../node_feature_detection/nodeSupportsDynamicImport.js"
|
|
13
14
|
import { createChildProcessOptions } from "./createChildProcessOptions.js"
|
|
14
15
|
import {
|
|
15
16
|
processOptionsFromExecArgv,
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import { scanNodeRuntimeFeatures } from "@jsenv/core/src/internal/node_feature_detection/node_feature_detection.js"
|
|
1
|
+
import { scanNodeRuntimeFeatures } from "@jsenv/core/src/internal/features/node_feature_detection/node_feature_detection.js"
|
|
2
2
|
|
|
3
3
|
export const getNodeRuntimeReport = async ({
|
|
4
4
|
runtime,
|
|
5
5
|
compileServerId,
|
|
6
6
|
compileServerOrigin,
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
moduleOutFormat,
|
|
9
|
+
forceCompilation,
|
|
8
10
|
coverageHandledFromOutside,
|
|
9
11
|
}) => {
|
|
10
12
|
const cache = cacheFromParams({
|
|
11
13
|
runtime,
|
|
12
14
|
compileServerId,
|
|
13
15
|
compileServerOrigin,
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
moduleOutFormat,
|
|
18
|
+
forceCompilation,
|
|
15
19
|
coverageHandledFromOutside,
|
|
16
20
|
})
|
|
17
21
|
const entry = cache.read()
|
|
@@ -20,7 +24,8 @@ export const getNodeRuntimeReport = async ({
|
|
|
20
24
|
}
|
|
21
25
|
const nodeRuntimeFeaturesReport = await scanNodeRuntimeFeatures({
|
|
22
26
|
compileServerOrigin,
|
|
23
|
-
|
|
27
|
+
moduleOutFormat,
|
|
28
|
+
forceCompilation,
|
|
24
29
|
coverageHandledFromOutside,
|
|
25
30
|
})
|
|
26
31
|
cache.write(nodeRuntimeFeaturesReport)
|
|
@@ -32,16 +37,19 @@ let currentCacheValue
|
|
|
32
37
|
const cacheFromParams = ({
|
|
33
38
|
compileServerId,
|
|
34
39
|
compileServerOrigin,
|
|
35
|
-
|
|
40
|
+
|
|
41
|
+
moduleOutFormat,
|
|
42
|
+
forceCompilation,
|
|
36
43
|
coverageHandledFromOutside,
|
|
37
44
|
}) => {
|
|
38
45
|
const params = {
|
|
39
46
|
compileServerId,
|
|
40
47
|
compileServerOrigin,
|
|
41
|
-
|
|
48
|
+
|
|
49
|
+
moduleOutFormat,
|
|
50
|
+
forceCompilation,
|
|
42
51
|
coverageHandledFromOutside,
|
|
43
52
|
}
|
|
44
|
-
|
|
45
53
|
if (!currentCacheParams) {
|
|
46
54
|
currentCacheParams = params
|
|
47
55
|
return {
|
|
@@ -51,7 +59,6 @@ const cacheFromParams = ({
|
|
|
51
59
|
},
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
|
-
|
|
55
62
|
if (JSON.stringify(currentCacheParams) !== JSON.stringify(params)) {
|
|
56
63
|
return {
|
|
57
64
|
read: () => null,
|
|
@@ -61,7 +68,6 @@ const cacheFromParams = ({
|
|
|
61
68
|
},
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
|
-
|
|
65
71
|
return {
|
|
66
72
|
read: () => currentCacheValue,
|
|
67
73
|
write: (value) => {
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { fetchUrl } from "../fetchUrl.js"
|
|
2
2
|
|
|
3
|
-
export const fetchSource = (url,
|
|
3
|
+
export const fetchSource = (url, options) => {
|
|
4
4
|
return fetchUrl(url, {
|
|
5
5
|
ignoreHttpsError: true,
|
|
6
|
-
|
|
7
|
-
...(executionId ? { "x-jsenv-execution-id": executionId } : {}),
|
|
8
|
-
},
|
|
6
|
+
...options,
|
|
9
7
|
})
|
|
10
8
|
}
|
|
@@ -12,7 +12,7 @@ export const execute = async ({
|
|
|
12
12
|
projectDirectoryUrl,
|
|
13
13
|
compileServerOrigin,
|
|
14
14
|
fileRelativeUrl,
|
|
15
|
-
|
|
15
|
+
jsenvDirectoryRelativeUrl,
|
|
16
16
|
compileId,
|
|
17
17
|
importDefaultExtension,
|
|
18
18
|
// do not log in the console
|
|
@@ -25,7 +25,6 @@ export const execute = async ({
|
|
|
25
25
|
collectPerformance,
|
|
26
26
|
}) => {
|
|
27
27
|
let finalizeExecutionResult = (result) => result
|
|
28
|
-
|
|
29
28
|
if (collectPerformance) {
|
|
30
29
|
const getPerformance = startObservingPerformances()
|
|
31
30
|
finalizeExecutionResult = async (executionResult) => {
|
|
@@ -36,12 +35,10 @@ export const execute = async ({
|
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
|
-
|
|
40
38
|
const { getErrorOriginalStackString } = installNodeErrorStackRemapping({
|
|
41
39
|
projectDirectoryUrl,
|
|
42
40
|
})
|
|
43
|
-
|
|
44
|
-
const compileDirectoryRelativeUrl = `${outDirectoryRelativeUrl}${compileId}/`
|
|
41
|
+
const compileDirectoryRelativeUrl = `${jsenvDirectoryRelativeUrl}${compileId}/`
|
|
45
42
|
|
|
46
43
|
const errorTransformer = async (error) => {
|
|
47
44
|
// code can throw something else than an error
|
|
@@ -8,38 +8,28 @@
|
|
|
8
8
|
</head>
|
|
9
9
|
|
|
10
10
|
<body>
|
|
11
|
-
<script
|
|
12
|
-
type="importmap"
|
|
13
|
-
src="../../../../node_resolution.importmap"
|
|
14
|
-
></script>
|
|
11
|
+
<script type="importmap" src="../../../node_resolution.importmap"></script>
|
|
15
12
|
<script type="module">
|
|
16
|
-
import { scanBrowserRuntimeFeatures } from "
|
|
13
|
+
import { scanBrowserRuntimeFeatures } from "../features/browser_feature_detection/browser_feature_detection.js"
|
|
17
14
|
|
|
18
15
|
const redirect = async () => {
|
|
19
16
|
const redirectTarget = new URLSearchParams(window.location.search).get(
|
|
20
17
|
"redirect",
|
|
21
18
|
)
|
|
22
|
-
const
|
|
23
|
-
failFastOnFeatureDetection: true,
|
|
24
|
-
})
|
|
25
|
-
|
|
19
|
+
const browserRuntimeProfile = await scanBrowserRuntimeFeatures()
|
|
26
20
|
const href = `${getDirectoryUrl(
|
|
27
|
-
|
|
21
|
+
browserRuntimeProfile,
|
|
28
22
|
)}${redirectTarget}`
|
|
29
23
|
// It's IMPORTANT to use location.replace and NOT location.href = url
|
|
30
24
|
// otherwise it would break the back button
|
|
31
25
|
window.location.replace(href)
|
|
32
26
|
}
|
|
33
27
|
|
|
34
|
-
const getDirectoryUrl = ({
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
compileId,
|
|
38
|
-
}) => {
|
|
39
|
-
if (canAvoidCompilation) {
|
|
40
|
-
return `/`
|
|
28
|
+
const getDirectoryUrl = ({ jsenvDirectoryRelativeUrl, compileId }) => {
|
|
29
|
+
if (compileId) {
|
|
30
|
+
return `/${jsenvDirectoryRelativeUrl}${compileId}/`
|
|
41
31
|
}
|
|
42
|
-
return
|
|
32
|
+
return `/`
|
|
43
33
|
}
|
|
44
34
|
|
|
45
35
|
redirect()
|
|
File without changes
|
|
File without changes
|
|
@@ -150,33 +150,28 @@ const normalizeUrlMappings = (urlMappings, baseUrl) => {
|
|
|
150
150
|
|
|
151
151
|
export const serverUrlToCompileInfo = (
|
|
152
152
|
url,
|
|
153
|
-
{ compileServerOrigin,
|
|
153
|
+
{ compileServerOrigin, jsenvDirectoryRelativeUrl },
|
|
154
154
|
) => {
|
|
155
|
-
const
|
|
156
|
-
|
|
155
|
+
const jsenvDirectoryServerUrl = resolveDirectoryUrl(
|
|
156
|
+
jsenvDirectoryRelativeUrl,
|
|
157
157
|
compileServerOrigin,
|
|
158
158
|
)
|
|
159
159
|
// not inside compile directory -> nothing to compile
|
|
160
|
-
if (!url.startsWith(
|
|
160
|
+
if (!url.startsWith(jsenvDirectoryServerUrl)) {
|
|
161
161
|
return { insideCompileDirectory: false }
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
const afterOutDirectory = url.slice(outDirectoryServerUrl.length)
|
|
165
|
-
|
|
163
|
+
const afterJsenvDirectory = url.slice(jsenvDirectoryServerUrl.length)
|
|
166
164
|
// serve files inside /.jsenv/* directly without compilation
|
|
167
165
|
// this is just to allow some files to be written inside outDirectory and read directly
|
|
168
|
-
|
|
169
|
-
if (!afterOutDirectory.includes("/") || afterOutDirectory[0] === "/") {
|
|
166
|
+
if (!afterJsenvDirectory.includes("/") || afterJsenvDirectory[0] === "/") {
|
|
170
167
|
return { insideCompileDirectory: true }
|
|
171
168
|
}
|
|
172
|
-
|
|
173
|
-
const parts = afterOutDirectory.split("/")
|
|
169
|
+
const parts = afterJsenvDirectory.split("/")
|
|
174
170
|
const compileId = parts[0]
|
|
175
171
|
// no compileId, we don't know what to compile (not supposed so happen)
|
|
176
172
|
if (compileId === "") {
|
|
177
173
|
return { insideCompileDirectory: true, compileId: null }
|
|
178
174
|
}
|
|
179
|
-
|
|
180
175
|
const afterCompileId = parts.slice(1).join("/")
|
|
181
176
|
// note: afterCompileId can be '' (but not supposed to happen)
|
|
182
177
|
return { insideCompileDirectory: true, compileId, afterCompileId }
|
|
@@ -260,7 +255,7 @@ const originalProjectUrlFromUrl = (
|
|
|
260
255
|
{
|
|
261
256
|
projectDirectoryUrl,
|
|
262
257
|
compileServerOrigin,
|
|
263
|
-
|
|
258
|
+
jsenvDirectoryRelativeUrl,
|
|
264
259
|
compileDirectoryRelativeUrl,
|
|
265
260
|
},
|
|
266
261
|
) => {
|
|
@@ -280,7 +275,7 @@ const originalProjectUrlFromUrl = (
|
|
|
280
275
|
compileDirectoryRelativeUrl = extractCompileDirectoryRelativeUrl({
|
|
281
276
|
serverUrl,
|
|
282
277
|
compileServerOrigin,
|
|
283
|
-
|
|
278
|
+
jsenvDirectoryRelativeUrl,
|
|
284
279
|
})
|
|
285
280
|
if (!compileDirectoryRelativeUrl) {
|
|
286
281
|
return projectUrl
|
|
@@ -305,14 +300,14 @@ const originalProjectUrlFromUrl = (
|
|
|
305
300
|
const extractCompileDirectoryRelativeUrl = ({
|
|
306
301
|
serverUrl,
|
|
307
302
|
compileServerOrigin,
|
|
308
|
-
|
|
303
|
+
jsenvDirectoryRelativeUrl,
|
|
309
304
|
}) => {
|
|
310
305
|
const compileInfo = serverUrlToCompileInfo(serverUrl, {
|
|
311
306
|
compileServerOrigin,
|
|
312
|
-
|
|
307
|
+
jsenvDirectoryRelativeUrl,
|
|
313
308
|
})
|
|
314
309
|
if (compileInfo.compiledId) {
|
|
315
|
-
return `${
|
|
310
|
+
return `${jsenvDirectoryRelativeUrl}${compileInfo.compileId}/`
|
|
316
311
|
}
|
|
317
312
|
return null
|
|
318
313
|
}
|