@jsenv/core 24.6.3 → 25.0.0-alpha.1
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 -1
- package/dist/browser_runtime/{browser_runtime-c7288751.js → browser_runtime_91c5a3b8.js} +213 -109
- package/dist/browser_runtime/browser_runtime_91c5a3b8.js.map +1089 -0
- package/dist/build_manifest.js +6 -6
- package/dist/compile_proxy/asset-manifest.json +2 -1
- package/dist/compile_proxy/{compile_proxy-28148b58.html → compile_proxy_7ad5faa6.html} +133 -40
- package/dist/compile_proxy/{compile_proxy.html__inline__20-4887fb1d.js.map → compile_proxy_e3b0c442_809f35f7.js.map} +7 -7
- package/dist/event_source_client/asset-manifest.json +2 -1
- package/dist/event_source_client/{event_source_client-9f14c8b9.js → event_source_client_620fbc2c.js} +6 -12
- package/dist/event_source_client/{event_source_client-9f14c8b9.js.map → event_source_client_620fbc2c.js.map} +2 -2
- package/dist/redirector/asset-manifest.json +2 -1
- package/dist/redirector/{redirector.html__inline__15-19e529b9.js.map → redirector_e3b0c442_e391410e.js.map} +7 -7
- package/dist/redirector/{redirector-3c05dbb2.html → redirector_eb92e8a7.html} +133 -40
- package/dist/toolbar/asset-manifest.json +11 -10
- package/dist/toolbar/assets/{compilation.css-209d68b4.map → compilation.css_e37c747b.map} +1 -1
- package/dist/toolbar/assets/{eventsource.css-38cd0a36.map → eventsource.css_c0c71e7b.map} +1 -1
- package/dist/toolbar/assets/{execution.css-0ebe522f.map → execution.css_f3377c10.map} +1 -1
- package/dist/toolbar/assets/{focus.css-3f9c156d.map → focus.css_896f3e45.map} +1 -1
- package/dist/toolbar/assets/{light-theme.css-78b19a80.map → light-theme.css_72a60fa3.map} +1 -1
- package/dist/toolbar/assets/{overflow-menu.css-d9688a1c.map → overflow-menu.css_2859d519.map} +1 -1
- package/dist/toolbar/assets/{settings.css-2b81b245.map → settings.css_61548139.map} +1 -1
- package/dist/toolbar/assets/{toolbar.main.css-846920e9.map → toolbar.main.css_269d7ce2.map} +9 -9
- package/dist/toolbar/assets/{tooltip.css-03395ee6.map → tooltip.css_a94a8bdd.map} +1 -1
- package/dist/toolbar/{toolbar.main-eb8acf83.js.map → toolbar.main2_6c1b3d82.js.map} +9 -9
- package/dist/toolbar/{toolbar-bab473ea.html → toolbar_04ba410c.html} +155 -62
- package/dist/toolbar_injector/asset-manifest.json +3 -2
- package/dist/toolbar_injector/assets/{jsenv-logo-188b9ca6.svg → jsenv-logo_188b9ca6.svg} +0 -0
- package/dist/toolbar_injector/{toolbar_injector-5e32f96a.js → toolbar_injector_4a48bc53.js} +25 -26
- package/dist/toolbar_injector/{toolbar_injector-5e32f96a.js.map → toolbar_injector_4a48bc53.js.map} +4 -5
- package/package.json +6 -5
- package/readme.md +34 -111
- package/src/buildProject.js +45 -32
- package/src/dev_server.js +13 -3
- package/src/execute.js +7 -1
- package/src/executeTestPlan.js +6 -0
- package/src/internal/browser_feature_detection/browser_feature_detection.js +18 -25
- package/src/internal/browser_runtime/browser_runtime.js +2 -2
- package/src/internal/browser_runtime/createBrowserRuntime.js +1 -1
- package/src/internal/browser_runtime/displayErrorInDocument.js +2 -0
- package/src/internal/browser_runtime/displayErrorNotification.js +1 -1
- package/src/internal/building/buildUsingRollup.js +12 -17
- package/src/internal/building/build_logs.js +2 -2
- package/src/internal/building/build_stats.js +11 -1
- package/src/internal/building/html/parseHtmlRessource.js +2 -26
- package/src/internal/building/js/parseJsRessource.js +3 -2
- package/src/internal/building/json_module.js +11 -0
- package/src/internal/building/parseRessource.js +1 -1
- package/src/internal/building/ressource_builder.js +210 -216
- package/src/internal/building/rollup_plugin_jsenv.js +536 -371
- package/src/internal/building/url_loader.js +8 -142
- package/src/internal/building/url_versioning.js +220 -0
- package/src/internal/compiling/compileHtml.js +8 -1
- package/src/internal/compiling/createCompiledFileService.js +32 -44
- package/src/internal/compiling/html_source_file_service.js +66 -51
- package/src/internal/compiling/js-compilation-service/babel_plugin_systemjs_prepend.js +23 -0
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +21 -63
- package/src/internal/compiling/js-compilation-service/transformJs.js +4 -4
- package/src/internal/compiling/jsenvCompilerForHtml.js +47 -48
- package/src/internal/compiling/jsenvCompilerForImportmap.js +15 -76
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +11 -2
- package/src/internal/compiling/startCompileServer.js +31 -7
- package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +9 -9
- package/src/internal/executing/executePlan.js +6 -0
- package/src/internal/generateGroupMap/{jsenvBabelPluginCompatMap.js → babel_plugins_compatibility.js} +0 -0
- package/src/internal/generateGroupMap/{featuresCompatMap.js → features_compatibility.js} +9 -1
- package/src/internal/generateGroupMap/generateGroupMap.js +6 -35
- package/src/internal/generateGroupMap/one_runtime_compat.js +9 -12
- package/src/internal/generateGroupMap/runtime_compat.js +10 -15
- package/src/internal/generateGroupMap/runtime_compat_composition.js +2 -2
- package/src/internal/generateGroupMap/shake_babel_plugin_map.js +21 -0
- package/src/internal/import-resolution/importmap_default.js +52 -0
- package/src/internal/node_feature_detection/node_feature_detection.js +25 -19
- package/src/internal/runtime/s.js +101 -6
- package/src/internal/unevalException.js +1 -1
- package/src/jsenvServiceWorkerFinalizer.js +10 -9
- package/dist/browser_runtime/browser_runtime-c7288751.js.map +0 -1069
- package/src/internal/building/asset_url_versioning.js +0 -50
- package/src/internal/building/rollup_build_sourcemap.js +0 -54
- package/src/internal/building/url-versioning.js +0 -96
- package/src/internal/compiling/js-compilation-service/findAsyncPluginNameInBabelPluginMap.js +0 -9
- package/src/internal/generateGroupMap/jsenvPluginCompatMap.js +0 -1
- package/src/internal/import-resolution/importmap-default.js +0 -34
- package/src/internal/renderNamePattern.js +0 -6
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
urlToFilename,
|
|
19
19
|
urlIsInsideOf,
|
|
20
20
|
} from "@jsenv/filesystem"
|
|
21
|
-
import { moveImportMap } from "@jsenv/importmap"
|
|
21
|
+
import { composeTwoImportMaps, moveImportMap } from "@jsenv/importmap"
|
|
22
22
|
import { createDetailedMessage } from "@jsenv/logger"
|
|
23
23
|
|
|
24
24
|
import {
|
|
@@ -28,6 +28,8 @@ import {
|
|
|
28
28
|
} from "@jsenv/core/dist/build_manifest.js"
|
|
29
29
|
import { fetchUrl } from "@jsenv/core/src/internal/fetchUrl.js"
|
|
30
30
|
import { stringifyDataUrl } from "@jsenv/core/src/internal/dataUrl.utils.js"
|
|
31
|
+
import { getDefaultImportmap } from "@jsenv/core/src/internal/import-resolution/importmap_default.js"
|
|
32
|
+
|
|
31
33
|
import {
|
|
32
34
|
parseHtmlString,
|
|
33
35
|
parseHtmlAstRessources,
|
|
@@ -155,14 +157,13 @@ const transformHTMLSourceFile = async ({
|
|
|
155
157
|
fileUrl = urlWithoutSearch(fileUrl)
|
|
156
158
|
|
|
157
159
|
const htmlAst = parseHtmlString(fileContent)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
160
|
+
await visitImportmapScripts({
|
|
161
|
+
logger,
|
|
162
|
+
htmlAst,
|
|
163
|
+
inlineImportMapIntoHTML,
|
|
164
|
+
htmlFileUrl: fileUrl,
|
|
165
|
+
projectDirectoryUrl,
|
|
166
|
+
})
|
|
166
167
|
|
|
167
168
|
const browserRuntimeBuildUrlRelativeToProject = urlToRelativeUrl(
|
|
168
169
|
BROWSER_RUNTIME_BUILD_URL,
|
|
@@ -277,59 +278,73 @@ const transformHTMLSourceFile = async ({
|
|
|
277
278
|
return stringifyHtmlAst(htmlAst)
|
|
278
279
|
}
|
|
279
280
|
|
|
280
|
-
const
|
|
281
|
+
const visitImportmapScripts = async ({
|
|
282
|
+
logger,
|
|
283
|
+
inlineImportMapIntoHTML,
|
|
284
|
+
htmlAst,
|
|
285
|
+
htmlFileUrl,
|
|
286
|
+
projectDirectoryUrl,
|
|
287
|
+
}) => {
|
|
281
288
|
const { scripts } = parseHtmlAstRessources(htmlAst)
|
|
282
|
-
const
|
|
289
|
+
const importmapScripts = scripts.filter((script) => {
|
|
283
290
|
const typeAttribute = getHtmlNodeAttributeByName(script, "type")
|
|
284
|
-
|
|
285
|
-
if (typeAttribute && typeAttribute.value === "importmap" && srcAttribute) {
|
|
291
|
+
if (typeAttribute && typeAttribute.value === "importmap") {
|
|
286
292
|
return true
|
|
287
293
|
}
|
|
288
294
|
return false
|
|
289
295
|
})
|
|
290
296
|
|
|
291
297
|
await Promise.all(
|
|
292
|
-
|
|
293
|
-
const srcAttribute = getHtmlNodeAttributeByName(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
298
|
+
importmapScripts.map(async (importmapScript) => {
|
|
299
|
+
const srcAttribute = getHtmlNodeAttributeByName(importmapScript, "src")
|
|
300
|
+
if (srcAttribute && inlineImportMapIntoHTML) {
|
|
301
|
+
const importMapUrl = resolveUrl(srcAttribute.value, htmlFileUrl)
|
|
302
|
+
const importMapResponse = await fetchUrl(importMapUrl)
|
|
303
|
+
if (importMapResponse.status !== 200) {
|
|
304
|
+
logger.warn(
|
|
305
|
+
createDetailedMessage(
|
|
306
|
+
importMapResponse.status === 404
|
|
307
|
+
? `Cannot inline importmap script because file cannot be found.`
|
|
308
|
+
: `Cannot inline importmap script due to unexpected response status (${importMapResponse.status}).`,
|
|
309
|
+
{
|
|
310
|
+
"importmap script src": srcAttribute.value,
|
|
311
|
+
"importmap url": importMapUrl,
|
|
312
|
+
"html url": htmlFileUrl,
|
|
313
|
+
},
|
|
314
|
+
),
|
|
315
|
+
)
|
|
316
|
+
return
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const importMapContent = await importMapResponse.json()
|
|
320
|
+
const importMapInlined = moveImportMap(
|
|
321
|
+
importMapContent,
|
|
322
|
+
importMapUrl,
|
|
323
|
+
htmlFileUrl,
|
|
311
324
|
)
|
|
312
|
-
return
|
|
313
|
-
}
|
|
314
325
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
326
|
+
replaceHtmlNode(
|
|
327
|
+
importmapScript,
|
|
328
|
+
`<script type="importmap">${JSON.stringify(
|
|
329
|
+
importMapInlined,
|
|
330
|
+
null,
|
|
331
|
+
" ",
|
|
332
|
+
)}</script>`,
|
|
333
|
+
{
|
|
334
|
+
attributesToIgnore: ["src"],
|
|
335
|
+
},
|
|
336
|
+
)
|
|
337
|
+
}
|
|
321
338
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
)
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
},
|
|
332
|
-
)
|
|
339
|
+
const textNode = getHtmlNodeTextNode(importmapScript)
|
|
340
|
+
if (!srcAttribute && textNode) {
|
|
341
|
+
const jsenvImportmap = getDefaultImportmap(htmlFileUrl, {
|
|
342
|
+
projectDirectoryUrl,
|
|
343
|
+
})
|
|
344
|
+
const htmlImportmap = JSON.parse(textNode.value)
|
|
345
|
+
const importmap = composeTwoImportMaps(jsenvImportmap, htmlImportmap)
|
|
346
|
+
textNode.value = JSON.stringify(importmap, null, " ")
|
|
347
|
+
}
|
|
333
348
|
}),
|
|
334
349
|
)
|
|
335
350
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs"
|
|
2
|
+
|
|
3
|
+
import { jsenvCoreDirectoryUrl } from "@jsenv/core/src/internal/jsenvCoreDirectoryUrl.js"
|
|
4
|
+
|
|
5
|
+
export const babelPluginSystemJsPrepend = (api) => {
|
|
6
|
+
api.assertVersion(7)
|
|
7
|
+
const systemJsUrl = new URL(
|
|
8
|
+
"src/internal/runtime/s.js",
|
|
9
|
+
jsenvCoreDirectoryUrl,
|
|
10
|
+
)
|
|
11
|
+
return {
|
|
12
|
+
name: "systemjs-prepend",
|
|
13
|
+
visitor: {
|
|
14
|
+
Program: {
|
|
15
|
+
exit(path) {
|
|
16
|
+
const code = String(readFileSync(systemJsUrl))
|
|
17
|
+
const ast = api.template.ast`${code}`
|
|
18
|
+
path.node.body.unshift(ast)
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -5,14 +5,13 @@ import { babelPluginTransformImportMeta } from "@jsenv/core/src/internal/babel_p
|
|
|
5
5
|
import {
|
|
6
6
|
getMinimalBabelPluginMap,
|
|
7
7
|
babelPluginsFromBabelPluginMap,
|
|
8
|
-
extractSyntaxBabelPluginMap,
|
|
9
8
|
} from "@jsenv/core/src/internal/compiling/babel_plugins.js"
|
|
10
9
|
import { babelPluginImportMetadata } from "@jsenv/core/src/internal/compiling/babel_plugin_import_metadata.js"
|
|
11
10
|
|
|
12
|
-
import { findAsyncPluginNameInBabelPluginMap } from "./findAsyncPluginNameInBabelPluginMap.js"
|
|
13
11
|
import { ansiToHTML } from "./ansiToHTML.js"
|
|
14
12
|
import { babelPluginRegeneratorRuntimeAsJsenvImport } from "./babel_plugin_regenerator_runtime_as_jsenv_import.js"
|
|
15
13
|
import { babelPluginBabelHelpersAsJsenvImports } from "./babel_plugin_babel_helpers_as_jsenv_imports.js"
|
|
14
|
+
import { babelPluginSystemJsPrepend } from "./babel_plugin_systemjs_prepend.js"
|
|
16
15
|
import { filePathToBabelHelperName } from "./babelHelper.js"
|
|
17
16
|
|
|
18
17
|
export const jsenvTransform = async ({
|
|
@@ -25,10 +24,10 @@ export const jsenvTransform = async ({
|
|
|
25
24
|
babelPluginMap,
|
|
26
25
|
moduleOutFormat,
|
|
27
26
|
importMetaFormat = moduleOutFormat,
|
|
27
|
+
topLevelAwait,
|
|
28
28
|
|
|
29
29
|
babelHelpersInjectionAsImport,
|
|
30
|
-
|
|
31
|
-
transformTopLevelAwait,
|
|
30
|
+
prependSystemJs,
|
|
32
31
|
transformGenerator,
|
|
33
32
|
regeneratorRuntimeImportPath,
|
|
34
33
|
sourcemapEnabled,
|
|
@@ -50,7 +49,11 @@ export const jsenvTransform = async ({
|
|
|
50
49
|
sourceFileName: inputPath,
|
|
51
50
|
// https://babeljs.io/docs/en/options#parseropts
|
|
52
51
|
parserOpts: {
|
|
53
|
-
allowAwaitOutsideFunction:
|
|
52
|
+
allowAwaitOutsideFunction:
|
|
53
|
+
topLevelAwait === undefined ||
|
|
54
|
+
topLevelAwait === "return" ||
|
|
55
|
+
topLevelAwait === "simple" ||
|
|
56
|
+
topLevelAwait === "ignore",
|
|
54
57
|
},
|
|
55
58
|
generatorOpts: {
|
|
56
59
|
compact: false,
|
|
@@ -76,7 +79,6 @@ export const jsenvTransform = async ({
|
|
|
76
79
|
],
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
|
-
|
|
80
82
|
babelPluginMap = {
|
|
81
83
|
...getMinimalBabelPluginMap(),
|
|
82
84
|
"transform-import-meta": [
|
|
@@ -146,75 +148,31 @@ export const jsenvTransform = async ({
|
|
|
146
148
|
: {}),
|
|
147
149
|
"import-metadata": [babelPluginImportMetadata],
|
|
148
150
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (
|
|
153
|
-
moduleOutFormat === "systemjs" &&
|
|
154
|
-
transformTopLevelAwait &&
|
|
155
|
-
asyncPluginName
|
|
156
|
-
) {
|
|
157
|
-
const babelPluginMapWithoutAsync = {
|
|
151
|
+
if (moduleOutFormat === "systemjs") {
|
|
152
|
+
babelPluginMap = {
|
|
158
153
|
...babelPluginMap,
|
|
159
154
|
"proposal-dynamic-import": [proposalDynamicImport],
|
|
160
155
|
"transform-modules-systemjs": [transformModulesSystemJs],
|
|
161
156
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
code,
|
|
168
|
-
options: {
|
|
169
|
-
...options,
|
|
170
|
-
plugins: babelPluginsFromBabelPluginMap(babelPluginMapWithoutAsync),
|
|
171
|
-
},
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
// we need to retranspile the await keywords now wrapped
|
|
175
|
-
// inside Systemjs function.
|
|
176
|
-
// They are ignored, at least by transform-async-to-promises
|
|
177
|
-
// see https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/26
|
|
178
|
-
const { babelSyntaxPluginMap } = extractSyntaxBabelPluginMap(babelPluginMap)
|
|
179
|
-
const finalResult = await babelTransform({
|
|
180
|
-
// ast: result.ast,
|
|
181
|
-
code: result.code,
|
|
182
|
-
options: {
|
|
183
|
-
...options,
|
|
184
|
-
// about inputSourceMap see
|
|
185
|
-
// https://github.com/babel/babel/blob/eac4c5bc17133c2857f2c94c1a6a8643e3b547a7/packages/babel-core/src/transformation/file/generate.js#L57
|
|
186
|
-
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-core/src/transformation/file/merge-map.js#L6s
|
|
187
|
-
inputSourceMap: result.map,
|
|
188
|
-
plugins: babelPluginsFromBabelPluginMap({
|
|
189
|
-
...babelSyntaxPluginMap,
|
|
190
|
-
[asyncPluginName]: babelPluginMap[asyncPluginName],
|
|
191
|
-
}),
|
|
192
|
-
},
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
...result,
|
|
197
|
-
...finalResult,
|
|
198
|
-
metadata: { ...result.metadata, ...finalResult.metadata },
|
|
157
|
+
}
|
|
158
|
+
if (prependSystemJs) {
|
|
159
|
+
babelPluginMap = {
|
|
160
|
+
...babelPluginMap,
|
|
161
|
+
"systemjs-prepend": [babelPluginSystemJsPrepend],
|
|
199
162
|
}
|
|
200
163
|
}
|
|
201
164
|
|
|
165
|
+
const asyncToPromise = babelPluginMap["transform-async-to-promises"]
|
|
166
|
+
if (topLevelAwait && asyncToPromise) {
|
|
167
|
+
asyncToPromise.options.topLevelAwait = topLevelAwait
|
|
168
|
+
}
|
|
169
|
+
|
|
202
170
|
const babelTransformReturnValue = await babelTransform({
|
|
203
171
|
ast,
|
|
204
172
|
code,
|
|
205
173
|
options: {
|
|
206
174
|
...options,
|
|
207
|
-
plugins: babelPluginsFromBabelPluginMap(
|
|
208
|
-
...babelPluginMap,
|
|
209
|
-
...(moduleOutFormat === "systemjs"
|
|
210
|
-
? {
|
|
211
|
-
"proposal-dynamic-import": [proposalDynamicImport],
|
|
212
|
-
...(moduleOutFormat === "systemjs"
|
|
213
|
-
? { "transform-modules-systemjs": [transformModulesSystemJs] }
|
|
214
|
-
: {}),
|
|
215
|
-
}
|
|
216
|
-
: {}),
|
|
217
|
-
}),
|
|
175
|
+
plugins: babelPluginsFromBabelPluginMap(babelPluginMap),
|
|
218
176
|
},
|
|
219
177
|
})
|
|
220
178
|
code = babelTransformReturnValue.code
|
|
@@ -12,8 +12,8 @@ export const transformJs = async ({
|
|
|
12
12
|
moduleOutFormat = "esmodule",
|
|
13
13
|
importMetaFormat = moduleOutFormat,
|
|
14
14
|
babelHelpersInjectionAsImport = moduleOutFormat === "esmodule",
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
prependSystemJs,
|
|
16
|
+
topLevelAwait,
|
|
17
17
|
transformGenerator = true,
|
|
18
18
|
sourcemapEnabled = true,
|
|
19
19
|
}) => {
|
|
@@ -52,8 +52,8 @@ export const transformJs = async ({
|
|
|
52
52
|
importMetaFormat,
|
|
53
53
|
|
|
54
54
|
babelHelpersInjectionAsImport,
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
prependSystemJs,
|
|
56
|
+
topLevelAwait,
|
|
57
57
|
transformGenerator,
|
|
58
58
|
sourcemapEnabled,
|
|
59
59
|
})
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
TOOLBAR_INJECTOR_BUILD_URL,
|
|
9
9
|
} from "@jsenv/core/dist/build_manifest.js"
|
|
10
10
|
import { fetchUrl } from "@jsenv/core/src/internal/fetchUrl.js"
|
|
11
|
-
import {
|
|
11
|
+
import { getDefaultImportmap } from "@jsenv/core/src/internal/import-resolution/importmap_default.js"
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
14
|
setJavaScriptSourceMappingUrl,
|
|
@@ -42,10 +42,10 @@ export const compileHtml = async ({
|
|
|
42
42
|
outDirectoryRelativeUrl,
|
|
43
43
|
compileId,
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
babelPluginMap,
|
|
46
46
|
moduleOutFormat,
|
|
47
47
|
importMetaFormat,
|
|
48
|
-
|
|
48
|
+
topLevelAwait,
|
|
49
49
|
|
|
50
50
|
sourcemapMethod,
|
|
51
51
|
|
|
@@ -120,83 +120,82 @@ export const compileHtml = async ({
|
|
|
120
120
|
importmapInfo = {
|
|
121
121
|
script,
|
|
122
122
|
url: resolveUrl(src, url),
|
|
123
|
-
|
|
123
|
+
load: async () => {
|
|
124
124
|
const importMapResponse = await fetchUrl(importmapInfo.url)
|
|
125
|
-
if (importMapResponse.status
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
"importmap url": importmapInfo.url,
|
|
133
|
-
"html url": url,
|
|
134
|
-
},
|
|
135
|
-
),
|
|
125
|
+
if (importMapResponse.status === 200) {
|
|
126
|
+
const importmapAsText = await importMapResponse.text()
|
|
127
|
+
let htmlImportmap = JSON.parse(importmapAsText)
|
|
128
|
+
htmlImportmap = moveImportMap(
|
|
129
|
+
htmlImportmap,
|
|
130
|
+
importmapInfo.url,
|
|
131
|
+
url,
|
|
136
132
|
)
|
|
137
|
-
|
|
133
|
+
sources.push(importmapInfo.url)
|
|
134
|
+
sourcesContent.push(importmapAsText)
|
|
135
|
+
return htmlImportmap
|
|
138
136
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
logger.warn(
|
|
138
|
+
createDetailedMessage(
|
|
139
|
+
importMapResponse.status === 404
|
|
140
|
+
? `importmap script file cannot be found.`
|
|
141
|
+
: `importmap script file unexpected response status (${importMapResponse.status}).`,
|
|
142
|
+
{
|
|
143
|
+
"importmap url": importmapInfo.url,
|
|
144
|
+
"html url": url,
|
|
145
|
+
},
|
|
146
|
+
),
|
|
147
147
|
)
|
|
148
|
-
|
|
149
|
-
importMapMoved,
|
|
150
|
-
null,
|
|
151
|
-
" ",
|
|
152
|
-
)
|
|
153
|
-
return compiledImportmapAsText
|
|
148
|
+
return {}
|
|
154
149
|
},
|
|
155
150
|
}
|
|
156
151
|
} else {
|
|
157
152
|
importmapInfo = {
|
|
158
153
|
script,
|
|
159
154
|
url: compiledUrl,
|
|
160
|
-
|
|
155
|
+
load: () => {
|
|
156
|
+
const jsenvImportmap = getDefaultImportmap(compiledUrl, {
|
|
157
|
+
projectDirectoryUrl,
|
|
158
|
+
compileDirectoryUrl: `${projectDirectoryUrl}${compileId}/${outDirectoryRelativeUrl}`,
|
|
159
|
+
})
|
|
160
|
+
const htmlImportmap = JSON.parse(
|
|
161
|
+
getHtmlNodeTextNode(script).value,
|
|
162
|
+
)
|
|
163
|
+
const importmap = composeTwoImportMaps(
|
|
164
|
+
jsenvImportmap,
|
|
165
|
+
htmlImportmap,
|
|
166
|
+
)
|
|
167
|
+
return importmap
|
|
168
|
+
},
|
|
161
169
|
}
|
|
162
170
|
}
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
173
|
})
|
|
166
174
|
if (importmapInfo) {
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
importMapFileUrl: compiledUrl,
|
|
170
|
-
projectDirectoryUrl,
|
|
171
|
-
compileDirectoryRelativeUrl: `${outDirectoryRelativeUrl}${compileId}/`,
|
|
172
|
-
})
|
|
173
|
-
const mappings = composeTwoImportMaps(importMapFromJsenv, htmlImportMap)
|
|
174
|
-
const importmapAsText = JSON.stringify(mappings, null, " ")
|
|
175
|
+
const importmap = await importmapInfo.load()
|
|
176
|
+
const importmapAsText = JSON.stringify(importmap, null, " ")
|
|
175
177
|
replaceHtmlNode(
|
|
176
178
|
importmapInfo.script,
|
|
177
179
|
`<script type="${
|
|
178
|
-
moduleOutFormat === "systemjs" ? "
|
|
180
|
+
moduleOutFormat === "systemjs" ? "systemjs-importmap" : "importmap"
|
|
179
181
|
}">${importmapAsText}</script>`,
|
|
180
182
|
{
|
|
181
183
|
attributesToIgnore: ["src"],
|
|
182
184
|
},
|
|
183
185
|
)
|
|
184
186
|
importmapInfo.inlinedFrom = importmapInfo.url
|
|
185
|
-
importmapInfo.url = compiledUrl
|
|
186
187
|
importmapInfo.text = importmapAsText
|
|
187
188
|
} else {
|
|
188
|
-
|
|
189
|
-
const defaultImportMap = getDefaultImportMap({
|
|
190
|
-
importMapFileUrl: compiledUrl,
|
|
189
|
+
const defaultImportMap = getDefaultImportmap(compiledUrl, {
|
|
191
190
|
projectDirectoryUrl,
|
|
192
|
-
|
|
191
|
+
compileDirectoryUrl: `${projectDirectoryUrl}${outDirectoryRelativeUrl}${compileId}/`,
|
|
193
192
|
})
|
|
194
193
|
const importmapAsText = JSON.stringify(defaultImportMap, null, " ")
|
|
195
194
|
manipulateHtmlAst(htmlAst, {
|
|
196
195
|
scriptInjections: [
|
|
197
196
|
{
|
|
198
197
|
type:
|
|
199
|
-
moduleOutFormat === "systemjs" ? "
|
|
198
|
+
moduleOutFormat === "systemjs" ? "systemjs-importmap" : "importmap",
|
|
200
199
|
// in case there is no importmap, force the presence
|
|
201
200
|
// so that '@jsenv/core/' are still remapped
|
|
202
201
|
text: importmapAsText,
|
|
@@ -284,10 +283,10 @@ export const compileHtml = async ({
|
|
|
284
283
|
compiledUrl: scriptCompiledFileUrl,
|
|
285
284
|
projectDirectoryUrl,
|
|
286
285
|
|
|
287
|
-
|
|
286
|
+
babelPluginMap,
|
|
288
287
|
moduleOutFormat,
|
|
289
288
|
importMetaFormat,
|
|
290
|
-
|
|
289
|
+
topLevelAwait,
|
|
291
290
|
})
|
|
292
291
|
} catch (e) {
|
|
293
292
|
// If there is a syntax error in inline script
|
|
@@ -1,89 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* allows the following:
|
|
3
|
-
*
|
|
4
|
-
* import "@jsenv/core/helpers/regenerator-runtime/regenerator-runtime.js"
|
|
5
|
-
* -> searches a file inside @jsenv/core/*
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { urlToRelativeUrl, urlIsInsideOf } from "@jsenv/filesystem"
|
|
10
1
|
import { composeTwoImportMaps } from "@jsenv/importmap"
|
|
11
2
|
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
export const compileImportmap = async ({ code, url }) => {
|
|
15
|
-
const importMapForProject = JSON.parse(code)
|
|
16
|
-
|
|
17
|
-
const topLevelRemappingForJsenvCore = {
|
|
18
|
-
"@jsenv/core/": urlToRelativeUrlRemapping(jsenvCoreDirectoryUrl, url),
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const importmapForSelfImport = {
|
|
22
|
-
imports: topLevelRemappingForJsenvCore,
|
|
23
|
-
scopes: generateJsenvCoreScopes({
|
|
24
|
-
importMapForProject,
|
|
25
|
-
topLevelRemappingForJsenvCore,
|
|
26
|
-
}),
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const importMap = [importmapForSelfImport, importMapForProject].reduce(
|
|
30
|
-
(previous, current) => composeTwoImportMaps(previous, current),
|
|
31
|
-
{},
|
|
32
|
-
)
|
|
3
|
+
import { getDefaultImportmap } from "@jsenv/core/src/internal/import-resolution/importmap_default.js"
|
|
33
4
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
5
|
+
export const compileImportmap = async ({
|
|
6
|
+
code,
|
|
7
|
+
url,
|
|
8
|
+
compiledUrl,
|
|
9
|
+
projectDirectoryUrl,
|
|
10
|
+
outDirectoryRelativeUrl,
|
|
11
|
+
compileId,
|
|
12
|
+
}) => {
|
|
13
|
+
const jsenvImportmap = getDefaultImportmap(compiledUrl, {
|
|
14
|
+
projectDirectoryUrl,
|
|
15
|
+
compileDirectoryUrl: `${projectDirectoryUrl}${outDirectoryRelativeUrl}${compileId}/`,
|
|
43
16
|
})
|
|
17
|
+
const projectImportmap = JSON.parse(code)
|
|
18
|
+
const importmap = composeTwoImportMaps(jsenvImportmap, projectImportmap)
|
|
44
19
|
|
|
45
20
|
return {
|
|
46
21
|
contentType: "application/importmap+json",
|
|
47
|
-
compiledSource: JSON.stringify(
|
|
22
|
+
compiledSource: JSON.stringify(importmap, null, " "),
|
|
48
23
|
sources: [url],
|
|
49
24
|
sourcesContent: [code],
|
|
50
25
|
assets: [],
|
|
51
26
|
assetsContent: [],
|
|
52
27
|
}
|
|
53
28
|
}
|
|
54
|
-
|
|
55
|
-
// this function just here to ensure relative urls starts with './'
|
|
56
|
-
// so that importmap do not consider them as bare specifiers
|
|
57
|
-
const urlToRelativeUrlRemapping = (url, baseUrl) => {
|
|
58
|
-
const relativeUrl = urlToRelativeUrl(url, baseUrl)
|
|
59
|
-
|
|
60
|
-
if (urlIsInsideOf(url, baseUrl)) {
|
|
61
|
-
if (relativeUrl.startsWith("../")) return relativeUrl
|
|
62
|
-
if (relativeUrl.startsWith("./")) return relativeUrl
|
|
63
|
-
return `./${relativeUrl}`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return relativeUrl
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const generateJsenvCoreScopes = ({
|
|
70
|
-
importMapForProject,
|
|
71
|
-
topLevelRemappingForJsenvCore,
|
|
72
|
-
}) => {
|
|
73
|
-
const { scopes } = importMapForProject
|
|
74
|
-
|
|
75
|
-
if (!scopes) {
|
|
76
|
-
return undefined
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// I must ensure jsenvCoreImports wins by default in every scope
|
|
80
|
-
// because scope may contains stuff like
|
|
81
|
-
// "/": "/"
|
|
82
|
-
// "/": "/folder/"
|
|
83
|
-
// to achieve this, we set jsenvCoreImports into every scope
|
|
84
|
-
const scopesForJsenvCore = {}
|
|
85
|
-
Object.keys(scopes).forEach((scopeKey) => {
|
|
86
|
-
scopesForJsenvCore[scopeKey] = topLevelRemappingForJsenvCore
|
|
87
|
-
})
|
|
88
|
-
return scopesForJsenvCore
|
|
89
|
-
}
|
|
@@ -9,13 +9,21 @@ export const compileJavascript = async ({
|
|
|
9
9
|
projectDirectoryUrl,
|
|
10
10
|
|
|
11
11
|
babelPluginMap,
|
|
12
|
-
|
|
12
|
+
workerUrls,
|
|
13
|
+
serviceWorkerUrls,
|
|
13
14
|
moduleOutFormat,
|
|
14
15
|
importMetaFormat,
|
|
16
|
+
topLevelAwait,
|
|
17
|
+
prependSystemJs,
|
|
15
18
|
|
|
16
19
|
sourcemapExcludeSources,
|
|
17
20
|
sourcemapMethod,
|
|
18
21
|
}) => {
|
|
22
|
+
if (prependSystemJs === undefined) {
|
|
23
|
+
prependSystemJs =
|
|
24
|
+
workerUrls.includes(url) || serviceWorkerUrls.includes(url)
|
|
25
|
+
}
|
|
26
|
+
|
|
19
27
|
const transformResult = await transformJs({
|
|
20
28
|
code,
|
|
21
29
|
map,
|
|
@@ -24,9 +32,10 @@ export const compileJavascript = async ({
|
|
|
24
32
|
projectDirectoryUrl,
|
|
25
33
|
|
|
26
34
|
babelPluginMap,
|
|
27
|
-
transformTopLevelAwait,
|
|
28
35
|
moduleOutFormat,
|
|
29
36
|
importMetaFormat,
|
|
37
|
+
topLevelAwait,
|
|
38
|
+
prependSystemJs,
|
|
30
39
|
})
|
|
31
40
|
|
|
32
41
|
return transformResultToCompilationResult(
|