@jsenv/core 27.0.0-alpha.6 → 27.0.0-alpha.60

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 (150) hide show
  1. package/dist/event_source_client.js +545 -0
  2. package/dist/event_source_client.js.map +187 -0
  3. package/dist/html_supervisor_installer.js +1236 -0
  4. package/dist/html_supervisor_installer.js.map +337 -0
  5. package/dist/html_supervisor_setup.js +95 -0
  6. package/dist/html_supervisor_setup.js.map +57 -0
  7. package/dist/import_meta_hot.js +86 -0
  8. package/dist/import_meta_hot.js.map +42 -0
  9. package/main.js +8 -1
  10. package/package.json +30 -28
  11. package/readme.md +6 -14
  12. package/src/build/build.js +943 -555
  13. package/src/build/build_urls_generator.js +48 -23
  14. package/src/build/graph_utils.js +31 -0
  15. package/src/build/{inject_version_mappings.js → inject_global_version_mappings.js} +33 -15
  16. package/src/build/inject_service_worker_urls.js +79 -0
  17. package/src/build/resync_ressource_hints.js +68 -0
  18. package/src/build/start_build_server.js +192 -0
  19. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -2
  20. package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -1
  21. package/src/dev/start_dev_server.js +136 -30
  22. package/src/execute/execute.js +31 -6
  23. package/src/execute/run.js +19 -56
  24. package/src/execute/runtimes/browsers/from_playwright.js +207 -147
  25. package/src/execute/runtimes/node/controllable_file.mjs +26 -10
  26. package/src/execute/runtimes/node/node_execution_performance.js +67 -0
  27. package/src/execute/runtimes/node/node_process.js +280 -39
  28. package/src/jsenv_root_directory_url.js +1 -0
  29. package/src/omega/{runtime_support/default_runtime_support.js → compat/default_runtime_compat.js} +3 -5
  30. package/src/omega/{runtime_support/features_compatibility.js → compat/features_compats.js} +66 -4
  31. package/src/omega/compat/runtime_compat.js +50 -0
  32. package/src/omega/errors.js +51 -58
  33. package/src/omega/fetched_content_compliance.js +24 -0
  34. package/src/omega/file_url_converter.js +8 -50
  35. package/src/omega/kitchen.js +482 -304
  36. package/src/omega/omega_server.js +2 -3
  37. package/src/omega/server/file_service.js +53 -25
  38. package/src/omega/server/user_agent.js +4 -2
  39. package/src/omega/url_graph/url_graph_load.js +22 -7
  40. package/src/omega/url_graph/url_graph_report.js +98 -48
  41. package/src/omega/url_graph/url_info_transformations.js +26 -9
  42. package/src/omega/url_graph.js +80 -16
  43. package/src/omega/web_workers.js +42 -0
  44. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/autoreload_preference.js +0 -0
  45. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/event_source_client.js +2 -2
  46. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/reload.js +0 -0
  47. package/src/{dev/plugins/autoreload → plugins/autoreload/dev_sse}/client/url_helpers.js +0 -0
  48. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +46 -0
  49. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +204 -0
  50. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +27 -0
  51. package/src/plugins/autoreload/jsenv_plugin_hmr.js +35 -0
  52. package/src/plugins/bundling/css/bundle_css.js +140 -0
  53. package/src/plugins/bundling/js_classic_workers/bundle_js_classic_workers.js +13 -0
  54. package/src/plugins/bundling/js_module/bundle_js_module.js +309 -0
  55. package/src/plugins/bundling/jsenv_plugin_bundling.js +54 -0
  56. package/src/plugins/cache_control/jsenv_plugin_cache_control.js +34 -0
  57. package/src/{omega/core_plugins → plugins}/commonjs_globals/jsenv_plugin_commonjs_globals.js +54 -41
  58. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +66 -0
  59. package/src/{omega/core_plugins → plugins}/filesystem_magic/jsenv_plugin_filesystem_magic.js +8 -5
  60. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_document.js +0 -0
  61. package/src/{omega/core_plugins → plugins}/html_supervisor/client/error_in_notification.js +0 -0
  62. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +242 -0
  63. package/src/plugins/html_supervisor/client/html_supervisor_setup.js +79 -0
  64. package/src/{omega/core_plugins → plugins}/html_supervisor/client/perf_browser.js +0 -0
  65. package/src/{omega/core_plugins → plugins}/html_supervisor/client/uneval_exception.js +0 -0
  66. package/src/{omega/core_plugins → plugins}/html_supervisor/jsenv_plugin_html_supervisor.js +83 -61
  67. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +12 -0
  68. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/babel_plugin_metadata_import_meta_hot.js +4 -5
  69. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/client/import_meta_hot.js +3 -1
  70. package/src/{dev/plugins/autoreload → plugins/import_meta_hot}/html_hot_dependencies.js +2 -2
  71. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +105 -0
  72. package/src/{omega/core_plugins → plugins}/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +33 -8
  73. package/src/plugins/import_meta_url/client/import_meta_url_browser.js +52 -0
  74. package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +9 -0
  75. package/src/{omega/core_plugins → plugins}/importmap/jsenv_plugin_importmap.js +39 -33
  76. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +67 -0
  77. package/src/{omega/core_plugins → plugins}/inline/client/inline_content.js +0 -0
  78. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_data_urls.js +18 -14
  79. package/src/{omega/core_plugins/inline/jsenv_plugin_js_and_css_inside_html.js → plugins/inline/jsenv_plugin_html_inline_content.js} +65 -44
  80. package/src/plugins/inline/jsenv_plugin_inline.js +36 -0
  81. package/src/{omega/core_plugins → plugins}/inline/jsenv_plugin_inline_query_param.js +6 -6
  82. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +297 -0
  83. package/src/plugins/leading_slash/jsenv_plugin_leading_slash.js +13 -0
  84. package/src/plugins/minification/css/minify_css.js +9 -0
  85. package/src/plugins/minification/html/minify_html.js +15 -0
  86. package/src/{build/plugins/minify_js/jsenv_plugin_minify_js.js → plugins/minification/js/minify_js.js} +6 -22
  87. package/src/plugins/minification/jsenv_plugin_minification.js +78 -0
  88. package/src/plugins/minification/json/minify_json.js +8 -0
  89. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +146 -0
  90. package/src/{omega → plugins}/plugin_controller.js +42 -11
  91. package/src/plugins/plugins.js +92 -0
  92. package/src/plugins/transpilation/as_js_classic/client/s.js +874 -0
  93. package/src/plugins/transpilation/as_js_classic/client/s.js.md +1 -0
  94. package/src/plugins/transpilation/as_js_classic/helpers/babel_plugin_transform_import_meta_url.js +47 -0
  95. package/src/plugins/transpilation/as_js_classic/helpers/systemjs_old.js +43 -0
  96. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +199 -0
  97. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +270 -0
  98. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_workers_type_module_as_classic.js +55 -0
  99. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +0 -0
  100. package/src/{omega/core_plugins → plugins/transpilation}/babel/global_this/client/global_this.js +0 -0
  101. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +0 -0
  102. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugin_structure.js +12 -19
  103. package/src/{omega/core_plugins → plugins/transpilation}/babel/helpers/babel_plugins_compatibility.js +0 -0
  104. package/src/{omega/core_plugins → plugins/transpilation}/babel/jsenv_plugin_babel.js +45 -27
  105. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +30 -6
  106. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/.eslintrc.cjs +0 -0
  107. package/src/{omega/core_plugins → plugins/transpilation}/babel/new_stylesheet/client/new_stylesheet.js +0 -0
  108. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +0 -0
  109. package/src/{omega/core_plugins → plugins/transpilation}/babel/regenerator_runtime/client/regenerator_runtime.js +0 -0
  110. package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +18 -0
  111. package/src/plugins/transpilation/fetch_original_url_info.js +30 -0
  112. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +181 -0
  113. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +80 -0
  114. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +44 -0
  115. package/src/plugins/url_analysis/css/css_urls.js +49 -0
  116. package/src/plugins/url_analysis/html/html_urls.js +269 -0
  117. package/src/plugins/url_analysis/js/js_urls.js +67 -0
  118. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +18 -0
  119. package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +17 -0
  120. package/src/{omega/core_plugins → plugins}/url_resolution/jsenv_plugin_url_resolution.js +12 -5
  121. package/src/plugins/url_version/jsenv_plugin_url_version.js +28 -0
  122. package/src/test/execute_plan.js +30 -18
  123. package/src/test/execute_test_plan.js +23 -8
  124. package/src/test/logs_file_execution.js +9 -8
  125. package/src/build/plugins/bundle_js_module/jsenv_plugin_bundle_js_module.js +0 -225
  126. package/src/build/plugins/minify_html/jsenv_plugin_minify_html.js +0 -30
  127. package/src/dev/plugins/autoreload/client/event_source_connection.js +0 -195
  128. package/src/dev/plugins/autoreload/jsenv_plugin_autoreload.js +0 -374
  129. package/src/dev/plugins/autoreload/sse_service.js +0 -149
  130. package/src/execute/runtimes/node/controlled_process.js +0 -316
  131. package/src/omega/core_plugins/file_urls/jsenv_plugin_file_urls.js +0 -67
  132. package/src/omega/core_plugins/html_supervisor/client/html_supervisor_installer.js +0 -168
  133. package/src/omega/core_plugins/html_supervisor/client/html_supervisor_setup.js +0 -77
  134. package/src/omega/core_plugins/import_assertions/helpers/babel_plugin_metadata_import_assertions.js +0 -98
  135. package/src/omega/core_plugins/import_assertions/helpers/json_module.js +0 -12
  136. package/src/omega/core_plugins/import_assertions/helpers/text_module.js +0 -6
  137. package/src/omega/core_plugins/import_assertions/jsenv_plugin_import_assertions.js +0 -211
  138. package/src/omega/core_plugins/inline/jsenv_plugin_inline.js +0 -13
  139. package/src/omega/core_plugins/inline/jsenv_plugin_new_inline_content.js +0 -210
  140. package/src/omega/core_plugins/leading_slash/jsenv_plugin_leading_slash.js +0 -12
  141. package/src/omega/core_plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +0 -77
  142. package/src/omega/core_plugins/url_version/jsenv_plugin_url_version.js +0 -50
  143. package/src/omega/core_plugins.js +0 -39
  144. package/src/omega/runtime_support/runtime_support.js +0 -20
  145. package/src/omega/url_graph/url_graph_sort.js +0 -29
  146. package/src/omega/url_mentions/css_url_mentions.js +0 -63
  147. package/src/omega/url_mentions/html_url_mentions.js +0 -185
  148. package/src/omega/url_mentions/js_module_url_mentions.js +0 -91
  149. package/src/omega/url_mentions/parse_url_mentions.js +0 -37
  150. package/src/omega/url_mentions/worker_classic_url_mentions.js +0 -37
