@jsenv/core 41.5.24 → 41.5.25
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/browserslist_index/browserslist_index.js +11 -0
- package/dist/build/build.js +35 -39
- package/dist/jsenv_core.js +1 -1
- package/dist/start_dev_server/start_dev_server.js +24 -21
- package/package.json +6 -6
- package/src/build/build.js +1 -1
- package/src/build/mappings_injection.js +24 -19
- package/src/dev/dev_server_plugins/dev_server_plugin_serve_source_files.js +14 -2
- package/src/kitchen/url_graph/url_info_injections.js +10 -19
|
@@ -2873,6 +2873,14 @@ var require$$1 = [
|
|
|
2873
2873
|
security: false,
|
|
2874
2874
|
v8: "13.6.233.17"
|
|
2875
2875
|
},
|
|
2876
|
+
{
|
|
2877
|
+
name: "nodejs",
|
|
2878
|
+
version: "24.21.0",
|
|
2879
|
+
date: "2026-09-07",
|
|
2880
|
+
lts: "Krypton",
|
|
2881
|
+
security: false,
|
|
2882
|
+
v8: "13.6.233.17"
|
|
2883
|
+
},
|
|
2876
2884
|
{
|
|
2877
2885
|
name: "nodejs",
|
|
2878
2886
|
version: "25.0.0",
|
|
@@ -3410,8 +3418,11 @@ function requireVersions () {
|
|
|
3410
3418
|
"43.3": "150",
|
|
3411
3419
|
"43.4": "150",
|
|
3412
3420
|
"43.5": "150",
|
|
3421
|
+
"43.6": "150",
|
|
3413
3422
|
"44.0": "152",
|
|
3414
3423
|
"44.1": "152",
|
|
3424
|
+
"44.2": "152",
|
|
3425
|
+
"44.3": "152",
|
|
3415
3426
|
"45.0": "155"
|
|
3416
3427
|
};
|
|
3417
3428
|
return versions;
|
package/dist/build/build.js
CHANGED
|
@@ -2460,7 +2460,7 @@ ${urlInfo.url}`,
|
|
|
2460
2460
|
const injectionSymbol = Symbol.for("jsenv_injection");
|
|
2461
2461
|
const INJECTIONS = {
|
|
2462
2462
|
/**
|
|
2463
|
-
* Inject `Object.assign(
|
|
2463
|
+
* Inject `Object.assign(globalThis, { [key]: value })` at the top of the file
|
|
2464
2464
|
* (into a script for html, into the module itself for js) instead of
|
|
2465
2465
|
* replacing a placeholder: the value is read at runtime as a global.
|
|
2466
2466
|
*/
|
|
@@ -2611,7 +2611,7 @@ const injectGlobals = (content, globals, urlInfo) => {
|
|
|
2611
2611
|
return globalInjectorOnHtml(content, globals, urlInfo);
|
|
2612
2612
|
}
|
|
2613
2613
|
if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
|
|
2614
|
-
return globalsInjectorOnJs(content, globals
|
|
2614
|
+
return globalsInjectorOnJs(content, globals);
|
|
2615
2615
|
}
|
|
2616
2616
|
throw new Error(
|
|
2617
2617
|
createDetailedMessage(`cannot inject globals into "${urlInfo.type}"`, {
|
|
@@ -2631,9 +2631,7 @@ const globalInjectorOnHtml = (content, globals, urlInfo) => {
|
|
|
2631
2631
|
url: urlInfo.url,
|
|
2632
2632
|
storeOriginalPositions: false,
|
|
2633
2633
|
});
|
|
2634
|
-
const clientCode = generateClientCodeForGlobals(globals
|
|
2635
|
-
isWebWorker: false,
|
|
2636
|
-
});
|
|
2634
|
+
const clientCode = generateClientCodeForGlobals(globals);
|
|
2637
2635
|
injectJsenvScript(htmlAst, {
|
|
2638
2636
|
content: clientCode,
|
|
2639
2637
|
pluginName: "jsenv:inject_globals",
|
|
@@ -2642,24 +2640,17 @@ const globalInjectorOnHtml = (content, globals, urlInfo) => {
|
|
|
2642
2640
|
content: stringifyHtmlAst(htmlAst),
|
|
2643
2641
|
};
|
|
2644
2642
|
};
|
|
2645
|
-
const globalsInjectorOnJs = (content, globals
|
|
2646
|
-
const clientCode = generateClientCodeForGlobals(globals
|
|
2647
|
-
isWebWorker:
|
|
2648
|
-
urlInfo.subtype === "worker" ||
|
|
2649
|
-
urlInfo.subtype === "service_worker" ||
|
|
2650
|
-
urlInfo.subtype === "shared_worker",
|
|
2651
|
-
});
|
|
2643
|
+
const globalsInjectorOnJs = (content, globals) => {
|
|
2644
|
+
const clientCode = generateClientCodeForGlobals(globals);
|
|
2652
2645
|
const magicSource = createMagicSource(content);
|
|
2653
2646
|
magicSource.prepend(clientCode);
|
|
2654
2647
|
return magicSource.toContentAndSourcemap();
|
|
2655
2648
|
};
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
" ",
|
|
2662
|
-
)});`;
|
|
2649
|
+
// "globalThis" is the global object in a window, a worker and a service worker alike;
|
|
2650
|
+
// naming one of "window"/"self" would require knowing the file's subtype, which is not
|
|
2651
|
+
// known yet when the browser fetches a service worker on its own (update check).
|
|
2652
|
+
const generateClientCodeForGlobals = (globals) => {
|
|
2653
|
+
return `Object.assign(globalThis, ${JSON.stringify(globals, null, " ")});`;
|
|
2663
2654
|
};
|
|
2664
2655
|
|
|
2665
2656
|
const defineGettersOnPropertiesDerivedFromOriginalContent = (
|
|
@@ -10858,28 +10849,33 @@ const logsDefault = {
|
|
|
10858
10849
|
// we nevery minify those because they are already very small
|
|
10859
10850
|
// and would hurt the readability of something that can be critical to debug
|
|
10860
10851
|
const injectGlobalMappings = async (urlInfo, mappings) => {
|
|
10861
|
-
if (
|
|
10862
|
-
|
|
10863
|
-
|
|
10864
|
-
|
|
10865
|
-
|
|
10866
|
-
globalName: "window",
|
|
10867
|
-
minification: false,
|
|
10868
|
-
});
|
|
10869
|
-
await prependContent(urlInfo, { type: "js_classic", content });
|
|
10852
|
+
if (
|
|
10853
|
+
urlInfo.type !== "html" &&
|
|
10854
|
+
urlInfo.type !== "js_classic" &&
|
|
10855
|
+
urlInfo.type !== "js_module"
|
|
10856
|
+
) {
|
|
10870
10857
|
return;
|
|
10871
10858
|
}
|
|
10872
|
-
|
|
10873
|
-
|
|
10874
|
-
|
|
10875
|
-
|
|
10876
|
-
|
|
10877
|
-
|
|
10878
|
-
|
|
10879
|
-
|
|
10880
|
-
|
|
10881
|
-
|
|
10859
|
+
// const minification = Boolean(
|
|
10860
|
+
// urlInfo.context.getPluginMeta("willMinifyJsClassic"),
|
|
10861
|
+
// );
|
|
10862
|
+
const content = generateClientCodeForMappings(mappings, {
|
|
10863
|
+
globalName: getGlobalName(urlInfo),
|
|
10864
|
+
minification: false,
|
|
10865
|
+
});
|
|
10866
|
+
await prependContent(urlInfo, { type: "js_classic", content });
|
|
10867
|
+
};
|
|
10868
|
+
|
|
10869
|
+
// "globalThis" names the global object in a window and in a worker alike;
|
|
10870
|
+
// the window/self split is only for runtimes predating it.
|
|
10871
|
+
const getGlobalName = (urlInfo) => {
|
|
10872
|
+
if (urlInfo.context.isSupportedOnCurrentClients("global_this")) {
|
|
10873
|
+
return "globalThis";
|
|
10874
|
+
}
|
|
10875
|
+
if (isWebWorkerUrlInfo(urlInfo)) {
|
|
10876
|
+
return "self";
|
|
10882
10877
|
}
|
|
10878
|
+
return "window";
|
|
10883
10879
|
};
|
|
10884
10880
|
|
|
10885
10881
|
const generateClientCodeForMappings = (
|
|
@@ -12801,7 +12797,7 @@ const jsenvPluginMappings = (mappings) => {
|
|
|
12801
12797
|
* `<script>window.backendUrl = __BACKEND_URL__;</script>` gets the JS literal,
|
|
12802
12798
|
* which is how a value is shared with every js file of the page.
|
|
12803
12799
|
* Use INJECTIONS.optional(value) for a placeholder that may be absent from the file
|
|
12804
|
-
* and INJECTIONS.global(value) to inject `Object.assign(
|
|
12800
|
+
* and INJECTIONS.global(value) to inject `Object.assign(globalThis, { ... })` instead of
|
|
12805
12801
|
* replacing a placeholder.
|
|
12806
12802
|
*
|
|
12807
12803
|
* @return {Promise<Object>} buildReturnValue
|
package/dist/jsenv_core.js
CHANGED
|
@@ -4,7 +4,7 @@ import "@jsenv/sourcemap";
|
|
|
4
4
|
const injectionSymbol = Symbol.for("jsenv_injection");
|
|
5
5
|
const INJECTIONS = {
|
|
6
6
|
/**
|
|
7
|
-
* Inject `Object.assign(
|
|
7
|
+
* Inject `Object.assign(globalThis, { [key]: value })` at the top of the file
|
|
8
8
|
* (into a script for html, into the module itself for js) instead of
|
|
9
9
|
* replacing a placeholder: the value is read at runtime as a global.
|
|
10
10
|
*/
|
|
@@ -5407,7 +5407,7 @@ const jsenvPluginDirectoryReferenceEffect = (
|
|
|
5407
5407
|
const injectionSymbol = Symbol.for("jsenv_injection");
|
|
5408
5408
|
const INJECTIONS = {
|
|
5409
5409
|
/**
|
|
5410
|
-
* Inject `Object.assign(
|
|
5410
|
+
* Inject `Object.assign(globalThis, { [key]: value })` at the top of the file
|
|
5411
5411
|
* (into a script for html, into the module itself for js) instead of
|
|
5412
5412
|
* replacing a placeholder: the value is read at runtime as a global.
|
|
5413
5413
|
*/
|
|
@@ -5558,7 +5558,7 @@ const injectGlobals = (content, globals, urlInfo) => {
|
|
|
5558
5558
|
return globalInjectorOnHtml(content, globals, urlInfo);
|
|
5559
5559
|
}
|
|
5560
5560
|
if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
|
|
5561
|
-
return globalsInjectorOnJs(content, globals
|
|
5561
|
+
return globalsInjectorOnJs(content, globals);
|
|
5562
5562
|
}
|
|
5563
5563
|
throw new Error(
|
|
5564
5564
|
createDetailedMessage(`cannot inject globals into "${urlInfo.type}"`, {
|
|
@@ -5578,9 +5578,7 @@ const globalInjectorOnHtml = (content, globals, urlInfo) => {
|
|
|
5578
5578
|
url: urlInfo.url,
|
|
5579
5579
|
storeOriginalPositions: false,
|
|
5580
5580
|
});
|
|
5581
|
-
const clientCode = generateClientCodeForGlobals(globals
|
|
5582
|
-
isWebWorker: false,
|
|
5583
|
-
});
|
|
5581
|
+
const clientCode = generateClientCodeForGlobals(globals);
|
|
5584
5582
|
injectJsenvScript(htmlAst, {
|
|
5585
5583
|
content: clientCode,
|
|
5586
5584
|
pluginName: "jsenv:inject_globals",
|
|
@@ -5589,24 +5587,17 @@ const globalInjectorOnHtml = (content, globals, urlInfo) => {
|
|
|
5589
5587
|
content: stringifyHtmlAst(htmlAst),
|
|
5590
5588
|
};
|
|
5591
5589
|
};
|
|
5592
|
-
const globalsInjectorOnJs = (content, globals
|
|
5593
|
-
const clientCode = generateClientCodeForGlobals(globals
|
|
5594
|
-
isWebWorker:
|
|
5595
|
-
urlInfo.subtype === "worker" ||
|
|
5596
|
-
urlInfo.subtype === "service_worker" ||
|
|
5597
|
-
urlInfo.subtype === "shared_worker",
|
|
5598
|
-
});
|
|
5590
|
+
const globalsInjectorOnJs = (content, globals) => {
|
|
5591
|
+
const clientCode = generateClientCodeForGlobals(globals);
|
|
5599
5592
|
const magicSource = createMagicSource(content);
|
|
5600
5593
|
magicSource.prepend(clientCode);
|
|
5601
5594
|
return magicSource.toContentAndSourcemap();
|
|
5602
5595
|
};
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
" ",
|
|
5609
|
-
)});`;
|
|
5596
|
+
// "globalThis" is the global object in a window, a worker and a service worker alike;
|
|
5597
|
+
// naming one of "window"/"self" would require knowing the file's subtype, which is not
|
|
5598
|
+
// known yet when the browser fetches a service worker on its own (update check).
|
|
5599
|
+
const generateClientCodeForGlobals = (globals) => {
|
|
5600
|
+
return `Object.assign(globalThis, ${JSON.stringify(globals, null, " ")});`;
|
|
5610
5601
|
};
|
|
5611
5602
|
|
|
5612
5603
|
const jsenvPluginInjections = (rawAssociations) => {
|
|
@@ -12124,8 +12115,20 @@ const devServerPluginServeSourceFiles = ({
|
|
|
12124
12115
|
rootDirectoryUrl: sourceDirectoryUrl,
|
|
12125
12116
|
})
|
|
12126
12117
|
: sourceDirectoryUrl;
|
|
12118
|
+
// What the graph knows this resource as: the specifier a reference
|
|
12119
|
+
// decodes to never carries "?hot" (the client adds it to re-import,
|
|
12120
|
+
// see jsenv_plugin_hot_search_param), so the request is compared
|
|
12121
|
+
// without it — or nothing inline ever matches its own re-import,
|
|
12122
|
+
// and a file that a re-cook could create is created twice.
|
|
12123
|
+
const requestResourceWithoutHot = WEB_URL_CONVERTER.asWebUrl(
|
|
12124
|
+
requestedUrl,
|
|
12125
|
+
{
|
|
12126
|
+
origin: request.origin,
|
|
12127
|
+
rootDirectoryUrl: sourceDirectoryUrl,
|
|
12128
|
+
},
|
|
12129
|
+
).slice(request.origin.length);
|
|
12127
12130
|
let reference = kitchen.graph.inferReference(
|
|
12128
|
-
|
|
12131
|
+
requestResourceWithoutHot,
|
|
12129
12132
|
parentUrl,
|
|
12130
12133
|
);
|
|
12131
12134
|
if (!reference) {
|
|
@@ -12168,7 +12171,7 @@ const devServerPluginServeSourceFiles = ({
|
|
|
12168
12171
|
});
|
|
12169
12172
|
}
|
|
12170
12173
|
reference = kitchen.graph.inferReference(
|
|
12171
|
-
|
|
12174
|
+
requestResourceWithoutHot,
|
|
12172
12175
|
inlineParentUrl,
|
|
12173
12176
|
);
|
|
12174
12177
|
if (!reference) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "41.5.
|
|
3
|
+
"version": "41.5.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Tool to develop, test and build js projects",
|
|
6
6
|
"repository": {
|
|
@@ -73,12 +73,12 @@
|
|
|
73
73
|
"test:snapshot_clear": "npx @jsenv/filesystem clear **/tests/**/side_effects/"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@jsenv/ast": "6.10.
|
|
77
|
-
"@jsenv/js-module-fallback": "1.6.
|
|
76
|
+
"@jsenv/ast": "6.10.6",
|
|
77
|
+
"@jsenv/js-module-fallback": "1.6.10",
|
|
78
78
|
"@jsenv/plugin-bundling": "2.10.28",
|
|
79
|
-
"@jsenv/plugin-minification": "1.7.
|
|
80
|
-
"@jsenv/plugin-supervisor": "1.8.
|
|
81
|
-
"@jsenv/plugin-transpilation": "1.7.
|
|
79
|
+
"@jsenv/plugin-minification": "1.7.23",
|
|
80
|
+
"@jsenv/plugin-supervisor": "1.8.25",
|
|
81
|
+
"@jsenv/plugin-transpilation": "1.7.10",
|
|
82
82
|
"@jsenv/server": "17.6.6",
|
|
83
83
|
"@jsenv/sourcemap": "1.4.9",
|
|
84
84
|
"react-table": "7.8.0"
|
package/src/build/build.js
CHANGED
|
@@ -177,7 +177,7 @@ import { jsenvPluginMappings } from "./jsenv_plugin_mappings.js";
|
|
|
177
177
|
* `<script>window.backendUrl = __BACKEND_URL__;</script>` gets the JS literal,
|
|
178
178
|
* which is how a value is shared with every js file of the page.
|
|
179
179
|
* Use INJECTIONS.optional(value) for a placeholder that may be absent from the file
|
|
180
|
-
* and INJECTIONS.global(value) to inject `Object.assign(
|
|
180
|
+
* and INJECTIONS.global(value) to inject `Object.assign(globalThis, { ... })` instead of
|
|
181
181
|
* replacing a placeholder.
|
|
182
182
|
*
|
|
183
183
|
* @return {Promise<Object>} buildReturnValue
|
|
@@ -18,28 +18,33 @@ import { prependContent } from "../kitchen/prepend_content.js";
|
|
|
18
18
|
// we nevery minify those because they are already very small
|
|
19
19
|
// and would hurt the readability of something that can be critical to debug
|
|
20
20
|
export const injectGlobalMappings = async (urlInfo, mappings) => {
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
globalName: "window",
|
|
27
|
-
minification: false,
|
|
28
|
-
});
|
|
29
|
-
await prependContent(urlInfo, { type: "js_classic", content });
|
|
21
|
+
if (
|
|
22
|
+
urlInfo.type !== "html" &&
|
|
23
|
+
urlInfo.type !== "js_classic" &&
|
|
24
|
+
urlInfo.type !== "js_module"
|
|
25
|
+
) {
|
|
30
26
|
return;
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
// const minification = Boolean(
|
|
29
|
+
// urlInfo.context.getPluginMeta("willMinifyJsClassic"),
|
|
30
|
+
// );
|
|
31
|
+
const content = generateClientCodeForMappings(mappings, {
|
|
32
|
+
globalName: getGlobalName(urlInfo),
|
|
33
|
+
minification: false,
|
|
34
|
+
});
|
|
35
|
+
await prependContent(urlInfo, { type: "js_classic", content });
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// "globalThis" names the global object in a window and in a worker alike;
|
|
39
|
+
// the window/self split is only for runtimes predating it.
|
|
40
|
+
const getGlobalName = (urlInfo) => {
|
|
41
|
+
if (urlInfo.context.isSupportedOnCurrentClients("global_this")) {
|
|
42
|
+
return "globalThis";
|
|
43
|
+
}
|
|
44
|
+
if (isWebWorkerUrlInfo(urlInfo)) {
|
|
45
|
+
return "self";
|
|
42
46
|
}
|
|
47
|
+
return "window";
|
|
43
48
|
};
|
|
44
49
|
|
|
45
50
|
const generateClientCodeForMappings = (
|
|
@@ -274,8 +274,20 @@ export const devServerPluginServeSourceFiles = ({
|
|
|
274
274
|
rootDirectoryUrl: sourceDirectoryUrl,
|
|
275
275
|
})
|
|
276
276
|
: sourceDirectoryUrl;
|
|
277
|
+
// What the graph knows this resource as: the specifier a reference
|
|
278
|
+
// decodes to never carries "?hot" (the client adds it to re-import,
|
|
279
|
+
// see jsenv_plugin_hot_search_param), so the request is compared
|
|
280
|
+
// without it — or nothing inline ever matches its own re-import,
|
|
281
|
+
// and a file that a re-cook could create is created twice.
|
|
282
|
+
const requestResourceWithoutHot = WEB_URL_CONVERTER.asWebUrl(
|
|
283
|
+
requestedUrl,
|
|
284
|
+
{
|
|
285
|
+
origin: request.origin,
|
|
286
|
+
rootDirectoryUrl: sourceDirectoryUrl,
|
|
287
|
+
},
|
|
288
|
+
).slice(request.origin.length);
|
|
277
289
|
let reference = kitchen.graph.inferReference(
|
|
278
|
-
|
|
290
|
+
requestResourceWithoutHot,
|
|
279
291
|
parentUrl,
|
|
280
292
|
);
|
|
281
293
|
if (!reference) {
|
|
@@ -318,7 +330,7 @@ export const devServerPluginServeSourceFiles = ({
|
|
|
318
330
|
});
|
|
319
331
|
}
|
|
320
332
|
reference = kitchen.graph.inferReference(
|
|
321
|
-
|
|
333
|
+
requestResourceWithoutHot,
|
|
322
334
|
inlineParentUrl,
|
|
323
335
|
);
|
|
324
336
|
if (!reference) {
|
|
@@ -5,7 +5,7 @@ import { composeTwoSourcemaps, createMagicSource } from "@jsenv/sourcemap";
|
|
|
5
5
|
const injectionSymbol = Symbol.for("jsenv_injection");
|
|
6
6
|
export const INJECTIONS = {
|
|
7
7
|
/**
|
|
8
|
-
* Inject `Object.assign(
|
|
8
|
+
* Inject `Object.assign(globalThis, { [key]: value })` at the top of the file
|
|
9
9
|
* (into a script for html, into the module itself for js) instead of
|
|
10
10
|
* replacing a placeholder: the value is read at runtime as a global.
|
|
11
11
|
*/
|
|
@@ -156,7 +156,7 @@ export const injectGlobals = (content, globals, urlInfo) => {
|
|
|
156
156
|
return globalInjectorOnHtml(content, globals, urlInfo);
|
|
157
157
|
}
|
|
158
158
|
if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
|
|
159
|
-
return globalsInjectorOnJs(content, globals
|
|
159
|
+
return globalsInjectorOnJs(content, globals);
|
|
160
160
|
}
|
|
161
161
|
throw new Error(
|
|
162
162
|
createDetailedMessage(`cannot inject globals into "${urlInfo.type}"`, {
|
|
@@ -176,9 +176,7 @@ const globalInjectorOnHtml = (content, globals, urlInfo) => {
|
|
|
176
176
|
url: urlInfo.url,
|
|
177
177
|
storeOriginalPositions: false,
|
|
178
178
|
});
|
|
179
|
-
const clientCode = generateClientCodeForGlobals(globals
|
|
180
|
-
isWebWorker: false,
|
|
181
|
-
});
|
|
179
|
+
const clientCode = generateClientCodeForGlobals(globals);
|
|
182
180
|
injectJsenvScript(htmlAst, {
|
|
183
181
|
content: clientCode,
|
|
184
182
|
pluginName: "jsenv:inject_globals",
|
|
@@ -187,22 +185,15 @@ const globalInjectorOnHtml = (content, globals, urlInfo) => {
|
|
|
187
185
|
content: stringifyHtmlAst(htmlAst),
|
|
188
186
|
};
|
|
189
187
|
};
|
|
190
|
-
const globalsInjectorOnJs = (content, globals
|
|
191
|
-
const clientCode = generateClientCodeForGlobals(globals
|
|
192
|
-
isWebWorker:
|
|
193
|
-
urlInfo.subtype === "worker" ||
|
|
194
|
-
urlInfo.subtype === "service_worker" ||
|
|
195
|
-
urlInfo.subtype === "shared_worker",
|
|
196
|
-
});
|
|
188
|
+
const globalsInjectorOnJs = (content, globals) => {
|
|
189
|
+
const clientCode = generateClientCodeForGlobals(globals);
|
|
197
190
|
const magicSource = createMagicSource(content);
|
|
198
191
|
magicSource.prepend(clientCode);
|
|
199
192
|
return magicSource.toContentAndSourcemap();
|
|
200
193
|
};
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
" ",
|
|
207
|
-
)});`;
|
|
194
|
+
// "globalThis" is the global object in a window, a worker and a service worker alike;
|
|
195
|
+
// naming one of "window"/"self" would require knowing the file's subtype, which is not
|
|
196
|
+
// known yet when the browser fetches a service worker on its own (update check).
|
|
197
|
+
const generateClientCodeForGlobals = (globals) => {
|
|
198
|
+
return `Object.assign(globalThis, ${JSON.stringify(globals, null, " ")});`;
|
|
208
199
|
};
|