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

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 +549 -0
  2. package/dist/event_source_client.js.map +188 -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 +36 -29
  11. package/readme.md +6 -14
  12. package/src/build/build.js +961 -559
  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 +200 -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 +150 -34
  22. package/src/execute/execute.js +33 -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 +475 -308
  36. package/src/omega/omega_server.js +2 -3
  37. package/src/omega/server/file_service.js +57 -26
  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 +94 -51
  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 +19 -12
  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 +7 -4
  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 +38 -19
  123. package/src/test/execute_test_plan.js +25 -8
  124. package/src/test/logs_file_execution.js +10 -12
  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,28 @@
1
- import { assertAndNormalizeDirectoryUrl } from "@jsenv/filesystem"
2
- import { createLogger } from "@jsenv/logger"
1
+ import { parentPort } from "node:worker_threads"
2
+ import {
3
+ assertAndNormalizeDirectoryUrl,
4
+ registerDirectoryLifecycle,
5
+ } from "@jsenv/filesystem"
6
+ import { createLogger, loggerToLevels } from "@jsenv/logger"
3
7
 
4
- import { createTaskLog } from "@jsenv/utils/logs/task_log.js"
8
+ import { createTaskLog } from "@jsenv/log"
9
+ import { getCallerPosition } from "@jsenv/utils/src/caller_position.js"
10
+ import { initReloadableProcess } from "@jsenv/utils/process_reload/process_reload.js"
11
+ import { getCorePlugins } from "@jsenv/core/src/plugins/plugins.js"
5
12
  import { createUrlGraph } from "@jsenv/core/src/omega/url_graph.js"
6
- import { getCorePlugins } from "@jsenv/core/src/omega/core_plugins.js"
7
13
  import { createKitchen } from "@jsenv/core/src/omega/kitchen.js"
8
14
  import { startOmegaServer } from "@jsenv/core/src/omega/omega_server.js"
9
15
 
10
- import { jsenvPluginAutoreload } from "./plugins/autoreload/jsenv_plugin_autoreload.js"
11
16
  import { jsenvPluginExplorer } from "./plugins/explorer/jsenv_plugin_explorer.js"
12
17
  import { jsenvPluginToolbar } from "./plugins/toolbar/jsenv_plugin_toolbar.js"
13
18
 
