@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.
- 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_f4285042.js.map +343 -0
- package/dist/compile_proxy/{compile_proxy_8dfaee51.html → compile_proxy_ab528227.html} +358 -397
- package/dist/redirector/asset-manifest.json +2 -2
- package/dist/redirector/redirector.html__inline__12_404b8295.js.map +349 -0
- package/dist/redirector/{redirector_3e9a97b9.html → redirector_6df2620a.html} +369 -407
- package/dist/toolbar/asset-manifest.json +2 -2
- package/dist/toolbar/toolbar.main_279b3a68.js.map +764 -0
- package/dist/toolbar/{toolbar_361afb84.html → toolbar_0a91ca3b.html} +1509 -1583
- package/dist/toolbar_injector/asset-manifest.json +2 -2
- package/dist/toolbar_injector/{toolbar_injector_fac1e995.js → toolbar_injector_34f6ad8e.js} +18 -15
- package/dist/toolbar_injector/{toolbar_injector_fac1e995.js.map → toolbar_injector_34f6ad8e.js.map} +15 -15
- package/package.json +10 -10
- package/src/buildProject.js +31 -26
- package/src/dev_server.js +111 -92
- package/src/execute.js +3 -8
- package/src/importUsingChildProcess.js +1 -0
- 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/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} +53 -36
- 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/transformJs.js +151 -23
- package/src/internal/compiling/jsenvCompilerForHtml.js +38 -43
- 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 +1 -1
- 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 +157 -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 +92 -78
- package/src/internal/dev_server/toolbar/settings/toolbar.settings.js +13 -0
- package/src/internal/dev_server/toolbar/toolbar.html +46 -16
- package/src/internal/dev_server/toolbar/toolbar.injector.js +17 -15
- package/src/internal/dev_server/toolbar/toolbar.main.js +12 -16
- 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 +89 -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/import-resolution/importmap_default.js +2 -17
- package/src/internal/node_launcher/createControllableNodeProcess.js +4 -6
- 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/nodeControllableFile.mjs +1 -5
- package/src/internal/node_runtime/node_execution_systemjs.js +2 -5
- package/src/internal/redirector/redirector.html +40 -0
- 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/toolbar.main_6c1b3d82.js.map +0 -802
- 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 -242
- package/src/internal/dev_server/redirector/redirector.html +0 -48
- 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/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
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import { urlToRelativeUrl } from "@jsenv/filesystem"
|
|
1
|
+
import { urlToRelativeUrl, urlToFileSystemPath } from "@jsenv/filesystem"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { require } from "@jsenv/core/src/internal/require.js"
|
|
4
|
+
import { createParseError } from "@jsenv/core/src/internal/compiling/babel_parse_error.js"
|
|
5
|
+
import { babelPluginTransformImportMeta } from "@jsenv/core/src/internal/compiling/babel_plugin_transform_import_meta.js"
|
|
6
|
+
import {
|
|
7
|
+
getMinimalBabelPluginMap,
|
|
8
|
+
babelPluginsFromBabelPluginMap,
|
|
9
|
+
} from "@jsenv/core/src/internal/compiling/babel_plugins.js"
|
|
10
|
+
import { babelPluginProxyExternalImports } from "@jsenv/core/src/internal/compiling/babel_plugin_proxy_external_imports.js"
|
|
11
|
+
import { babelPluginImportMetadata } from "@jsenv/core/src/internal/compiling/babel_plugin_import_metadata.js"
|
|
12
|
+
|
|
13
|
+
import { ansiToHTML } from "./ansiToHTML.js"
|
|
14
|
+
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
15
|
+
import { babelPluginBabelHelpersAsJsenvImports } from "./babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
16
|
+
import { babelPluginSystemJsPrepend } from "./babel_plugin_systemjs_prepend.js"
|
|
17
|
+
import { babelHelperNameFromUrl } from "./babelHelper.js"
|
|
4
18
|
|
|
5
19
|
export const transformJs = async ({
|
|
6
20
|
projectDirectoryUrl,
|
|
@@ -17,6 +31,7 @@ export const transformJs = async ({
|
|
|
17
31
|
sourcemapEnabled = true,
|
|
18
32
|
|
|
19
33
|
map,
|
|
34
|
+
ast,
|
|
20
35
|
code,
|
|
21
36
|
}) => {
|
|
22
37
|
if (typeof projectDirectoryUrl !== "string") {
|
|
@@ -40,29 +55,142 @@ export const transformJs = async ({
|
|
|
40
55
|
`babelHelpersInjectionAsImport can be enabled only when "moduleOutFormat" is "esmodule"`,
|
|
41
56
|
)
|
|
42
57
|
}
|
|
58
|
+
const relativeUrl = url.startsWith(projectDirectoryUrl)
|
|
59
|
+
? urlToRelativeUrl(url, projectDirectoryUrl)
|
|
60
|
+
: undefined
|
|
43
61
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
const inputPath = computeInputPath(url)
|
|
63
|
+
// https://babeljs.io/docs/en/options
|
|
64
|
+
const options = {
|
|
65
|
+
filename: inputPath,
|
|
66
|
+
filenameRelative: relativeUrl,
|
|
67
|
+
inputSourceMap: map,
|
|
68
|
+
configFile: false,
|
|
69
|
+
babelrc: false, // trust only these options, do not read any babelrc config file
|
|
70
|
+
ast: true,
|
|
71
|
+
sourceMaps: sourcemapEnabled,
|
|
72
|
+
sourceFileName: inputPath,
|
|
73
|
+
// https://babeljs.io/docs/en/options#parseropts
|
|
74
|
+
parserOpts: {
|
|
75
|
+
allowAwaitOutsideFunction:
|
|
76
|
+
topLevelAwait === undefined ||
|
|
77
|
+
topLevelAwait === "return" ||
|
|
78
|
+
topLevelAwait === "simple" ||
|
|
79
|
+
topLevelAwait === "ignore",
|
|
80
|
+
},
|
|
81
|
+
generatorOpts: {
|
|
82
|
+
compact: false,
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
const babelHelperName = babelHelperNameFromUrl(url)
|
|
86
|
+
// to prevent typeof circular dependency
|
|
87
|
+
if (babelHelperName === "typeof") {
|
|
88
|
+
const babelPluginMapWithoutTransformTypeOf = { ...babelPluginMap }
|
|
89
|
+
delete babelPluginMapWithoutTransformTypeOf["transform-typeof-symbol"]
|
|
90
|
+
babelPluginMap = babelPluginMapWithoutTransformTypeOf
|
|
91
|
+
}
|
|
92
|
+
if (transformGenerator) {
|
|
93
|
+
babelPluginMap = {
|
|
94
|
+
...babelPluginMap,
|
|
95
|
+
"regenerator-runtime-as-jsenv-import": [
|
|
96
|
+
babelPluginRegeneratorRuntimeAsJsenvImport,
|
|
97
|
+
],
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
babelPluginMap = {
|
|
101
|
+
...getMinimalBabelPluginMap(),
|
|
102
|
+
"transform-import-meta": [
|
|
103
|
+
babelPluginTransformImportMeta,
|
|
104
|
+
{ importMetaFormat },
|
|
105
|
+
],
|
|
106
|
+
...babelPluginMap,
|
|
107
|
+
...(babelHelpersInjectionAsImport
|
|
108
|
+
? {
|
|
109
|
+
"babel-helpers-as-jsenv-imports": [
|
|
110
|
+
babelPluginBabelHelpersAsJsenvImports,
|
|
111
|
+
],
|
|
112
|
+
}
|
|
113
|
+
: {}),
|
|
114
|
+
...(jsenvRemoteDirectory
|
|
115
|
+
? {
|
|
116
|
+
"proxy-external-imports": [
|
|
117
|
+
babelPluginProxyExternalImports,
|
|
118
|
+
{ jsenvRemoteDirectory },
|
|
119
|
+
],
|
|
120
|
+
}
|
|
121
|
+
: {}),
|
|
122
|
+
"import-metadata": [babelPluginImportMetadata],
|
|
123
|
+
}
|
|
124
|
+
if (moduleOutFormat === "systemjs") {
|
|
125
|
+
const transformModulesSystemJs = require("@babel/plugin-transform-modules-systemjs")
|
|
126
|
+
const proposalDynamicImport = require("@babel/plugin-proposal-dynamic-import")
|
|
127
|
+
babelPluginMap = {
|
|
128
|
+
...babelPluginMap,
|
|
129
|
+
"proposal-dynamic-import": [proposalDynamicImport],
|
|
130
|
+
"transform-modules-systemjs": [transformModulesSystemJs],
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (prependSystemJs) {
|
|
134
|
+
babelPluginMap = {
|
|
135
|
+
...babelPluginMap,
|
|
136
|
+
"systemjs-prepend": [babelPluginSystemJsPrepend],
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const asyncToPromise = babelPluginMap["transform-async-to-promises"]
|
|
141
|
+
if (topLevelAwait && asyncToPromise) {
|
|
142
|
+
asyncToPromise.options.topLevelAwait = topLevelAwait
|
|
143
|
+
}
|
|
144
|
+
const babelTransformReturnValue = await babelTransform({
|
|
145
|
+
ast,
|
|
51
146
|
code,
|
|
52
|
-
|
|
147
|
+
options: {
|
|
148
|
+
...options,
|
|
149
|
+
plugins: babelPluginsFromBabelPluginMap(babelPluginMap),
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
code = babelTransformReturnValue.code
|
|
153
|
+
map = babelTransformReturnValue.map
|
|
154
|
+
ast = babelTransformReturnValue.ast
|
|
155
|
+
const { metadata } = babelTransformReturnValue
|
|
156
|
+
return { code, map, metadata, ast }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const computeInputPath = (url) => {
|
|
160
|
+
if (url.startsWith("file://")) {
|
|
161
|
+
return urlToFileSystemPath(url)
|
|
162
|
+
}
|
|
163
|
+
return url
|
|
164
|
+
}
|
|
53
165
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
importMetaFormat,
|
|
166
|
+
const babelTransform = async ({ ast, code, options }) => {
|
|
167
|
+
const { transformAsync, transformFromAstAsync } = await import("@babel/core")
|
|
57
168
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
169
|
+
try {
|
|
170
|
+
if (ast) {
|
|
171
|
+
const result = await transformFromAstAsync(ast, code, options)
|
|
172
|
+
return result
|
|
173
|
+
}
|
|
174
|
+
return await transformAsync(code, options)
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (error && error.code === "BABEL_PARSE_ERROR") {
|
|
177
|
+
const message = error.message
|
|
178
|
+
const messageWithoutAnsi = message.replace(ansiRegex, "")
|
|
179
|
+
throw createParseError({
|
|
180
|
+
cause: error,
|
|
181
|
+
message: messageWithoutAnsi,
|
|
182
|
+
messageHTML: ansiToHTML(message),
|
|
183
|
+
filename: options.filename,
|
|
184
|
+
lineNumber: error.loc.line,
|
|
185
|
+
columnNumber: error.loc.column,
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
throw error
|
|
189
|
+
}
|
|
68
190
|
}
|
|
191
|
+
|
|
192
|
+
const pattern = [
|
|
193
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
194
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))",
|
|
195
|
+
].join("|")
|
|
196
|
+
const ansiRegex = new RegExp(pattern, "g")
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
visitHtmlAst,
|
|
37
37
|
addHtmlNodeAttribute,
|
|
38
38
|
} from "./compileHtml.js"
|
|
39
|
-
import { generateCompilationAssetUrl } from "./
|
|
39
|
+
import { generateCompilationAssetUrl } from "./jsenv_directory/compile_asset.js"
|
|
40
40
|
|
|
41
41
|
export const compileHtml = async ({
|
|
42
42
|
// cancellationToken,
|
|
@@ -46,12 +46,11 @@ export const compileHtml = async ({
|
|
|
46
46
|
projectDirectoryUrl,
|
|
47
47
|
jsenvRemoteDirectory,
|
|
48
48
|
compileServerOrigin,
|
|
49
|
-
|
|
49
|
+
jsenvDirectoryRelativeUrl,
|
|
50
50
|
|
|
51
|
+
compileProfile,
|
|
51
52
|
compileId,
|
|
52
53
|
babelPluginMap,
|
|
53
|
-
moduleOutFormat,
|
|
54
|
-
importMetaFormat,
|
|
55
54
|
topLevelAwait,
|
|
56
55
|
jsenvScriptInjection = true,
|
|
57
56
|
jsenvEventSourceClientInjection,
|
|
@@ -61,7 +60,7 @@ export const compileHtml = async ({
|
|
|
61
60
|
sourcemapMethod,
|
|
62
61
|
code,
|
|
63
62
|
}) => {
|
|
64
|
-
const compileDirectoryUrl = `${projectDirectoryUrl}${
|
|
63
|
+
const compileDirectoryUrl = `${projectDirectoryUrl}${jsenvDirectoryRelativeUrl}${compileId}/`
|
|
65
64
|
const browserRuntimeBuildUrlRelativeToProject = urlToRelativeUrl(
|
|
66
65
|
BROWSER_RUNTIME_BUILD_URL,
|
|
67
66
|
projectDirectoryUrl,
|
|
@@ -133,21 +132,23 @@ export const compileHtml = async ({
|
|
|
133
132
|
specifier,
|
|
134
133
|
})
|
|
135
134
|
}
|
|
136
|
-
if (moduleOutFormat !== "esmodule") {
|
|
135
|
+
if (compileProfile.moduleOutFormat !== "esmodule") {
|
|
137
136
|
const ressourceHints = collectRessourceHints(htmlAst)
|
|
138
137
|
await visitRessourceHints({
|
|
139
138
|
ressourceHints,
|
|
140
139
|
addHtmlMutation,
|
|
141
140
|
})
|
|
142
141
|
}
|
|
143
|
-
await
|
|
144
|
-
htmlAst,
|
|
142
|
+
await visitImportmapScripts({
|
|
145
143
|
logger,
|
|
146
144
|
url,
|
|
147
145
|
compiledUrl,
|
|
148
146
|
projectDirectoryUrl,
|
|
149
147
|
compileDirectoryUrl,
|
|
150
|
-
|
|
148
|
+
|
|
149
|
+
compileProfile,
|
|
150
|
+
|
|
151
|
+
htmlAst,
|
|
151
152
|
scripts,
|
|
152
153
|
addHtmlMutation,
|
|
153
154
|
addHtmlSourceFile,
|
|
@@ -161,9 +162,8 @@ export const compileHtml = async ({
|
|
|
161
162
|
url,
|
|
162
163
|
compiledUrl,
|
|
163
164
|
|
|
165
|
+
compileProfile,
|
|
164
166
|
babelPluginMap,
|
|
165
|
-
moduleOutFormat,
|
|
166
|
-
importMetaFormat,
|
|
167
167
|
topLevelAwait,
|
|
168
168
|
sourcemapMethod,
|
|
169
169
|
|
|
@@ -245,14 +245,16 @@ const visitRessourceHints = async ({ ressourceHints, addHtmlMutation }) => {
|
|
|
245
245
|
)
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
const
|
|
249
|
-
htmlAst,
|
|
248
|
+
const visitImportmapScripts = async ({
|
|
250
249
|
logger,
|
|
251
250
|
url,
|
|
252
251
|
compiledUrl,
|
|
253
252
|
projectDirectoryUrl,
|
|
254
253
|
compileDirectoryUrl,
|
|
255
|
-
|
|
254
|
+
|
|
255
|
+
compileProfile,
|
|
256
|
+
|
|
257
|
+
htmlAst,
|
|
256
258
|
scripts,
|
|
257
259
|
addHtmlMutation,
|
|
258
260
|
addHtmlSourceFile,
|
|
@@ -263,14 +265,15 @@ const visitImportmapScript = async ({
|
|
|
263
265
|
const type = typeAttribute ? typeAttribute.value : "application/javascript"
|
|
264
266
|
return type === "importmap"
|
|
265
267
|
})
|
|
268
|
+
const jsenvImportmap = getDefaultImportmap(compiledUrl, {
|
|
269
|
+
projectDirectoryUrl,
|
|
270
|
+
compileDirectoryUrl,
|
|
271
|
+
})
|
|
272
|
+
|
|
266
273
|
// in case there is no importmap, force the presence
|
|
267
274
|
// so that '@jsenv/core/' are still remapped
|
|
268
275
|
if (importmapScripts.length === 0) {
|
|
269
|
-
const
|
|
270
|
-
projectDirectoryUrl,
|
|
271
|
-
compileDirectoryUrl,
|
|
272
|
-
})
|
|
273
|
-
const defaultImportMapAsText = JSON.stringify(defaultImportMap, null, " ")
|
|
276
|
+
const defaultImportMapAsText = JSON.stringify(jsenvImportmap, null, " ")
|
|
274
277
|
onHtmlImportmapInfo({
|
|
275
278
|
url: compiledUrl,
|
|
276
279
|
text: defaultImportMapAsText,
|
|
@@ -280,7 +283,7 @@ const visitImportmapScript = async ({
|
|
|
280
283
|
scriptInjections: [
|
|
281
284
|
{
|
|
282
285
|
type:
|
|
283
|
-
moduleOutFormat === "systemjs"
|
|
286
|
+
compileProfile.moduleOutFormat === "systemjs"
|
|
284
287
|
? "systemjs-importmap"
|
|
285
288
|
: "importmap",
|
|
286
289
|
text: defaultImportMapAsText,
|
|
@@ -322,6 +325,7 @@ const visitImportmapScript = async ({
|
|
|
322
325
|
)
|
|
323
326
|
importmap = {}
|
|
324
327
|
}
|
|
328
|
+
importmap = composeTwoImportMaps(jsenvImportmap, importmap)
|
|
325
329
|
const importmapAsText = JSON.stringify(importmap, null, " ")
|
|
326
330
|
onHtmlImportmapInfo({
|
|
327
331
|
url: importmapUrl,
|
|
@@ -330,7 +334,7 @@ const visitImportmapScript = async ({
|
|
|
330
334
|
addHtmlMutation(() => {
|
|
331
335
|
removeHtmlNodeAttribute(firstImportmapScript, srcAttribute)
|
|
332
336
|
setHtmlNodeText(firstImportmapScript, importmapAsText)
|
|
333
|
-
if (moduleOutFormat === "systemjs") {
|
|
337
|
+
if (compileProfile.moduleOutFormat === "systemjs") {
|
|
334
338
|
const typeAttribute = getHtmlNodeAttributeByName(
|
|
335
339
|
firstImportmapScript,
|
|
336
340
|
"type",
|
|
@@ -341,10 +345,6 @@ const visitImportmapScript = async ({
|
|
|
341
345
|
return
|
|
342
346
|
}
|
|
343
347
|
|
|
344
|
-
const jsenvImportmap = getDefaultImportmap(compiledUrl, {
|
|
345
|
-
projectDirectoryUrl,
|
|
346
|
-
compileDirectoryUrl,
|
|
347
|
-
})
|
|
348
348
|
const htmlImportmap = JSON.parse(
|
|
349
349
|
getHtmlNodeTextNode(firstImportmapScript).value,
|
|
350
350
|
)
|
|
@@ -357,7 +357,7 @@ const visitImportmapScript = async ({
|
|
|
357
357
|
addHtmlMutation(() => {
|
|
358
358
|
removeHtmlNodeAttribute(firstImportmapScript, srcAttribute)
|
|
359
359
|
setHtmlNodeText(firstImportmapScript, importmapAsText)
|
|
360
|
-
if (moduleOutFormat === "systemjs") {
|
|
360
|
+
if (compileProfile.moduleOutFormat === "systemjs") {
|
|
361
361
|
const typeAttribute = getHtmlNodeAttributeByName(
|
|
362
362
|
firstImportmapScript,
|
|
363
363
|
"type",
|
|
@@ -371,14 +371,13 @@ const visitImportmapScript = async ({
|
|
|
371
371
|
const visitScripts = async ({
|
|
372
372
|
logger,
|
|
373
373
|
projectDirectoryUrl,
|
|
374
|
-
compileServerOrigin,
|
|
375
374
|
jsenvRemoteDirectory,
|
|
375
|
+
compileServerOrigin,
|
|
376
376
|
url,
|
|
377
377
|
compiledUrl,
|
|
378
378
|
|
|
379
|
+
compileProfile,
|
|
379
380
|
babelPluginMap,
|
|
380
|
-
moduleOutFormat,
|
|
381
|
-
importMetaFormat,
|
|
382
381
|
topLevelAwait,
|
|
383
382
|
sourcemapMethod,
|
|
384
383
|
|
|
@@ -398,7 +397,7 @@ const visitScripts = async ({
|
|
|
398
397
|
if (type === "module") {
|
|
399
398
|
if (src) {
|
|
400
399
|
addHtmlMutation(() => {
|
|
401
|
-
if (moduleOutFormat === "systemjs") {
|
|
400
|
+
if (compileProfile.moduleOutFormat === "systemjs") {
|
|
402
401
|
removeHtmlNodeAttribute(script, typeAttribute)
|
|
403
402
|
}
|
|
404
403
|
if (integrityAttribute) {
|
|
@@ -406,7 +405,7 @@ const visitScripts = async ({
|
|
|
406
405
|
}
|
|
407
406
|
removeHtmlNodeAttribute(script, srcAttribute)
|
|
408
407
|
const jsenvMethod =
|
|
409
|
-
moduleOutFormat === "systemjs"
|
|
408
|
+
compileProfile.moduleOutFormat === "systemjs"
|
|
410
409
|
? "executeFileUsingSystemJs"
|
|
411
410
|
: "executeFileUsingDynamicImport"
|
|
412
411
|
let specifier
|
|
@@ -442,9 +441,8 @@ const visitScripts = async ({
|
|
|
442
441
|
compiledUrl: scriptCompiledUrl,
|
|
443
442
|
|
|
444
443
|
type: "module",
|
|
444
|
+
compileProfile,
|
|
445
445
|
babelPluginMap,
|
|
446
|
-
moduleOutFormat,
|
|
447
|
-
importMetaFormat,
|
|
448
446
|
topLevelAwait,
|
|
449
447
|
|
|
450
448
|
sourcemapMethod,
|
|
@@ -453,12 +451,12 @@ const visitScripts = async ({
|
|
|
453
451
|
})
|
|
454
452
|
const specifier = `./${urlToRelativeUrl(scriptCompiledUrl, compiledUrl)}`
|
|
455
453
|
addHtmlMutation(() => {
|
|
456
|
-
if (moduleOutFormat === "systemjs") {
|
|
454
|
+
if (compileProfile.moduleOutFormat === "systemjs") {
|
|
457
455
|
removeHtmlNodeAttribute(script, typeAttribute)
|
|
458
456
|
}
|
|
459
457
|
removeHtmlNodeAttribute(script, srcAttribute)
|
|
460
458
|
const jsenvMethod =
|
|
461
|
-
moduleOutFormat === "systemjs"
|
|
459
|
+
compileProfile.moduleOutFormat === "systemjs"
|
|
462
460
|
? "executeFileUsingSystemJs"
|
|
463
461
|
: "executeFileUsingDynamicImport"
|
|
464
462
|
setHtmlNodeText(
|
|
@@ -531,9 +529,8 @@ const visitScripts = async ({
|
|
|
531
529
|
compiledUrl: scriptCompiledUrl,
|
|
532
530
|
|
|
533
531
|
type: "classic",
|
|
532
|
+
compileProfile,
|
|
534
533
|
babelPluginMap,
|
|
535
|
-
moduleOutFormat,
|
|
536
|
-
importMetaFormat,
|
|
537
534
|
topLevelAwait,
|
|
538
535
|
|
|
539
536
|
sourcemapMethod,
|
|
@@ -566,9 +563,8 @@ const visitScripts = async ({
|
|
|
566
563
|
compiledUrl: scriptCompiledUrl,
|
|
567
564
|
|
|
568
565
|
type: "classic",
|
|
566
|
+
compileProfile,
|
|
569
567
|
babelPluginMap,
|
|
570
|
-
moduleOutFormat,
|
|
571
|
-
importMetaFormat,
|
|
572
568
|
topLevelAwait,
|
|
573
569
|
|
|
574
570
|
code: textNode.value,
|
|
@@ -591,9 +587,8 @@ const transformHtmlScript = async ({
|
|
|
591
587
|
compiledUrl,
|
|
592
588
|
|
|
593
589
|
type,
|
|
590
|
+
compileProfile,
|
|
594
591
|
babelPluginMap,
|
|
595
|
-
moduleOutFormat,
|
|
596
|
-
importMetaFormat,
|
|
597
592
|
topLevelAwait,
|
|
598
593
|
|
|
599
594
|
code,
|
|
@@ -608,8 +603,8 @@ const transformHtmlScript = async ({
|
|
|
608
603
|
compiledUrl,
|
|
609
604
|
|
|
610
605
|
babelPluginMap,
|
|
611
|
-
moduleOutFormat:
|
|
612
|
-
|
|
606
|
+
moduleOutFormat:
|
|
607
|
+
type === "module" ? compileProfile.moduleOutFormat : "global",
|
|
613
608
|
topLevelAwait: type === "module" ? topLevelAwait : false,
|
|
614
609
|
babelHelpersInjectionAsImport: type === "module" ? undefined : false,
|
|
615
610
|
|
|
@@ -7,12 +7,12 @@ export const compileImportmap = async ({
|
|
|
7
7
|
url,
|
|
8
8
|
compiledUrl,
|
|
9
9
|
projectDirectoryUrl,
|
|
10
|
-
|
|
10
|
+
jsenvDirectoryRelativeUrl,
|
|
11
11
|
compileId,
|
|
12
12
|
}) => {
|
|
13
13
|
const jsenvImportmap = getDefaultImportmap(compiledUrl, {
|
|
14
14
|
projectDirectoryUrl,
|
|
15
|
-
compileDirectoryUrl: `${projectDirectoryUrl}${
|
|
15
|
+
compileDirectoryUrl: `${projectDirectoryUrl}${jsenvDirectoryRelativeUrl}${compileId}/`,
|
|
16
16
|
})
|
|
17
17
|
const projectImportmap = JSON.parse(code)
|
|
18
18
|
const importmap = composeTwoImportMaps(jsenvImportmap, projectImportmap)
|
|
@@ -9,11 +9,10 @@ export const compileJavascript = async ({
|
|
|
9
9
|
url,
|
|
10
10
|
compiledUrl,
|
|
11
11
|
|
|
12
|
+
compileProfile,
|
|
12
13
|
babelPluginMap,
|
|
13
14
|
workerUrls,
|
|
14
15
|
serviceWorkerUrls,
|
|
15
|
-
moduleOutFormat,
|
|
16
|
-
importMetaFormat,
|
|
17
16
|
topLevelAwait,
|
|
18
17
|
prependSystemJs,
|
|
19
18
|
|
|
@@ -33,8 +32,7 @@ export const compileJavascript = async ({
|
|
|
33
32
|
compiledUrl,
|
|
34
33
|
|
|
35
34
|
babelPluginMap,
|
|
36
|
-
moduleOutFormat,
|
|
37
|
-
importMetaFormat,
|
|
35
|
+
moduleOutFormat: compileProfile.moduleOutFormat,
|
|
38
36
|
topLevelAwait,
|
|
39
37
|
prependSystemJs,
|
|
40
38
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const sameValueInTwoObjects = (object, secondObject) => {
|
|
2
|
+
const objectKeys = Object.keys(object)
|
|
3
|
+
const secondObjectKeys = Object.keys(secondObject)
|
|
4
|
+
if (!sameValuesInTwoArrays(objectKeys, secondObjectKeys)) {
|
|
5
|
+
return false
|
|
6
|
+
}
|
|
7
|
+
return objectKeys.every((key) => {
|
|
8
|
+
const objectKeyValue = object[key]
|
|
9
|
+
const secondObjectKeyValue = secondObject[key]
|
|
10
|
+
if (
|
|
11
|
+
typeof objectKeyValue === "object" &&
|
|
12
|
+
objectKeyValue !== null &&
|
|
13
|
+
typeof secondObjectKeyValue === "object" &&
|
|
14
|
+
secondObjectKeyValue !== null
|
|
15
|
+
) {
|
|
16
|
+
return sameValueInTwoObjects(objectKeyValue, secondObjectKeyValue)
|
|
17
|
+
}
|
|
18
|
+
return objectKeyValue === secondObjectKeyValue
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const sameValuesInTwoArrays = (array, secondArray) => {
|
|
23
|
+
return array.every((value) => secondArray.includes(value))
|
|
24
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { resolveUrl, readFile } from "@jsenv/filesystem"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TOOLBAR_INJECTOR_BUILD_URL,
|
|
5
|
+
EVENT_SOURCE_CLIENT_BUILD_URL,
|
|
6
|
+
BROWSER_RUNTIME_BUILD_URL,
|
|
7
|
+
} from "@jsenv/core/dist/build_manifest.js"
|
|
8
|
+
import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js"
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
sameValuesInTwoArrays,
|
|
12
|
+
sameValueInTwoObjects,
|
|
13
|
+
} from "./comparison_utils.js"
|
|
14
|
+
|
|
15
|
+
const COMPARERS = {
|
|
16
|
+
preservedUrls: sameValueInTwoObjects,
|
|
17
|
+
workers: sameValuesInTwoArrays,
|
|
18
|
+
serviceWorkers: sameValuesInTwoArrays,
|
|
19
|
+
replaceProcessEnvNodeEnv: (a, b) => a === b,
|
|
20
|
+
inlineImportMapIntoHTML: (a, b) => a === b,
|
|
21
|
+
|
|
22
|
+
jsenvCorePackageVersion: (a, b) => a === b,
|
|
23
|
+
TOOLBAR_INJECTOR_BUILD_URL: (a, b) => a === b,
|
|
24
|
+
EVENT_SOURCE_CLIENT_BUILD_URL: (a, b) => a === b,
|
|
25
|
+
BROWSER_RUNTIME_BUILD_URL: (a, b) => a === b,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const compareCompileContexts = (
|
|
29
|
+
compileContext,
|
|
30
|
+
secondCompileContext,
|
|
31
|
+
) => {
|
|
32
|
+
return Object.keys(COMPARERS).every((key) => {
|
|
33
|
+
return COMPARERS[key](compileContext[key], secondCompileContext[key])
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const createCompileContext = async ({
|
|
38
|
+
preservedUrls,
|
|
39
|
+
workers,
|
|
40
|
+
serviceWorkers,
|
|
41
|
+
replaceProcessEnvNodeEnv,
|
|
42
|
+
inlineImportMapIntoHTML,
|
|
43
|
+
}) => {
|
|
44
|
+
return {
|
|
45
|
+
preservedUrls,
|
|
46
|
+
workers,
|
|
47
|
+
serviceWorkers,
|
|
48
|
+
replaceProcessEnvNodeEnv,
|
|
49
|
+
inlineImportMapIntoHTML,
|
|
50
|
+
|
|
51
|
+
// when "jsenvCorePackageVersion" is different, it means compile logic may have changed
|
|
52
|
+
jsenvCorePackageVersion: await readJsenvCoreVersionFromPackageFile(),
|
|
53
|
+
TOOLBAR_INJECTOR_BUILD_URL,
|
|
54
|
+
EVENT_SOURCE_CLIENT_BUILD_URL,
|
|
55
|
+
BROWSER_RUNTIME_BUILD_URL,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const readJsenvCoreVersionFromPackageFile = async () => {
|
|
60
|
+
const jsenvCorePackageFileUrl = resolveUrl(
|
|
61
|
+
"./package.json",
|
|
62
|
+
jsenvCoreDirectoryUrl,
|
|
63
|
+
)
|
|
64
|
+
const jsenvCoreVersion = await readFile(jsenvCorePackageFileUrl, {
|
|
65
|
+
as: "json",
|
|
66
|
+
}).version
|
|
67
|
+
return jsenvCoreVersion
|
|
68
|
+
}
|