@@ -1,21 +1,26 @@
1
- import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
1
+ import {
2
+ assertAndNormalizeDirectoryUrl,
3
+ registerDirectoryLifecycle,
4
+ } from "@jsenv/filesystem"
2
5
  import { createLogger } from "@jsenv/logger"
3
6
 
7
+ import { initReloadableProcess } from "@jsenv/utils/process_reload/process_reload.js"
4
8
  import { createTaskLog } from "@jsenv/utils/logs/task_log.js"
9
+ import { getCorePlugins } from "@jsenv/core/src/plugins/plugins.js"
5
10
  import { createUrlGraph } from "@jsenv/core/src/omega/url_graph.js"
6
- import { getCorePlugins } from "@jsenv/core/src/omega/core_plugins.js"
7
11
  import { createKitchen } from "@jsenv/core/src/omega/kitchen.js"
8
12
  import { startOmegaServer } from "@jsenv/core/src/omega/omega_server.js"
9
13
 
10
- import { jsenvPluginAutoreload } from "./plugins/autoreload/jsenv_plugin_autoreload.js"
11
14
  import { jsenvPluginExplorer } from "./plugins/explorer/jsenv_plugin_explorer.js"
12
15
  import { jsenvPluginToolbar } from "./plugins/toolbar/jsenv_plugin_toolbar.js"
