@jsenv/core 27.4.0 → 27.5.0

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 (84) hide show
  1. package/dist/js/autoreload.js +359 -0
  2. package/dist/js/execute_using_dynamic_import.js +1 -1
  3. package/dist/js/html_supervisor_installer.js +221 -73
  4. package/dist/js/html_supervisor_setup.js +3 -4
  5. package/dist/js/new_stylesheet.js +26 -58
  6. package/dist/js/server_events_client.js +307 -0
  7. package/dist/main.js +7483 -7281
  8. package/package.json +11 -10
  9. package/{README.md → readme.md} +8 -9
  10. package/src/build/build.js +12 -16
  11. package/src/build/start_build_server.js +24 -28
  12. package/src/dev/start_dev_server.js +30 -94
  13. package/src/execute/execute.js +17 -35
  14. package/src/omega/errors.js +20 -18
  15. package/src/omega/kitchen.js +7 -6
  16. package/src/omega/omega_server.js +96 -127
  17. package/src/omega/server/file_service.js +247 -46
  18. package/src/omega/url_graph.js +33 -20
  19. package/src/plugins/autoreload/client/autoreload.js +201 -0
  20. package/src/plugins/autoreload/{dev_sse/client → client}/autoreload_preference.js +0 -0
  21. package/src/plugins/autoreload/{dev_sse/client → client}/reload.js +29 -10
  22. package/src/plugins/autoreload/{dev_sse/client → client}/url_helpers.js +0 -0
  23. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +4 -4
  24. package/src/plugins/autoreload/{dev_sse/jsenv_plugin_dev_sse_client.js → jsenv_plugin_autoreload_client.js} +8 -8
  25. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +196 -0
  26. package/src/{dev/plugins → plugins}/explorer/client/explorer.html +0 -0
  27. package/src/{dev/plugins → plugins}/explorer/client/jsenv.png +0 -0
  28. package/src/{dev/plugins → plugins}/explorer/jsenv_plugin_explorer.js +1 -3
  29. package/src/plugins/html_supervisor/client/{error_in_document.js → error_overlay.js} +73 -17
  30. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +127 -54
  31. package/src/plugins/html_supervisor/client/html_supervisor_setup.js +3 -4
  32. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +19 -12
  33. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +97 -117
  34. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +66 -58
  35. package/src/plugins/plugin_controller.js +102 -67
  36. package/src/plugins/plugins.js +10 -8
  37. package/src/{helpers/event_source/event_source.js → plugins/server_events/client/event_source_connection.js} +102 -31
  38. package/src/plugins/server_events/client/server_events_client.js +17 -0
  39. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +48 -0
  40. package/src/plugins/server_events/server_events_dispatcher.js +69 -0
  41. package/src/{dev/plugins → plugins}/toolbar/client/animation/toolbar_animation.js +0 -0
  42. package/src/{dev/plugins → plugins}/toolbar/client/eventsource/eventsource.css +0 -0
  43. package/src/{dev/plugins → plugins}/toolbar/client/eventsource/toolbar_eventsource.js +0 -0
  44. package/src/{dev/plugins → plugins}/toolbar/client/execution/execution.css +0 -0
  45. package/src/{dev/plugins → plugins}/toolbar/client/execution/toolbar_execution.js +0 -0
  46. package/src/{dev/plugins → plugins}/toolbar/client/focus/focus.css +0 -0
  47. package/src/{dev/plugins → plugins}/toolbar/client/focus/toolbar_focus.js +0 -0
  48. package/src/{dev/plugins → plugins}/toolbar/client/jsenv_logo.svg +0 -0
  49. package/src/{dev/plugins → plugins}/toolbar/client/notification/toolbar_notification.js +0 -0
  50. package/src/{dev/plugins → plugins}/toolbar/client/responsive/overflow_menu.css +0 -0
  51. package/src/{dev/plugins → plugins}/toolbar/client/responsive/toolbar_responsive.js +0 -0
  52. package/src/{dev/plugins → plugins}/toolbar/client/settings/settings.css +0 -0
  53. package/src/{dev/plugins → plugins}/toolbar/client/settings/toolbar_settings.js +0 -0
  54. package/src/{dev/plugins → plugins}/toolbar/client/theme/jsenv_theme.css +0 -0
  55. package/src/{dev/plugins → plugins}/toolbar/client/theme/light_theme.css +0 -0
  56. package/src/{dev/plugins → plugins}/toolbar/client/theme/toolbar_theme.js +0 -0
  57. package/src/{dev/plugins → plugins}/toolbar/client/toolbar.html +0 -0
  58. package/src/{dev/plugins → plugins}/toolbar/client/toolbar_injector.js +0 -0
  59. package/src/{dev/plugins → plugins}/toolbar/client/toolbar_main.css +0 -0
  60. package/src/{dev/plugins → plugins}/toolbar/client/toolbar_main.js +0 -0
  61. package/src/{dev/plugins → plugins}/toolbar/client/tooltip/tooltip.css +0 -0
  62. package/src/{dev/plugins → plugins}/toolbar/client/tooltip/tooltip.js +0 -0
  63. package/src/{dev/plugins → plugins}/toolbar/client/util/animation.js +0 -0
  64. package/src/{dev/plugins → plugins}/toolbar/client/util/dom.js +0 -0
  65. package/src/{dev/plugins → plugins}/toolbar/client/util/fetch_using_xhr.js +0 -0
  66. package/src/{dev/plugins → plugins}/toolbar/client/util/fetching.js +0 -0
  67. package/src/{dev/plugins → plugins}/toolbar/client/util/iframe_to_parent_href.js +0 -0
  68. package/src/{dev/plugins → plugins}/toolbar/client/util/jsenv_logger.js +0 -0
  69. package/src/{dev/plugins → plugins}/toolbar/client/util/preferences.js +0 -0
  70. package/src/{dev/plugins → plugins}/toolbar/client/util/responsive.js +0 -0
  71. package/src/{dev/plugins → plugins}/toolbar/client/util/util.js +0 -0
  72. package/src/{dev/plugins → plugins}/toolbar/client/variant/variant.js +0 -0
  73. package/src/{dev/plugins → plugins}/toolbar/jsenv_plugin_toolbar.js +0 -0
  74. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +4 -3
  75. package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +25 -55
  76. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +44 -24
  77. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +6 -1
  78. package/src/plugins/url_analysis/html/html_urls.js +8 -8
  79. package/src/test/execute_plan.js +36 -54
  80. package/src/test/execute_test_plan.js +2 -2
  81. package/dist/js/event_source_client.js +0 -549
  82. package/src/helpers/event_source/sse_service.js +0 -53
  83. package/src/plugins/autoreload/dev_sse/client/event_source_client.js +0 -193
  84. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_server.js +0 -192
