@jsenv/core 34.3.0 → 35.0.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.
Files changed (74) hide show
  1. package/README.md +2 -9
  2. package/dist/js/ws.js +1 -145
  3. package/dist/{jsenv.js → jsenv_core.js} +1056 -3850
  4. package/package.json +8 -23
  5. package/src/build/build.js +2 -2
  6. package/src/dev/file_service.js +8 -8
  7. package/src/dev/start_dev_server.js +3 -3
  8. package/src/dev/user_agent.js +1 -1
  9. package/src/main.js +0 -23
  10. package/src/plugins/supervisor/jsenv_plugin_supervisor.js +1 -1
  11. package/src/plugins/transpilation/babel/require_babel_plugin.js +1 -1
  12. package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +1 -1
  13. package/dist/controllable_child_process.mjs +0 -129
  14. package/dist/controllable_worker_thread.mjs +0 -91
  15. package/dist/importmap_node_loader.mjs +0 -49
  16. package/dist/js/execute_using_dynamic_import.js +0 -850
  17. package/dist/js/resolveImport.js +0 -504
  18. package/dist/js/v8_coverage.js +0 -508
  19. package/dist/no_experimental_warnings.cjs +0 -8
  20. package/src/execute/execute.js +0 -111
  21. package/src/execute/run.js +0 -161
  22. package/src/execute/runtimes/browsers/chromium.js +0 -10
  23. package/src/execute/runtimes/browsers/firefox.js +0 -9
  24. package/src/execute/runtimes/browsers/from_playwright.js +0 -574
  25. package/src/execute/runtimes/browsers/middleware_istanbul.js +0 -65
  26. package/src/execute/runtimes/browsers/middleware_js_supervisor.js +0 -100
  27. package/src/execute/runtimes/browsers/webkit.js +0 -26
  28. package/src/execute/runtimes/node/child_exec_options.js +0 -166
  29. package/src/execute/runtimes/node/controllable_child_process.mjs +0 -135
  30. package/src/execute/runtimes/node/controllable_worker_thread.mjs +0 -103
  31. package/src/execute/runtimes/node/exec_options.js +0 -57
  32. package/src/execute/runtimes/node/execute_using_dynamic_import.js +0 -55
  33. package/src/execute/runtimes/node/exit_codes.js +0 -9
  34. package/src/execute/runtimes/node/importmap_node_loader.mjs +0 -51
  35. package/src/execute/runtimes/node/importmap_node_loader_file_url.js +0 -4
  36. package/src/execute/runtimes/node/kill_process_tree.js +0 -76
  37. package/src/execute/runtimes/node/no_experimental_warnings.cjs +0 -12
  38. package/src/execute/runtimes/node/no_experimental_warnings_file_url.js +0 -4
  39. package/src/execute/runtimes/node/node_child_process.js +0 -363
  40. package/src/execute/runtimes/node/node_execution_performance.js +0 -67
  41. package/src/execute/runtimes/node/node_worker_thread.js +0 -295
  42. package/src/execute/runtimes/node/profiler_v8_coverage.js +0 -56
  43. package/src/execute/runtimes/readme.md +0 -13
  44. package/src/execute/web_server_param.js +0 -74
  45. package/src/test/coverage/babel_plugin_instrument.js +0 -48
  46. package/src/test/coverage/coverage_reporter_html_directory.js +0 -32
  47. package/src/test/coverage/coverage_reporter_json_file.js +0 -17
  48. package/src/test/coverage/coverage_reporter_text_log.js +0 -19
  49. package/src/test/coverage/empty_coverage_factory.js +0 -52
  50. package/src/test/coverage/file_by_file_coverage.js +0 -25
  51. package/src/test/coverage/istanbul_coverage_composition.js +0 -28
  52. package/src/test/coverage/istanbul_coverage_map_from_coverage.js +0 -16
  53. package/src/test/coverage/list_files_not_covered.js +0 -15
  54. package/src/test/coverage/missing_coverage.js +0 -41
  55. package/src/test/coverage/report_to_coverage.js +0 -198
  56. package/src/test/coverage/v8_and_istanbul.js +0 -37
  57. package/src/test/coverage/v8_coverage.js +0 -26
  58. package/src/test/coverage/v8_coverage_composition.js +0 -24
  59. package/src/test/coverage/v8_coverage_node_directory.js +0 -85
  60. package/src/test/coverage/v8_coverage_to_istanbul.js +0 -99
  61. package/src/test/execute_steps.js +0 -425
  62. package/src/test/execute_test_plan.js +0 -372
  63. package/src/test/execution_colors.js +0 -10
  64. package/src/test/execution_steps.js +0 -65
  65. package/src/test/gc.js +0 -9
  66. package/src/test/logs_file_execution.js +0 -427
  67. package/src/test/logs_file_execution.test.mjs +0 -41
  68. package/src/test/readme.md +0 -3
  69. /package/src/{basic_fetch.js → helpers/basic_fetch.js} +0 -0
  70. /package/src/{lookup_package_directory.js → helpers/lookup_package_directory.js} +0 -0
  71. /package/src/{ping_server.js → helpers/ping_server.js} +0 -0
  72. /package/src/{require_from_jsenv.js → helpers/require_from_jsenv.js} +0 -0
  73. /package/src/{watch_source_files.js → helpers/watch_source_files.js} +0 -0
  74. /package/src/{web_url_converter.js → helpers/web_url_converter.js} +0 -0
