@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.
Files changed (57) hide show
  1. package/dist/controllable_child_process.mjs +1 -2
  2. package/dist/controllable_worker_thread.mjs +1 -2
  3. package/dist/js/autoreload.js +25 -9
  4. package/dist/js/execute_using_dynamic_import.js +804 -1
  5. package/dist/js/script_type_module_supervisor.js +122 -0
  6. package/dist/js/supervisor.js +933 -0
  7. package/dist/js/{wrapper.mjs → ws.js} +0 -0
  8. package/dist/main.js +452 -504
  9. package/package.json +13 -13
  10. package/readme.md +1 -1
  11. package/src/build/inject_global_version_mappings.js +3 -3
  12. package/src/dev/start_dev_server.js +2 -2
  13. package/src/execute/execute.js +1 -1
  14. package/src/execute/run.js +26 -38
  15. package/src/execute/runtimes/browsers/from_playwright.js +51 -77
  16. package/src/execute/runtimes/node/node_child_process.js +36 -36
  17. package/src/execute/runtimes/node/node_worker_thread.js +36 -36
  18. package/src/omega/kitchen.js +28 -9
  19. package/src/omega/omega_server.js +2 -2
  20. package/src/omega/server/file_service.js +2 -2
  21. package/src/omega/url_graph/url_info_transformations.js +8 -1
  22. package/src/plugins/autoreload/client/reload.js +20 -7
  23. package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +4 -4
  24. package/src/plugins/import_meta_hot/html_hot_dependencies.js +2 -2
  25. package/src/plugins/importmap/jsenv_plugin_importmap.js +5 -3
  26. package/src/plugins/inject_globals/inject_globals.js +3 -3
  27. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -1
  28. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +10 -5
  29. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +2 -13
  30. package/src/plugins/plugins.js +5 -5
  31. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +4 -4
  32. package/src/plugins/supervisor/client/script_type_module_supervisor.js +99 -0
  33. package/src/plugins/supervisor/client/supervisor.js +933 -0
  34. package/src/plugins/{html_supervisor/jsenv_plugin_html_supervisor.js → supervisor/jsenv_plugin_supervisor.js} +128 -102
  35. package/src/plugins/toolbar/client/execution/toolbar_execution.js +1 -1
  36. package/src/plugins/toolbar/jsenv_plugin_toolbar.js +4 -4
  37. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +7 -5
  38. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +5 -4
  39. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +13 -7
  40. package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +6 -4
  41. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +4 -2
  42. package/src/plugins/url_analysis/html/html_urls.js +11 -10
  43. package/src/test/coverage/babel_plugin_instrument.js +1 -35
  44. package/src/test/coverage/empty_coverage_factory.js +1 -1
  45. package/src/test/execute_plan.js +7 -3
  46. package/src/test/execute_test_plan.js +2 -1
  47. package/src/test/logs_file_execution.js +49 -8
  48. package/dist/js/html_supervisor_installer.js +0 -1091
  49. package/dist/js/html_supervisor_setup.js +0 -89
  50. package/dist/js/uneval.js +0 -804
  51. package/src/plugins/html_supervisor/client/error_formatter.js +0 -426
  52. package/src/plugins/html_supervisor/client/error_in_notification.js +0 -21
  53. package/src/plugins/html_supervisor/client/error_overlay.js +0 -191
  54. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +0 -315
  55. package/src/plugins/html_supervisor/client/html_supervisor_setup.js +0 -89
  56. package/src/plugins/html_supervisor/client/perf_browser.js +0 -17
  57. package/src/plugins/html_supervisor/client/uneval_exception.js +0 -8
package/dist/main.js CHANGED
@@ -23,7 +23,7 @@ import v8, { takeCoverage } from "node:v8";
23
23
  import wrapAnsi from "wrap-ansi";
24
24
  import stripAnsi from "strip-ansi";
25
25
  import cuid from "cuid";
26
- import { runInNewContext, Script } from "node:vm";
26
+ import { runInNewContext } from "node:vm";
27
27
  import { fork } from "node:child_process";
28
28
 
29
29
  /*
@@ -1159,7 +1159,7 @@ const removeNoop = () => {};
1159
1159
  */