13
16
 
14
17
  export const startDevServer = async ({
15
18
  signal = new AbortController().signal,
16
- logLevel,
17
- port,
18
- protocol,
19
+ handleSIGINT,
20
+ logLevel = "info",
21
+ omegaServerLogLevel = "warn",
22
+ port = 3456,
23
+ protocol = "http",
19
24
  listenAnyIp,
20
25
  // it's better to use http1 by default because it allows to get statusText in devtools
21
26
  // which gives valuable information when there is errors
@@ -23,18 +28,29 @@ export const startDevServer = async ({
23
28
  certificate,
24
29
  privateKey,
25
30
  keepProcessAlive = true,
26
-
27
31
  rootDirectoryUrl,
28
- plugins = [],
29
-
30
- sourcemaps = "inline",
31
- autoreload = true,
32
- autoreloadPatterns = {
32
+ devServerFiles = {
33
+ "./package.json": true,
34
+ "./jsenv.config.mjs": true,
35
+ },
36
+ devServerMainFile,
37
+ devServerAutoreload = false,
38
+ clientFiles = {
33
39
  "./**": true,
34
- "./**/.*/": false, // any folder starting with a dot is ignored (includes .git for instance)
35
- "./dist/": false,
40
+ "./**/.*/": false, // any folder starting with a dot is ignored (includes .git,.jsenv for instance)
41
+ "./**/dist/": false,
36
42
  "./**/node_modules/": false,
37
43
  },
44
+ cooldownBetweenFileEvents,
45
+ clientAutoreload = true,
46
+
47
+ sourcemaps = "inline",
48
+ plugins = [],
49
+ htmlSupervisor = true,
50
+ injectedGlobals,
51
+ nodeEsmResolution,
52
+ fileSystemMagicResolution,
53
+ transpilation,
38
54
  explorerGroups = {
39
55
  source: {
40
56
  "./*.html": true,
@@ -47,37 +63,121 @@ export const startDevServer = async ({
47
63
  toolbar = false,
48
64
  }) => {
49
65
  const logger = createLogger({ logLevel })
66
+ rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
67
+ const reloadableProcess = await initReloadableProcess({
68
+ signal,
69
+ handleSIGINT,
70
+ ...(devServerAutoreload
71
+ ? {
72
+ enabled: true,
73
+ logLevel: "warn",
74
+ fileToRestart: devServerMainFile,
75
+ }
76
+ : {
77
+ enabled: false,
78
+ }),
79
+ })
80
+ if (reloadableProcess.isPrimary) {
81
+ const devServerFileChangeCallback = ({ relativeUrl, event }) => {
82
+ const url = new URL(relativeUrl, rootDirectoryUrl).href
83
+ if (devServerAutoreload) {
84
+ logger.info(`file ${event} ${url} -> restarting server...`)
85
+ reloadableProcess.reload()
86
+ }
87
+ }
88
+ const unregisterDevServerFilesWatcher = registerDirectoryLifecycle(
89
+ rootDirectoryUrl,
90
+ {
91
+ watchPatterns: {
92
+ [devServerMainFile]: true,
93
+ ...devServerFiles,
94
+ },
95
+ cooldownBetweenFileEvents,
96
+ keepProcessAlive: false,
97
+ recursive: true,
98
+ added: ({ relativeUrl }) => {
99
+ devServerFileChangeCallback({ relativeUrl, event: "added" })
100
+ },
101
+ updated: ({ relativeUrl }) => {
102
+ devServerFileChangeCallback({ relativeUrl, event: "modified" })
103
+ },
104
+ removed: ({ relativeUrl }) => {
105
+ devServerFileChangeCallback({ relativeUrl, event: "removed" })
106
+ },
107
+ },
108
+ )
109
+ signal.addEventListener("abort", () => {
110
+ unregisterDevServerFilesWatcher()
111
+ })
112
+ return {
113
+ origin: `${protocol}://127.0.0.1:${port}`,
114
+ stop: () => {
115
+ unregisterDevServerFilesWatcher()
116
+ reloadableProcess.stop()
117
+ },
118
+ }
119
+ }
120
+
50
121
  const startServerTask = createTaskLog(logger, "start server")
51
122
 
52
- rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
53
- const urlGraph = createUrlGraph()
123
+ const clientFileChangeCallbackList = []
124
+ const clientFilesPruneCallbackList = []
125
+ const clientFileChangeCallback = ({ relativeUrl, event }) => {
126
+ const url = new URL(relativeUrl, rootDirectoryUrl).href
127
+ clientFileChangeCallbackList.forEach((callback) => {
128
+ callback({ url, event })
129
+ })
130
+ }
131
+ const stopWatchingClientFiles = registerDirectoryLifecycle(rootDirectoryUrl, {
132
+ watchPatterns: clientFiles,
133
+ cooldownBetweenFileEvents,
134
+ keepProcessAlive: false,
135
+ recursive: true,
136
+ added: ({ relativeUrl }) => {
137
+ clientFileChangeCallback({ event: "added", relativeUrl })
138
+ },
139
+ updated: ({ relativeUrl }) => {
140
+ clientFileChangeCallback({ event: "modified", relativeUrl })
141
+ },
142
+ removed: ({ relativeUrl }) => {
143
+ clientFileChangeCallback({ event: "removed", relativeUrl })
144
+ },
145
+ })
146
+ const urlGraph = createUrlGraph({
147
+ clientFileChangeCallbackList,
148
+ clientFilesPruneCallbackList,
149
+ })
54
150
  const kitchen = createKitchen({
55
151
  signal,
56
152
  logger,
57
153
  rootDirectoryUrl,
58
154
  urlGraph,
155
+ scenario: "dev",
156
+ sourcemaps,
59
157
  plugins: [
60
158
  ...plugins,
61
- ...getCorePlugins(),
62
- ...(autoreload
63
- ? [
64
- jsenvPluginAutoreload({
65
- rootDirectoryUrl,
66
- urlGraph,
67
- autoreloadPatterns,
68
- }),
69
- ]
70
- : []),
159
+ ...getCorePlugins({
160
+ rootDirectoryUrl,
161
+ urlGraph,
162
+ scenario: "dev",
163
+
164
+ htmlSupervisor,
165
+ injectedGlobals,
166
+ nodeEsmResolution,
167
+ fileSystemMagicResolution,
168
+ transpilation,
169
+ clientAutoreload,
170
+ clientFileChangeCallbackList,
171
+ clientFilesPruneCallbackList,
172
+ }),
71
173
  jsenvPluginExplorer({
72
174
  groups: explorerGroups,
73
175
  }),
74
176
  ...(toolbar ? [jsenvPluginToolbar(toolbar)] : []),
75
177
  ],
76
- scenario: "dev",
77
- sourcemaps,
78
178
  })
79
179
  const server = await startOmegaServer({
80
- logger,
180
+ logLevel: omegaServerLogLevel,
81
181
  keepProcessAlive,
82
182
  listenAnyIp,
83
183
  port,
@@ -101,5 +201,11 @@ export const startDevServer = async ({
101
201
  kitchen.pluginController.callHooks("destroy")
102
202
  }
103
203
  })
104
- return server
204
+ return {
205
+ origin: server.origin,
206
+ stop: () => {
207
+ stopWatchingClientFiles()
208
+ server.stop()
209
+ },
210
+ }
105
211
  }
@@ -3,8 +3,8 @@ import { Abort, raceProcessTeardownEvents } from "@jsenv/abort"
3
3
  import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
4
4
  import { createLogger } from "@jsenv/logger"
5
5
 
6
+ import { getCorePlugins } from "@jsenv/core/src/plugins/plugins.js"
6
7
  import { createUrlGraph } from "@jsenv/core/src/omega/url_graph.js"
7
- import { getCorePlugins } from "@jsenv/core/src/omega/core_plugins.js"
8
8
  import { createKitchen } from "@jsenv/core/src/omega/kitchen.js"
9
9
  import { startOmegaServer } from "@jsenv/core/src/omega/omega_server.js"
10
10
 
@@ -23,12 +23,18 @@ export const execute = async ({
23
23
  collectConsole,
24
24
  collectCoverage,
25
25
  coverageTempDirectoryUrl,
26
+ collectPerformance = false,
26
27
  runtime,
27
28
  runtimeParams,
28
29
 
29
- plugins = [],
30
30
  scenario = "dev",
31
31
  sourcemaps = "inline",
32
+ plugins = [],
33
+ nodeEsmResolution,
34
+ fileSystemMagicResolution,
35
+ injectedGlobals,
36
+ transpilation,
37
+ htmlSupervisor = true,
32
38
 
33
39
  port,
34
40
  protocol,
@@ -53,6 +59,7 @@ export const execute = async ({
53
59
  })
54
60
  }
55
61
 
62
+ let resultTransformer = (result) => result
56
63
  runtimeParams = {
57
64
  rootDirectoryUrl,
58
65
  fileRelativeUrl,
@@ -65,14 +72,26 @@ export const execute = async ({
65
72
  logger,
66
73
  rootDirectoryUrl,
67
74
  urlGraph,
68
- plugins: [...plugins, ...getCorePlugins()],
69
75
  scenario,
70
76
  sourcemaps,
77
+ plugins: [
78
+ ...plugins,
79
+ ...getCorePlugins({
80
+ rootDirectoryUrl,
81
+ urlGraph,
82
+ scenario,
83
+
84
+ htmlSupervisor,
85
+ injectedGlobals,
86
+ nodeEsmResolution,
87
+ fileSystemMagicResolution,
88
+ transpilation,
89
+ }),
90
+ ],
71
91
  })
72
- const serverLogger = createLogger({ logLevel: "warn" })
73
92
  const server = await startOmegaServer({
74
93
  signal: executeOperation.signal,
75
- logger: serverLogger,
94
+ logLevel: "warn",
76
95
  rootDirectoryUrl,
77
96
  urlGraph,
78
97
  kitchen,
@@ -91,9 +110,13 @@ export const execute = async ({
91
110
  ...runtimeParams,
92
111
  server,
93
112
  }
113
+ resultTransformer = (result) => {
114
+ result.server = server
115
+ return result
116
+ }
94
117
  }
95
118
 
96
- const result = await run({
119
+ let result = await run({
97
120
  signal: executeOperation.signal,
98
121
  logger,
99
122
  allocatedMs,
@@ -102,9 +125,11 @@ export const execute = async ({
102
125
  collectConsole,
103
126
  collectCoverage,
104
127
  coverageTempDirectoryUrl,
128
+ collectPerformance,
105
129
  runtime,
106
130
  runtimeParams,
107
131
  })
132
+ result = resultTransformer(result)
108
133
 
109
134
  try {
110
135
  if (result.status === "errored") {
@@ -1,7 +1,6 @@
1
1
  import cuid from "cuid"
2
2
  import { Abort, raceCallbacks } from "@jsenv/abort"
3
3
  import { resolveUrl, writeFile } from "@jsenv/filesystem"
4
- import { createDetailedMessage } from "@jsenv/logger"
5
4
 
6
5
  export const run = async ({
7
6
  signal = new AbortController().signal,
@@ -12,15 +11,12 @@ export const run = async ({
12
11
  collectConsole = false,
13
12
  collectCoverage = false,
14
13
  coverageTempDirectoryUrl,
15
- // measurePerformance,
16
- // collectPerformance = false,
14
+ collectPerformance = false,
17
15
 
18
16
  runtime,
19
17
  runtimeParams,
20
18
  }) => {
21
- const onErrorRef = { current: () => {} }
22
19
  const onConsoleRef = { current: () => {} }
23
- const onStopRef = { current: () => {} }
24
20
  const stopSignal = { notify: () => {} }
25
21
 
26
22
  let resultTransformer = (result) => result
@@ -105,7 +101,7 @@ export const run = async ({
105
101
  try {
106
102
  logger.debug(`run() ${runtimeLabel}`)
107
103
  runOperation.throwIfAborted()
108
- const winnerPromise = new Promise((resolve, reject) => {
104
+ const winnerPromise = new Promise((resolve) => {
109
105
  raceCallbacks(
110
106
  {
111
107
  aborted: (cb) => {
@@ -114,35 +110,23 @@ export const run = async ({
114
110
  runOperation.signal.removeEventListener("abort", cb)
115
111
  }
116
112
  },
117
- errored: (cb) => {
118
- onErrorRef.current = (error) => {
119
- logger.debug(
120
- createDetailedMessage(`error during execution`, {
121
- ["error stack"]: error.stack,
122
- ["runtime"]: runtimeLabel,
123
- }),
124
- )
125
- cb(error)
126
- }
127
- },
128
- stopped: (cb) => {
129
- onStopRef.current = cb
130
- },
131
113
  runned: async (cb) => {
132
114
  try {
133
- await runtime.run({
134
- signal,
115
+ const result = await runtime.run({
116
+ signal: runOperation.signal,
135
117
  logger,
136
118
  ...runtimeParams,
119
+ collectPerformance,
137
120
  keepRunning,
138
121
  stopSignal,
139
- onStop: (stopInfo) => onStopRef.current(stopInfo),
140
- onError: (error) => onErrorRef.current(error),
141
122
  onConsole: (log) => onConsoleRef.current(log),
142
- onResult: cb,
143
123
  })
124
+ cb(result)
144
125
  } catch (e) {
145
- reject(e)
126
+ cb({
127
+ status: "errored",
128
+ error: e,
129
+ })
146
130
  }
147
131
  },
148
132
  },
@@ -153,31 +137,16 @@ export const run = async ({
153
137
  if (winner.name === "aborted") {
154
138
  runOperation.throwIfAborted()
155
139
  }
156
- if (winner.name === "errored") {
157
- return await resultTransformer(
158
- createErroredExecutionResult({
159
- error: winner.data,
160
- }),
161
- )
162
- }
163
- if (winner.name === "stopped") {
164
- return await resultTransformer(
165
- createErroredExecutionResult({
166
- error: new Error(`runtime stopped during execution`),
167
- }),
168
- )
169
- }
170
- onErrorRef.current = (error) => {
171
- throw error
140
+ let result = winner.data
141
+ result = await resultTransformer(result)
142
+ return result
143
+ } catch (e) {
144
+ let result = {
145
+ status: "errored",
146
+ error: e,
172
147
  }
173
- const result = winner.data
174
- return await resultTransformer(result)
175
- } catch (error) {
176
- return await resultTransformer(
177
- createErroredExecutionResult({
178
- error,
179
- }),
180
- )
148
+ result = await resultTransformer(result)
149
+ return result
181
150
  } finally {
182
151
  await runOperation.end()
183
152
  }
@@ -200,9 +169,3 @@ const createTimedoutResult = () => {
200
169
  status: "timedout",
201
170
  }
202
171
  }
203
- const createErroredExecutionResult = ({ error }) => {
204
- return {
205
- status: "errored",
206
- error,
207
- }
208
- }