@jsenv/core 27.0.0-alpha.2 → 27.0.0-alpha.20

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 (219) hide show
  1. package/main.js +4 -0
  2. package/package.json +16 -12
  3. package/readme.md +4 -12
  4. package/src/build/build.js +512 -304
  5. package/src/build/build_urls_generator.js +33 -21
  6. package/src/build/graph_utils.js +31 -0
  7. package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +33 -15
  8. package/src/build/inject_service_worker_urls.js +79 -0
  9. package/src/build/resync_ressource_hints.js +83 -0
  10. package/src/build/start_build_server.js +188 -0
  11. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -2
  12. package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
  13. package/src/dev/start_dev_server.js +19 -22
  14. package/src/execute/execute.js +23 -4
  15. package/src/execute/run.js +17 -54
  16. package/src/execute/runtimes/browsers/from_playwright.js +167 -146
  17. package/src/execute/runtimes/node/node_process.js +281 -37
  18. package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
  19. package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +66 -4
  20. package/src/omega/compat/runtime_compat.js +50 -0
  21. package/src/omega/errors.js +51 -58
  22. package/src/omega/fetched_content_compliance.js +24 -0
  23. package/src/omega/file_url_converter.js +8 -50
  24. package/src/omega/kitchen.js +405 -286
  25. package/src/omega/server/file_service.js +9 -11
  26. package/src/omega/url_graph/url_graph_load.js +14 -7
  27. package/src/omega/url_graph/url_graph_report.js +7 -5
  28. package/src/omega/url_graph.js +22 -9
  29. package/src/omega/web_workers.js +42 -0
  30. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
  31. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
  32. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
  33. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
  34. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +41 -0
  35. package/src/{dev/plugins/autoreload/jsenv_plugin_autoreload.js → plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js} +27 -168
  36. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +25 -0
  37. package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
  38. package/src/plugins/bundling/css/bundle_css.js +21 -0
  39. package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
  40. package/src/{build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js → plugins/bundling/js_module/bundle_js_module.js} +105 -78
  41. package/src/plugins/bundling/jsenv_plugin_bundling.js +51 -0
  42. package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +48 -41
  43. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
  44. package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +7 -4
  45. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
  46. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
  47. package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_installer.js +3 -2
  48. package/src/{omega/core_plugins → plugins}/html_supervisor/client/html_supervisor_setup.js +0 -0
  49. package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
  50. package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
  51. package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +38 -46
  52. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
  53. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
  54. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
  55. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
  56. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +98 -0
  57. package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +41 -13
  58. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
  59. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
  60. package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +37 -31
  61. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +25 -0
  62. package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
  63. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
  64. package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +61 -40
  65. package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
  66. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
  67. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +263 -0
  68. package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
  69. package/src/plugins/minification/css/minify_css.js +9 -0
  70. package/src/plugins/minification/html/minify_html.js +15 -0
  71. package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
  72. package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
  73. package/src/plugins/minification/json/minify_json.js +8 -0
  74. package/src/{omega/core_plugins → plugins}/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +15 -15
  75. package/src/{omega → plugins}/plugin_controller.js +18 -10
  76. package/src/plugins/plugins.js +73 -0
  77. package/src/plugins/transpilation/as_js_classic/client/s.js +808 -0
  78. package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
  79. package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
  80. package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
  81. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +191 -0
  82. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +156 -0
  83. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_top_level_await.js +37 -0
  84. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +133 -0
  85. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
  86. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
  87. package/src/{omega/core_plugins/babel/babel_helper → plugins/transpilation/babel/helpers}/babel_plugin_babel_helpers_as_jsenv_imports.js +1 -2
  88. package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +158 -0
  89. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
  90. package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +38 -22
  91. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +0 -0
  92. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
  93. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
  94. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
  95. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
  96. package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
  97. package/src/{omega/core_plugins → plugins/transpilation}/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -0
  98. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +243 -0
  99. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +40 -0
  100. package/src/plugins/url_references/css/css_urls.js +49 -0
  101. package/src/plugins/url_references/html/html_urls.js +273 -0
  102. package/src/plugins/url_references/js/js_urls.js +170 -0
  103. package/src/plugins/url_references/jsenv_plugin_url_references.js +18 -0
  104. package/src/plugins/url_references/webmanifest/webmanifest_urls.js +17 -0
  105. package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
  106. package/src/{omega/core_plugins → plugins}/url_version/jsenv_plugin_url_version.js +8 -8
  107. package/src/test/execute_plan.js +25 -11
  108. package/src/test/execute_test_plan.js +14 -1
  109. package/src/test/logs_file_execution.js +8 -7
  110. package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
  111. package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
  112. package/src/dev/plugins/autoreload/sse_service.js +0 -149
  113. package/src/execute/runtimes/node/controlled_process.js +0 -316
  114. package/src/omega/core_plugins/babel/babel_helper/babel_helper_directory.js +0 -29
  115. package/src/omega/core_plugins/babel/babel_helper/client/.eslintrc.cjs +0 -24
  116. package/src/omega/core_plugins/babel/babel_helper/client/AsyncGenerator/AsyncGenerator.js +0 -81
  117. package/src/omega/core_plugins/babel/babel_helper/client/AwaitValue/AwaitValue.js +0 -3
  118. package/src/omega/core_plugins/babel/babel_helper/client/applyDecoratorDescriptor/applyDecoratorDescriptor.js +0 -33
  119. package/src/omega/core_plugins/babel/babel_helper/client/arrayLikeToArray/arrayLikeToArray.js +0 -7
  120. package/src/omega/core_plugins/babel/babel_helper/client/arrayWithHoles/arrayWithHoles.js +0 -4
  121. package/src/omega/core_plugins/babel/babel_helper/client/arrayWithoutHoles/arrayWithoutHoles.js +0 -6
  122. package/src/omega/core_plugins/babel/babel_helper/client/assertThisInitialized/assertThisInitialized.js +0 -7
  123. package/src/omega/core_plugins/babel/babel_helper/client/asyncGeneratorDelegate/asyncGeneratorDelegate.js +0 -40
  124. package/src/omega/core_plugins/babel/babel_helper/client/asyncIterator/asyncIterator.js +0 -65
  125. package/src/omega/core_plugins/babel/babel_helper/client/asyncToGenerator/asyncToGenerator.js +0 -34
  126. package/src/omega/core_plugins/babel/babel_helper/client/awaitAsyncGenerator/awaitAsyncGenerator.js +0 -5
  127. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +0 -20
  128. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorGet/classApplyDescriptorGet.js +0 -6
  129. package/src/omega/core_plugins/babel/babel_helper/client/classApplyDescriptorSet/classApplyDescriptorSet.js +0 -13
  130. package/src/omega/core_plugins/babel/babel_helper/client/classCallCheck/classCallCheck.js +0 -5
  131. package/src/omega/core_plugins/babel/babel_helper/client/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +0 -5
  132. package/src/omega/core_plugins/babel/babel_helper/client/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +0 -6
  133. package/src/omega/core_plugins/babel/babel_helper/client/classExtractFieldDescriptor/classExtractFieldDescriptor.js +0 -7
  134. package/src/omega/core_plugins/babel/babel_helper/client/classNameTDZError/classNameTDZError.js +0 -4
  135. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +0 -7
  136. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldGet/classPrivateFieldGet.js +0 -7
  137. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +0 -6
  138. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +0 -5
  139. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateFieldSet/classPrivateFieldSet.js +0 -8
  140. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateMethodGet/classPrivateMethodGet.js +0 -6
  141. package/src/omega/core_plugins/babel/babel_helper/client/classPrivateMethodSet/classPrivateMethodSet.js +0 -3
  142. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +0 -9
  143. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +0 -15
  144. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +0 -6
  145. package/src/omega/core_plugins/babel/babel_helper/client/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +0 -3
  146. package/src/omega/core_plugins/babel/babel_helper/client/construct/construct.js +0 -16
  147. package/src/omega/core_plugins/babel/babel_helper/client/createClass/createClass.js +0 -15
  148. package/src/omega/core_plugins/babel/babel_helper/client/createForOfIteratorHelper/createForOfIteratorHelper.js +0 -60
  149. package/src/omega/core_plugins/babel/babel_helper/client/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +0 -23
  150. package/src/omega/core_plugins/babel/babel_helper/client/createRawReactElement/createRawReactElement.js +0 -50
  151. package/src/omega/core_plugins/babel/babel_helper/client/createSuper/createSuper.js +0 -22
  152. package/src/omega/core_plugins/babel/babel_helper/client/decorate/decorate.js +0 -403
  153. package/src/omega/core_plugins/babel/babel_helper/client/defaults/defaults.js +0 -11
  154. package/src/omega/core_plugins/babel/babel_helper/client/defineEnumerableProperties/defineEnumerableProperties.js +0 -23
  155. package/src/omega/core_plugins/babel/babel_helper/client/defineProperty/defineProperty.js +0 -18
  156. package/src/omega/core_plugins/babel/babel_helper/client/extends/extends.js +0 -14
  157. package/src/omega/core_plugins/babel/babel_helper/client/get/get.js +0 -19
  158. package/src/omega/core_plugins/babel/babel_helper/client/getPrototypeOf/getPrototypeOf.js +0 -4
  159. package/src/omega/core_plugins/babel/babel_helper/client/inherits/inherits.js +0 -19
  160. package/src/omega/core_plugins/babel/babel_helper/client/inheritsLoose/inheritsLoose.js +0 -7
  161. package/src/omega/core_plugins/babel/babel_helper/client/initializerDefineProperty/initializerDefineProperty.js +0 -10
  162. package/src/omega/core_plugins/babel/babel_helper/client/initializerWarningHelper/initializerWarningHelper.js +0 -6
  163. package/src/omega/core_plugins/babel/babel_helper/client/instanceof/instanceof.js +0 -6
  164. package/src/omega/core_plugins/babel/babel_helper/client/interopRequireDefault/interopRequireDefault.js +0 -3
  165. package/src/omega/core_plugins/babel/babel_helper/client/interopRequireWildcard/interopRequireWildcard.js +0 -37
  166. package/src/omega/core_plugins/babel/babel_helper/client/isNativeFunction/isNativeFunction.js +0 -4
  167. package/src/omega/core_plugins/babel/babel_helper/client/isNativeReflectConstruct/isNativeReflectConstruct.js +0 -21
  168. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArray/iterableToArray.js +0 -7
  169. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArrayLimit/iterableToArrayLimit.js +0 -36
  170. package/src/omega/core_plugins/babel/babel_helper/client/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +0 -10
  171. package/src/omega/core_plugins/babel/babel_helper/client/jsx/jsx.js +0 -50
  172. package/src/omega/core_plugins/babel/babel_helper/client/maybeArrayLike/maybeArrayLike.js +0 -10
  173. package/src/omega/core_plugins/babel/babel_helper/client/newArrowCheck/newArrowCheck.js +0 -5
  174. package/src/omega/core_plugins/babel/babel_helper/client/nonIterableRest/nonIterableRest.js +0 -5
  175. package/src/omega/core_plugins/babel/babel_helper/client/nonIterableSpread/nonIterableSpread.js +0 -5
  176. package/src/omega/core_plugins/babel/babel_helper/client/objectDestructuringEmpty/objectDestructuringEmpty.js +0 -3
  177. package/src/omega/core_plugins/babel/babel_helper/client/objectSpread/objectSpread.js +0 -23
  178. package/src/omega/core_plugins/babel/babel_helper/client/objectSpread2/objectSpread2.js +0 -41
  179. package/src/omega/core_plugins/babel/babel_helper/client/objectWithoutProperties/objectWithoutProperties.js +0 -19
  180. package/src/omega/core_plugins/babel/babel_helper/client/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +0 -13
  181. package/src/omega/core_plugins/babel/babel_helper/client/possibleConstructorReturn/possibleConstructorReturn.js +0 -10
  182. package/src/omega/core_plugins/babel/babel_helper/client/readOnlyError/readOnlyError.js +0 -4
  183. package/src/omega/core_plugins/babel/babel_helper/client/readme.md +0 -8
  184. package/src/omega/core_plugins/babel/babel_helper/client/set/set.js +0 -44
  185. package/src/omega/core_plugins/babel/babel_helper/client/setPrototypeOf/setPrototypeOf.js +0 -6
  186. package/src/omega/core_plugins/babel/babel_helper/client/skipFirstGeneratorNext/skipFirstGeneratorNext.js +0 -8
  187. package/src/omega/core_plugins/babel/babel_helper/client/slicedToArray/slicedToArray.js +0 -10
  188. package/src/omega/core_plugins/babel/babel_helper/client/slicedToArrayLoose/slicedToArrayLoose.js +0 -13
  189. package/src/omega/core_plugins/babel/babel_helper/client/superPropBase/superPropBase.js +0 -10
  190. package/src/omega/core_plugins/babel/babel_helper/client/taggedTemplateLiteral/taggedTemplateLiteral.js +0 -10
  191. package/src/omega/core_plugins/babel/babel_helper/client/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +0 -7
  192. package/src/omega/core_plugins/babel/babel_helper/client/tdz/tdz.js +0 -4
  193. package/src/omega/core_plugins/babel/babel_helper/client/temporalRef/temporalRef.js +0 -6
  194. package/src/omega/core_plugins/babel/babel_helper/client/temporalUndefined/temporalUndefined.js +0 -3
  195. package/src/omega/core_plugins/babel/babel_helper/client/toArray/toArray.js +0 -10
  196. package/src/omega/core_plugins/babel/babel_helper/client/toConsumableArray/toConsumableArray.js +0 -10
  197. package/src/omega/core_plugins/babel/babel_helper/client/toPrimitive/toPrimitive.js +0 -10
  198. package/src/omega/core_plugins/babel/babel_helper/client/toPropertyKey/toPropertyKey.js +0 -6
  199. package/src/omega/core_plugins/babel/babel_helper/client/typeof/typeof.js +0 -14
  200. package/src/omega/core_plugins/babel/babel_helper/client/unsupportedIterableToArray/unsupportedIterableToArray.js +0 -12
  201. package/src/omega/core_plugins/babel/babel_helper/client/wrapAsyncGenerator/wrapAsyncGenerator.js +0 -8
  202. package/src/omega/core_plugins/babel/babel_helper/client/wrapNativeSuper/wrapNativeSuper.js +0 -30
  203. package/src/omega/core_plugins/babel/babel_helper/client/wrapRegExp/wrapRegExp.js +0 -63
  204. package/src/omega/core_plugins/babel/babel_helper/client/writeOnlyError/writeOnlyError.js +0 -4
  205. package/src/omega/core_plugins/babel/helpers/babel_plugin_structure.js +0 -187
  206. package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
  207. package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
  208. package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
  209. package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
  210. package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
  211. package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -210
  212. package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
  213. package/src/omega/core_plugins.js +0 -39
  214. package/src/omega/runtime_support/runtime_support.js +0 -20
  215. package/src/omega/url_mentions/css_url_mentions.js +0 -63
  216. package/src/omega/url_mentions/html_url_mentions.js +0 -185
  217. package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
  218. package/src/omega/url_mentions/parse_url_mentions.js +0 -37
  219. package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
