@jsenv/core 28.0.1 → 28.1.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/controllable_child_process.mjs +1 -2
- package/dist/controllable_worker_thread.mjs +1 -2
- package/dist/js/autoreload.js +25 -9
- package/dist/js/execute_using_dynamic_import.js +804 -1
- package/dist/js/script_type_module_supervisor.js +122 -0
- package/dist/js/supervisor.js +933 -0
- package/dist/js/{wrapper.mjs → ws.js} +0 -0
- package/dist/main.js +452 -504
- package/package.json +13 -13
- package/readme.md +1 -1
- package/src/build/inject_global_version_mappings.js +3 -3
- package/src/dev/start_dev_server.js +2 -2
- package/src/execute/execute.js +1 -1
- package/src/execute/run.js +26 -38
- package/src/execute/runtimes/browsers/from_playwright.js +51 -77
- package/src/execute/runtimes/node/node_child_process.js +36 -36
- package/src/execute/runtimes/node/node_worker_thread.js +36 -36
- package/src/omega/kitchen.js +28 -9
- package/src/omega/omega_server.js +2 -2
- package/src/omega/server/file_service.js +2 -2
- package/src/omega/url_graph/url_info_transformations.js +8 -1
- package/src/plugins/autoreload/client/reload.js +20 -7
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +4 -4
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +2 -2
- package/src/plugins/importmap/jsenv_plugin_importmap.js +5 -3
- package/src/plugins/inject_globals/inject_globals.js +3 -3
- package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -1
- package/src/plugins/inline/jsenv_plugin_html_inline_content.js +10 -5
- package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +2 -13
- package/src/plugins/plugins.js +5 -5
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +4 -4
- package/src/plugins/supervisor/client/script_type_module_supervisor.js +99 -0
- package/src/plugins/supervisor/client/supervisor.js +933 -0
- package/src/plugins/{html_supervisor/jsenv_plugin_html_supervisor.js → supervisor/jsenv_plugin_supervisor.js} +128 -102
- package/src/plugins/toolbar/client/execution/toolbar_execution.js +1 -1
- package/src/plugins/toolbar/jsenv_plugin_toolbar.js +4 -4
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +7 -5
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +5 -4
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +13 -7
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +6 -4
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +4 -2
- package/src/plugins/url_analysis/html/html_urls.js +11 -10
- package/src/test/coverage/babel_plugin_instrument.js +1 -35
- package/src/test/coverage/empty_coverage_factory.js +1 -1
- package/src/test/execute_plan.js +7 -3
- package/src/test/execute_test_plan.js +2 -1
- package/src/test/logs_file_execution.js +49 -8
- package/dist/js/html_supervisor_installer.js +0 -1091
- package/dist/js/html_supervisor_setup.js +0 -89
- package/dist/js/uneval.js +0 -804
- package/src/plugins/html_supervisor/client/error_formatter.js +0 -426
- package/src/plugins/html_supervisor/client/error_in_notification.js +0 -21
- package/src/plugins/html_supervisor/client/error_overlay.js +0 -191
- package/src/plugins/html_supervisor/client/html_supervisor_installer.js +0 -315
- package/src/plugins/html_supervisor/client/html_supervisor_setup.js +0 -89
- package/src/plugins/html_supervisor/client/perf_browser.js +0 -17
- package/src/plugins/html_supervisor/client/uneval_exception.js +0 -8
|
@@ -1,7 +1,46 @@
|
|
|
1
1
|
/*
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Jsenv needs to wait for all js execution inside an HTML page before killing the browser.
|
|
3
|
+
* A naive approach would consider execution done when "load" event is dispatched on window but:
|
|
4
|
+
*
|
|
5
|
+
* scenario | covered by window "load"
|
|
6
|
+
* ------------------------------------------- | -------------------------
|
|
7
|
+
* js referenced by <script src> | yes
|
|
8
|
+
* js inlined into <script> | yes
|
|
9
|
+
* js referenced by <script type="module" src> | partially (not for import and top level await)
|
|
10
|
+
* js inlined into <script type="module"> | not at all
|
|
11
|
+
*
|
|
12
|
+
* This plugin provides a way for jsenv to know when js execution is done
|
|
13
|
+
* As a side effect this plugin enables ability to hot reload js inlined into <script hot-accept>
|
|
14
|
+
*
|
|
15
|
+
* <script src="file.js">
|
|
16
|
+
* becomes
|
|
17
|
+
* <script>
|
|
18
|
+
* window.__supervisor__.superviseScript({ src: 'file.js' })
|
|
19
|
+
* </script>
|
|
20
|
+
*
|
|
21
|
+
* <script>
|
|
22
|
+
* console.log(42)
|
|
23
|
+
* </script>
|
|
24
|
+
* becomes
|
|
25
|
+
* <script>
|
|
26
|
+
* window.__supervisor__.superviseScript({ src: 'main.html@L10-L13.js' })
|
|
27
|
+
* </script>
|
|
28
|
+
*
|
|
29
|
+
* <script type="module" src="module.js"></script>
|
|
30
|
+
* becomes
|
|
31
|
+
* <script type="module">
|
|
32
|
+
* import { superviseScriptTypeModule } from 'supervisor'
|
|
33
|
+
* superviseScriptTypeModule({ src: "module.js" })
|
|
34
|
+
* </script>
|
|
35
|
+
*
|
|
36
|
+
* <script type="module">
|
|
37
|
+
* console.log(42)
|
|
38
|
+
* </script>
|
|
39
|
+
* becomes
|
|
40
|
+
* <script type="module">
|
|
41
|
+
* import { superviseScriptTypeModule } from 'supervisor'
|
|
42
|
+
* superviseScriptTypeModule({ src: 'main.html@L10-L13.js' })
|
|
43
|
+
* </script>
|
|
5
44
|
*/
|
|
6
45
|
|
|
7
46
|
import { fileURLToPath } from "node:url"
|
|
@@ -24,32 +63,30 @@ import { getOriginalPosition } from "@jsenv/sourcemap"
|
|
|
24
63
|
|
|
25
64
|
import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
|
|
26
65
|
|
|
27
|
-
export const
|
|
66
|
+
export const jsenvPluginSupervisor = ({
|
|
28
67
|
logs = false,
|
|
29
68
|
measurePerf = false,
|
|
30
69
|
errorOverlay = true,
|
|
31
70
|
openInEditor = true,
|
|
32
71
|
errorBaseUrl,
|
|
33
72
|
}) => {
|
|
34
|
-
const
|
|
35
|
-
"./client/
|
|
73
|
+
const supervisorFileUrl = new URL(
|
|
74
|
+
"./client/supervisor.js?js_classic",
|
|
36
75
|
import.meta.url,
|
|
37
76
|
).href
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"./client/html_supervisor_installer.js",
|
|
77
|
+
const scriptTypeModuleSupervisorFileUrl = new URL(
|
|
78
|
+
"./client/script_type_module_supervisor.js",
|
|
41
79
|
import.meta.url,
|
|
42
80
|
).href
|
|
43
81
|
|
|
44
82
|
return {
|
|
45
|
-
name: "jsenv:
|
|
83
|
+
name: "jsenv:supervisor",
|
|
46
84
|
appliesDuring: "dev",
|
|
47
85
|
serve: async (request, context) => {
|
|
48
86
|
if (request.pathname.startsWith("/__get_code_frame__/")) {
|
|
49
87
|
const { pathname, searchParams } = new URL(request.url)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
88
|
+
let urlWithLineAndColumn = pathname.slice("/__get_code_frame__/".length)
|
|
89
|
+
urlWithLineAndColumn = decodeURIComponent(urlWithLineAndColumn)
|
|
53
90
|
const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/)
|
|
54
91
|
if (!match) {
|
|
55
92
|
return {
|
|
@@ -63,21 +100,28 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
63
100
|
const urlInfo = context.urlGraph.getUrlInfo(file)
|
|
64
101
|
if (!urlInfo) {
|
|
65
102
|
return {
|
|
66
|
-
status:
|
|
103
|
+
status: 204,
|
|
104
|
+
headers: {
|
|
105
|
+
"cache-control": "no-store",
|
|
106
|
+
},
|
|
67
107
|
}
|
|
68
108
|
}
|
|
69
109
|
const remap = searchParams.has("remap")
|
|
70
110
|
if (remap) {
|
|
71
111
|
const sourcemap = urlInfo.sourcemap
|
|
72
112
|
if (sourcemap) {
|
|
73
|
-
const original =
|
|
113
|
+
const original = getOriginalPosition({
|
|
74
114
|
sourcemap,
|
|
75
115
|
url: file,
|
|
76
116
|
line,
|
|
77
117
|
column,
|
|
78
118
|
})
|
|
79
|
-
|
|
80
|
-
|
|
119
|
+
if (original.line !== null) {
|
|
120
|
+
line = original.line
|
|
121
|
+
if (original.column !== null) {
|
|
122
|
+
column = original.column
|
|
123
|
+
}
|
|
124
|
+
}
|
|
81
125
|
}
|
|
82
126
|
}
|
|
83
127
|
const codeFrame = stringifyUrlSite({
|
|
@@ -89,6 +133,7 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
89
133
|
return {
|
|
90
134
|
status: 200,
|
|
91
135
|
headers: {
|
|
136
|
+
"cache-control": "no-store",
|
|
92
137
|
"content-type": "text/plain",
|
|
93
138
|
"content-length": Buffer.byteLength(codeFrame),
|
|
94
139
|
},
|
|
@@ -96,7 +141,8 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
96
141
|
}
|
|
97
142
|
}
|
|
98
143
|
if (request.pathname.startsWith("/__get_error_cause__/")) {
|
|
99
|
-
|
|
144
|
+
let file = request.pathname.slice("/__get_error_cause__/".length)
|
|
145
|
+
file = decodeURIComponent(file)
|
|
100
146
|
if (!file) {
|
|
101
147
|
return {
|
|
102
148
|
status: 400,
|
|
@@ -141,7 +187,7 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
141
187
|
return {
|
|
142
188
|
status: 200,
|
|
143
189
|
headers: {
|
|
144
|
-
"cache-control": "no-
|
|
190
|
+
"cache-control": "no-store",
|
|
145
191
|
"content-type": "application/json",
|
|
146
192
|
"content-length": Buffer.byteLength(body),
|
|
147
193
|
},
|
|
@@ -149,7 +195,8 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
149
195
|
}
|
|
150
196
|
}
|
|
151
197
|
if (request.pathname.startsWith("/__open_in_editor__/")) {
|
|
152
|
-
|
|
198
|
+
let file = request.pathname.slice("/__open_in_editor__/".length)
|
|
199
|
+
file = decodeURIComponent(file)
|
|
153
200
|
if (!file) {
|
|
154
201
|
return {
|
|
155
202
|
status: 400,
|
|
@@ -177,9 +224,7 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
177
224
|
const handleInlineScript = (node, htmlNodeText) => {
|
|
178
225
|
const { type, extension } = analyzeScriptNode(node)
|
|
179
226
|
const { line, column, lineEnd, columnEnd, isOriginal } =
|
|
180
|
-
getHtmlNodePosition(node, {
|
|
181
|
-
preferOriginal: true,
|
|
182
|
-
})
|
|
227
|
+
getHtmlNodePosition(node, { preferOriginal: true })
|
|
183
228
|
let inlineScriptUrl = generateInlineContentUrl({
|
|
184
229
|
url,
|
|
185
230
|
extension: extension || ".js",
|
|
@@ -218,9 +263,6 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
218
263
|
getHtmlNodeAttribute(node, "crossorigin") !== undefined
|
|
219
264
|
const defer = getHtmlNodeAttribute(node, "defer") !== undefined
|
|
220
265
|
const async = getHtmlNodeAttribute(node, "async") !== undefined
|
|
221
|
-
setHtmlNodeAttributes(node, {
|
|
222
|
-
src: undefined,
|
|
223
|
-
})
|
|
224
266
|
scriptsToSupervise.push({
|
|
225
267
|
node,
|
|
226
268
|
type,
|
|
@@ -237,15 +279,15 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
237
279
|
if (type !== "js_classic" && type !== "js_module") {
|
|
238
280
|
return
|
|
239
281
|
}
|
|
240
|
-
const
|
|
241
|
-
if (injectedBy !== undefined) {
|
|
242
|
-
return
|
|
243
|
-
}
|
|
244
|
-
const noHtmlSupervisor = getHtmlNodeAttribute(
|
|
282
|
+
const jsenvPluginOwner = getHtmlNodeAttribute(
|
|
245
283
|
node,
|
|
246
|
-
"
|
|
284
|
+
"jsenv-plugin-owner",
|
|
247
285
|
)
|
|
248
|
-
if (
|
|
286
|
+
if (jsenvPluginOwner !== undefined) {
|
|
287
|
+
return
|
|
288
|
+
}
|
|
289
|
+
const noSupervisor = getHtmlNodeAttribute(node, "no-supervisor")
|
|
290
|
+
if (noSupervisor !== undefined) {
|
|
249
291
|
return
|
|
250
292
|
}
|
|
251
293
|
const htmlNodeText = getHtmlNodeText(node)
|
|
@@ -260,22 +302,23 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
260
302
|
}
|
|
261
303
|
},
|
|
262
304
|
})
|
|
263
|
-
const [
|
|
305
|
+
const [scriptTypeModuleSupervisorFileReference] =
|
|
264
306
|
context.referenceUtils.inject({
|
|
265
307
|
type: "js_import_export",
|
|
266
308
|
expectedType: "js_module",
|
|
267
|
-
specifier:
|
|
309
|
+
specifier: scriptTypeModuleSupervisorFileUrl,
|
|
268
310
|
})
|
|
311
|
+
const [supervisorFileReference] = context.referenceUtils.inject({
|
|
312
|
+
type: "script_src",
|
|
313
|
+
expectedType: "js_classic",
|
|
314
|
+
specifier: supervisorFileUrl,
|
|
315
|
+
})
|
|
269
316
|
injectScriptNodeAsEarlyAsPossible(
|
|
270
317
|
htmlAst,
|
|
271
318
|
createHtmlNode({
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
import { installHtmlSupervisor } from ${
|
|
276
|
-
htmlSupervisorInstallerFileReference.generatedSpecifier
|
|
277
|
-
}
|
|
278
|
-
installHtmlSupervisor(${JSON.stringify(
|
|
319
|
+
tagName: "script",
|
|
320
|
+
textContent: `
|
|
321
|
+
window.__supervisor__.setup(${JSON.stringify(
|
|
279
322
|
{
|
|
280
323
|
rootDirectoryUrl: context.rootDirectoryUrl,
|
|
281
324
|
errorBaseUrl,
|
|
@@ -286,24 +329,20 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
286
329
|
},
|
|
287
330
|
null,
|
|
288
331
|
" ",
|
|
289
|
-
)})
|
|
290
|
-
|
|
332
|
+
)})
|
|
333
|
+
`,
|
|
291
334
|
}),
|
|
335
|
+
"jsenv:supervisor",
|
|
292
336
|
)
|
|
293
|
-
const [htmlSupervisorSetupFileReference] =
|
|
294
|
-
context.referenceUtils.inject({
|
|
295
|
-
type: "script_src",
|
|
296
|
-
expectedType: "js_classic",
|
|
297
|
-
specifier: htmlSupervisorSetupFileUrl,
|
|
298
|
-
})
|
|
299
337
|
injectScriptNodeAsEarlyAsPossible(
|
|
300
338
|
htmlAst,
|
|
301
339
|
createHtmlNode({
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
"injected-by": "jsenv:html_supervisor",
|
|
340
|
+
tagName: "script",
|
|
341
|
+
src: supervisorFileReference.generatedSpecifier,
|
|
305
342
|
}),
|
|
343
|
+
"jsenv:supervisor",
|
|
306
344
|
)
|
|
345
|
+
|
|
307
346
|
scriptsToSupervise.forEach(
|
|
308
347
|
({
|
|
309
348
|
node,
|
|
@@ -315,25 +354,43 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
315
354
|
integrity,
|
|
316
355
|
crossorigin,
|
|
317
356
|
}) => {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
async,
|
|
326
|
-
integrity,
|
|
327
|
-
crossorigin,
|
|
328
|
-
htmlSupervisorInstallerSpecifier:
|
|
329
|
-
htmlSupervisorInstallerFileReference.generatedSpecifier,
|
|
330
|
-
}),
|
|
331
|
-
)
|
|
332
|
-
setHtmlNodeAttributes(node, {
|
|
333
|
-
"generated-by": "jsenv:html_supervisor",
|
|
334
|
-
...(src ? { "generated-from-src": src } : {}),
|
|
335
|
-
...(isInline ? { "generated-from-inline-content": "" } : {}),
|
|
357
|
+
const paramsAsJson = JSON.stringify({
|
|
358
|
+
src,
|
|
359
|
+
isInline,
|
|
360
|
+
defer,
|
|
361
|
+
async,
|
|
362
|
+
integrity,
|
|
363
|
+
crossorigin,
|
|
336
364
|
})
|
|
365
|
+
if (type === "js_module") {
|
|
366
|
+
setHtmlNodeText(
|
|
367
|
+
node,
|
|
368
|
+
`
|
|
369
|
+
import { superviseScriptTypeModule } from ${scriptTypeModuleSupervisorFileReference.generatedSpecifier}
|
|
370
|
+
superviseScriptTypeModule(${paramsAsJson})
|
|
371
|
+
`,
|
|
372
|
+
)
|
|
373
|
+
} else {
|
|
374
|
+
setHtmlNodeText(
|
|
375
|
+
node,
|
|
376
|
+
`
|
|
377
|
+
window.__supervisor__.superviseScript(${paramsAsJson})
|
|
378
|
+
`,
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
if (src) {
|
|
382
|
+
setHtmlNodeAttributes(node, {
|
|
383
|
+
"jsenv-plugin-owner": "jsenv:supervisor",
|
|
384
|
+
"jsenv-plugin-action": "inlined",
|
|
385
|
+
"src": undefined,
|
|
386
|
+
"inlined-from-src": src,
|
|
387
|
+
})
|
|
388
|
+
} else {
|
|
389
|
+
setHtmlNodeAttributes(node, {
|
|
390
|
+
"jsenv-plugin-owner": "jsenv:supervisor",
|
|
391
|
+
"jsenv-plugin-action": "content_cooked",
|
|
392
|
+
})
|
|
393
|
+
}
|
|
337
394
|
},
|
|
338
395
|
)
|
|
339
396
|
const htmlModified = stringifyHtmlAst(htmlAst)
|
|
@@ -344,34 +401,3 @@ export const jsenvPluginHtmlSupervisor = ({
|
|
|
344
401
|
},
|
|
345
402
|
}
|
|
346
403
|
}
|
|
347
|
-
|
|
348
|
-
// Ideally jsenv should take into account eventual
|
|
349
|
-
// "integrity" and "crossorigin" attribute during supervision
|
|
350
|
-
const generateCodeToSuperviseScript = ({
|
|
351
|
-
type,
|
|
352
|
-
src,
|
|
353
|
-
isInline,
|
|
354
|
-
defer,
|
|
355
|
-
async,
|
|
356
|
-
integrity,
|
|
357
|
-
crossorigin,
|
|
358
|
-
htmlSupervisorInstallerSpecifier,
|
|
359
|
-
}) => {
|
|
360
|
-
const paramsAsJson = JSON.stringify({
|
|
361
|
-
src,
|
|
362
|
-
isInline,
|
|
363
|
-
defer,
|
|
364
|
-
async,
|
|
365
|
-
integrity,
|
|
366
|
-
crossorigin,
|
|
367
|
-
})
|
|
368
|
-
if (type === "js_module") {
|
|
369
|
-
return `
|
|
370
|
-
import { superviseScriptTypeModule } from ${htmlSupervisorInstallerSpecifier}
|
|
371
|
-
superviseScriptTypeModule(${paramsAsJson})
|
|
372
|
-
`
|
|
373
|
-
}
|
|
374
|
-
return `
|
|
375
|
-
window.__html_supervisor__.superviseScript(${paramsAsJson})
|
|
376
|
-
`
|
|
377
|
-
}
|
|
@@ -9,7 +9,7 @@ export const renderExecutionInToolbar = async () => {
|
|
|
9
9
|
removeForceHideElement(document.querySelector("#execution-indicator"))
|
|
10
10
|
|
|
11
11
|
const { status, startTime, endTime } =
|
|
12
|
-
await window.parent.
|
|
12
|
+
await window.parent.__supervisor__.getScriptExecutionResults()
|
|
13
13
|
const execution = { status, startTime, endTime }
|
|
14
14
|
applyExecutionIndicator(execution)
|
|
15
15
|
const executionStorageKey = window.location.href
|
|
@@ -37,9 +37,9 @@ export const jsenvPluginToolbar = ({ logs = false } = {}) => {
|
|
|
37
37
|
injectScriptNodeAsEarlyAsPossible(
|
|
38
38
|
htmlAst,
|
|
39
39
|
createHtmlNode({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
tagName: "script",
|
|
41
|
+
type: "module",
|
|
42
|
+
textContent: `
|
|
43
43
|
import { injectToolbar } from ${toolbarInjectorReference.generatedSpecifier}
|
|
44
44
|
injectToolbar(${JSON.stringify(
|
|
45
45
|
{
|
|
@@ -49,8 +49,8 @@ injectToolbar(${JSON.stringify(
|
|
|
49
49
|
null,
|
|
50
50
|
" ",
|
|
51
51
|
)})`,
|
|
52
|
-
"injected-by": "jsenv:toolbar",
|
|
53
52
|
}),
|
|
53
|
+
"jsenv:toolbar",
|
|
54
54
|
)
|
|
55
55
|
const htmlModified = stringifyHtmlAst(htmlAst)
|
|
56
56
|
return {
|
|
@@ -24,7 +24,7 @@ import { jsenvPluginAsJsClassicWorkers } from "./jsenv_plugin_as_js_classic_work
|
|
|
24
24
|
// because of https://github.com/rpetrich/babel-plugin-transform-async-to-promises/issues/84
|
|
25
25
|
import customAsyncToPromises from "./async-to-promises.js"
|
|
26
26
|
|
|
27
|
-
export const jsenvPluginAsJsClassic = ({ systemJsInjection }) => {
|
|
27
|
+
export const jsenvPluginAsJsClassic = ({ systemJsInjection = true }) => {
|
|
28
28
|
const systemJsClientFileUrl = new URL(
|
|
29
29
|
"./client/s.js?js_classic",
|
|
30
30
|
import.meta.url,
|
|
@@ -108,7 +108,7 @@ const jsenvPluginAsJsClassicConversion = ({
|
|
|
108
108
|
// - the reference contains ?entry_point
|
|
109
109
|
// When js is entry point there can be no HTML to inject systemjs
|
|
110
110
|
// and systemjs must be injected into the js file
|
|
111
|
-
|
|
111
|
+
urlInfo.isEntryPoint &&
|
|
112
112
|
// if it's an entry point without dependency (it does not use import)
|
|
113
113
|
// then we can use UMD, otherwise we have to use systemjs
|
|
114
114
|
// because it is imported by systemjs
|
|
@@ -118,7 +118,8 @@ const jsenvPluginAsJsClassicConversion = ({
|
|
|
118
118
|
const { content, sourcemap } = await convertJsModuleToJsClassic({
|
|
119
119
|
systemJsInjection,
|
|
120
120
|
systemJsClientFileUrl,
|
|
121
|
-
urlInfo
|
|
121
|
+
urlInfo,
|
|
122
|
+
originalUrlInfo,
|
|
122
123
|
jsClassicFormat,
|
|
123
124
|
})
|
|
124
125
|
urlInfo.data.jsClassicFormat = jsClassicFormat
|
|
@@ -160,6 +161,7 @@ const convertJsModuleToJsClassic = async ({
|
|
|
160
161
|
systemJsInjection,
|
|
161
162
|
systemJsClientFileUrl,
|
|
162
163
|
urlInfo,
|
|
164
|
+
originalUrlInfo,
|
|
163
165
|
jsClassicFormat,
|
|
164
166
|
}) => {
|
|
165
167
|
const { code, map } = await applyBabelPlugins({
|
|
@@ -188,9 +190,9 @@ const convertJsModuleToJsClassic = async ({
|
|
|
188
190
|
requireFromJsenv("@babel/plugin-transform-modules-umd"),
|
|
189
191
|
]),
|
|
190
192
|
],
|
|
191
|
-
urlInfo,
|
|
193
|
+
urlInfo: originalUrlInfo,
|
|
192
194
|
})
|
|
193
|
-
let sourcemap =
|
|
195
|
+
let sourcemap = originalUrlInfo.sourcemap
|
|
194
196
|
sourcemap = await composeTwoSourcemaps(sourcemap, map)
|
|
195
197
|
if (
|
|
196
198
|
systemJsInjection &&
|
|
@@ -191,7 +191,8 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
191
191
|
setHtmlNodeText(moduleScriptNode, newUrlInfo.content)
|
|
192
192
|
setHtmlNodeAttributes(moduleScriptNode, {
|
|
193
193
|
"type": undefined,
|
|
194
|
-
"
|
|
194
|
+
"jsenv-plugin-owner": "jsenv:as_js_classic_html",
|
|
195
|
+
"jsenv-plugin-action": "content_cooked",
|
|
195
196
|
})
|
|
196
197
|
})
|
|
197
198
|
}
|
|
@@ -270,10 +271,10 @@ export const jsenvPluginAsJsClassicHtml = ({
|
|
|
270
271
|
injectScriptNodeAsEarlyAsPossible(
|
|
271
272
|
htmlAst,
|
|
272
273
|
createHtmlNode({
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
"injected-by": "jsenv:as_js_classic_html",
|
|
274
|
+
tagName: "script",
|
|
275
|
+
src: systemJsReference.generatedSpecifier,
|
|
276
276
|
}),
|
|
277
|
+
"jsenv:as_js_classic_html",
|
|
277
278
|
)
|
|
278
279
|
}
|
|
279
280
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { applyBabelPlugins } from "@jsenv/ast"
|
|
2
|
+
import { URL_META } from "@jsenv/url-meta"
|
|
2
3
|
|
|
3
4
|
import { babelPluginInstrument } from "@jsenv/core/src/test/coverage/babel_plugin_instrument.js"
|
|
4
5
|
import { RUNTIME_COMPAT } from "@jsenv/core/src/omega/compat/runtime_compat.js"
|
|
@@ -58,13 +59,18 @@ export const jsenvPluginBabel = ({
|
|
|
58
59
|
if (context.scenarios.dev) {
|
|
59
60
|
const requestHeaders = context.request.headers
|
|
60
61
|
if (requestHeaders["x-coverage-instanbul"]) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const coverageConfig = JSON.parse(
|
|
63
|
+
requestHeaders["x-coverage-instanbul"],
|
|
64
|
+
)
|
|
65
|
+
const associations = URL_META.resolveAssociations(
|
|
66
|
+
{ cover: coverageConfig },
|
|
67
|
+
context.rootDirectoryUrl,
|
|
68
|
+
)
|
|
69
|
+
if (
|
|
70
|
+
URL_META.applyAssociations({ url: urlInfo.url, associations }).cover
|
|
71
|
+
) {
|
|
72
|
+
babelPluginStructure["transform-instrument"] = [babelPluginInstrument]
|
|
73
|
+
}
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
76
|
if (getCustomBabelPlugins) {
|
|
@@ -13,10 +13,12 @@ export const babelPluginNewStylesheetAsJsenvImport = (
|
|
|
13
13
|
return {
|
|
14
14
|
name: "new-stylesheet-as-jsenv-import",
|
|
15
15
|
visitor: {
|
|
16
|
-
Program: (programPath,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
Program: (programPath, babelState) => {
|
|
17
|
+
if (babelState.filename) {
|
|
18
|
+
const fileUrl = pathToFileURL(babelState.filename).href
|
|
19
|
+
if (fileUrl === newStylesheetClientFileUrl) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
let usesNewStylesheet = false
|
|
22
24
|
programPath.traverse({
|
|
@@ -17,7 +17,6 @@ export const jsenvPluginTranspilation = ({
|
|
|
17
17
|
importAssertions = true,
|
|
18
18
|
css = true,
|
|
19
19
|
jsModuleAsJsClassic = true,
|
|
20
|
-
systemJsInjection = true,
|
|
21
20
|
topLevelAwait = true,
|
|
22
21
|
babelHelpersAsImport = true,
|
|
23
22
|
getCustomBabelPlugins,
|
|
@@ -25,6 +24,9 @@ export const jsenvPluginTranspilation = ({
|
|
|
25
24
|
if (importAssertions === true) {
|
|
26
25
|
importAssertions = {}
|
|
27
26
|
}
|
|
27
|
+
if (jsModuleAsJsClassic === true) {
|
|
28
|
+
jsModuleAsJsClassic = {}
|
|
29
|
+
}
|
|
28
30
|
return [
|
|
29
31
|
// import assertions we want it all the time
|
|
30
32
|
...(importAssertions
|
|
@@ -41,7 +43,7 @@ export const jsenvPluginTranspilation = ({
|
|
|
41
43
|
// so the build function will disable jsModuleAsJsClassic during build
|
|
42
44
|
// and enable it manually during postbuild
|
|
43
45
|
...(jsModuleAsJsClassic
|
|
44
|
-
? [jsenvPluginAsJsClassic(
|
|
46
|
+
? [jsenvPluginAsJsClassic(jsModuleAsJsClassic)]
|
|
45
47
|
: []),
|
|
46
48
|
// topLevelAwait must come after js_module_as_js_classic because it's related to the module format
|
|
47
49
|
// so we want to wait to know the module format before transforming things related to top level await
|
|
@@ -96,12 +96,12 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
|
|
|
96
96
|
attributeName,
|
|
97
97
|
specifier,
|
|
98
98
|
}) => {
|
|
99
|
-
const
|
|
100
|
-
getHtmlNodeAttribute(node, "
|
|
99
|
+
const isContentCooked =
|
|
100
|
+
getHtmlNodeAttribute(node, "jsenv-plugin-action") === "content_cooked"
|
|
101
101
|
let position
|
|
102
|
-
if (
|
|
102
|
+
if (isContentCooked) {
|
|
103
103
|
// when generated from inline content,
|
|
104
|
-
// line, column is not "src" nor "
|
|
104
|
+
// line, column is not "src" nor "inlined-from-src" but "original-position"
|
|
105
105
|
position = getHtmlNodePosition(node)
|
|
106
106
|
} else {
|
|
107
107
|
position = getHtmlNodeAttributePosition(node, attributeName)
|
|
@@ -126,8 +126,8 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
|
|
|
126
126
|
const visitAttributeAsUrlSpecifier = ({ node, attributeName, ...rest }) => {
|
|
127
127
|
const value = getHtmlNodeAttribute(node, attributeName)
|
|
128
128
|
if (value) {
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
129
|
+
const jsenvPluginOwner = getHtmlNodeAttribute(node, "jsenv-plugin-owner")
|
|
130
|
+
if (jsenvPluginOwner === "jsenv:importmap") {
|
|
131
131
|
// during build the importmap is inlined
|
|
132
132
|
// and shoud not be considered as a dependency anymore
|
|
133
133
|
return
|
|
@@ -137,8 +137,8 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
|
|
|
137
137
|
node,
|
|
138
138
|
attributeName,
|
|
139
139
|
specifier:
|
|
140
|
-
attributeName === "
|
|
141
|
-
attributeName === "
|
|
140
|
+
attributeName === "inlined-from-src" ||
|
|
141
|
+
attributeName === "inlined-from-href"
|
|
142
142
|
? new URL(value, url).href
|
|
143
143
|
: value,
|
|
144
144
|
})
|
|
@@ -146,13 +146,13 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
|
|
|
146
146
|
visitAttributeAsUrlSpecifier({
|
|
147
147
|
...rest,
|
|
148
148
|
node,
|
|
149
|
-
attributeName: "
|
|
149
|
+
attributeName: "inlined-from-src",
|
|
150
150
|
})
|
|
151
151
|
} else if (attributeName === "href") {
|
|
152
152
|
visitAttributeAsUrlSpecifier({
|
|
153
153
|
...rest,
|
|
154
154
|
node,
|
|
155
|
-
attributeName: "
|
|
155
|
+
attributeName: "inlined-from-href",
|
|
156
156
|
})
|
|
157
157
|
}
|
|
158
158
|
}
|
|
@@ -193,6 +193,7 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
|
|
|
193
193
|
if (type === "text") {
|
|
194
194
|
// ignore <script type="whatever" src="./file.js">
|
|
195
195
|
// per HTML spec https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type
|
|
196
|
+
// this will be handled by jsenv_plugin_html_inline_content
|
|
196
197
|
return
|
|
197
198
|
}
|
|
198
199
|
visitAttributeAsUrlSpecifier({
|
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
import { URL_META } from "@jsenv/url-meta"
|
|
2
|
-
import { fileSystemPathToUrl } from "@jsenv/urls"
|
|
3
|
-
|
|
4
1
|
import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
|
|
5
2
|
|
|
6
3
|
// https://github.com/istanbuljs/babel-plugin-istanbul/blob/321740f7b25d803f881466ea819d870f7ed6a254/src/index.js
|
|
7
4
|
|
|
8
|
-
export const babelPluginInstrument = (
|
|
9
|
-
api,
|
|
10
|
-
{
|
|
11
|
-
rootDirectoryUrl,
|
|
12
|
-
useInlineSourceMaps = false,
|
|
13
|
-
coverageConfig = { "./**/*": true },
|
|
14
|
-
},
|
|
15
|
-
) => {
|
|
5
|
+
export const babelPluginInstrument = (api, { useInlineSourceMaps = false }) => {
|
|
16
6
|
const { programVisitor } = requireFromJsenv("istanbul-lib-instrument")
|
|
17
|
-
|
|
18
7
|
const { types } = api
|
|
19
8
|
|
|
20
|
-
const associations = URL_META.resolveAssociations(
|
|
21
|
-
{ cover: coverageConfig },
|
|
22
|
-
rootDirectoryUrl,
|
|
23
|
-
)
|
|
24
|
-
const shouldInstrument = (url) => {
|
|
25
|
-
return URL_META.applyAssociations({ url, associations }).cover
|
|
26
|
-
}
|
|
27
|
-
|
|
28
9
|
return {
|
|
29
10
|
name: "transform-instrument",
|
|
30
11
|
visitor: {
|
|
@@ -32,21 +13,7 @@ export const babelPluginInstrument = (
|
|
|
32
13
|
enter(path) {
|
|
33
14
|
const { file } = this
|
|
34
15
|
const { opts } = file
|
|
35
|
-
if (!opts.sourceFileName) {
|
|
36
|
-
console.warn(
|
|
37
|
-
`cannot instrument file when "sourceFileName" option is not set`,
|
|
38
|
-
)
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
const fileUrl = fileSystemPathToUrl(opts.sourceFileName)
|
|
42
|
-
if (!shouldInstrument(fileUrl)) {
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.__dv__ = null
|
|
47
|
-
|
|
48
16
|
let inputSourceMap
|
|
49
|
-
|
|
50
17
|
if (useInlineSourceMaps) {
|
|
51
18
|
// https://github.com/istanbuljs/babel-plugin-istanbul/commit/a9e15643d249a2985e4387e4308022053b2cd0ad#diff-1fdf421c05c1140f6d71444ea2b27638R65
|
|
52
19
|
inputSourceMap =
|
|
@@ -56,7 +23,6 @@ export const babelPluginInstrument = (
|
|
|
56
23
|
} else {
|
|
57
24
|
inputSourceMap = opts.inputSourceMap
|
|
58
25
|
}
|
|
59
|
-
|
|
60
26
|
this.__dv__ = programVisitor(
|
|
61
27
|
types,
|
|
62
28
|
opts.filenameRelative || opts.filename,
|
|
@@ -19,7 +19,7 @@ export const relativeUrlToEmptyCoverage = async (
|
|
|
19
19
|
|
|
20
20
|
operation.throwIfAborted()
|
|
21
21
|
const { metadata } = await applyBabelPlugins({
|
|
22
|
-
babelPlugins: [
|
|
22
|
+
babelPlugins: [babelPluginInstrument],
|
|
23
23
|
urlInfo: {
|
|
24
24
|
originalUrl: fileUrl,
|
|
25
25
|
content,
|