@jsenv/core 27.0.0-alpha.69 → 27.0.0-alpha.71
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/js/html_supervisor_installer.js +57 -57
- package/dist/main.js +26 -24
- package/package.json +2 -2
- package/src/build/start_build_server.js +1 -1
- package/src/dev/start_dev_server.js +1 -1
- package/src/plugins/html_supervisor/client/html_supervisor_installer.js +64 -52
- package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +1 -1
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +2 -1
- package/src/plugins/transpilation/babel/require_babel_plugin.js +8 -0
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +1 -2
|
@@ -393,25 +393,19 @@ const installHtmlSupervisor = ({
|
|
|
393
393
|
}
|
|
394
394
|
};
|
|
395
395
|
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
if (next) {
|
|
403
|
-
__html_supervisor__.addScriptToExecute(next);
|
|
396
|
+
const classicExecutionQueue = createExecutionQueue(performExecution);
|
|
397
|
+
const deferedExecutionQueue = createExecutionQueue(performExecution);
|
|
398
|
+
deferedExecutionQueue.waitFor(new Promise(resolve => {
|
|
399
|
+
if (document.readyState === "interactive" || document.readyState === "complete") {
|
|
400
|
+
resolve();
|
|
404
401
|
} else {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
402
|
+
document.addEventListener("readystatechange", () => {
|
|
403
|
+
if (document.readyState === "interactive") {
|
|
404
|
+
resolve();
|
|
405
|
+
}
|
|
406
|
+
});
|
|
410
407
|
}
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
const deferQueue = [];
|
|
414
|
-
let previousDeferDonePromise = null;
|
|
408
|
+
}));
|
|
415
409
|
|
|
416
410
|
__html_supervisor__.addScriptToExecute = async scriptToExecute => {
|
|
417
411
|
if (scriptToExecute.async) {
|
|
@@ -422,52 +416,19 @@ const installHtmlSupervisor = ({
|
|
|
422
416
|
const useDeferQueue = scriptToExecute.defer || scriptToExecute.type === "js_module";
|
|
423
417
|
|
|
424
418
|
if (useDeferQueue) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
if (previousDonePromise) {
|
|
431
|
-
// defer must wait for the regular script to be done
|
|
432
|
-
deferQueue.push(scriptToExecute);
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
419
|
+
// defer must wait for classic script to be done
|
|
420
|
+
const classicExecutionPromise = classicExecutionQueue.getPromise();
|
|
435
421
|
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
return;
|
|
422
|
+
if (classicExecutionPromise) {
|
|
423
|
+
deferedExecutionQueue.waitFor(classicExecutionPromise);
|
|
439
424
|
}
|
|
440
425
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
dequeue();
|
|
445
|
-
return;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
if (previousDonePromise) {
|
|
449
|
-
queue.push(scriptToExecute);
|
|
450
|
-
return;
|
|
426
|
+
deferedExecutionQueue.executeAsap(scriptToExecute);
|
|
427
|
+
} else {
|
|
428
|
+
classicExecutionQueue.executeAsap(scriptToExecute);
|
|
451
429
|
}
|
|
452
|
-
|
|
453
|
-
previousDonePromise = performExecution(scriptToExecute);
|
|
454
|
-
await previousDonePromise;
|
|
455
|
-
previousDonePromise = null;
|
|
456
|
-
dequeue();
|
|
457
430
|
};
|
|
458
431
|
|
|
459
|
-
if (document.readyState !== "interactive" && document.readyState !== "complete") {
|
|
460
|
-
document.addEventListener("readystatechange", () => {
|
|
461
|
-
if (document.readyState === "interactive") {
|
|
462
|
-
const nextDefered = deferQueue.shift();
|
|
463
|
-
|
|
464
|
-
if (nextDefered) {
|
|
465
|
-
__html_supervisor__.addScriptToExecute(nextDefered);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
|
|
471
432
|
__html_supervisor__.collectScriptResults = async () => {
|
|
472
433
|
collectCalled = true;
|
|
473
434
|
|
|
@@ -519,4 +480,43 @@ const superviseScriptTypeModule = ({
|
|
|
519
480
|
});
|
|
520
481
|
};
|
|
521
482
|
|
|
483
|
+
const createExecutionQueue = execute => {
|
|
484
|
+
const scripts = [];
|
|
485
|
+
let promiseToWait = null;
|
|
486
|
+
|
|
487
|
+
const waitFor = async promise => {
|
|
488
|
+
promiseToWait = promise;
|
|
489
|
+
promiseToWait.then(() => {
|
|
490
|
+
promiseToWait = null;
|
|
491
|
+
dequeue();
|
|
492
|
+
}, () => {
|
|
493
|
+
promiseToWait = null;
|
|
494
|
+
dequeue();
|
|
495
|
+
});
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
const executeAsap = async script => {
|
|
499
|
+
if (promiseToWait) {
|
|
500
|
+
scripts.push(script);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
waitFor(execute(script));
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
const dequeue = () => {
|
|
508
|
+
const scriptWaiting = scripts.shift();
|
|
509
|
+
|
|
510
|
+
if (scriptWaiting) {
|
|
511
|
+
__html_supervisor__.addScriptToExecute(scriptWaiting);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
return {
|
|
516
|
+
waitFor,
|
|
517
|
+
executeAsap,
|
|
518
|
+
getPromise: () => promiseToWait
|
|
519
|
+
};
|
|
520
|
+
};
|
|
521
|
+
|
|
522
522
|
export { installHtmlSupervisor, superviseScriptTypeModule };
|
package/dist/main.js
CHANGED
|
@@ -2724,30 +2724,12 @@ export default inlineContent.text`
|
|
|
2724
2724
|
return [asJsonModule, asCssModule, asTextModule];
|
|
2725
2725
|
};
|
|
2726
2726
|
|
|
2727
|
-
|
|
2728
|
-
// the list of possible helpers:
|
|
2729
|
-
// https://github.com/babel/babel/blob/99f4f6c3b03c7f3f67cf1b9f1a21b80cfd5b0224/packages/babel-helpers/src/helpers.js#L13
|
|
2730
|
-
const babelHelperClientDirectoryUrl = new URL("./babel_helpers/", import.meta.url).href; // we cannot use "@jsenv/core/src/*" because babel helper might be injected
|
|
2731
|
-
// into node_modules not depending on "@jsenv/core"
|
|
2732
|
-
|
|
2733
|
-
const getBabelHelperFileUrl = babelHelperName => {
|
|
2734
|
-
const babelHelperFileUrl = new URL(`./${babelHelperName}/${babelHelperName}.js`, babelHelperClientDirectoryUrl).href;
|
|
2735
|
-
return babelHelperFileUrl;
|
|
2736
|
-
};
|
|
2737
|
-
const babelHelperNameFromUrl = url => {
|
|
2738
|
-
if (!url.startsWith(babelHelperClientDirectoryUrl)) {
|
|
2739
|
-
return null;
|
|
2740
|
-
}
|
|
2741
|
-
|
|
2742
|
-
const afterBabelHelperDirectory = url.slice(babelHelperClientDirectoryUrl.length);
|
|
2743
|
-
const babelHelperName = afterBabelHelperDirectory.slice(0, afterBabelHelperDirectory.indexOf("/"));
|
|
2744
|
-
return babelHelperName;
|
|
2745
|
-
};
|
|
2746
|
-
|
|
2747
|
-
const require$4 = createRequire(import.meta.url); // eslint-disable-next-line import/no-dynamic-require
|
|
2727
|
+
const require$4 = createRequire(import.meta.url);
|
|
2748
2728
|
|
|
2729
|
+
const babelPluginPackagePath = require$4.resolve("@jsenv/babel-plugins");
|
|
2749
2730
|
|
|
2750
|
-
const
|
|
2731
|
+
const babelPluginPackageUrl = pathToFileURL(babelPluginPackagePath);
|
|
2732
|
+
const requireBabelPlugin = createRequire(babelPluginPackageUrl);
|
|
2751
2733
|
|
|
2752
2734
|
const babelPluginTransformImportMetaUrl = babel => {
|
|
2753
2735
|
return {
|
|
@@ -3499,6 +3481,26 @@ const getFeatureCompat = feature => {
|
|
|
3499
3481
|
return feature;
|
|
3500
3482
|
};
|
|
3501
3483
|
|
|
3484
|
+
// https://github.com/babel/babel/blob/99f4f6c3b03c7f3f67cf1b9f1a21b80cfd5b0224/packages/babel-core/src/tools/build-external-helpers.js
|
|
3485
|
+
// the list of possible helpers:
|
|
3486
|
+
// https://github.com/babel/babel/blob/99f4f6c3b03c7f3f67cf1b9f1a21b80cfd5b0224/packages/babel-helpers/src/helpers.js#L13
|
|
3487
|
+
const babelHelperClientDirectoryUrl = new URL("./babel_helpers/", import.meta.url).href; // we cannot use "@jsenv/core/src/*" because babel helper might be injected
|
|
3488
|
+
// into node_modules not depending on "@jsenv/core"
|
|
3489
|
+
|
|
3490
|
+
const getBabelHelperFileUrl = babelHelperName => {
|
|
3491
|
+
const babelHelperFileUrl = new URL(`./${babelHelperName}/${babelHelperName}.js`, babelHelperClientDirectoryUrl).href;
|
|
3492
|
+
return babelHelperFileUrl;
|
|
3493
|
+
};
|
|
3494
|
+
const babelHelperNameFromUrl = url => {
|
|
3495
|
+
if (!url.startsWith(babelHelperClientDirectoryUrl)) {
|
|
3496
|
+
return null;
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
const afterBabelHelperDirectory = url.slice(babelHelperClientDirectoryUrl.length);
|
|
3500
|
+
const babelHelperName = afterBabelHelperDirectory.slice(0, afterBabelHelperDirectory.indexOf("/"));
|
|
3501
|
+
return babelHelperName;
|
|
3502
|
+
};
|
|
3503
|
+
|
|
3502
3504
|
/* eslint-disable camelcase */
|
|
3503
3505
|
// copied from
|
|
3504
3506
|
// https://github.com/babel/babel/blob/e498bee10f0123bb208baa228ce6417542a2c3c4/packages/babel-compat-data/data/plugins.json#L1
|
|
@@ -8403,7 +8405,7 @@ const startDevServer = async ({
|
|
|
8403
8405
|
// - inside a forked child process
|
|
8404
8406
|
// - inside a worker thread
|
|
8405
8407
|
// (because node cluster won't work)
|
|
8406
|
-
devServerAutoreload = typeof process.send !== "function" && !parentPort && !process.
|
|
8408
|
+
devServerAutoreload = typeof process.send !== "function" && !parentPort && !process.env.VSCODE_INSPECTOR_OPTIONS,
|
|
8407
8409
|
clientFiles = {
|
|
8408
8410
|
"./**": true,
|
|
8409
8411
|
"./**/.*/": false,
|
|
@@ -13143,7 +13145,7 @@ const startBuildServer = async ({
|
|
|
13143
13145
|
// - inside a forked child process
|
|
13144
13146
|
// - inside a worker thread
|
|
13145
13147
|
// (because node cluster won't work)
|
|
13146
|
-
buildServerAutoreload = typeof process.send !== "function" && !parentPort && !process.
|
|
13148
|
+
buildServerAutoreload = typeof process.send !== "function" && !parentPort && !process.env.VSCODE_INSPECTOR_OPTIONS,
|
|
13147
13149
|
cooldownBetweenFileEvents
|
|
13148
13150
|
}) => {
|
|
13149
13151
|
const logger = createLogger({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/core",
|
|
3
|
-
"version": "27.0.0-alpha.
|
|
3
|
+
"version": "27.0.0-alpha.71",
|
|
4
4
|
"description": "Tool to develop, test and build js projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"@c88/v8-coverage": "0.1.1",
|
|
69
69
|
"@financial-times/polyfill-useragent-normaliser": "2.0.1",
|
|
70
70
|
"@jsenv/abort": "4.1.2",
|
|
71
|
-
"@jsenv/babel-plugins": "1.0.
|
|
71
|
+
"@jsenv/babel-plugins": "1.0.3",
|
|
72
72
|
"@jsenv/filesystem": "4.0.2",
|
|
73
73
|
"@jsenv/importmap": "1.2.0",
|
|
74
74
|
"@jsenv/integrity": "0.0.1",
|
|
@@ -61,7 +61,7 @@ export const startBuildServer = async ({
|
|
|
61
61
|
// (because node cluster won't work)
|
|
62
62
|
buildServerAutoreload = typeof process.send !== "function" &&
|
|
63
63
|
!parentPort &&
|
|
64
|
-
!process.
|
|
64
|
+
!process.env.VSCODE_INSPECTOR_OPTIONS,
|
|
65
65
|
cooldownBetweenFileEvents,
|
|
66
66
|
}) => {
|
|
67
67
|
const logger = createLogger({ logLevel })
|
|
@@ -42,7 +42,7 @@ export const startDevServer = async ({
|
|
|
42
42
|
// (because node cluster won't work)
|
|
43
43
|
devServerAutoreload = typeof process.send !== "function" &&
|
|
44
44
|
!parentPort &&
|
|
45
|
-
!process.
|
|
45
|
+
!process.env.VSCODE_INSPECTOR_OPTIONS,
|
|
46
46
|
clientFiles = {
|
|
47
47
|
"./**": true,
|
|
48
48
|
"./**/.*/": false, // any folder starting with a dot is ignored (includes .git,.jsenv for instance)
|
|
@@ -133,21 +133,24 @@ export const installHtmlSupervisor = ({ logs, measurePerf }) => {
|
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
136
|
+
const classicExecutionQueue = createExecutionQueue(performExecution)
|
|
137
|
+
const deferedExecutionQueue = createExecutionQueue(performExecution)
|
|
138
|
+
deferedExecutionQueue.waitFor(
|
|
139
|
+
new Promise((resolve) => {
|
|
140
|
+
if (
|
|
141
|
+
document.readyState === "interactive" ||
|
|
142
|
+
document.readyState === "complete"
|
|
143
|
+
) {
|
|
144
|
+
resolve()
|
|
145
|
+
} else {
|
|
146
|
+
document.addEventListener("readystatechange", () => {
|
|
147
|
+
if (document.readyState === "interactive") {
|
|
148
|
+
resolve()
|
|
149
|
+
}
|
|
150
|
+
})
|
|
146
151
|
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const deferQueue = []
|
|
150
|
-
let previousDeferDonePromise = null
|
|
152
|
+
}),
|
|
153
|
+
)
|
|
151
154
|
__html_supervisor__.addScriptToExecute = async (scriptToExecute) => {
|
|
152
155
|
if (scriptToExecute.async) {
|
|
153
156
|
performExecution(scriptToExecute)
|
|
@@ -156,46 +159,15 @@ export const installHtmlSupervisor = ({ logs, measurePerf }) => {
|
|
|
156
159
|
const useDeferQueue =
|
|
157
160
|
scriptToExecute.defer || scriptToExecute.type === "js_module"
|
|
158
161
|
if (useDeferQueue) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (previousDonePromise) {
|
|
164
|
-
// defer must wait for the regular script to be done
|
|
165
|
-
deferQueue.push(scriptToExecute)
|
|
166
|
-
return
|
|
167
|
-
}
|
|
168
|
-
if (previousDeferDonePromise) {
|
|
169
|
-
deferQueue.push(scriptToExecute)
|
|
170
|
-
return
|
|
162
|
+
// defer must wait for classic script to be done
|
|
163
|
+
const classicExecutionPromise = classicExecutionQueue.getPromise()
|
|
164
|
+
if (classicExecutionPromise) {
|
|
165
|
+
deferedExecutionQueue.waitFor(classicExecutionPromise)
|
|
171
166
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
dequeue()
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
if (previousDonePromise) {
|
|
179
|
-
queue.push(scriptToExecute)
|
|
180
|
-
return
|
|
167
|
+
deferedExecutionQueue.executeAsap(scriptToExecute)
|
|
168
|
+
} else {
|
|
169
|
+
classicExecutionQueue.executeAsap(scriptToExecute)
|
|
181
170
|
}
|
|
182
|
-
previousDonePromise = performExecution(scriptToExecute)
|
|
183
|
-
await previousDonePromise
|
|
184
|
-
previousDonePromise = null
|
|
185
|
-
dequeue()
|
|
186
|
-
}
|
|
187
|
-
if (
|
|
188
|
-
document.readyState !== "interactive" &&
|
|
189
|
-
document.readyState !== "complete"
|
|
190
|
-
) {
|
|
191
|
-
document.addEventListener("readystatechange", () => {
|
|
192
|
-
if (document.readyState === "interactive") {
|
|
193
|
-
const nextDefered = deferQueue.shift()
|
|
194
|
-
if (nextDefered) {
|
|
195
|
-
__html_supervisor__.addScriptToExecute(nextDefered)
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
171
|
}
|
|
200
172
|
|
|
201
173
|
__html_supervisor__.collectScriptResults = async () => {
|
|
@@ -240,3 +212,43 @@ export const superviseScriptTypeModule = ({ src, isInline }) => {
|
|
|
240
212
|
execute: () => import(new URL(src, document.location.href).href),
|
|
241
213
|
})
|
|
242
214
|
}
|
|
215
|
+
|
|
216
|
+
const createExecutionQueue = (execute) => {
|
|
217
|
+
const scripts = []
|
|
218
|
+
|
|
219
|
+
let promiseToWait = null
|
|
220
|
+
const waitFor = async (promise) => {
|
|
221
|
+
promiseToWait = promise
|
|
222
|
+
promiseToWait.then(
|
|
223
|
+
() => {
|
|
224
|
+
promiseToWait = null
|
|
225
|
+
dequeue()
|
|
226
|
+
},
|
|
227
|
+
() => {
|
|
228
|
+
promiseToWait = null
|
|
229
|
+
dequeue()
|
|
230
|
+
},
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const executeAsap = async (script) => {
|
|
235
|
+
if (promiseToWait) {
|
|
236
|
+
scripts.push(script)
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
waitFor(execute(script))
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const dequeue = () => {
|
|
243
|
+
const scriptWaiting = scripts.shift()
|
|
244
|
+
if (scriptWaiting) {
|
|
245
|
+
__html_supervisor__.addScriptToExecute(scriptWaiting)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
waitFor,
|
|
251
|
+
executeAsap,
|
|
252
|
+
getPromise: () => promiseToWait,
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -15,11 +15,11 @@ import { createRequire } from "node:module"
|
|
|
15
15
|
import { urlToFilename, injectQueryParams } from "@jsenv/urls"
|
|
16
16
|
import { readFileSync } from "@jsenv/filesystem"
|
|
17
17
|
|
|
18
|
-
import { requireBabelPlugin } from "@jsenv/babel-plugins"
|
|
19
18
|
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
20
19
|
import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
|
|
21
20
|
import { composeTwoSourcemaps } from "@jsenv/utils/sourcemap/sourcemap_composition_v3.js"
|
|
22
21
|
|
|
22
|
+
import { requireBabelPlugin } from "../babel/require_babel_plugin.js"
|
|
23
23
|
import { babelPluginTransformImportMetaUrl } from "./helpers/babel_plugin_transform_import_meta_url.js"
|
|
24
24
|
import { jsenvPluginAsJsClassicHtml } from "./jsenv_plugin_as_js_classic_html.js"
|
|
25
25
|
import { jsenvPluginAsJsClassicWorkers } from "./jsenv_plugin_as_js_classic_workers.js"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getBabelHelperFileUrl
|
|
1
|
+
import { getBabelHelperFileUrl } from "@jsenv/babel-plugins"
|
|
2
|
+
import { requireBabelPlugin } from "../require_babel_plugin.js"
|
|
2
3
|
import { babelPluginCompatMap } from "./babel_plugins_compatibility.js"
|
|
3
4
|
|
|
4
5
|
export const getBaseBabelPluginStructure = ({
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createRequire } from "node:module"
|
|
2
|
+
import { pathToFileURL } from "node:url"
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url)
|
|
5
|
+
const babelPluginPackagePath = require.resolve("@jsenv/babel-plugins")
|
|
6
|
+
const babelPluginPackageUrl = pathToFileURL(babelPluginPackagePath)
|
|
7
|
+
|
|
8
|
+
export const requireBabelPlugin = createRequire(babelPluginPackageUrl)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { requireBabelPlugin } from "@jsenv/babel-plugins"
|
|
2
|
-
|
|
3
1
|
import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
|
|
2
|
+
import { requireBabelPlugin } from "./babel/require_babel_plugin.js"
|
|
4
3
|
|
|
5
4
|
export const jsenvPluginTopLevelAwait = () => {
|
|
6
5
|
return {
|