@@ -1,4 +1,22 @@
1
- import { createControlledProcess } from "./controlled_process.js"
1
+ import { fork } from "node:child_process"
2
+ import { urlToFileSystemPath } from "@jsenv/filesystem"
3
+ import { createDetailedMessage } from "@jsenv/logger"
4
+ import {
5
+ Abort,
6
+ raceCallbacks,
7
+ createCallbackListNotifiedOnce,
8
+ } from "@jsenv/abort"
9
+ import { uneval } from "@jsenv/uneval"
10
+
11
+ import { memoize } from "@jsenv/utils/memoize/memoize.js"
12
+ import { createChildExecOptions } from "./child_exec_options.js"
13
+ import { ExecOptions } from "./exec_options.js"
14
+ import { killProcessTree } from "./kill_process_tree.js"
15
+
16
+ const NODE_CONTROLLABLE_FILE_URL = new URL(
17
+ "./controllable_file.mjs",
18
+ import.meta.url,
19
+ ).href
2
20
 
3
21
  export const nodeProcess = {
4
22
  name: "node",
@@ -8,17 +26,14 @@ export const nodeProcess = {
8
26
  nodeProcess.run = async ({
9
27
  signal = new AbortController().signal,
10
28
  logger,
11
- logProcessCommand,
29
+ logProcessCommand = false,
12
30
  rootDirectoryUrl,
13
31
  fileRelativeUrl,
14
32
 
15
33
  keepRunning,
16
34
  gracefulStopAllocatedMs = 4000,
17
35
  stopSignal,
18
- onStop,
19
- onError,
20
36
  onConsole,
21
- onResult,
22
37
 
23
38
  measurePerformance,
24
39
  collectPerformance,
@@ -29,12 +44,15 @@ nodeProcess.run = async ({
29
44
  debugMode,
30
45
  debugModeInheritBreak,
31
46
  env,
32
- inheritProcessEnv,
47
+ inheritProcessEnv = true,
33
48
  commandLineOptions = [],
34
- stdin,
35
- stdout,
36
- stderr,
49
+ stdin = "pipe",
50
+ stdout = "pipe",
51
+ stderr = "pipe",
37
52
  }) => {
53
+ if (env !== undefined && typeof env !== "object") {
54
+ throw new TypeError(`env must be an object, got ${env}`)
55
+ }
38
56
  env = {
39
57
  ...env,
40
58
  COVERAGE_ENABLED: collectCoverage,
@@ -49,44 +67,270 @@ nodeProcess.run = async ({
49
67
  "--experimental-import-meta-resolve",
50
68
  ...commandLineOptions,
51
69
  ]
52
- const { stop, requestActionOnChildProcess } = await createControlledProcess({
70
+
71
+ const cleanupCallbackList = createCallbackListNotifiedOnce()
72
+ const cleanup = async (reason) => {
73
+ await cleanupCallbackList.notify({ reason })
74
+ }
75
+
76
+ const childExecOptions = await createChildExecOptions({
53
77
  signal,
54
- logger,
55
78
  debugPort,
56
79
  debugMode,
57
80
  debugModeInheritBreak,
58
- env,
59
- inheritProcessEnv,
60
- commandLineOptions,
61
- stdin,
62
- stdout,
63
- stderr,
64
- logProcessCommand,
65
-
66
- stopSignal,
67
- onStop,
68
- onError,
69
- onConsole,
70
81
  })
71
- const namespace = await requestActionOnChildProcess({
72
- signal,
73
- actionType: "execute-using-dynamic-import",
74
- actionParams: {
75
- fileUrl: new URL(fileRelativeUrl, rootDirectoryUrl).href,
76
- measurePerformance,
77
- collectPerformance,
78
- collectCoverage,
82
+ const execArgv = ExecOptions.toExecArgv({
83
+ ...childExecOptions,
84
+ ...ExecOptions.fromExecArgv(commandLineOptions),
85
+ })
86
+ const envForChildProcess = {
87
+ ...(inheritProcessEnv ? process.env : {}),
88
+ ...env,
89
+ }
90
+ logger[logProcessCommand ? "info" : "debug"](
91
+ `${process.argv[0]} ${execArgv.join(" ")} ${urlToFileSystemPath(
92
+ NODE_CONTROLLABLE_FILE_URL,
93
+ )}`,
94
+ )
95
+ const childProcess = fork(urlToFileSystemPath(NODE_CONTROLLABLE_FILE_URL), {
96
+ execArgv,
97
+ // silent: true
98
+ stdio: ["pipe", "pipe", "pipe", "ipc"],
99
+ env: envForChildProcess,
100
+ })
101
+ logger.debug(
102
+ createDetailedMessage(`child process forked (pid ${childProcess.pid})`, {
103
+ "execArgv": execArgv.join(`\n`),
104
+ "custom env": JSON.stringify(env, null, " "),
105
+ }),
106
+ )
107
+ // if we pass stream, pipe them https://github.com/sindresorhus/execa/issues/81
108
+ if (typeof stdin === "object") {
109
+ stdin.pipe(childProcess.stdin)
110
+ }
111
+ if (typeof stdout === "object") {
112
+ childProcess.stdout.pipe(stdout)
113
+ }
114
+ if (typeof stderr === "object") {
115
+ childProcess.stderr.pipe(stderr)
116
+ }
117
+ const childProcessReadyPromise = new Promise((resolve) => {
118
+ onceProcessMessage(childProcess, "ready", resolve)
119
+ })
120
+ const removeOutputListener = installProcessOutputListener(
121
+ childProcess,
122
+ ({ type, text }) => {
123
+ onConsole({ type, text })
79
124
  },
125
+ )
126
+ const stop = memoize(async ({ gracefulStopAllocatedMs } = {}) => {
127
+ // all libraries are facing problem on windows when trying
128
+ // to kill a process spawning other processes.
129
+ // "killProcessTree" is theorically correct but sometimes keep process handing forever.
130
+ // Inside GitHub workflow the whole Virtual machine gets unresponsive and ends up being killed
131
+ // There is no satisfying solution to this problem so we stick to the basic
132
+ // childProcess.kill()
133
+ if (process.platform === "win32") {
134
+ childProcess.kill()
135
+ return
136
+ }
137
+ if (gracefulStopAllocatedMs) {
138
+ try {
139
+ await killProcessTree(childProcess.pid, {
140
+ signal: GRACEFUL_STOP_SIGNAL,
141
+ timeout: gracefulStopAllocatedMs,
142
+ })
143
+ return
144
+ } catch (e) {
145
+ if (e.code === "TIMEOUT") {
146
+ logger.debug(
147
+ `kill with SIGTERM because gracefulStop still pending after ${gracefulStopAllocatedMs}ms`,
148
+ )
149
+ await killProcessTree(childProcess.pid, {
150
+ signal: GRACEFUL_STOP_FAILED_SIGNAL,
151
+ })
152
+ return
153
+ }
154
+ throw e
155
+ }
156
+ }
157
+ await killProcessTree(childProcess.pid, { signal: STOP_SIGNAL })
158
+ return
80
159
  })
81
- onResult({
82
- status: "completed",
83
- namespace,
160
+
161
+ const actionOperation = Abort.startOperation()
162
+ actionOperation.addAbortSignal(signal)
163
+ const winnerPromise = new Promise((resolve) => {
164
+ raceCallbacks(
165
+ {
166
+ // https://nodejs.org/api/child_process.html#child_process_event_disconnect
167
+ // disconnect: (cb) => {
168
+ // return onceProcessEvent(childProcess, "disconnect", cb)
169
+ // },
170
+ // https://nodejs.org/api/child_process.html#child_process_event_error
171
+ error: (cb) => {
172
+ return onceProcessEvent(childProcess, "error", cb)
173
+ },
174
+ exit: (cb) => {
175
+ return onceProcessEvent(childProcess, "exit", (code, signal) => {
176
+ cb({ code, signal })
177
+ })
178
+ },
179
+ response: (cb) => {
180
+ onceProcessMessage(childProcess, "action-result", cb)
181
+ },
182
+ },
183
+ resolve,
184
+ )
84
185
  })
186
+ const getResult = async () => {
187
+ actionOperation.throwIfAborted()
188
+ await childProcessReadyPromise
189
+ actionOperation.throwIfAborted()
190
+ await sendToProcess(childProcess, "action", {
191
+ actionType: "execute-using-dynamic-import",
192
+ actionParams: {
193
+ fileUrl: new URL(fileRelativeUrl, rootDirectoryUrl).href,
194
+ measurePerformance,
195
+ collectPerformance,
196
+ collectCoverage,
197
+ },
198
+ })
199
+ const winner = await winnerPromise
200
+ if (winner.name === "error") {
201
+ const error = winner.data
202
+ removeOutputListener()
203
+ return {
204
+ status: "errored",
205
+ error,
206
+ }
207
+ }
208
+ if (winner.name === "exit") {
209
+ const { code } = winner.data
210
+ await cleanup("process exit")
211
+ if (code === 12) {
212
+ return {
213
+ status: "errored",
214
+ error: new Error(
215
+ `node process exited with 12 (the forked child process wanted to use a non-available port for debug)`,
216
+ ),
217
+ }
218
+ }
219
+ if (
220
+ code === null ||
221
+ code === 0 ||
222
+ code === SIGINT_EXIT_CODE ||
223
+ code === SIGTERM_EXIT_CODE ||
224
+ code === SIGABORT_EXIT_CODE
225
+ ) {
226
+ return {
227
+ status: "errored",
228
+ error: new Error(`node process exited during execution`),
229
+ }
230
+ }
231
+ // process.exit(1) in child process or process.exitCode = 1 + process.exit()
232
+ // means there was an error even if we don't know exactly what.
233
+ return {
234
+ status: "errored",
235
+ error: new Error(
236
+ `node process exited with code ${code} during execution`,
237
+ ),
238
+ }
239
+ }
240
+ const { status, value } = winner.data
241
+ if (status === "action-failed") {
242
+ return {
243
+ status: "errored",
244
+ error: value,
245
+ }
246
+ }
247
+ return {
248
+ status: "completed",
249
+ namespace: value,
250
+ }
251
+ }
252
+
253
+ let result
254
+ try {
255
+ result = await getResult()
256
+ } catch (e) {
257
+ result = {
258
+ status: "errored",
259
+ error: e,
260
+ }
261
+ }
85
262
  if (keepRunning) {
86
263
  stopSignal.notify = stop
87
- return
264
+ } else {
265
+ await stop({
266
+ gracefulStopAllocatedMs,
267
+ })
88
268
  }
89
- await stop({
90
- gracefulStopAllocatedMs,
269
+ await actionOperation.end()
270
+ return result
271
+ }
272
+
273
+ // https://nodejs.org/api/process.html#process_signal_events
274
+ const SIGINT_SIGNAL_NUMBER = 2
275
+ const SIGABORT_SIGNAL_NUMBER = 6
276
+ const SIGTERM_SIGNAL_NUMBER = 15
277
+ const SIGINT_EXIT_CODE = 128 + SIGINT_SIGNAL_NUMBER
278
+ const SIGABORT_EXIT_CODE = 128 + SIGABORT_SIGNAL_NUMBER
279
+ const SIGTERM_EXIT_CODE = 128 + SIGTERM_SIGNAL_NUMBER
280
+ // http://man7.org/linux/man-pages/man7/signal.7.html
281
+ // https:// github.com/nodejs/node/blob/1d9511127c419ec116b3ddf5fc7a59e8f0f1c1e4/lib/internal/child_process.js#L472
282
+ const GRACEFUL_STOP_SIGNAL = "SIGTERM"
283
+ const STOP_SIGNAL = "SIGKILL"
284
+ // it would be more correct if GRACEFUL_STOP_FAILED_SIGNAL was SIGHUP instead of SIGKILL.
285
+ // but I'm not sure and it changes nothing so just use SIGKILL
286
+ const GRACEFUL_STOP_FAILED_SIGNAL = "SIGKILL"
287
+
288
+ const sendToProcess = async (childProcess, type, data) => {
289
+ const source = uneval(data, { functionAllowed: true })
290
+ return new Promise((resolve, reject) => {
291
+ childProcess.send({ type, data: source }, (error) => {
292
+ if (error) {
293
+ reject(error)
294
+ } else {
295
+ resolve()
296
+ }
297
+ })
91
298
  })
92
299
  }
300
+
301
+ const installProcessOutputListener = (childProcess, callback) => {
302
+ // beware that we may receive ansi output here, should not be a problem but keep that in mind
303
+ const stdoutDataCallback = (chunk) => {
304
+ callback({ type: "log", text: String(chunk) })
305
+ }
306
+ childProcess.stdout.on("data", stdoutDataCallback)
307
+ const stdErrorDataCallback = (chunk) => {
308
+ callback({ type: "error", text: String(chunk) })
309
+ }
310
+ childProcess.stderr.on("data", stdErrorDataCallback)
311
+ return () => {
312
+ childProcess.stdout.removeListener("data", stdoutDataCallback)
313
+ childProcess.stderr.removeListener("data", stdoutDataCallback)
314
+ }
315
+ }
316
+
317
+ const onceProcessMessage = (childProcess, type, callback) => {
318
+ const onmessage = (message) => {
319
+ if (message.type === type) {
320
+ childProcess.removeListener("message", onmessage)
321
+ // eslint-disable-next-line no-eval
322
+ callback(message.data ? eval(`(${message.data})`) : "")
323
+ }
324
+ }
325
+ childProcess.on("message", onmessage)
326
+ return () => {
327
+ childProcess.removeListener("message", onmessage)
328
+ }
329
+ }
330
+
331
+ const onceProcessEvent = (childProcess, type, callback) => {
332
+ childProcess.once(type, callback)
333
+ return () => {
334
+ childProcess.removeListener(type, callback)
335
+ }
336
+ }
@@ -1,13 +1,11 @@
1
1
  // correspond to dynamic import
2
- export const defaultRuntimeSupport = {
2
+ export const defaultRuntimeCompat = {
3
3
  // android: "8",
4
4
  chrome: "63",
5
5
  edge: "79",
6
- electron: "8.1",
7
6
  firefox: "67",
8
- ios: "11",
7
+ ios: "11.3",
9
8
  opera: "50",
10
9
  safari: "11.3",
11
- node: "13.2",
12
- samsung: "8.0",
10
+ samsung: "8.2",
13
11
  }
@@ -1,4 +1,4 @@
1
- export const featuresCompatMap = {
1
+ export const featureCompats = {
2
2
  script_type_module: {
3
3
  edge: "16",
4
4
  firefox: "60",
@@ -9,6 +9,15 @@ export const featuresCompatMap = {
9
9
  android: "61",
10
10
  samsung: "8.2",
11
11
  },
12
+ document_current_script: {
13
+ edge: "12",
14
+ firefox: "4",
15
+ chrome: "29",
16
+ safari: "8",
17
+ opera: "16",
18
+ android: "4.4",
19
+ samsung: "4",
20
+ },
12
21
  import_meta: {
13
22
  chrome: "64",
14
23
  edge: "79",
@@ -18,13 +27,16 @@ export const featuresCompatMap = {
18
27
  ios: "12",
19
28
  android: "9",
20
29
  },
30
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
21
31
  import_dynamic: {
32
+ android: "8",
33
+ chrome: "63",
22
34
  edge: "79",
23
35
  firefox: "67",
24
- chrome: "63",
25
- safari: "11.3",
36
+ ios: "11.3",
26
37
  opera: "50",
27
- android: "8",
38
+ safari: "11.3",
39
+ samsung: "8.0",
28
40
  node: "13.2",
29
41
  },
30
42
  top_level_await: {
@@ -52,6 +64,7 @@ export const featuresCompatMap = {
52
64
  chrome: "93",
53
65
  edge: "93",
54
66
  },
67
+ import_type_text: {},
55
68
  // https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet#browser_compatibility
56
69
  new_stylesheet: {
57
70
  chrome: "73",
@@ -59,6 +72,18 @@ export const featuresCompatMap = {
59
72
  opera: "53",
60
73
  android: "73",
61
74
  },
75
+ // https://caniuse.com/?search=worker
76
+ worker: {
77
+ ie: "10",
78
+ edge: "12",
79
+ firefox: "3.5",
80
+ chrome: "4",
81
+ opera: "11.5",
82
+ safari: "4",
83
+ ios: "5",
84
+ android: "4.4",
85
+ },
86
+ // https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker#browser_compatibility
62
87
  worker_type_module: {
63
88
  chrome: "80",
64
89
  edge: "80",
@@ -66,6 +91,32 @@ export const featuresCompatMap = {
66
91
  android: "80",
67
92
  },
68
93
  worker_importmap: {},
94
+ service_worker: {
95
+ edge: "17",
96
+ firefox: "44",
97
+ chrome: "40",
98
+ safari: "11.1",
99
+ opera: "27",
100
+ ios: "11.3",
101
+ android: "12.12",
102
+ },
103
+ service_worker_type_module: {
104
+ chrome: "80",
105
+ edge: "80",
106
+ opera: "67",
107
+ android: "80",
108
+ },
109
+ shared_worker: {
110
+ chrome: "4",
111
+ edge: "79",
112
+ firefox: "29",
113
+ opera: "10.6",
114
+ },
115
+ shared_worker_type_module: {
116
+ chrome: "80",
117
+ edge: "80",
118
+ opera: "67",
119
+ },
69
120
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis#browser_compatibility
70
121
  global_this: {
71
122
  edge: "79",
@@ -88,4 +139,15 @@ export const featuresCompatMap = {
88
139
  samsung: "8",
89
140
  electron: "3",
90
141
  },
142
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#browser_compatibility
143
+ template_literals: {
144
+ chrome: "41",
145
+ edge: "12",
146
+ firefox: "34",
147
+ opera: "28",
148
+ safari: "9",
149
+ ios: "9",
150
+ android: "4",
151
+ node: "4",
152
+ },
91
153
  }
@@ -0,0 +1,50 @@
1
+ import { findHighestVersion } from "@jsenv/utils/semantic_versioning/highest_version.js"
2
+ import { featureCompats } from "./features_compats.js"
3
+
4
+ export const RUNTIME_COMPAT = {
5
+ featureCompats,
6
+
7
+ add: (originalRuntimeCompat, feature) => {
8
+ const featureCompat = getFeatureCompat(feature)
9
+ const runtimeCompat = {
10
+ ...originalRuntimeCompat,
11
+ }
12
+ Object.keys(featureCompat).forEach((runtimeName) => {
13
+ const firstVersion = originalRuntimeCompat[runtimeName]
14
+ const secondVersion = featureCompat[runtimeName]
15
+ runtimeCompat[runtimeName] = firstVersion
16
+ ? findHighestVersion(firstVersion, secondVersion)
17
+ : secondVersion
18
+ })
19
+ return runtimeCompat
20
+ },
21
+
22
+ isSupported: (runtimeCompat, feature) => {
23
+ const featureCompat = getFeatureCompat(feature)
24
+ const runtimeNames = Object.keys(runtimeCompat)
25
+ const runtimeWithoutCompat = runtimeNames.find((runtimeName) => {
26
+ const runtimeVersion = runtimeCompat[runtimeName]
27
+ const runtimeVersionCompatible = featureCompat[runtimeName] || "Infinity"
28
+ const highestVersion = findHighestVersion(
29
+ runtimeVersion,
30
+ runtimeVersionCompatible,
31
+ )
32
+ return highestVersion !== runtimeVersion
33
+ })
34
+ return !runtimeWithoutCompat
35
+ },
36
+ }
37
+
38
+ const getFeatureCompat = (feature) => {
39
+ if (typeof feature === "string") {
40
+ const compat = featureCompats[feature]
41
+ if (!compat) {
42
+ throw new Error(`"${feature}" feature is unknown`)
43
+ }
44
+ return compat
45
+ }
46
+ if (typeof feature !== "object") {
47
+ throw new TypeError(`feature must be a string or an object, got ${feature}`)
48
+ }
49
+ return feature
50
+ }