1160
1160
  const Abort = {
1161
1161
  isAbortError: error => {
1162
- return error.name === "AbortError";
1162
+ return error && error.name === "AbortError";
1163
1163
  },
1164
1164
  startOperation: () => {
1165
1165
  return createOperation();
@@ -1475,52 +1475,44 @@ const readDirectory = async (url, {
1475
1475
  emfileMaxWait = 1000
1476
1476
  } = {}) => {
1477
1477
  const directoryUrl = assertAndNormalizeDirectoryUrl(url);
1478
- const directoryPath = urlToFileSystemPath(directoryUrl);
1478
+ const directoryUrlObject = new URL(directoryUrl);
1479
1479
  const startMs = Date.now();
1480
1480
  let attemptCount = 0;
1481
1481
 
1482
- const attempt = () => {
1483
- return readdirNaive(directoryPath, {
1484
- handleTooManyFilesOpenedError: async error => {
1482
+ const attempt = async () => {
1483
+ try {
1484
+ const names = await new Promise((resolve, reject) => {
1485
+ readdir(directoryUrlObject, (error, names) => {
1486
+ if (error) {
1487
+ reject(error);
1488
+ } else {
1489
+ resolve(names);
1490
+ }
1491
+ });
1492
+ });
1493
+ return names.map(encodeURIComponent);
1494
+ } catch (e) {
1495
+ // https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#errors_common_system_errors
1496
+ if (e.code === "EMFILE" || e.code === "ENFILE") {
1485
1497
  attemptCount++;
1486
1498
  const nowMs = Date.now();
1487
1499
  const timeSpentWaiting = nowMs - startMs;
1488
1500
 
1489
1501
  if (timeSpentWaiting > emfileMaxWait) {
1490
- throw error;
1502
+ throw e;
1491
1503
  }
1492
1504
 
1493
- return new Promise(resolve => {
1494
- setTimeout(() => {
1495
- resolve(attempt());
1496
- }, attemptCount);
1497
- });
1505
+ await new Promise(resolve => setTimeout(resolve), attemptCount);
1506
+ return await attempt();
1498
1507
  }
1499
- });
1508
+
1509
+ throw e;
1510
+ }
1500
1511
  };
1501
1512
 
1502
1513
  return attempt();
1503
1514
  };
1504
1515
 
1505
- const readdirNaive = (directoryPath, {
1506
- handleTooManyFilesOpenedError = null
1507
- } = {}) => {
1508
- return new Promise((resolve, reject) => {
1509
- readdir(directoryPath, (error, names) => {
1510
- if (error) {
1511
- // https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#errors_common_system_errors
1512
- if (handleTooManyFilesOpenedError && (error.code === "EMFILE" || error.code === "ENFILE")) {
1513
- resolve(handleTooManyFilesOpenedError(error));
1514
- } else {
1515
- reject(error);
1516
- }
1517
- } else {
1518
- resolve(names);
1519
- }
1520
- });
1521
- });
1522
- };
1523
-
1524
1516
  const comparePathnames = (leftPathame, rightPathname) => {
1525
1517
  const leftPartArray = leftPathame.split("/");
1526
1518
  const rightPartArray = rightPathname.split("/");
@@ -3080,6 +3072,7 @@ const FAILURE_RAW = canUseUnicode ? `✖` : `×`;
3080
3072
  const DEBUG_RAW = canUseUnicode ? `◆` : `♦`;
3081
3073
  const INFO_RAW = canUseUnicode ? `ℹ` : `i`;
3082
3074
  const WARNING_RAW = canUseUnicode ? `⚠` : `‼`;
3075
+ const CIRCLE_CROSS_RAW = canUseUnicode ? `ⓧ` : `(×)`;
3083
3076
  const COMMAND = ANSI.color(COMMAND_RAW, ANSI.GREY); // ANSI_MAGENTA)
3084
3077
 
3085
3078
  const OK = ANSI.color(OK_RAW, ANSI.GREEN);
@@ -3087,6 +3080,7 @@ const FAILURE = ANSI.color(FAILURE_RAW, ANSI.RED);
3087
3080
  const DEBUG = ANSI.color(DEBUG_RAW, ANSI.GREY);
3088
3081
  const INFO = ANSI.color(INFO_RAW, ANSI.BLUE);
3089
3082
  const WARNING = ANSI.color(WARNING_RAW, ANSI.YELLOW);
3083
+ const CIRCLE_CROSS = ANSI.color(CIRCLE_CROSS_RAW, ANSI.RED);
3090
3084
  const UNICODE = {
3091
3085
  COMMAND,
3092
3086
  OK,
@@ -3094,12 +3088,14 @@ const UNICODE = {
3094
3088
  DEBUG,
3095
3089
  INFO,
3096
3090
  WARNING,
3091
+ CIRCLE_CROSS,
3097
3092
  COMMAND_RAW,
3098
3093
  OK_RAW,
3099
3094
  FAILURE_RAW,
3100
3095
  DEBUG_RAW,
3101
3096
  INFO_RAW,
3102
3097
  WARNING_RAW,
3098
+ CIRCLE_CROSS_RAW,
3103
3099
  supported: canUseUnicode
3104
3100
  };
3105
3101
 
@@ -4305,12 +4301,12 @@ const visitHtmlUrls = ({
4305
4301
  attributeName,
4306
4302
  specifier
4307
4303
  }) => {
4308
- const generatedFromInlineContent = getHtmlNodeAttribute(node, "generated-from-inline-content") !== undefined;
4304
+ const isContentCooked = getHtmlNodeAttribute(node, "jsenv-plugin-action") === "content_cooked";
4309
4305
  let position;
4310
4306
 
4311
- if (generatedFromInlineContent) {
4307
+ if (isContentCooked) {
4312
4308
  // when generated from inline content,
4313
- // line, column is not "src" nor "generated-from-src" but "original-position"
4309
+ // line, column is not "src" nor "inlined-from-src" but "original-position"
4314
4310
  position = getHtmlNodePosition(node);
4315
4311
  } else {
4316
4312
  position = getHtmlNodeAttributePosition(node, attributeName);
@@ -4342,9 +4338,9 @@ const visitHtmlUrls = ({
4342
4338
  const value = getHtmlNodeAttribute(node, attributeName);
4343
4339
 
4344
4340
  if (value) {
4345
- const generatedBy = getHtmlNodeAttribute(node, "generated-by");
4341
+ const jsenvPluginOwner = getHtmlNodeAttribute(node, "jsenv-plugin-owner");
4346
4342
 
4347
- if (generatedBy !== undefined) {
4343
+ if (jsenvPluginOwner === "jsenv:importmap") {
4348
4344
  // during build the importmap is inlined
4349
4345
  // and shoud not be considered as a dependency anymore
4350
4346
  return;
@@ -4353,17 +4349,17 @@ const visitHtmlUrls = ({
4353
4349
  addDependency({ ...rest,
4354
4350
  node,
4355
4351
  attributeName,
4356
- specifier: attributeName === "generated-from-src" || attributeName === "generated-from-href" ? new URL(value, url).href : value
4352
+ specifier: attributeName === "inlined-from-src" || attributeName === "inlined-from-href" ? new URL(value, url).href : value
4357
4353
  });
4358
4354
  } else if (attributeName === "src") {
4359
4355
  visitAttributeAsUrlSpecifier({ ...rest,
4360
4356
  node,
4361
- attributeName: "generated-from-src"
4357
+ attributeName: "inlined-from-src"
4362
4358
  });
4363
4359
  } else if (attributeName === "href") {
4364
4360
  visitAttributeAsUrlSpecifier({ ...rest,
4365
4361
  node,
4366
- attributeName: "generated-from-href"
4362
+ attributeName: "inlined-from-href"
4367
4363
  });
4368
4364
  }
4369
4365
  };
@@ -4413,6 +4409,7 @@ const visitHtmlUrls = ({
4413
4409
  if (type === "text") {
4414
4410
  // ignore <script type="whatever" src="./file.js">
4415
4411
  // per HTML spec https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type
4412
+ // this will be handled by jsenv_plugin_html_inline_content
4416
4413
  return;
4417
4414
  }
4418
4415
 
@@ -5001,7 +4998,8 @@ const jsenvPluginHtmlInlineContent = ({
5001
4998
  });
5002
4999
  setHtmlNodeText(styleNode, inlineStyleUrlInfo.content);
5003
5000
  setHtmlNodeAttributes(styleNode, {
5004
- "generated-by": "jsenv:html_inline_content"
5001
+ "jsenv-plugin-owner": "jsenv:html_inline_content",
5002
+ "jsenv-plugin-action": "content_cooked"
5005
5003
  });
5006
5004
  });
5007
5005
  },
@@ -5015,13 +5013,13 @@ const jsenvPluginHtmlInlineContent = ({
5015
5013
  // - we want to avoid cooking twice a script during build
5016
5014
 
5017
5015
 
5018
- const generatedBy = getHtmlNodeAttribute(scriptNode, "generated-by");
5016
+ const jsenvPluginOwner = getHtmlNodeAttribute(scriptNode, "jsenv-plugin-owner");
5019
5017
 
5020
- if (generatedBy === "jsenv:as_js_classic_html" && !analyzeConvertedScripts) {
5018
+ if (jsenvPluginOwner === "jsenv:as_js_classic_html" && !analyzeConvertedScripts) {
5021
5019
  return;
5022
5020
  }
5023
5021
 
5024
- if (generatedBy === "jsenv:html_supervisor") {
5022
+ if (jsenvPluginOwner === "jsenv:supervisor") {
5025
5023
  return;
5026
5024
  }
5027
5025
 
@@ -5067,7 +5065,8 @@ const jsenvPluginHtmlInlineContent = ({
5067
5065
  });
5068
5066
  setHtmlNodeText(scriptNode, inlineScriptUrlInfo.content);
5069
5067
  setHtmlNodeAttributes(scriptNode, {
5070
- "generated-by": "jsenv:html_inline_content",
5068
+ "jsenv-plugin-owner": "jsenv:html_inline_content",
5069
+ "jsenv-plugin-action": "content_cooked",
5071
5070
  ...(extension ? {
5072
5071
  type: type === "js_module" ? "module" : undefined
5073
5072
  } : {})
@@ -5605,7 +5604,7 @@ const jsenvPluginDataUrls = () => {
5605
5604
  }
5606
5605
 
5607
5606
  const specifier = DATA_URL.stringify({
5608
- contentType: urlInfo.headers["content-type"],
5607
+ contentType: urlInfo.contentType,
5609
5608
  base64Flag: urlInfo.data.base64Flag,
5610
5609
  data: urlInfo.data.base64Flag ? dataToBase64(urlInfo.content) : String(urlInfo.content)
5611
5610
  });
@@ -5943,7 +5942,8 @@ const jsenvPluginAsJsClassicHtml = ({
5943
5942
  setHtmlNodeText(moduleScriptNode, newUrlInfo.content);
5944
5943
  setHtmlNodeAttributes(moduleScriptNode, {
5945
5944
  "type": undefined,
5946
- "generated-by": "jsenv:as_js_classic_html"
5945
+ "jsenv-plugin-owner": "jsenv:as_js_classic_html",
5946
+ "jsenv-plugin-action": "content_cooked"
5947
5947
  });
5948
5948
  });
5949
5949
  }
@@ -6010,10 +6010,9 @@ const jsenvPluginAsJsClassicHtml = ({
6010
6010
  specifier: systemJsClientFileUrl
6011
6011
  });
6012
6012
  injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
6013
- "tagName": "script",
6014
- "src": systemJsReference.generatedSpecifier,
6015
- "injected-by": "jsenv:as_js_classic_html"
6016
- }));
6013
+ tagName: "script",
6014
+ src: systemJsReference.generatedSpecifier
6015
+ }), "jsenv:as_js_classic_html");
6017
6016
  }
6018
6017
  }
6019
6018
 
@@ -10409,7 +10408,7 @@ function default_1({
10409
10408
  * and prefer to unique identifier based solely on the specifier basename for instance
10410
10409
  */
10411
10410
  const jsenvPluginAsJsClassic = ({
10412
- systemJsInjection
10411
+ systemJsInjection = true
10413
10412
  }) => {
10414
10413
  const systemJsClientFileUrl = new URL("./js/s.js", import.meta.url).href;
10415
10414
  return [jsenvPluginAsJsClassicConversion({
@@ -10483,7 +10482,7 @@ const jsenvPluginAsJsClassicConversion = ({
10483
10482
  // - the reference contains ?entry_point
10484
10483
  // When js is entry point there can be no HTML to inject systemjs
10485
10484
  // and systemjs must be injected into the js file
10486
- originalUrlInfo.isEntryPoint && // if it's an entry point without dependency (it does not use import)
10485
+ urlInfo.isEntryPoint && // if it's an entry point without dependency (it does not use import)
10487
10486
  // then we can use UMD, otherwise we have to use systemjs
10488
10487
  // because it is imported by systemjs
10489
10488
  !originalUrlInfo.data.usesImport ? "umd" : "system";
@@ -10493,7 +10492,8 @@ const jsenvPluginAsJsClassicConversion = ({
10493
10492
  } = await convertJsModuleToJsClassic({
10494
10493
  systemJsInjection,
10495
10494
  systemJsClientFileUrl,
10496
- urlInfo: originalUrlInfo,
10495
+ urlInfo,
10496
+ originalUrlInfo,
10497
10497
  jsClassicFormat
10498
10498
  });
10499
10499
  urlInfo.data.jsClassicFormat = jsClassicFormat;
@@ -10537,6 +10537,7 @@ const convertJsModuleToJsClassic = async ({
10537
10537
  systemJsInjection,
10538
10538
  systemJsClientFileUrl,
10539
10539
  urlInfo,
10540
+ originalUrlInfo,
10540
10541
  jsClassicFormat
10541
10542
  }) => {
10542
10543
  const {
@@ -10550,9 +10551,9 @@ const convertJsModuleToJsClassic = async ({
10550
10551
  }]] : [[requireBabelPlugin("babel-plugin-transform-async-to-promises"), {
10551
10552
  topLevelAwait: "simple"
10552
10553
  }], babelPluginTransformImportMetaUrl, requireFromJsenv("@babel/plugin-transform-modules-umd")])],
10553
- urlInfo
10554
+ urlInfo: originalUrlInfo
10554
10555
  });
10555
- let sourcemap = urlInfo.sourcemap;
10556
+ let sourcemap = originalUrlInfo.sourcemap;
10556
10557
  sourcemap = await composeTwoSourcemaps(sourcemap, map);
10557
10558
 
10558
10559
  if (systemJsInjection && jsClassicFormat === "system" && urlInfo.isEntryPoint) {
@@ -11397,7 +11398,8 @@ const jsenvPluginImportmap = () => {
11397
11398
  });
11398
11399
  setHtmlNodeText(importmap, inlineImportmapUrlInfo.content);
11399
11400
  setHtmlNodeAttributes(importmap, {
11400
- "generated-by": "jsenv:importmap"
11401
+ "jsenv-plugin-owner": "jsenv:importmap",
11402
+ "jsenv-plugin-action": "content_cooked"
11401
11403
  });
11402
11404
  onHtmlImportmapParsed(JSON.parse(inlineImportmapUrlInfo.content), htmlUrlInfo.url);
11403
11405
  };
@@ -11417,8 +11419,9 @@ const jsenvPluginImportmap = () => {
11417
11419
  setHtmlNodeText(importmap, importmapUrlInfo.content);
11418
11420
  setHtmlNodeAttributes(importmap, {
11419
11421
  "src": undefined,
11420
- "generated-by": "jsenv:importmap",
11421
- "generated-from-src": src
11422
+ "jsenv-plugin-owner": "jsenv:importmap",
11423
+ "jsenv-plugin-action": "inlined",
11424
+ "inlined-from-src": src
11422
11425
  });
11423
11426
  const {
11424
11427
  line,
@@ -12862,7 +12865,7 @@ const jsenvPluginNodeEsmResolution = ({
12862
12865
  }
12863
12866
  },
12864
12867
  resolveUrl: {
12865
- js_import_export: (reference, context) => {
12868
+ js_import_export: reference => {
12866
12869
  const {
12867
12870
  parentUrl,
12868
12871
  specifier
@@ -12882,16 +12885,7 @@ const jsenvPluginNodeEsmResolution = ({
12882
12885
  // changes
12883
12886
 
12884
12887
  const dependsOnPackageJson = type !== "relative_specifier" && type !== "absolute_specifier" && type !== "node_builtin_specifier";
12885
- const relatedUrlInfos = context.urlGraph.getRelatedUrlInfos(reference.parentUrl);
12886
- relatedUrlInfos.forEach(relatedUrlInfo => {
12887
- if (relatedUrlInfo.dependsOnPackageJson) {
12888
- // the url may depend due to an other reference
12889
- // in that case keep dependsOnPackageJson to true
12890
- return;
12891
- }
12892
-
12893
- relatedUrlInfo.dependsOnPackageJson = dependsOnPackageJson;
12894
- });
12888
+ reference.dependsOnPackageJson = dependsOnPackageJson;
12895
12889
  return url;
12896
12890
  }
12897
12891
  },
@@ -13173,21 +13167,60 @@ const jsenvPluginHttpUrls = () => {
13173
13167
  };
13174
13168
 
13175
13169
  /*
13176
- * Things happening here
13177
- * - html supervisor module injection
13178
- * - scripts are wrapped to be supervised
13170
+ * Jsenv needs to wait for all js execution inside an HTML page before killing the browser.
13171
+ * A naive approach would consider execution done when "load" event is dispatched on window but:
13172
+ *
13173
+ * scenario | covered by window "load"
13174
+ * ------------------------------------------- | -------------------------
13175
+ * js referenced by <script src> | yes
13176
+ * js inlined into <script> | yes
13177
+ * js referenced by <script type="module" src> | partially (not for import and top level await)
13178
+ * js inlined into <script type="module"> | not at all
13179
+ *
13180
+ * This plugin provides a way for jsenv to know when js execution is done
13181
+ * As a side effect this plugin enables ability to hot reload js inlined into <script hot-accept>
13182
+ *
13183
+ * <script src="file.js">
13184
+ * becomes
13185
+ * <script>
13186
+ * window.__supervisor__.superviseScript({ src: 'file.js' })
13187
+ * </script>
13188
+ *
13189
+ * <script>
13190
+ * console.log(42)
13191
+ * </script>
13192
+ * becomes
13193
+ * <script>
13194
+ * window.__supervisor__.superviseScript({ src: 'main.html@L10-L13.js' })
13195
+ * </script>
13196
+ *
13197
+ * <script type="module" src="module.js"></script>
13198
+ * becomes
13199
+ * <script type="module">
13200
+ * import { superviseScriptTypeModule } from 'supervisor'
13201
+ * superviseScriptTypeModule({ src: "module.js" })
13202
+ * </script>
13203
+ *
13204
+ * <script type="module">
13205
+ * console.log(42)
13206
+ * </script>
13207
+ * becomes
13208
+ * <script type="module">
13209
+ * import { superviseScriptTypeModule } from 'supervisor'
13210
+ * superviseScriptTypeModule({ src: 'main.html@L10-L13.js' })
13211
+ * </script>
13179
13212
  */
13180
- const jsenvPluginHtmlSupervisor = ({
13213
+ const jsenvPluginSupervisor = ({
13181
13214
  logs = false,
13182
13215
  measurePerf = false,
13183
13216
  errorOverlay = true,
13184
13217
  openInEditor = true,
13185
13218
  errorBaseUrl
13186
13219
  }) => {
13187
- const htmlSupervisorSetupFileUrl = new URL("./js/html_supervisor_setup.js", import.meta.url).href;
13188
- const htmlSupervisorInstallerFileUrl = new URL("./js/html_supervisor_installer.js", import.meta.url).href;
13220
+ const supervisorFileUrl = new URL("./js/supervisor.js", import.meta.url).href;
13221
+ const scriptTypeModuleSupervisorFileUrl = new URL("./js/script_type_module_supervisor.js", import.meta.url).href;
13189
13222
  return {
13190
- name: "jsenv:html_supervisor",
13223
+ name: "jsenv:supervisor",
13191
13224
  appliesDuring: "dev",
13192
13225
  serve: async (request, context) => {
13193
13226
  if (request.pathname.startsWith("/__get_code_frame__/")) {
@@ -13195,7 +13228,8 @@ const jsenvPluginHtmlSupervisor = ({
13195
13228
  pathname,
13196
13229
  searchParams
13197
13230
  } = new URL(request.url);
13198
- const urlWithLineAndColumn = pathname.slice("/__get_code_frame__/".length);
13231
+ let urlWithLineAndColumn = pathname.slice("/__get_code_frame__/".length);
13232
+ urlWithLineAndColumn = decodeURIComponent(urlWithLineAndColumn);
13199
13233
  const match = urlWithLineAndColumn.match(/:([0-9]+):([0-9]+)$/);
13200
13234
 
13201
13235
  if (!match) {
@@ -13212,7 +13246,10 @@ const jsenvPluginHtmlSupervisor = ({
13212
13246
 
13213
13247
  if (!urlInfo) {
13214
13248
  return {
13215
- status: 404
13249
+ status: 204,
13250
+ headers: {
13251
+ "cache-control": "no-store"
13252
+ }
13216
13253
  };
13217
13254
  }
13218
13255
 
@@ -13222,14 +13259,20 @@ const jsenvPluginHtmlSupervisor = ({
13222
13259
  const sourcemap = urlInfo.sourcemap;
13223
13260
 
13224
13261
  if (sourcemap) {
13225
- const original = await getOriginalPosition({
13262
+ const original = getOriginalPosition({
13226
13263
  sourcemap,
13227
13264
  url: file,
13228
13265
  line,
13229
13266
  column
13230
13267
  });
13231
- line = original.line;
13232
- column = original.column;
13268
+
13269
+ if (original.line !== null) {
13270
+ line = original.line;
13271
+
13272
+ if (original.column !== null) {
13273
+ column = original.column;
13274
+ }
13275
+ }
13233
13276
  }
13234
13277
  }
13235
13278
 
@@ -13242,6 +13285,7 @@ const jsenvPluginHtmlSupervisor = ({
13242
13285
  return {
13243
13286
  status: 200,
13244
13287
  headers: {
13288
+ "cache-control": "no-store",
13245
13289
  "content-type": "text/plain",
13246
13290
  "content-length": Buffer.byteLength(codeFrame)
13247
13291
  },
@@ -13250,7 +13294,8 @@ const jsenvPluginHtmlSupervisor = ({
13250
13294
  }
13251
13295
 
13252
13296
  if (request.pathname.startsWith("/__get_error_cause__/")) {
13253
- const file = request.pathname.slice("/__get_error_cause__/".length);
13297
+ let file = request.pathname.slice("/__get_error_cause__/".length);
13298
+ file = decodeURIComponent(file);
13254
13299
 
13255
13300
  if (!file) {
13256
13301
  return {
@@ -13301,7 +13346,7 @@ const jsenvPluginHtmlSupervisor = ({
13301
13346
  return {
13302
13347
  status: 200,
13303
13348
  headers: {
13304
- "cache-control": "no-cache",
13349
+ "cache-control": "no-store",
13305
13350
  "content-type": "application/json",
13306
13351
  "content-length": Buffer.byteLength(body)
13307
13352
  },
@@ -13310,7 +13355,8 @@ const jsenvPluginHtmlSupervisor = ({
13310
13355
  }
13311
13356
 
13312
13357
  if (request.pathname.startsWith("/__open_in_editor__/")) {
13313
- const file = request.pathname.slice("/__open_in_editor__/".length);
13358
+ let file = request.pathname.slice("/__open_in_editor__/".length);
13359
+ file = decodeURIComponent(file);
13314
13360
 
13315
13361
  if (!file) {
13316
13362
  return {
@@ -13396,9 +13442,6 @@ const jsenvPluginHtmlSupervisor = ({
13396
13442
  const crossorigin = getHtmlNodeAttribute(node, "crossorigin") !== undefined;
13397
13443
  const defer = getHtmlNodeAttribute(node, "defer") !== undefined;
13398
13444
  const async = getHtmlNodeAttribute(node, "async") !== undefined;
13399
- setHtmlNodeAttributes(node, {
13400
- src: undefined
13401
- });
13402
13445
  scriptsToSupervise.push({
13403
13446
  node,
13404
13447
  type,
@@ -13420,15 +13463,15 @@ const jsenvPluginHtmlSupervisor = ({
13420
13463
  return;
13421
13464
  }
13422
13465
 
13423
- const injectedBy = getHtmlNodeAttribute(node, "injected-by");
13466
+ const jsenvPluginOwner = getHtmlNodeAttribute(node, "jsenv-plugin-owner");
13424
13467
 
13425
- if (injectedBy !== undefined) {
13468
+ if (jsenvPluginOwner !== undefined) {
13426
13469
  return;
13427
13470
  }
13428
13471
 
13429
- const noHtmlSupervisor = getHtmlNodeAttribute(node, "no-html-supervisor");
13472
+ const noSupervisor = getHtmlNodeAttribute(node, "no-supervisor");
13430
13473
 
13431
- if (noHtmlSupervisor !== undefined) {
13474
+ if (noSupervisor !== undefined) {
13432
13475
  return;
13433
13476
  }
13434
13477
 
@@ -13447,36 +13490,33 @@ const jsenvPluginHtmlSupervisor = ({
13447
13490
  }
13448
13491
  }
13449
13492
  });
13450
- const [htmlSupervisorInstallerFileReference] = context.referenceUtils.inject({
13493
+ const [scriptTypeModuleSupervisorFileReference] = context.referenceUtils.inject({
13451
13494
  type: "js_import_export",
13452
13495
  expectedType: "js_module",
13453
- specifier: htmlSupervisorInstallerFileUrl
13496
+ specifier: scriptTypeModuleSupervisorFileUrl
13497
+ });
13498
+ const [supervisorFileReference] = context.referenceUtils.inject({
13499
+ type: "script_src",
13500
+ expectedType: "js_classic",
13501
+ specifier: supervisorFileUrl
13454
13502
  });
13455
13503
  injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
13456
- "tagName": "script",
13457
- "type": "module",
13458
- "textContent": `
13459
- import { installHtmlSupervisor } from ${htmlSupervisorInstallerFileReference.generatedSpecifier}
13460
- installHtmlSupervisor(${JSON.stringify({
13504
+ tagName: "script",
13505
+ textContent: `
13506
+ window.__supervisor__.setup(${JSON.stringify({
13461
13507
  rootDirectoryUrl: context.rootDirectoryUrl,
13462
13508
  errorBaseUrl,
13463
13509
  logs,
13464
13510
  measurePerf,
13465
13511
  errorOverlay,
13466
13512
  openInEditor
13467
- }, null, " ")})`,
13468
- "injected-by": "jsenv:html_supervisor"
13469
- }));
13470
- const [htmlSupervisorSetupFileReference] = context.referenceUtils.inject({
13471
- type: "script_src",
13472
- expectedType: "js_classic",
13473
- specifier: htmlSupervisorSetupFileUrl
13474
- });
13513
+ }, null, " ")})
13514
+ `
13515
+ }), "jsenv:supervisor");
13475
13516
  injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
13476
- "tagName": "script",
13477
- "src": htmlSupervisorSetupFileReference.generatedSpecifier,
13478
- "injected-by": "jsenv:html_supervisor"
13479
- }));
13517
+ tagName: "script",
13518
+ src: supervisorFileReference.generatedSpecifier
13519
+ }), "jsenv:supervisor");
13480
13520
  scriptsToSupervise.forEach(({
13481
13521
  node,
13482
13522
  isInline,
@@ -13487,25 +13527,39 @@ const jsenvPluginHtmlSupervisor = ({
13487
13527
  integrity,
13488
13528
  crossorigin
13489
13529
  }) => {
13490
- setHtmlNodeText(node, generateCodeToSuperviseScript({
13491
- type,
13530
+ const paramsAsJson = JSON.stringify({
13492
13531
  src,
13493
13532
  isInline,
13494
13533
  defer,
13495
13534
  async,
13496
13535
  integrity,
13497
- crossorigin,
13498
- htmlSupervisorInstallerSpecifier: htmlSupervisorInstallerFileReference.generatedSpecifier
13499
- }));
13500
- setHtmlNodeAttributes(node, {
13501
- "generated-by": "jsenv:html_supervisor",
13502
- ...(src ? {
13503
- "generated-from-src": src
13504
- } : {}),
13505
- ...(isInline ? {
13506
- "generated-from-inline-content": ""
13507
- } : {})
13536
+ crossorigin
13508
13537
  });
13538
+
13539
+ if (type === "js_module") {
13540
+ setHtmlNodeText(node, `
13541
+ import { superviseScriptTypeModule } from ${scriptTypeModuleSupervisorFileReference.generatedSpecifier}
13542
+ superviseScriptTypeModule(${paramsAsJson})
13543
+ `);
13544
+ } else {
13545
+ setHtmlNodeText(node, `
13546
+ window.__supervisor__.superviseScript(${paramsAsJson})
13547
+ `);
13548
+ }
13549
+
13550
+ if (src) {
13551
+ setHtmlNodeAttributes(node, {
13552
+ "jsenv-plugin-owner": "jsenv:supervisor",
13553
+ "jsenv-plugin-action": "inlined",
13554
+ "src": undefined,
13555
+ "inlined-from-src": src
13556
+ });
13557
+ } else {
13558
+ setHtmlNodeAttributes(node, {
13559
+ "jsenv-plugin-owner": "jsenv:supervisor",
13560
+ "jsenv-plugin-action": "content_cooked"
13561
+ });
13562
+ }
13509
13563
  });
13510
13564
  const htmlModified = stringifyHtmlAst(htmlAst);
13511
13565
  return {
@@ -13514,38 +13568,6 @@ const jsenvPluginHtmlSupervisor = ({
13514
13568
  }
13515
13569
  }
13516
13570
  };
13517
- }; // Ideally jsenv should take into account eventual
13518
- // "integrity" and "crossorigin" attribute during supervision
13519
-
13520
- const generateCodeToSuperviseScript = ({
13521
- type,
13522
- src,
13523
- isInline,
13524
- defer,
13525
- async,
13526
- integrity,
13527
- crossorigin,
13528
- htmlSupervisorInstallerSpecifier
13529
- }) => {
13530
- const paramsAsJson = JSON.stringify({
13531
- src,
13532
- isInline,
13533
- defer,
13534
- async,
13535
- integrity,
13536
- crossorigin
13537
- });
13538
-
13539
- if (type === "js_module") {
13540
- return `
13541
- import { superviseScriptTypeModule } from ${htmlSupervisorInstallerSpecifier}
13542
- superviseScriptTypeModule(${paramsAsJson})
13543
- `;
13544
- }
13545
-
13546
- return `
13547
- window.__html_supervisor__.superviseScript(${paramsAsJson})
13548
- `;
13549
13571
  };
13550
13572
 
13551
13573
  /*
@@ -14053,11 +14075,7 @@ export default inlineContent.text`,
14053
14075
  };
14054
14076
 
14055
14077
  const babelPluginInstrument = (api, {
14056
- rootDirectoryUrl,
14057
- useInlineSourceMaps = false,
14058
- coverageConfig = {
14059
- "./**/*": true
14060
- }
14078
+ useInlineSourceMaps = false
14061
14079
  }) => {
14062
14080
  const {
14063
14081
  programVisitor
@@ -14065,17 +14083,6 @@ const babelPluginInstrument = (api, {
14065
14083
  const {
14066
14084
  types
14067
14085
  } = api;
14068
- const associations = URL_META.resolveAssociations({
14069
- cover: coverageConfig
14070
- }, rootDirectoryUrl);
14071
-
14072
- const shouldInstrument = url => {
14073
- return URL_META.applyAssociations({
14074
- url,
14075
- associations
14076
- }).cover;
14077
- };
14078
-
14079
14086
  return {
14080
14087
  name: "transform-instrument",
14081
14088
  visitor: {
@@ -14087,19 +14094,6 @@ const babelPluginInstrument = (api, {
14087
14094
  const {
14088
14095
  opts
14089
14096
  } = file;
14090
-
14091
- if (!opts.sourceFileName) {
14092
- console.warn(`cannot instrument file when "sourceFileName" option is not set`);
14093
- return;
14094
- }
14095
-
14096
- const fileUrl = fileSystemPathToUrl$1(opts.sourceFileName);
14097
-
14098
- if (!shouldInstrument(fileUrl)) {
14099
- return;
14100
- }
14101
-
14102
- this.__dv__ = null;
14103
14097
  let inputSourceMap;
14104
14098
 
14105
14099
  if (useInlineSourceMaps) {
@@ -15078,13 +15072,13 @@ const babelPluginNewStylesheetAsJsenvImport = (babel, {
15078
15072
  return {
15079
15073
  name: "new-stylesheet-as-jsenv-import",
15080
15074
  visitor: {
15081
- Program: (programPath, {
15082
- filename
15083
- }) => {
15084
- const fileUrl = pathToFileURL(filename).href;
15075
+ Program: (programPath, babelState) => {
15076
+ if (babelState.filename) {
15077
+ const fileUrl = pathToFileURL(babelState.filename).href;
15085
15078
 
15086
- if (fileUrl === newStylesheetClientFileUrl) {
15087
- return;
15079
+ if (fileUrl === newStylesheetClientFileUrl) {
15080
+ return;
15081
+ }
15088
15082
  }
15089
15083
 
15090
15084
  let usesNewStylesheet = false;
@@ -15318,10 +15312,17 @@ const jsenvPluginBabel = ({
15318
15312
  const requestHeaders = context.request.headers;
15319
15313
 
15320
15314
  if (requestHeaders["x-coverage-instanbul"]) {
15321
- babelPluginStructure["transform-instrument"] = [babelPluginInstrument, {
15322
- rootDirectoryUrl: context.rootDirectoryUrl,
15323
- coverageConfig: JSON.parse(requestHeaders["x-coverage-instanbul"])
15324
- }];
15315
+ const coverageConfig = JSON.parse(requestHeaders["x-coverage-instanbul"]);
15316
+ const associations = URL_META.resolveAssociations({
15317
+ cover: coverageConfig
15318
+ }, context.rootDirectoryUrl);
15319
+
15320
+ if (URL_META.applyAssociations({
15321
+ url: urlInfo.url,
15322
+ associations
15323
+ }).cover) {
15324
+ babelPluginStructure["transform-instrument"] = [babelPluginInstrument];
15325
+ }
15325
15326
  }
15326
15327
  }
15327
15328
 
@@ -15481,7 +15482,6 @@ const jsenvPluginTranspilation = ({
15481
15482
  importAssertions = true,
15482
15483
  css = true,
15483
15484
  jsModuleAsJsClassic = true,
15484
- systemJsInjection = true,
15485
15485
  topLevelAwait = true,
15486
15486
  babelHelpersAsImport = true,
15487
15487
  getCustomBabelPlugins
@@ -15490,6 +15490,10 @@ const jsenvPluginTranspilation = ({
15490
15490
  importAssertions = {};
15491
15491
  }
15492
15492
 
15493
+ if (jsModuleAsJsClassic === true) {
15494
+ jsModuleAsJsClassic = {};
15495
+ }
15496
+
15493
15497
  return [// import assertions we want it all the time
15494
15498
  ...(importAssertions ? [jsenvPluginImportAssertions(importAssertions)] : []), // babel also so that rollup can bundle babel helpers for instance
15495
15499
  jsenvPluginBabel({
@@ -15500,9 +15504,7 @@ const jsenvPluginTranspilation = ({
15500
15504
  // we want to do it after bundling
15501
15505
  // so the build function will disable jsModuleAsJsClassic during build
15502
15506
  // and enable it manually during postbuild
15503
- ...(jsModuleAsJsClassic ? [jsenvPluginAsJsClassic({
15504
- systemJsInjection
15505
- })] : []), // topLevelAwait must come after js_module_as_js_classic because it's related to the module format
15507
+ ...(jsModuleAsJsClassic ? [jsenvPluginAsJsClassic(jsModuleAsJsClassic)] : []), // topLevelAwait must come after js_module_as_js_classic because it's related to the module format
15506
15508
  // so we want to wait to know the module format before transforming things related to top level await
15507
15509
  ...(topLevelAwait ? [jsenvPluginTopLevelAwait()] : []), ...(css ? [jsenvPluginCssParcel()] : [])];
15508
15510
  };
@@ -16315,7 +16317,7 @@ const collectHotDataFromHtmlAst = htmlAst => {
16315
16317
  });
16316
16318
  visitUrlSpecifierAttribute({
16317
16319
  node,
16318
- attributeName: "generated-from-href",
16320
+ attributeName: "inlined-from-href",
16319
16321
  hotAccepted
16320
16322
  });
16321
16323
  }
@@ -16328,7 +16330,7 @@ const collectHotDataFromHtmlAst = htmlAst => {
16328
16330
  });
16329
16331
  visitUrlSpecifierAttribute({
16330
16332
  node,
16331
- attributeName: "generated-from-src",
16333
+ attributeName: "inlined-from-src",
16332
16334
  hotAccepted
16333
16335
  });
16334
16336
  }
@@ -16696,11 +16698,10 @@ const jsenvPluginAutoreloadClient = () => {
16696
16698
  specifier: autoreloadClientFileUrl
16697
16699
  });
16698
16700
  injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
16699
- "tagName": "script",
16700
- "type": "module",
16701
- "src": autoreloadClientReference.generatedSpecifier,
16702
- "injected-by": "jsenv:autoreload_client"
16703
- }));
16701
+ tagName: "script",
16702
+ type: "module",
16703
+ src: autoreloadClientReference.generatedSpecifier
16704
+ }), "jsenv:autoreload_client");
16704
16705
  const htmlModified = stringifyHtmlAst(htmlAst);
16705
16706
  return {
16706
16707
  content: htmlModified
@@ -17048,7 +17049,7 @@ const getCorePlugins = ({
17048
17049
  rootDirectoryUrl,
17049
17050
  runtimeCompat,
17050
17051
  urlAnalysis = {},
17051
- htmlSupervisor,
17052
+ supervisor,
17052
17053
  nodeEsmResolution = true,
17053
17054
  fileSystemMagicResolution,
17054
17055
  directoryReferenceAllowed,
@@ -17060,8 +17061,8 @@ const getCorePlugins = ({
17060
17061
  clientFilesPruneCallbackList,
17061
17062
  explorer
17062
17063
  } = {}) => {
17063
- if (htmlSupervisor === true) {
17064
- htmlSupervisor = {};
17064
+ if (supervisor === true) {
17065
+ supervisor = {};
17065
17066
  }
17066
17067
 
17067
17068
  if (nodeEsmResolution === true) {
@@ -17079,7 +17080,7 @@ const getCorePlugins = ({
17079
17080
  return [jsenvPluginUrlAnalysis({
17080
17081
  rootDirectoryUrl,
17081
17082
  ...urlAnalysis
17082
- }), jsenvPluginTranspilation(transpilation), ...(htmlSupervisor ? [jsenvPluginHtmlSupervisor(htmlSupervisor)] : []), // before inline as it turns inline <script> into <script src>
17083
+ }), jsenvPluginTranspilation(transpilation), ...(supervisor ? [jsenvPluginSupervisor(supervisor)] : []), // before inline as it turns inline <script> into <script src>
17083
17084
  jsenvPluginImportmap(), // before node esm to handle bare specifiers
17084
17085
  // + before node esm to handle importmap before inline content
17085
17086
  jsenvPluginInline(), // before "file urls" to resolve and load inline urls
@@ -19800,7 +19801,7 @@ const startServer = async ({
19800
19801
  const websocketClients = new Set();
19801
19802
  const {
19802
19803
  WebSocketServer
19803
- } = await import("./js/wrapper.mjs");
19804
+ } = await import("./js/ws.js");
19804
19805
  let websocketServer = new WebSocketServer({
19805
19806
  noServer: true
19806
19807
  });
@@ -21357,6 +21358,10 @@ const createUrlInfoTransformer = ({
21357
21358
 
21358
21359
  if (!SOURCEMAP.enabledOnContentType(urlInfo.contentType)) {
21359
21360
  return;
21361
+ }
21362
+
21363
+ if (urlInfo.generatedUrl.startsWith("data:")) {
21364
+ return;
21360
21365
  } // sourcemap is a special kind of reference:
21361
21366
  // It's a reference to a content generated dynamically the content itself.
21362
21367
  // For this reason sourcemap are not added to urlInfo.references
@@ -21463,7 +21468,7 @@ const createUrlInfoTransformer = ({
21463
21468
  await applyIntermediateTransformations(urlInfo, transformations);
21464
21469
  }
21465
21470
 
21466
- if (sourcemapsEnabled && urlInfo.sourcemap) {
21471
+ if (sourcemapsEnabled && urlInfo.sourcemap && !urlInfo.generatedUrl.startsWith("data:")) {
21467
21472
  // during build this function can be called after the file is cooked
21468
21473
  // - to update content and sourcemap after "optimize" hook
21469
21474
  // - to inject versioning into the entry point content
@@ -21953,6 +21958,7 @@ const createKitchen = ({
21953
21958
  isInline = false,
21954
21959
  injected = false,
21955
21960
  isResourceHint = false,
21961
+ dependsOnPackageJson,
21956
21962
  content,
21957
21963
  contentType,
21958
21964
  assert,
@@ -21991,6 +21997,7 @@ const createKitchen = ({
21991
21997
  isInline,
21992
21998
  injected,
21993
21999
  isResourceHint,
22000
+ dependsOnPackageJson,
21994
22001
  // for inline resources the reference contains the content
21995
22002
  content,
21996
22003
  contentType,
@@ -22007,9 +22014,9 @@ const createKitchen = ({
22007
22014
  newReference.original = reference.original || reference; // newReference.isEntryPoint = reference.isEntryPoint
22008
22015
  };
22009
22016
 
22010
- const resolveReference = reference => {
22017
+ const resolveReference = (reference, context = kitchenContext) => {
22011
22018
  try {
22012
- let resolvedUrl = pluginController.callHooksUntil("resolveUrl", reference, kitchenContext);
22019
+ let resolvedUrl = pluginController.callHooksUntil("resolveUrl", reference, context);
22013
22020
 
22014
22021
  if (!resolvedUrl) {
22015
22022
  throw new Error(`NO_RESOLVE`);
@@ -22017,7 +22024,7 @@ const createKitchen = ({
22017
22024
 
22018
22025
  resolvedUrl = normalizeUrl(resolvedUrl);
22019
22026
  reference.url = resolvedUrl;
22020
- pluginController.callHooks("redirectUrl", reference, kitchenContext, returnValue => {
22027
+ pluginController.callHooks("redirectUrl", reference, context, returnValue => {
22021
22028
  const normalizedReturnValue = normalizeUrl(returnValue);
22022
22029
 
22023
22030
  if (normalizedReturnValue === reference.url) {
@@ -22038,20 +22045,20 @@ const createKitchen = ({
22038
22045
  }
22039
22046
 
22040
22047
  const urlInfo = urlGraph.reuseOrCreateUrlInfo(reference.url);
22041
- applyReferenceEffectsOnUrlInfo(reference, urlInfo, kitchenContext); // This hook must touch reference.generatedUrl, NOT reference.url
22048
+ applyReferenceEffectsOnUrlInfo(reference, urlInfo, context); // This hook must touch reference.generatedUrl, NOT reference.url
22042
22049
  // And this is because this hook inject query params used to:
22043
22050
  // - bypass browser cache (?v)
22044
22051
  // - convey information (?hmr)
22045
22052
  // But do not represent an other resource, it is considered as
22046
22053
  // the same resource under the hood
22047
22054
 
22048
- pluginController.callHooks("transformUrlSearchParams", reference, kitchenContext, returnValue => {
22055
+ pluginController.callHooks("transformUrlSearchParams", reference, context, returnValue => {
22049
22056
  Object.keys(returnValue).forEach(key => {
22050
22057
  referenceUrlObject.searchParams.set(key, returnValue[key]);
22051
22058
  });
22052
22059
  reference.generatedUrl = normalizeUrl(referenceUrlObject.href);
22053
22060
  });
22054
- const returnValue = pluginController.callHooksUntil("formatUrl", reference, kitchenContext);
22061
+ const returnValue = pluginController.callHooksUntil("formatUrl", reference, context);
22055
22062
  reference.generatedSpecifier = returnValue || reference.generatedUrl;
22056
22063
  reference.generatedSpecifier = urlSpecifierEncoding.encode(reference);
22057
22064
  return urlInfo;
@@ -22248,7 +22255,7 @@ const createKitchen = ({
22248
22255
  ...props
22249
22256
  });
22250
22257
  references.push(reference);
22251
- const referencedUrlInfo = resolveReference(reference);
22258
+ const referencedUrlInfo = resolveReference(reference, context);
22252
22259
  return [reference, referencedUrlInfo];
22253
22260
  };
22254
22261
 
@@ -22323,7 +22330,7 @@ const createKitchen = ({
22323
22330
  });
22324
22331
  references[index] = nextReference;
22325
22332
  mutateReference(previousReference, nextReference);
22326
- const newUrlInfo = resolveReference(nextReference);
22333
+ const newUrlInfo = resolveReference(nextReference, context);
22327
22334
  const currentUrlInfo = context.urlGraph.getUrlInfo(currentReference.url);
22328
22335
 
22329
22336
  if (currentUrlInfo && currentUrlInfo !== newUrlInfo && currentUrlInfo.dependents.size === 0) {
@@ -22519,7 +22526,8 @@ const createKitchen = ({
22519
22526
  reference: originalReference
22520
22527
  });
22521
22528
 
22522
- if (originalUrlInfo.dependents.size === 0) {
22529
+ if (originalUrlInfo.dependents.size === 0 // && context.scenarios.build
22530
+ ) {
22523
22531
  context.urlGraph.deleteUrlInfo(originalUrlInfo.url);
22524
22532
  }
22525
22533
 
@@ -22623,6 +22631,21 @@ const applyReferenceEffectsOnUrlInfo = (reference, urlInfo, context) => {
22623
22631
  urlInfo.originalContent = context.scenarios.build ? urlInfo.originalContent === undefined ? reference.content : urlInfo.originalContent : reference.content;
22624
22632
  urlInfo.content = reference.content;
22625
22633
  }
22634
+
22635
+ const {
22636
+ dependsOnPackageJson
22637
+ } = reference;
22638
+ urlInfo.dependsOnPackageJson = dependsOnPackageJson;
22639
+ const relatedUrlInfos = context.urlGraph.getRelatedUrlInfos(reference.parentUrl);
22640
+ relatedUrlInfos.forEach(relatedUrlInfo => {
22641
+ if (relatedUrlInfo.dependsOnPackageJson) {
22642
+ // the url may depend due to an other reference
22643
+ // in that case keep dependsOnPackageJson to true
22644
+ return;
22645
+ }
22646
+
22647
+ relatedUrlInfo.dependsOnPackageJson = dependsOnPackageJson;
22648
+ });
22626
22649
  };
22627
22650
 
22628
22651
  const adjustUrlSite = (urlInfo, {
@@ -23362,12 +23385,11 @@ const injectors = {
23362
23385
  storeOriginalPositions: false
23363
23386
  });
23364
23387
  injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
23365
- "tagName": "script",
23366
- "textContent": generateClientCodeForVersionMappings(versionMappings, {
23388
+ tagName: "script",
23389
+ textContent: generateClientCodeForVersionMappings(versionMappings, {
23367
23390
  globalName: "window"
23368
- }),
23369
- "injected-by": "jsenv:versioning"
23370
- }));
23391
+ })
23392
+ }), "jsenv:versioning");
23371
23393
  return {
23372
23394
  content: stringifyHtmlAst(htmlAst)
23373
23395
  };
@@ -25024,11 +25046,10 @@ const jsenvPluginServerEventsClientInjection = () => {
25024
25046
  specifier: serverEventsClientFileUrl
25025
25047
  });
25026
25048
  injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
25027
- "tagName": "script",
25028
- "type": "module",
25029
- "src": serverEventsClientFileReference.generatedSpecifier,
25030
- "injected-by": "jsenv:server_events"
25031
- }));
25049
+ tagName: "script",
25050
+ type: "module",
25051
+ src: serverEventsClientFileReference.generatedSpecifier
25052
+ }), "jsenv:server_events");
25032
25053
  const htmlModified = stringifyHtmlAst(htmlAst);
25033
25054
  return {
25034
25055
  content: htmlModified
@@ -25074,7 +25095,7 @@ const createFileService = ({
25074
25095
  runtimeCompat,
25075
25096
  plugins,
25076
25097
  urlAnalysis,
25077
- htmlSupervisor,
25098
+ supervisor,
25078
25099
  nodeEsmResolution,
25079
25100
  fileSystemMagicResolution,
25080
25101
  transpilation,
@@ -25188,7 +25209,7 @@ const createFileService = ({
25188
25209
  rootDirectoryUrl,
25189
25210
  runtimeCompat,
25190
25211
  urlAnalysis,
25191
- htmlSupervisor,
25212
+ supervisor,
25192
25213
  nodeEsmResolution,
25193
25214
  fileSystemMagicResolution,
25194
25215
  transpilation,
@@ -25467,7 +25488,7 @@ const startOmegaServer = async ({
25467
25488
  runtimeCompat,
25468
25489
  plugins,
25469
25490
  urlAnalysis,
25470
- htmlSupervisor,
25491
+ supervisor,
25471
25492
  nodeEsmResolution,
25472
25493
  fileSystemMagicResolution,
25473
25494
  transpilation,
@@ -25520,7 +25541,7 @@ const startOmegaServer = async ({
25520
25541
  runtimeCompat,
25521
25542
  plugins,
25522
25543
  urlAnalysis,
25523
- htmlSupervisor,
25544
+ supervisor,
25524
25545
  nodeEsmResolution,
25525
25546
  fileSystemMagicResolution,
25526
25547
  transpilation,
@@ -25628,7 +25649,7 @@ const startDevServer = async ({
25628
25649
  runtimeCompat = defaultRuntimeCompat,
25629
25650
  plugins = [],
25630
25651
  urlAnalysis = {},
25631
- htmlSupervisor = true,
25652
+ supervisor = true,
25632
25653
  nodeEsmResolution,
25633
25654
  fileSystemMagicResolution,
25634
25655
  transpilation,
@@ -25754,7 +25775,7 @@ const startDevServer = async ({
25754
25775
  runtimeCompat,
25755
25776
  plugins,
25756
25777
  urlAnalysis,
25757
- htmlSupervisor,
25778
+ supervisor,
25758
25779
  nodeEsmResolution,
25759
25780
  fileSystemMagicResolution,
25760
25781
  transpilation,
@@ -26149,9 +26170,7 @@ const relativeUrlToEmptyCoverage = async (relativeUrl, {
26149
26170
  const {
26150
26171
  metadata
26151
26172
  } = await applyBabelPlugins({
26152
- babelPlugins: [[babelPluginInstrument, {
26153
- rootDirectoryUrl
26154
- }]],
26173
+ babelPlugins: [babelPluginInstrument],
26155
26174
  urlInfo: {
26156
26175
  originalUrl: fileUrl,
26157
26176
  content
@@ -26386,7 +26405,11 @@ const run = async ({
26386
26405
  runtime,
26387
26406
  runtimeParams
26388
26407
  }) => {
26389
- const result = {};
26408
+ const result = {
26409
+ status: "pending",
26410
+ errors: [],
26411
+ namespace: null
26412
+ };
26390
26413
  const callbacks = [];
26391
26414
  const onConsoleRef = {
26392
26415
  current: () => {}
@@ -26397,25 +26420,14 @@ const run = async ({
26397
26420
  const runtimeLabel = `${runtime.name}/${runtime.version}`;
26398
26421
  const runOperation = Abort.startOperation();
26399
26422
  runOperation.addAbortSignal(signal);
26423
+ let timeoutAbortSource;
26400
26424
 
26401
26425
  if ( // ideally we would rather log than the timeout is ignored
26402
26426
  // when keepRunning is true
26403
26427
  !keepRunning && typeof allocatedMs === "number" && allocatedMs !== Infinity) {
26404
- const timeoutAbortSource = runOperation.timeout(allocatedMs);
26405
- callbacks.push(() => {
26406
- if (result.status === "errored" && Abort.isAbortError(result.error) && timeoutAbortSource.signal.aborted) {
26407
- result.status = "timedout";
26408
- delete result.error;
26409
- }
26410
- });
26428
+ timeoutAbortSource = runOperation.timeout(allocatedMs);
26411
26429
  }
26412
26430
 
26413
- callbacks.push(() => {
26414
- if (result.status === "errored" && Abort.isAbortError(result.error)) {
26415
- result.status = "aborted";
26416
- delete result.error;
26417
- }
26418
- });
26419
26431
  const consoleCalls = [];
26420
26432
 
26421
26433
  onConsoleRef.current = ({
@@ -26439,9 +26451,7 @@ const run = async ({
26439
26451
  };
26440
26452
 
26441
26453
  if (collectConsole) {
26442
- callbacks.push(() => {
26443
- result.consoleCalls = consoleCalls;
26444
- });
26454
+ result.consoleCalls = consoleCalls;
26445
26455
  } // we do not keep coverage in memory, it can grow very big
26446
26456
  // instead we store it on the filesystem
26447
26457
  // and they can be read later at "coverageFileUrl"
@@ -26508,35 +26518,35 @@ const run = async ({
26508
26518
  const {
26509
26519
  status,
26510
26520
  namespace,
26511
- error,
26521
+ errors,
26512
26522
  performance
26513
26523
  } = winner.data;
26514
26524
  result.status = status;
26515
-
26516
- if (status === "errored") {
26517
- result.error = error;
26518
- } else {
26519
- result.namespace = namespace;
26520
- }
26525
+ result.errors.push(...errors);
26526
+ result.namespace = namespace;
26521
26527
 
26522
26528
  if (collectPerformance) {
26523
26529
  result.performance = performance;
26524
26530
  }
26525
-
26526
- callbacks.forEach(callback => {
26527
- callback();
26528
- });
26529
- return result;
26530
26531
  } catch (e) {
26531
- result.status = "errored";
26532
- result.error = e;
26533
- callbacks.forEach(callback => {
26534
- callback();
26535
- });
26536
- return result;
26532
+ if (Abort.isAbortError(e)) {
26533
+ if (timeoutAbortSource && timeoutAbortSource.signal.aborted) {
26534
+ result.status = "timedout";
26535
+ } else {
26536
+ result.status = "aborted";
26537
+ }
26538
+ } else {
26539
+ result.status = "errored";
26540
+ result.errors.push(e);
26541
+ }
26537
26542
  } finally {
26538
26543
  await runOperation.end();
26539
26544
  }
26545
+
26546
+ callbacks.forEach(callback => {
26547
+ callback();
26548
+ });
26549
+ return result;
26540
26550
  };
26541
26551
 
26542
26552
  const pingServer = async url => {
@@ -26685,9 +26695,10 @@ const createExecutionLog = ({
26685
26695
 
26686
26696
  const {
26687
26697
  consoleCalls = [],
26688
- error
26698
+ errors = []
26689
26699
  } = executionResult;
26690
26700
  const consoleOutput = formatConsoleCalls(consoleCalls);
26701
+ const errorsOutput = formatErrors(errors);
26691
26702
  return formatExecution({
26692
26703
  label: `${description}${summary}`,
26693
26704
  details: {
@@ -26697,14 +26708,39 @@ const createExecutionLog = ({
26697
26708
  } : {}),
26698
26709
  ...(logEachDuration ? {
26699
26710
  duration: status === "executing" ? msAsEllapsedTime(Date.now() - startMs) : msAsDuration(endMs - startMs)
26700
- } : {}),
26701
- ...(error ? {
26702
- error: error.stack || error.message || error
26703
26711
  } : {})
26704
26712
  },
26705
- consoleOutput
26713
+ consoleOutput,
26714
+ errorsOutput
26715
+ });
26716
+ };
26717
+
26718
+ const formatErrors = errors => {
26719
+ if (errors.length === 0) {
26720
+ return "";
26721
+ }
26722
+
26723
+ const formatError = error => error.stack || error.message || error;
26724
+
26725
+ if (errors.length === 1) {
26726
+ return `${ANSI.color(`-------- error --------`, ANSI.RED)}
26727
+ ${formatError(errors[0])}
26728
+ ${ANSI.color(`-------------------------`, ANSI.RED)}`;
26729
+ }
26730
+
26731
+ let output = [];
26732
+ errors.forEach(error => {
26733
+ output.push(prefixFirstAndIndentRemainingLines({
26734
+ prefix: `${UNICODE.CIRCLE_CROSS} `,
26735
+ indentation: " ",
26736
+ text: formatError(error)
26737
+ }));
26706
26738
  });
26739
+ return `${ANSI.color(`-------- errors (${errors.length}) --------`, ANSI.RED)}
26740
+ ${output.join(`\n`)}
26741
+ ${ANSI.color(`-------------------------`, ANSI.RED)}`;
26707
26742
  };
26743
+
26708
26744
  const createSummaryLog = summary => `-------------- summary -----------------
26709
26745
  ${createAllExecutionsSummary(summary)}
26710
26746
  total duration: ${msAsDuration(summary.duration)}
@@ -26909,6 +26945,7 @@ const formatConsoleOutput = consoleCalls => {
26909
26945
  const textFormatted = prefixFirstAndIndentRemainingLines({
26910
26946
  prefix: CONSOLE_ICONS[regroupedCall.type],
26911
26947
  text,
26948
+ trimLines: true,
26912
26949
  trimLastLine: index === regroupedCalls.length - 1
26913
26950
  });
26914
26951
  consoleOutput += textFormatted;
@@ -26918,17 +26955,18 @@ const formatConsoleOutput = consoleCalls => {
26918
26955
 
26919
26956
  const prefixFirstAndIndentRemainingLines = ({
26920
26957
  prefix,
26958
+ indentation = " ",
26921
26959
  text,
26960
+ trimLines,
26922
26961
  trimLastLine
26923
26962
  }) => {
26924
26963
  const lines = text.split(/\r?\n/);
26925
26964
  const firstLine = lines.shift();
26926
26965
  let result = `${prefix} ${firstLine}`;
26927
26966
  let i = 0;
26928
- const indentation = ` `;
26929
26967
 
26930
26968
  while (i < lines.length) {
26931
- const line = lines[i].trim();
26969
+ const line = trimLines ? lines[i].trim() : lines[i];
26932
26970
  i++;
26933
26971
  result += line.length ? `\n${indentation}${line}` : trimLastLine && i === lines.length ? "" : `\n`;
26934
26972
  }
@@ -26979,7 +27017,8 @@ const formatConsoleSummary = repartition => {
26979
27017
  const formatExecution = ({
26980
27018
  label,
26981
27019
  details = {},
26982
- consoleOutput
27020
+ consoleOutput,
27021
+ errorsOutput
26983
27022
  }) => {
26984
27023
  let message = ``;
26985
27024
  message += label;
@@ -26989,8 +27028,11 @@ ${key}: ${details[key]}`;
26989
27028
  });
26990
27029
 
26991
27030
  if (consoleOutput) {
26992
- message += `
26993
- ${consoleOutput}`;
27031
+ message += `\n${consoleOutput}`;
27032
+ }
27033
+
27034
+ if (errorsOutput) {
27035
+ message += `\n${errorsOutput}`;
26994
27036
  }
26995
27037
 
26996
27038
  return message;
@@ -27000,6 +27042,7 @@ const executePlan = async (plan, {
27000
27042
  signal,
27001
27043
  handleSIGINT,
27002
27044
  logger,
27045
+ logRefresh,
27003
27046
  logRuntime,
27004
27047
  logEachDuration,
27005
27048
  logSummary,
@@ -27172,7 +27215,7 @@ const executePlan = async (plan, {
27172
27215
 
27173
27216
  const debugLogsEnabled = loggerToLevels(logger).debug;
27174
27217
  const executionLogsEnabled = loggerToLevels(logger).info;
27175
- const executionSpinner = !debugLogsEnabled && executionLogsEnabled && process.stdout.isTTY && // if there is an error during execution npm will mess up the output
27218
+ const executionSpinner = logRefresh && !debugLogsEnabled && executionLogsEnabled && process.stdout.isTTY && // if there is an error during execution npm will mess up the output
27176
27219
  // (happens when npm runs several command in a workspace)
27177
27220
  // so we enable spinner only when !process.exitCode (no error so far)
27178
27221
  process.exitCode !== 1;
@@ -27272,7 +27315,7 @@ const executePlan = async (plan, {
27272
27315
  } else {
27273
27316
  executionResult = {
27274
27317
  status: "errored",
27275
- error: new Error(`No file at ${fileRelativeUrl} for execution "${executionName}"`)
27318
+ errors: [new Error(`No file at ${fileRelativeUrl} for execution "${executionName}"`)]
27276
27319
  };
27277
27320
  }
27278
27321
 
@@ -27518,6 +27561,7 @@ const executeTestPlan = async ({
27518
27561
  signal = new AbortController().signal,
27519
27562
  handleSIGINT = true,
27520
27563
  logLevel = "info",
27564
+ logRefresh = true,
27521
27565
  logRuntime = true,
27522
27566
  logEachDuration = true,
27523
27567
  logSummary = true,
@@ -27608,7 +27652,7 @@ const executeTestPlan = async ({
27608
27652
  signal,
27609
27653
  handleSIGINT,
27610
27654
  logger,
27611
- logLevel,
27655
+ logRefresh,
27612
27656
  logSummary,
27613
27657
  logRuntime,
27614
27658
  logEachDuration,
@@ -27690,54 +27734,6 @@ const executeTestPlan = async ({
27690
27734
  };
27691
27735
  };
27692
27736
 
27693
- const escapeChars = (string, replacements) => {
27694
- const charsToEscape = Object.keys(replacements);
27695
- let result = "";
27696
- let last = 0;
27697
- let i = 0;
27698
-
27699
- while (i < string.length) {
27700
- const char = string[i];
27701
- i++;
27702
-
27703
- if (charsToEscape.includes(char) && !isEscaped(i - 1, string)) {
27704
- if (last === i - 1) {
27705
- result += replacements[char];
27706
- } else {
27707
- result += `${string.slice(last, i - 1)}${replacements[char]}`;
27708
- }
27709
-
27710
- last = i;
27711
- }
27712
- }
27713
-
27714
- if (last !== string.length) {
27715
- result += string.slice(last);
27716
- }
27717
-
27718
- return result;
27719
- };
27720
-
27721
- const escapeRegexpSpecialChars = string => {
27722
- return escapeChars(String(string), {
27723
- "/": "\\/",
27724
- "^": "\\^",
27725
- "\\": "\\\\",
27726
- "[": "\\[",
27727
- "]": "\\]",
27728
- "(": "\\(",
27729
- ")": "\\)",
27730
- "{": "\\{",
27731
- "}": "\\}",
27732
- "?": "\\?",
27733
- "+": "\\+",
27734
- "*": "\\*",
27735
- ".": "\\.",
27736
- "|": "\\|",
27737
- "$": "\\$"
27738
- });
27739
- };
27740
-
27741
27737
  const createRuntimeFromPlaywright = ({
27742
27738
  browserName,
27743
27739
  browserVersion,
@@ -27853,7 +27849,11 @@ const createRuntimeFromPlaywright = ({
27853
27849
  }
27854
27850
  };
27855
27851
 
27856
- const result = {};
27852
+ const result = {
27853
+ status: "pending",
27854
+ namespace: null,
27855
+ errors: []
27856
+ };
27857
27857
  const callbacks = [];
27858
27858
 
27859
27859
  if (coverageEnabled) {
@@ -27975,19 +27975,18 @@ const createRuntimeFromPlaywright = ({
27975
27975
  });
27976
27976
  },
27977
27977
  // https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-pageerror
27978
- pageerror: cb => {
27979
- return registerEvent({
27980
- object: page,
27981
- eventType: "pageerror",
27982
- callback: error => {
27983
- if (ignoreErrorHook(error)) {
27984
- return;
27985
- }
27986
-
27987
- cb(transformErrorHook(error));
27988
- }
27989
- });
27990
- },
27978
+ // pageerror: () => {
27979
+ // return registerEvent({
27980
+ // object: page,
27981
+ // eventType: "pageerror",
27982
+ // callback: (error) => {
27983
+ // if (ignoreErrorHook(error)) {
27984
+ // return
27985
+ // }
27986
+ // result.errors.push(transformErrorHook(error))
27987
+ // },
27988
+ // })
27989
+ // },
27991
27990
  closed: cb => {
27992
27991
  // https://github.com/GoogleChrome/puppeteer/blob/v1.4.0/docs/api.md#event-disconnected
27993
27992
  if (isBrowserDedicatedToExecution) {
@@ -28033,39 +28032,15 @@ const createRuntimeFromPlaywright = ({
28033
28032
 
28034
28033
  /* istanbul ignore next */
28035
28034
  () => {
28036
- if (!window.__html_supervisor__) {
28037
- throw new Error(`window.__html_supervisor__ not found`);
28035
+ if (!window.__supervisor__) {
28036
+ throw new Error(`window.__supervisor__ not found`);
28038
28037
  }
28039
28038
 
28040
- return window.__html_supervisor__.getScriptExecutionResults();
28039
+ return window.__supervisor__.getScriptExecutionResults();
28041
28040
  }
28042
28041
  /* eslint-enable no-undef */
28043
28042
  );
28044
- const {
28045
- status,
28046
- scriptExecutionResults
28047
- } = returnValue;
28048
-
28049
- if (status === "errored") {
28050
- const {
28051
- exceptionSource
28052
- } = returnValue;
28053
- const error = evalException(exceptionSource, {
28054
- rootDirectoryUrl,
28055
- devServerOrigin,
28056
- transformErrorHook
28057
- });
28058
- cb({
28059
- status: "errored",
28060
- error,
28061
- namespace: scriptExecutionResults
28062
- });
28063
- } else {
28064
- cb({
28065
- status: "completed",
28066
- namespace: scriptExecutionResults
28067
- });
28068
- }
28043
+ cb(returnValue);
28069
28044
  } catch (e) {
28070
28045
  reject(e);
28071
28046
  }
@@ -28073,47 +28048,48 @@ const createRuntimeFromPlaywright = ({
28073
28048
  }, resolve);
28074
28049
  });
28075
28050
 
28076
- const getResult = async () => {
28051
+ const writeResult = async () => {
28077
28052
  const winner = await winnerPromise;
28078
28053
 
28079
28054
  if (winner.name === "aborted") {
28080
- return {
28081
- status: "aborted"
28082
- };
28055
+ result.status = "aborted";
28056
+ return;
28083
28057
  }
28084
28058
 
28085
- if (winner.name === "error" || winner.name === "pageerror") {
28086
- const error = winner.data;
28087
- return {
28088
- status: "errored",
28089
- error
28090
- };
28059
+ if (winner.name === "error") {
28060
+ let error = winner.data;
28061
+ result.status = "errored";
28062
+ result.errors.push(error);
28063
+ return;
28091
28064
  }
28092
28065
 
28093
28066
  if (winner.name === "closed") {
28094
- return {
28095
- status: "errored",
28096
- error: isBrowserDedicatedToExecution ? new Error(`browser disconnected during execution`) : new Error(`page closed during execution`)
28097
- };
28098
- }
28067
+ result.status = "errored";
28068
+ result.errors.push(isBrowserDedicatedToExecution ? new Error(`browser disconnected during execution`) : new Error(`page closed during execution`));
28069
+ return;
28070
+ } // winner.name = 'response'
28099
28071
 
28100
- return winner.data;
28072
+
28073
+ const {
28074
+ executionResults
28075
+ } = winner.data;
28076
+ result.status = "completed";
28077
+ result.namespace = executionResults;
28078
+ Object.keys(executionResults).forEach(key => {
28079
+ const executionResult = executionResults[key];
28080
+
28081
+ if (executionResult.status === "errored") {
28082
+ result.status = "errored";
28083
+ result.errors.push({ ...executionResult.exception,
28084
+ stack: executionResult.exception.text
28085
+ });
28086
+ }
28087
+ });
28088
+ return;
28101
28089
  };
28102
28090
 
28103
28091
  try {
28104
- const {
28105
- status,
28106
- error,
28107
- namespace,
28108
- performance
28109
- } = await getResult();
28110
- result.status = status;
28111
-
28112
- if (status === "errored") {
28113
- result.error = error;
28114
- } else {
28115
- result.namespace = namespace;
28116
- }
28092
+ await writeResult();
28117
28093
 
28118
28094
  if (collectPerformance) {
28119
28095
  result.performance = performance;
@@ -28125,7 +28101,7 @@ const createRuntimeFromPlaywright = ({
28125
28101
  }, Promise.resolve());
28126
28102
  } catch (e) {
28127
28103
  result.status = "errored";
28128
- result.error = e;
28104
+ result.errors = [e];
28129
28105
  }
28130
28106
 
28131
28107
  if (keepRunning) {
@@ -28286,25 +28262,6 @@ const registerEvent = ({
28286
28262
  };
28287
28263
  };
28288
28264
 
28289
- const evalException = (exceptionSource, {
28290
- rootDirectoryUrl,
28291
- devServerOrigin,
28292
- transformErrorHook
28293
- }) => {
28294
- const script = new Script(exceptionSource, {
28295
- filename: ""
28296
- });
28297
- const error = script.runInThisContext();
28298
-
28299
- if (error && error instanceof Error) {
28300
- const remoteRootRegexp = new RegExp(escapeRegexpSpecialChars(`${devServerOrigin}/`), "g");
28301
- error.stack = error.stack.replace(remoteRootRegexp, rootDirectoryUrl);
28302
- error.message = error.message.replace(remoteRootRegexp, rootDirectoryUrl);
28303
- }
28304
-
28305
- return transformErrorHook(error);
28306
- };
28307
-
28308
28265
  const chromium = createRuntimeFromPlaywright({
28309
28266
  browserName: "chromium",
28310
28267
  browserVersion: "104.0.5112.48",
@@ -28800,8 +28757,13 @@ nodeChildProcess.run = async ({
28800
28757
  }
28801
28758
  }, resolve);
28802
28759
  });
28760
+ const result = {
28761
+ status: "executing",
28762
+ errors: [],
28763
+ namespace: null
28764
+ };
28803
28765
 
28804
- const getResult = async () => {
28766
+ const writeResult = async () => {
28805
28767
  actionOperation.throwIfAborted();
28806
28768
  await childProcessReadyPromise;
28807
28769
  actionOperation.throwIfAborted();
@@ -28824,18 +28786,16 @@ nodeChildProcess.run = async ({
28824
28786
  const winner = await winnerPromise;
28825
28787
 
28826
28788
  if (winner.name === "aborted") {
28827
- return {
28828
- status: "aborted"
28829
- };
28789
+ result.status = "aborted";
28790
+ return;
28830
28791
  }
28831
28792
 
28832
28793
  if (winner.name === "error") {
28833
28794
  const error = winner.data;
28834
28795
  removeOutputListener();
28835
- return {
28836
- status: "errored",
28837
- error
28838
- };
28796
+ result.status = "errored";
28797
+ result.errors.push(error);
28798
+ return;
28839
28799
  }
28840
28800
 
28841
28801
  if (winner.name === "exit") {
@@ -28845,25 +28805,22 @@ nodeChildProcess.run = async ({
28845
28805
  await cleanup("process exit");
28846
28806
 
28847
28807
  if (code === 12) {
28848
- return {
28849
- status: "errored",
28850
- error: new Error(`node process exited with 12 (the forked child process wanted to use a non-available port for debug)`)
28851
- };
28808
+ result.status = "errored";
28809
+ result.errors.push(new Error(`node process exited with 12 (the forked child process wanted to use a non-available port for debug)`));
28810
+ return;
28852
28811
  }
28853
28812
 
28854
28813
  if (code === null || code === 0 || code === EXIT_CODES.SIGINT || code === EXIT_CODES.SIGTERM || code === EXIT_CODES.SIGABORT) {
28855
- return {
28856
- status: "errored",
28857
- error: new Error(`node process exited during execution`)
28858
- };
28814
+ result.status = "errored";
28815
+ result.errors.push(new Error(`node process exited during execution`));
28816
+ return;
28859
28817
  } // process.exit(1) in child process or process.exitCode = 1 + process.exit()
28860
28818
  // means there was an error even if we don't know exactly what.
28861
28819
 
28862
28820
 
28863
- return {
28864
- status: "errored",
28865
- error: new Error(`node process exited with code ${code} during execution`)
28866
- };
28821
+ result.status = "errored";
28822
+ result.errors.push(new Error(`node process exited with code ${code} during execution`));
28823
+ return;
28867
28824
  }
28868
28825
 
28869
28826
  const {
@@ -28872,27 +28829,27 @@ nodeChildProcess.run = async ({
28872
28829
  } = winner.data;
28873
28830
 
28874
28831
  if (status === "action-failed") {
28875
- return {
28876
- status: "errored",
28877
- error: value
28878
- };
28832
+ result.status = "errored";
28833
+ result.errors.push(value);
28834
+ return;
28879
28835
  }
28880
28836
 
28881
- return {
28882
- status: "completed",
28883
- ...value
28884
- };
28837
+ const {
28838
+ namespace,
28839
+ performance,
28840
+ coverage
28841
+ } = value;
28842
+ result.status = "completed";
28843
+ result.namespace = namespace;
28844
+ result.performance = performance;
28845
+ result.coverage = coverage;
28885
28846
  };
28886
28847
 
28887
- let result;
28888
-
28889
28848
  try {
28890
- result = await getResult();
28849
+ await writeResult();
28891
28850
  } catch (e) {
28892
- result = {
28893
- status: "errored",
28894
- error: e
28895
- };
28851
+ result.status = "errored";
28852
+ result.errors.push(e);
28896
28853
  }
28897
28854
 
28898
28855
  if (keepRunning) {
@@ -29099,8 +29056,13 @@ nodeWorkerThread.run = async ({
29099
29056
  }
29100
29057
  }, resolve);
29101
29058
  });
29059
+ const result = {
29060
+ status: "executing",
29061
+ errors: [],
29062
+ namespace: null
29063
+ };
29102
29064
 
29103
- const getResult = async () => {
29065
+ const writeResult = async () => {
29104
29066
  actionOperation.throwIfAborted();
29105
29067
  await workerThreadReadyPromise;
29106
29068
  actionOperation.throwIfAborted();
@@ -29123,18 +29085,16 @@ nodeWorkerThread.run = async ({
29123
29085
  const winner = await winnerPromise;
29124
29086
 
29125
29087
  if (winner.name === "aborted") {
29126
- return {
29127
- status: "aborted"
29128
- };
29088
+ result.status = "aborted";
29089
+ return;
29129
29090
  }
29130
29091
 
29131
29092
  if (winner.name === "error") {
29132
29093
  const error = winner.data;
29133
29094
  removeOutputListener();
29134
- return {
29135
- status: "errored",
29136
- error
29137
- };
29095
+ result.status = "errored";
29096
+ result.errors.push(error);
29097
+ return;
29138
29098
  }
29139
29099
 
29140
29100
  if (winner.name === "exit") {
@@ -29144,25 +29104,21 @@ nodeWorkerThread.run = async ({
29144
29104
  await cleanup("process exit");
29145
29105
 
29146
29106
  if (code === 12) {
29147
- return {
29148
- status: "errored",
29149
- error: new Error(`node process exited with 12 (the forked child process wanted to use a non-available port for debug)`)
29150
- };
29107
+ result.status = "errored";
29108
+ result.errors.push(new Error(`node process exited with 12 (the forked child process wanted to use a non-available port for debug)`));
29109
+ return;
29151
29110
  }
29152
29111
 
29153
29112
  if (code === null || code === 0 || code === EXIT_CODES.SIGINT || code === EXIT_CODES.SIGTERM || code === EXIT_CODES.SIGABORT) {
29154
- return {
29155
- status: "errored",
29156
- error: new Error(`node worker thread exited during execution`)
29157
- };
29113
+ result.status = "errored";
29114
+ result.errors.push(new Error(`node worker thread exited during execution`));
29115
+ return;
29158
29116
  } // process.exit(1) in child process or process.exitCode = 1 + process.exit()
29159
29117
  // means there was an error even if we don't know exactly what.
29160
29118
 
29161
29119
 
29162
- return {
29163
- status: "errored",
29164
- error: new Error(`node worker thread exited with code ${code} during execution`)
29165
- };
29120
+ result.status = "errored";
29121
+ result.errors.push(new Error(`node worker thread exited with code ${code} during execution`));
29166
29122
  }
29167
29123
 
29168
29124
  const {
@@ -29171,10 +29127,9 @@ nodeWorkerThread.run = async ({
29171
29127
  } = winner.data;
29172
29128
 
29173
29129
  if (status === "action-failed") {
29174
- return {
29175
- status: "errored",
29176
- error: value
29177
- };
29130
+ result.status = "errored";
29131
+ result.errors.push(value);
29132
+ return;
29178
29133
  }
29179
29134
 
29180
29135
  const {
@@ -29182,23 +29137,17 @@ nodeWorkerThread.run = async ({
29182
29137
  performance,
29183
29138
  coverage
29184
29139
  } = value;
29185
- return {
29186
- status: "completed",
29187
- namespace,
29188
- performance,
29189
- coverage
29190
- };
29140
+ result.status = "completed";
29141
+ result.namespace = namespace;
29142
+ result.performance = performance;
29143
+ result.coverage = coverage;
29191
29144
  };
29192
29145
 
29193
- let result;
29194
-
29195
29146
  try {
29196
- result = await getResult();
29147
+ await writeResult();
29197
29148
  } catch (e) {
29198
- result = {
29199
- status: "errored",
29200
- error: e
29201
- };
29149
+ result.status = "errored";
29150
+ result.errors.push(e);
29202
29151
  }
29203
29152
 
29204
29153
  if (keepRunning) {
@@ -29585,7 +29534,7 @@ const execute = async ({
29585
29534
  */
29586
29535
 
29587
29536
 
29588
- throw result.error;
29537
+ throw result.errors[result.errors.length - 1];
29589
29538
  }
29590
29539
 
29591
29540
  return result;
@@ -29618,10 +29567,9 @@ const globalInjectorOnHtml = async (urlInfo, globals) => {
29618
29567
  isWebWorker: false
29619
29568
  });
29620
29569
  injectScriptNodeAsEarlyAsPossible(htmlAst, createHtmlNode({
29621
- "tagName": "script",
29622
- "textContent": clientCode,
29623
- "injected-by": "jsenv:inject_globals"
29624
- }));
29570
+ tagName: "script",
29571
+ textContent: clientCode
29572
+ }), "jsenv:inject_globals");
29625
29573
  return stringifyHtmlAst(htmlAst);
29626
29574
  };
29627
29575