@@ -14,7 +14,11 @@ import { urlToFilename, injectQueryParams } from "@jsenv/urls"
14
14
 
15
15
  import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js"
16
16
 
17
- export const jsenvPluginImportAssertions = () => {
17
+ export const jsenvPluginImportAssertions = ({
18
+ json = "auto",
19
+ css = "auto",
20
+ text = "auto",
21
+ }) => {
18
22
  const updateReference = (reference, searchParam) => {
19
23
  reference.expectedType = "js_module"
20
24
  reference.filename = `${urlToFilename(reference.url)}.js`
@@ -33,42 +37,58 @@ export const jsenvPluginImportAssertions = () => {
33
37
  const importAssertions = {
34
38
  name: "jsenv:import_assertions",
35
39
  appliesDuring: "*",
40
+ init: (context) => {
41
+ // transpilation is forced during build so that
42
+ // - avoid rollup to see import assertions
43
+ // We would have to tell rollup to ignore import with assertion
44
+ // - means rollup can bundle more js file together
45
+ // - means url versioning can work for css inlined in js
46
+ if (context.scenario === "build") {
47
+ json = true
48
+ css = true
49
+ text = true
50
+ }
51
+ },
36
52
  redirectUrl: {
37
53
  js_import_export: (reference, context) => {
38
54
  if (!reference.assert) {
39
55
  return null
40
56
  }
41
- // during build always replace import assertions with the js:
42
- // - avoid rollup to see import assertions
43
- // We would have to tell rollup to ignore import with assertion
44
- // - means rollup can bundle more js file together
45
- // - means url versioning can work for css inlined in js
46
57
  if (reference.assert.type === "json") {
47
- if (
48
- context.scenario !== "build" &&
49
- context.isSupportedOnCurrentClients("import_type_json")
50
- ) {
51
- return null
58
+ const shouldTranspileJsonImportAssertion =
59
+ json === true
60
+ ? true
61
+ : json === "auto"
62
+ ? !context.isSupportedOnCurrentClients("import_type_json")
63
+ : false
64
+ if (shouldTranspileJsonImportAssertion) {
65
+ return updateReference(reference, "as_json_module")
52
66
  }
53
- return updateReference(reference, "as_json_module")
67
+ return null
54
68
  }
55
69
  if (reference.assert.type === "css") {
56
- if (
57
- context.scenario !== "build" &&
58
- context.isSupportedOnCurrentClients("import_type_css")
59
- ) {
60
- return null
70
+ const shouldTranspileCssImportAssertion =
71
+ css === true
72
+ ? true
73
+ : css === "auto"
74
+ ? !context.isSupportedOnCurrentClients("import_type_css")
75
+ : false
76
+ if (shouldTranspileCssImportAssertion) {
77
+ return updateReference(reference, "as_css_module")
61
78
  }
62
- return updateReference(reference, "as_css_module")
79
+ return null
63
80
  }
64
81
  if (reference.assert.type === "text") {
65
- if (
66
- context.scenario !== "build" &&
67
- context.isSupportedOnCurrentClients("import_type_text")
68
- ) {
69
- return null
82
+ const shouldTranspileTextImportAssertion =
83
+ text === true
84
+ ? true
85
+ : text === "auto"
86
+ ? !context.isSupportedOnCurrentClients("import_type_text")
87
+ : false
88
+ if (shouldTranspileTextImportAssertion) {
89
+ return updateReference(reference, "as_text_module")
70
90
  }
71
- return updateReference(reference, "as_text_module")
91
+ return null
72
92
  }
73
93
  return null
74
94
  },
@@ -22,9 +22,14 @@ export const jsenvPluginTranspilation = ({
22
22
  babelHelpersAsImport = true,
23
23
  getCustomBabelPlugins,
24
24
  }) => {
25
+ if (importAssertions === true) {
26
+ importAssertions = {}
27
+ }
25
28
  return [
26
29
  // import assertions we want it all the time
27
- ...(importAssertions ? [jsenvPluginImportAssertions()] : []),
30
+ ...(importAssertions
31
+ ? [jsenvPluginImportAssertions(importAssertions)]
32
+ : []),
28
33
  // babel also so that rollup can bundle babel helpers for instance
29
34
  jsenvPluginBabel({
30
35
  topLevelAwait,
@@ -5,6 +5,7 @@ import {
5
5
  getHtmlNodePosition,
6
6
  setHtmlNodeAttributes,
7
7
  getHtmlNodeAttributePosition,
8
+ analyzeScriptNode,
8
9
  parseSrcSet,
9
10
  stringifyHtmlAst,
10
11
  } from "@jsenv/ast"
@@ -188,16 +189,15 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
188
189
  },
189
190
  // style: () => {},
190
191
  script: (node) => {
191
- const type = getHtmlNodeAttribute(node, "type")
192
- const expectedType = {
193
- "undefined": "js_classic",
194
- "text/javascript": "js_classic",
195
- "module": "js_module",
196
- "importmap": "importmap",
197
- }[type]
192
+ const { type } = analyzeScriptNode(node)
193
+ if (type === "text") {
194
+ // ignore <script type="whatever" src="./file.js">
195
+ // per HTML spec https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type
196
+ return
197
+ }
198
198
  visitAttributeAsUrlSpecifier({
199
199
  type: "script_src",
200
- expectedType,
200
+ expectedType: type,
201
201
  node,
202
202
  attributeName: "src",
203
203
  })
@@ -16,9 +16,6 @@ import { ensureEmptyDirectory, writeFileSync } from "@jsenv/filesystem"
16
16
 
17
17
  import { babelPluginInstrument } from "./coverage/babel_plugin_instrument.js"
18
18
  import { reportToCoverage } from "./coverage/report_to_coverage.js"
19
- import { createUrlGraph } from "@jsenv/core/src/omega/url_graph.js"
20
- import { getCorePlugins } from "@jsenv/core/src/plugins/plugins.js"
21
- import { createKitchen } from "@jsenv/core/src/omega/kitchen.js"
22
19
  import { startOmegaServer } from "@jsenv/core/src/omega/omega_server.js"
23
20
  import { run } from "@jsenv/core/src/execute/run.js"
24
21
 
@@ -43,6 +40,7 @@ export const executePlan = async (
43
40
 
44
41
  rootDirectoryUrl,
45
42
  keepRunning,
43
+ services,
46
44
  defaultMsAllocatedPerExecution,
47
45
  maxExecutionsInParallel,
48
46
  failFast,
@@ -68,7 +66,7 @@ export const executePlan = async (
68
66
  protocol,
69
67
  privateKey,
70
68
  certificate,
71
- ip,
69
+ host,
72
70
  port,
73
71
 
74
72
  beforeExecutionCallback = () => {},
@@ -198,64 +196,48 @@ export const executePlan = async (
198
196
  stopAfterAllSignal,
199
197
  }
200
198
  if (someNeedsServer) {
201
- const urlGraph = createUrlGraph()
202
- const kitchen = createKitchen({
203
- signal,
204
- logger,
205
- rootDirectoryUrl,
206
- urlGraph,
207
- scenario,
208
- sourcemaps,
209
- runtimeCompat: runtimes,
210
- writeGeneratedFiles,
211
- plugins: [
212
- ...plugins,
213
- ...getCorePlugins({
214
- rootDirectoryUrl,
215
- urlGraph,
216
- scenario,
217
- runtimeCompat: runtimes,
218
-
219
- htmlSupervisor: true,
220
- nodeEsmResolution,
221
- fileSystemMagicResolution,
222
- transpilation: {
223
- ...transpilation,
224
- getCustomBabelPlugins: ({ clientRuntimeCompat }) => {
225
- if (
226
- coverageEnabled &&
227
- (coverageMethodForBrowsers !== "playwright_api" ||
228
- Object.keys(clientRuntimeCompat)[0] !== "chrome")
229
- ) {
230
- return {
231
- "transform-instrument": [
232
- babelPluginInstrument,
233
- {
234
- rootDirectoryUrl,
235
- coverageConfig,
236
- },
237
- ],
238
- }
239
- }
240
- return {}
241
- },
242
- },
243
- }),
244
- ],
245
- })
246
199
  const server = await startOmegaServer({
247
200
  signal: multipleExecutionsOperation.signal,
248
201
  logLevel: "warn",
249
- rootDirectoryUrl,
250
- urlGraph,
251
- kitchen,
252
- scenario,
253
202
  keepProcessAlive: false,
254
203
  port,
255
- ip,
204
+ host,
256
205
  protocol,
257
206
  certificate,
258
207
  privateKey,
208
+ services,
209
+
210
+ rootDirectoryUrl,
211
+ scenario,
212
+ runtimeCompat: runtimes,
213
+
214
+ plugins,
215
+ htmlSupervisor: true,
216
+ nodeEsmResolution,
217
+ fileSystemMagicResolution,
218
+ transpilation: {
219
+ ...transpilation,
220
+ getCustomBabelPlugins: ({ clientRuntimeCompat }) => {
221
+ if (
222
+ coverageEnabled &&
223
+ (coverageMethodForBrowsers !== "playwright_api" ||
224
+ Object.keys(clientRuntimeCompat)[0] !== "chrome")
225
+ ) {
226
+ return {
227
+ "transform-instrument": [
228
+ babelPluginInstrument,
229
+ {
230
+ rootDirectoryUrl,
231
+ coverageConfig,
232
+ },
233
+ ],
234
+ }
235
+ }
236
+ return {}
237
+ },
238
+ },
239
+ sourcemaps,
240
+ writeGeneratedFiles,
259
241
  })
260
242
  multipleExecutionsOperation.addEndCallback(async () => {
261
243
  await server.stop()
@@ -90,7 +90,7 @@ export const executeTestPlan = async ({
90
90
  protocol,
91
91
  privateKey,
92
92
  certificate,
93
- ip,
93
+ host,
94
94
  port,
95
95
  }) => {
96
96
  const logger = createLogger({ logLevel })
@@ -177,7 +177,7 @@ export const executeTestPlan = async ({
177
177
  protocol,
178
178
  privateKey,
179
179
  certificate,
180
- ip,
180
+ host,
181
181
  port,
182
182
  })
183
183
  if (