@@ -1,504 +0,0 @@
1
- // duplicated from @jsenv/log to avoid the dependency
2
- const createDetailedMessage = (message, details = {}) => {
3
- let string = `${message}`;
4
- Object.keys(details).forEach(key => {
5
- const value = details[key];
6
- string += `
7
- --- ${key} ---
8
- ${Array.isArray(value) ? value.join(`
9
- `) : value}`;
10
- });
11
- return string;
12
- };
13
-
14
- const assertImportMap = value => {
15
- if (value === null) {
16
- throw new TypeError(`an importMap must be an object, got null`);
17
- }
18
- const type = typeof value;
19
- if (type !== "object") {
20
- throw new TypeError(`an importMap must be an object, received ${value}`);
21
- }
22
- if (Array.isArray(value)) {
23
- throw new TypeError(`an importMap must be an object, received array ${value}`);
24
- }
25
- };
26
-
27
- const hasScheme = string => {
28
- return /^[a-zA-Z]{2,}:/.test(string);
29
- };
30
-
31
- const urlToScheme = urlString => {
32
- const colonIndex = urlString.indexOf(":");
33
- if (colonIndex === -1) return "";
34
- return urlString.slice(0, colonIndex);
35
- };
36
-
37
- const urlToPathname = urlString => {
38
- return ressourceToPathname(urlToRessource(urlString));
39
- };
40
- const urlToRessource = urlString => {
41
- const scheme = urlToScheme(urlString);
42
- if (scheme === "file") {
43
- return urlString.slice("file://".length);
44
- }
45
- if (scheme === "https" || scheme === "http") {
46
- // remove origin
47
- const afterProtocol = urlString.slice(scheme.length + "://".length);
48
- const pathnameSlashIndex = afterProtocol.indexOf("/", "://".length);
49
- return afterProtocol.slice(pathnameSlashIndex);
50
- }
51
- return urlString.slice(scheme.length + 1);
52
- };
53
- const ressourceToPathname = ressource => {
54
- const searchSeparatorIndex = ressource.indexOf("?");
55
- return searchSeparatorIndex === -1 ? ressource : ressource.slice(0, searchSeparatorIndex);
56
- };
57
-
58
- const urlToOrigin = urlString => {
59
- const scheme = urlToScheme(urlString);
60
- if (scheme === "file") {
61
- return "file://";
62
- }
63
- if (scheme === "http" || scheme === "https") {
64
- const secondProtocolSlashIndex = scheme.length + "://".length;
65
- const pathnameSlashIndex = urlString.indexOf("/", secondProtocolSlashIndex);
66
- if (pathnameSlashIndex === -1) return urlString;
67
- return urlString.slice(0, pathnameSlashIndex);
68
- }
69
- return urlString.slice(0, scheme.length + 1);
70
- };
71
-
72
- const pathnameToParentPathname = pathname => {
73
- const slashLastIndex = pathname.lastIndexOf("/");
74
- if (slashLastIndex === -1) {
75
- return "/";
76
- }
77
- return pathname.slice(0, slashLastIndex + 1);
78
- };
79
-
80
- // could be useful: https://url.spec.whatwg.org/#url-miscellaneous
81
- const resolveUrl = (specifier, baseUrl) => {
82
- if (baseUrl) {
83
- if (typeof baseUrl !== "string") {
84
- throw new TypeError(writeBaseUrlMustBeAString({
85
- baseUrl,
86
- specifier
87
- }));
88
- }
89
- if (!hasScheme(baseUrl)) {
90
- throw new Error(writeBaseUrlMustBeAbsolute({
91
- baseUrl,
92
- specifier
93
- }));
94
- }
95
- }
96
- if (hasScheme(specifier)) {
97
- return specifier;
98
- }
99
- if (!baseUrl) {
100
- throw new Error(writeBaseUrlRequired({
101
- baseUrl,
102
- specifier
103
- }));
104
- }
105
-
106
- // scheme relative
107
- if (specifier.slice(0, 2) === "//") {
108
- return `${urlToScheme(baseUrl)}:${specifier}`;
109
- }
110
-
111
- // origin relative
112
- if (specifier[0] === "/") {
113
- return `${urlToOrigin(baseUrl)}${specifier}`;
114
- }
115
- const baseOrigin = urlToOrigin(baseUrl);
116
- const basePathname = urlToPathname(baseUrl);
117
- if (specifier === ".") {
118
- const baseDirectoryPathname = pathnameToParentPathname(basePathname);
119
- return `${baseOrigin}${baseDirectoryPathname}`;
120
- }
121
-
122
- // pathname relative inside
123
- if (specifier.slice(0, 2) === "./") {
124
- const baseDirectoryPathname = pathnameToParentPathname(basePathname);
125
- return `${baseOrigin}${baseDirectoryPathname}${specifier.slice(2)}`;
126
- }
127
-
128
- // pathname relative outside
129
- if (specifier.slice(0, 3) === "../") {
130
- let unresolvedPathname = specifier;
131
- const importerFolders = basePathname.split("/");
132
- importerFolders.pop();
133
- while (unresolvedPathname.slice(0, 3) === "../") {
134
- unresolvedPathname = unresolvedPathname.slice(3);
135
- // when there is no folder left to resolved
136
- // we just ignore '../'
137
- if (importerFolders.length) {
138
- importerFolders.pop();
139
- }
140
- }
141
- const resolvedPathname = `${importerFolders.join("/")}/${unresolvedPathname}`;
142
- return `${baseOrigin}${resolvedPathname}`;
143
- }
144
-
145
- // bare
146
- if (basePathname === "") {
147
- return `${baseOrigin}/${specifier}`;
148
- }
149
- if (basePathname[basePathname.length] === "/") {
150
- return `${baseOrigin}${basePathname}${specifier}`;
151
- }
152
- return `${baseOrigin}${pathnameToParentPathname(basePathname)}${specifier}`;
153
- };
154
- const writeBaseUrlMustBeAString = ({
155
- baseUrl,
156
- specifier
157
- }) => `baseUrl must be a string.
158
- --- base url ---
159
- ${baseUrl}
160
- --- specifier ---
161
- ${specifier}`;
162
- const writeBaseUrlMustBeAbsolute = ({
163
- baseUrl,
164
- specifier
165
- }) => `baseUrl must be absolute.
166
- --- base url ---
167
- ${baseUrl}
168
- --- specifier ---
169
- ${specifier}`;
170
- const writeBaseUrlRequired = ({
171
- baseUrl,
172
- specifier
173
- }) => `baseUrl required to resolve relative specifier.
174
- --- base url ---
175
- ${baseUrl}
176
- --- specifier ---
177
- ${specifier}`;
178
-
179
- const tryUrlResolution = (string, url) => {
180
- const result = resolveUrl(string, url);
181
- return hasScheme(result) ? result : null;
182
- };
183
-
184
- const resolveSpecifier = (specifier, importer) => {
185
- if (specifier === "." || specifier[0] === "/" || specifier.startsWith("./") || specifier.startsWith("../")) {
186
- return resolveUrl(specifier, importer);
187
- }
188
- if (hasScheme(specifier)) {
189
- return specifier;
190
- }
191
- return null;
192
- };
193
-
194
- const applyImportMap = ({
195
- importMap,
196
- specifier,
197
- importer,
198
- createBareSpecifierError = ({
199
- specifier,
200
- importer
201
- }) => {
202
- return new Error(createDetailedMessage(`Unmapped bare specifier.`, {
203
- specifier,
204
- importer
205
- }));
206
- },
207
- onImportMapping = () => {}
208
- }) => {
209
- assertImportMap(importMap);
210
- if (typeof specifier !== "string") {
211
- throw new TypeError(createDetailedMessage("specifier must be a string.", {
212
- specifier,
213
- importer
214
- }));
215
- }
216
- if (importer) {
217
- if (typeof importer !== "string") {
218
- throw new TypeError(createDetailedMessage("importer must be a string.", {
219
- importer,
220
- specifier
221
- }));
222
- }
223
- if (!hasScheme(importer)) {
224
- throw new Error(createDetailedMessage(`importer must be an absolute url.`, {
225
- importer,
226
- specifier
227
- }));
228
- }
229
- }
230
- const specifierUrl = resolveSpecifier(specifier, importer);
231
- const specifierNormalized = specifierUrl || specifier;
232
- const {
233
- scopes
234
- } = importMap;
235
- if (scopes && importer) {
236
- const scopeSpecifierMatching = Object.keys(scopes).find(scopeSpecifier => {
237
- return scopeSpecifier === importer || specifierIsPrefixOf(scopeSpecifier, importer);
238
- });
239
- if (scopeSpecifierMatching) {
240
- const scopeMappings = scopes[scopeSpecifierMatching];
241
- const mappingFromScopes = applyMappings(scopeMappings, specifierNormalized, scopeSpecifierMatching, onImportMapping);
242
- if (mappingFromScopes !== null) {
243
- return mappingFromScopes;
244
- }
245
- }
246
- }
247
- const {
248
- imports
249
- } = importMap;
250
- if (imports) {
251
- const mappingFromImports = applyMappings(imports, specifierNormalized, undefined, onImportMapping);
252
- if (mappingFromImports !== null) {
253
- return mappingFromImports;
254
- }
255
- }
256
- if (specifierUrl) {
257
- return specifierUrl;
258
- }
259
- throw createBareSpecifierError({
260
- specifier,
261
- importer
262
- });
263
- };
264
- const applyMappings = (mappings, specifierNormalized, scope, onImportMapping) => {
265
- const specifierCandidates = Object.keys(mappings);
266
- let i = 0;
267
- while (i < specifierCandidates.length) {
268
- const specifierCandidate = specifierCandidates[i];
269
- i++;
270
- if (specifierCandidate === specifierNormalized) {
271
- const address = mappings[specifierCandidate];
272
- onImportMapping({
273
- scope,
274
- from: specifierCandidate,
275
- to: address,
276
- before: specifierNormalized,
277
- after: address
278
- });
279
- return address;
280
- }
281
- if (specifierIsPrefixOf(specifierCandidate, specifierNormalized)) {
282
- const address = mappings[specifierCandidate];
283
- const afterSpecifier = specifierNormalized.slice(specifierCandidate.length);
284
- const addressFinal = tryUrlResolution(afterSpecifier, address);
285
- onImportMapping({
286
- scope,
287
- from: specifierCandidate,
288
- to: address,
289
- before: specifierNormalized,
290
- after: addressFinal
291
- });
292
- return addressFinal;
293
- }
294
- }
295
- return null;
296
- };
297
- const specifierIsPrefixOf = (specifierHref, href) => {
298
- return specifierHref[specifierHref.length - 1] === "/" && href.startsWith(specifierHref);
299
- };
300
-
301
- const sortImports = imports => {
302
- const mappingsSorted = {};
303
- Object.keys(imports).sort(compareLengthOrLocaleCompare).forEach(name => {
304
- mappingsSorted[name] = imports[name];
305
- });
306
- return mappingsSorted;
307
- };
308
- const sortScopes = scopes => {
309
- const scopesSorted = {};
310
- Object.keys(scopes).sort(compareLengthOrLocaleCompare).forEach(scopeSpecifier => {
311
- scopesSorted[scopeSpecifier] = sortImports(scopes[scopeSpecifier]);
312
- });
313
- return scopesSorted;
314
- };
315
- const compareLengthOrLocaleCompare = (a, b) => {
316
- return b.length - a.length || a.localeCompare(b);
317
- };
318
-
319
- const normalizeImportMap = (importMap, baseUrl) => {
320
- assertImportMap(importMap);
321
- if (!isStringOrUrl(baseUrl)) {
322
- throw new TypeError(formulateBaseUrlMustBeStringOrUrl({
323
- baseUrl
324
- }));
325
- }
326
- const {
327
- imports,
328
- scopes
329
- } = importMap;
330
- return {
331
- imports: imports ? normalizeMappings(imports, baseUrl) : undefined,
332
- scopes: scopes ? normalizeScopes(scopes, baseUrl) : undefined
333
- };
334
- };
335
- const isStringOrUrl = value => {
336
- if (typeof value === "string") {
337
- return true;
338
- }
339
- if (typeof URL === "function" && value instanceof URL) {
340
- return true;
341
- }
342
- return false;
343
- };
344
- const normalizeMappings = (mappings, baseUrl) => {
345
- const mappingsNormalized = {};
346
- Object.keys(mappings).forEach(specifier => {
347
- const address = mappings[specifier];
348
- if (typeof address !== "string") {
349
- console.warn(formulateAddressMustBeAString({
350
- address,
351
- specifier
352
- }));
353
- return;
354
- }
355
- const specifierResolved = resolveSpecifier(specifier, baseUrl) || specifier;
356
- const addressUrl = tryUrlResolution(address, baseUrl);
357
- if (addressUrl === null) {
358
- console.warn(formulateAdressResolutionFailed({
359
- address,
360
- baseUrl,
361
- specifier
362
- }));
363
- return;
364
- }
365
- if (specifier.endsWith("/") && !addressUrl.endsWith("/")) {
366
- console.warn(formulateAddressUrlRequiresTrailingSlash({
367
- addressUrl,
368
- address,
369
- specifier
370
- }));
371
- return;
372
- }
373
- mappingsNormalized[specifierResolved] = addressUrl;
374
- });
375
- return sortImports(mappingsNormalized);
376
- };
377
- const normalizeScopes = (scopes, baseUrl) => {
378
- const scopesNormalized = {};
379
- Object.keys(scopes).forEach(scopeSpecifier => {
380
- const scopeMappings = scopes[scopeSpecifier];
381
- const scopeUrl = tryUrlResolution(scopeSpecifier, baseUrl);
382
- if (scopeUrl === null) {
383
- console.warn(formulateScopeResolutionFailed({
384
- scope: scopeSpecifier,
385
- baseUrl
386
- }));
387
- return;
388
- }
389
- const scopeValueNormalized = normalizeMappings(scopeMappings, baseUrl);
390
- scopesNormalized[scopeUrl] = scopeValueNormalized;
391
- });
392
- return sortScopes(scopesNormalized);
393
- };
394
- const formulateBaseUrlMustBeStringOrUrl = ({
395
- baseUrl
396
- }) => `baseUrl must be a string or an url.
397
- --- base url ---
398
- ${baseUrl}`;
399
- const formulateAddressMustBeAString = ({
400
- specifier,
401
- address
402
- }) => `Address must be a string.
403
- --- address ---
404
- ${address}
405
- --- specifier ---
406
- ${specifier}`;
407
- const formulateAdressResolutionFailed = ({
408
- address,
409
- baseUrl,
410
- specifier
411
- }) => `Address url resolution failed.
412
- --- address ---
413
- ${address}
414
- --- base url ---
415
- ${baseUrl}
416
- --- specifier ---
417
- ${specifier}`;
418
- const formulateAddressUrlRequiresTrailingSlash = ({
419
- addressURL,
420
- address,
421
- specifier
422
- }) => `Address must end with /.
423
- --- address url ---
424
- ${addressURL}
425
- --- address ---
426
- ${address}
427
- --- specifier ---
428
- ${specifier}`;
429
- const formulateScopeResolutionFailed = ({
430
- scope,
431
- baseUrl
432
- }) => `Scope url resolution failed.
433
- --- scope ---
434
- ${scope}
435
- --- base url ---
436
- ${baseUrl}`;
437
-
438
- const pathnameToExtension = pathname => {
439
- const slashLastIndex = pathname.lastIndexOf("/");
440
- if (slashLastIndex !== -1) {
441
- pathname = pathname.slice(slashLastIndex + 1);
442
- }
443
- const dotLastIndex = pathname.lastIndexOf(".");
444
- if (dotLastIndex === -1) return "";
445
- // if (dotLastIndex === pathname.length - 1) return ""
446
- return pathname.slice(dotLastIndex);
447
- };
448
-
449
- const resolveImport = ({
450
- specifier,
451
- importer,
452
- importMap,
453
- defaultExtension = false,
454
- createBareSpecifierError,
455
- onImportMapping = () => {}
456
- }) => {
457
- let url;
458
- if (importMap) {
459
- url = applyImportMap({
460
- importMap,
461
- specifier,
462
- importer,
463
- createBareSpecifierError,
464
- onImportMapping
465
- });
466
- } else {
467
- url = resolveUrl(specifier, importer);
468
- }
469
- if (defaultExtension) {
470
- url = applyDefaultExtension({
471
- url,
472
- importer,
473
- defaultExtension
474
- });
475
- }
476
- return url;
477
- };
478
- const applyDefaultExtension = ({
479
- url,
480
- importer,
481
- defaultExtension
482
- }) => {
483
- if (urlToPathname(url).endsWith("/")) {
484
- return url;
485
- }
486
- if (typeof defaultExtension === "string") {
487
- const extension = pathnameToExtension(url);
488
- if (extension === "") {
489
- return `${url}${defaultExtension}`;
490
- }
491
- return url;
492
- }
493
- if (defaultExtension === true) {
494
- const extension = pathnameToExtension(url);
495
- if (extension === "" && importer) {
496
- const importerPathname = urlToPathname(importer);
497
- const importerExtension = pathnameToExtension(importerPathname);
498
- return `${url}${importerExtension}`;
499
- }
500
- }
501
- return url;
502
- };
503
-
504
- export { assertImportMap, normalizeImportMap, resolveImport, resolveUrl };