14
19
  export const startDevServer = async ({
15
20
  signal = new AbortController().signal,
16
- logLevel,
17
- port,
18
- protocol,
21
+ handleSIGINT,
22
+ logLevel = "info",
23
+ omegaServerLogLevel = "warn",
24
+ port = 3456,
25
+ protocol = "http",
19
26
  listenAnyIp,
20
27
  // it's better to use http1 by default because it allows to get statusText in devtools
21
28
  // which gives valuable information when there is errors
@@ -23,18 +30,33 @@ export const startDevServer = async ({
23
30
  certificate,
24
31
  privateKey,
25
32
  keepProcessAlive = true,
26
-
27
33
  rootDirectoryUrl,
28
- plugins = [],
29
-
30
- sourcemaps = "inline",
31
- autoreload = true,
32
- autoreloadPatterns = {
34
+ devServerFiles = {
35
+ "./package.json": true,
36
+ "./jsenv.config.mjs": true,
37
+ },
38
+ devServerMainFile = getCallerPosition().url,
39
+ // force disable server autoreload when this code is executed:
40
+ // - inside a forked child process
41
+ // - inside a worker thread
42
+ // (because node cluster won't work)
43
+ devServerAutoreload = typeof process.send !== "function" && !parentPort,
44
+ clientFiles = {
33
45
  "./**": true,
34
- "./**/.*/": false, // any folder starting with a dot is ignored (includes .git for instance)
35
- "./dist/": false,
46
+ "./**/.*/": false, // any folder starting with a dot is ignored (includes .git,.jsenv for instance)
47
+ "./**/dist/": false,
36
48
  "./**/node_modules/": false,
37
49
  },
50
+ cooldownBetweenFileEvents,
51
+ clientAutoreload = true,
52
+
53
+ sourcemaps = "inline",
54
+ plugins = [],
55
+ htmlSupervisor = true,
56
+ injectedGlobals,
57
+ nodeEsmResolution,
58
+ fileSystemMagicResolution,
59
+ transpilation,
38
60
  explorerGroups = {
39
61
  source: {
40
62
  "./*.html": true,
@@ -45,39 +67,127 @@ export const startDevServer = async ({
45
67
  },
46
68
  },
47
69
  toolbar = false,
70
+ writeGeneratedFiles = true,
48
71
  }) => {
49
72
  const logger = createLogger({ logLevel })
50
- const startServerTask = createTaskLog(logger, "start server")
51
-
52
73
  rootDirectoryUrl = assertAndNormalizeDirectoryUrl(rootDirectoryUrl)
53
- const urlGraph = createUrlGraph()
74
+ const reloadableProcess = await initReloadableProcess({
75
+ signal,
76
+ handleSIGINT,
77
+ ...(devServerAutoreload
78
+ ? {
79
+ enabled: true,
80
+ logLevel: "warn",
81
+ fileToRestart: devServerMainFile,
82
+ }
83
+ : {
84
+ enabled: false,
85
+ }),
86
+ })
87
+ if (reloadableProcess.isPrimary) {
88
+ const devServerFileChangeCallback = ({ relativeUrl, event }) => {
89
+ const url = new URL(relativeUrl, rootDirectoryUrl).href
90
+ if (devServerAutoreload) {
91
+ logger.info(`file ${event} ${url} -> restarting server...`)
92
+ reloadableProcess.reload()
93
+ }
94
+ }
95
+ const unregisterDevServerFilesWatcher = registerDirectoryLifecycle(
96
+ rootDirectoryUrl,
97
+ {
98
+ watchPatterns: {
99
+ [devServerMainFile]: true,
100
+ ...devServerFiles,
101
+ },
102
+ cooldownBetweenFileEvents,
103
+ keepProcessAlive: false,
104
+ recursive: true,
105
+ added: ({ relativeUrl }) => {
106
+ devServerFileChangeCallback({ relativeUrl, event: "added" })
107
+ },
108
+ updated: ({ relativeUrl }) => {
109
+ devServerFileChangeCallback({ relativeUrl, event: "modified" })
110
+ },
111
+ removed: ({ relativeUrl }) => {
112
+ devServerFileChangeCallback({ relativeUrl, event: "removed" })
113
+ },
114
+ },
115
+ )
116
+ signal.addEventListener("abort", () => {
117
+ unregisterDevServerFilesWatcher()
118
+ })
119
+ return {
120
+ origin: `${protocol}://127.0.0.1:${port}`,
121
+ stop: () => {
122
+ unregisterDevServerFilesWatcher()
123
+ reloadableProcess.stop()
124
+ },
125
+ }
126
+ }
127
+
128
+ const startDevServerTask = createTaskLog("start dev server", {
129
+ disabled: !loggerToLevels(logger).info,
130
+ })
131
+
132
+ const clientFileChangeCallbackList = []
133
+ const clientFilesPruneCallbackList = []
134
+ const clientFileChangeCallback = ({ relativeUrl, event }) => {
135
+ const url = new URL(relativeUrl, rootDirectoryUrl).href
136
+ clientFileChangeCallbackList.forEach((callback) => {
137
+ callback({ url, event })
138
+ })
139
+ }
140
+ const stopWatchingClientFiles = registerDirectoryLifecycle(rootDirectoryUrl, {
141
+ watchPatterns: clientFiles,
142
+ cooldownBetweenFileEvents,
143
+ keepProcessAlive: false,
144
+ recursive: true,
145
+ added: ({ relativeUrl }) => {
146
+ clientFileChangeCallback({ event: "added", relativeUrl })
147
+ },
148
+ updated: ({ relativeUrl }) => {
149
+ clientFileChangeCallback({ event: "modified", relativeUrl })
150
+ },
151
+ removed: ({ relativeUrl }) => {
152
+ clientFileChangeCallback({ event: "removed", relativeUrl })
153
+ },
154
+ })
155
+ const urlGraph = createUrlGraph({
156
+ clientFileChangeCallbackList,
157
+ clientFilesPruneCallbackList,
158
+ })
54
159
  const kitchen = createKitchen({
55
160
  signal,
56
161
  logger,
57
162
  rootDirectoryUrl,
58
163
  urlGraph,
164
+ scenario: "dev",
165
+ sourcemaps,
166
+ writeGeneratedFiles,
59
167
  plugins: [
60
168
  ...plugins,
61
- ...getCorePlugins(),
62
- ...(autoreload
63
- ? [
64
- jsenvPluginAutoreload({
65
- rootDirectoryUrl,
66
- urlGraph,
67
- autoreloadPatterns,
68
- }),
69
- ]
70
- : []),
169
+ ...getCorePlugins({
170
+ rootDirectoryUrl,
171
+ urlGraph,
172
+ scenario: "dev",
173
+
174
+ htmlSupervisor,
175
+ injectedGlobals,
176
+ nodeEsmResolution,
177
+ fileSystemMagicResolution,
178
+ transpilation,
179
+ clientAutoreload,
180
+ clientFileChangeCallbackList,
181
+ clientFilesPruneCallbackList,
182
+ }),
71
183
  jsenvPluginExplorer({
72
184
  groups: explorerGroups,
73
185
  }),
74
186
  ...(toolbar ? [jsenvPluginToolbar(toolbar)] : []),
75
187
  ],
76
- scenario: "dev",
77
- sourcemaps,
78
188
  })
79
189
  const server = await startOmegaServer({
80
- logger,
190
+ logLevel: omegaServerLogLevel,
81
191
  keepProcessAlive,
82
192
  listenAnyIp,
83
193
  port,
@@ -90,7 +200,7 @@ export const startDevServer = async ({
90
200
  kitchen,
91
201
  scenario: "dev",
92
202
  })
93
- startServerTask.done()
203
+ startDevServerTask.done()
94
204
  logger.info(``)
95
205
  Object.keys(server.origins).forEach((key) => {
96
206
  logger.info(`- ${server.origins[key]}`)
@@ -101,5 +211,11 @@ export const startDevServer = async ({
101
211
  kitchen.pluginController.callHooks("destroy")
102
212
  }
103
213
  })
104
- return server
214
+ return {
215
+ origin: server.origin,
216
+ stop: () => {
217
+ stopWatchingClientFiles()
218
+ server.stop()
219
+ },
220
+ }
105
221
  }
@@ -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,19 @@ 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,
38
+ writeGeneratedFiles = false,
32
39
 
33
40
  port,
34
41
  protocol,
@@ -53,6 +60,7 @@ export const execute = async ({
53
60
  })
54
61
  }
55
62
 
63
+ let resultTransformer = (result) => result
56
64
  runtimeParams = {
57
65
  rootDirectoryUrl,
58
66
  fileRelativeUrl,
@@ -65,14 +73,27 @@ export const execute = async ({
65
73
  logger,
66
74
  rootDirectoryUrl,
67
75
  urlGraph,
68
- plugins: [...plugins, ...getCorePlugins()],
69
76
  scenario,
70
77
  sourcemaps,
78
+ writeGeneratedFiles,
79
+ plugins: [
80
+ ...plugins,
81
+ ...getCorePlugins({
82
+ rootDirectoryUrl,
83
+ urlGraph,
84
+ scenario,
85
+
86
+ htmlSupervisor,
87
+ injectedGlobals,
88
+ nodeEsmResolution,
89
+ fileSystemMagicResolution,
90
+ transpilation,
91
+ }),
92
+ ],
71
93
  })
72
- const serverLogger = createLogger({ logLevel: "warn" })
73
94
  const server = await startOmegaServer({
74
95
  signal: executeOperation.signal,
75
- logger: serverLogger,
96
+ logLevel: "warn",
76
97
  rootDirectoryUrl,
77
98
  urlGraph,
78
99
  kitchen,
@@ -91,9 +112,13 @@ export const execute = async ({
91
112
  ...runtimeParams,
92
113
  server,
93
114
  }
115
+ resultTransformer = (result) => {
116
+ result.server = server
117
+ return result
118
+ }
94
119
  }
95
120
 
96
- const result = await run({
121
+ let result = await run({
97
122
  signal: executeOperation.signal,
98
123
  logger,
99
124
  allocatedMs,
@@ -102,9 +127,11 @@ export const execute = async ({
102
127
  collectConsole,
103
128
  collectCoverage,
104
129
  coverageTempDirectoryUrl,
130
+ collectPerformance,
105
131
  runtime,
106
132
  runtimeParams,
107
133
  })
134
+ result = resultTransformer(result)
108
135
 
109
136
  try {
110
137
  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
- }