@jsenv/core 27.0.0-alpha.61 → 27.0.0-alpha.64

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 (43) hide show
  1. package/dist/event_source_client.js +3 -3
  2. package/dist/event_source_client.js.map +7 -8
  3. package/dist/html_supervisor_installer.js +1 -1
  4. package/dist/html_supervisor_installer.js.map +2 -2
  5. package/dist/s.js +626 -0
  6. package/dist/s.js.map +207 -0
  7. package/main.js +1 -0
  8. package/package.json +8 -8
  9. package/src/build/build.js +23 -8
  10. package/src/build/inject_global_version_mappings.js +18 -5
  11. package/src/build/start_build_server.js +49 -32
  12. package/src/dev/start_dev_server.js +11 -3
  13. package/src/execute/runtimes/browsers/from_playwright.js +10 -0
  14. package/src/execute/runtimes/node/node_process.js +8 -0
  15. package/src/omega/kitchen.js +57 -150
  16. package/src/omega/server/file_service.js +34 -17
  17. package/src/omega/url_graph/url_graph_load.js +10 -17
  18. package/src/omega/url_graph/url_info_transformations.js +1 -4
  19. package/src/omega/url_graph.js +6 -2
  20. package/src/omega/url_specifier_encoding.js +59 -0
  21. package/src/plugins/autoreload/dev_sse/client/event_source_client.js +7 -3
  22. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +1 -1
  23. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +1 -1
  24. package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -4
  25. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +51 -42
  26. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -4
  27. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +3 -5
  28. package/src/plugins/inline/jsenv_plugin_inline_query_param.js +1 -4
  29. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -4
  30. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +4 -0
  31. package/src/plugins/plugins.js +4 -1
  32. package/src/plugins/transpilation/as_js_classic/client/s.js +362 -807
  33. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +28 -12
  34. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_workers_type_module_as_classic.js → jsenv_plugin_as_js_classic_workers.js} +2 -2
  35. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +165 -133
  36. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -2
  37. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -2
  38. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +4 -1
  39. package/src/test/execute_plan.js +39 -14
  40. package/src/test/execute_test_plan.js +2 -0
  41. package/src/test/logs_file_execution.js +47 -38
  42. package/src/plugins/transpilation/as_js_classic/client/s.js.md +0 -1
  43. package/src/plugins/transpilation/fetch_original_url_info.js +0 -30
@@ -96,11 +96,15 @@ const applyHotReload = async ({ hotInstructions }) => {
96
96
  // if (!urlHotMeta) {return }
97
97
 
98
98
  if (type === "prune") {
99
- console.group(`[jsenv] prune: ${boundary} (inside ${acceptedBy})`)
99
+ console.groupCollapsed(
100
+ `[jsenv] prune: ${boundary} (inside ${acceptedBy})`,
101
+ )
100
102
  } else if (acceptedBy === boundary) {
101
- console.group(`[jsenv] hot reloading: ${boundary}`)
103
+ console.groupCollapsed(`[jsenv] hot reloading: ${boundary}`)
102
104
  } else {
103
- console.group(`[jsenv] hot reloading: ${acceptedBy} inside ${boundary}`)
105
+ console.groupCollapsed(
106
+ `[jsenv] hot reloading: ${acceptedBy} inside ${boundary}`,
107
+ )
104
108
  }
105
109
  if (urlHotMeta && urlHotMeta.disposeCallback) {
106
110
  console.log(`call dispose callback`)
@@ -22,7 +22,7 @@ export const jsenvPluginCommonJsGlobals = () => {
22
22
  const isJsModule = urlInfo.type === "js_module"
23
23
  const replaceMap = {
24
24
  "process.env.NODE_ENV": `("${
25
- scenario === "dev" || scenario === "test" ? "dev" : "prod"
25
+ scenario === "dev" || scenario === "test" ? "development" : "production"
26
26
  }")`,
27
27
  "global": "globalThis",
28
28
  "__filename": isJsModule
@@ -185,7 +185,7 @@ export const installHtmlSupervisor = ({ logs, measurePerf }) => {
185
185
  dequeue()
186
186
  }
187
187
  if (
188
- document.readyState !== "intractive" &&
188
+ document.readyState !== "interactive" &&
189
189
  document.readyState !== "complete"
190
190
  ) {
191
191
  document.addEventListener("readystatechange", () => {
@@ -130,9 +130,8 @@ export const jsenvPluginImportmap = () => {
130
130
  contentType: "application/importmap+json",
131
131
  content: textNode.value,
132
132
  })
133
- await context.cook({
133
+ await context.cook(inlineImportmapUrlInfo, {
134
134
  reference: inlineImportmapReference,
135
- urlInfo: inlineImportmapUrlInfo,
136
135
  })
137
136
  setHtmlNodeGeneratedText(importmap, {
138
137
  generatedText: inlineImportmapUrlInfo.content,
@@ -154,9 +153,8 @@ export const jsenvPluginImportmap = () => {
154
153
  const importmapUrlInfo = context.urlGraph.getUrlInfo(
155
154
  importmapReference.url,
156
155
  )
157
- await context.cook({
156
+ await context.cook(importmapUrlInfo, {
158
157
  reference: importmapReference,
159
- urlInfo: importmapUrlInfo,
160
158
  })
161
159
  onHtmlImportmapParsed(
162
160
  JSON.parse(importmapUrlInfo.content),
@@ -11,56 +11,65 @@ export const jsenvPluginInjectGlobals = (globals = {}) => {
11
11
  if (Object.keys(globals).length === 0) {
12
12
  return []
13
13
  }
14
-
15
- const globalInjectorOnHtmlEntryPoint = (urlInfo) => {
16
- if (!urlInfo.data.isEntryPoint) {
17
- return null
18
- }
19
- // ideally we would inject an importmap but browser support is too low
20
- // (even worse for worker/service worker)
21
- // so for now we inject code into entry points
22
- const htmlAst = parseHtmlString(urlInfo.content, {
23
- storeOriginalPositions: false,
24
- })
25
- injectScriptAsEarlyAsPossible(
26
- htmlAst,
27
- createHtmlNode({
28
- "tagName": "script",
29
- "textContent": generateClientCodeForGlobals({
30
- globals,
31
- isWebWorker: false,
32
- }),
33
- "injected-by": "jsenv:inject_globals",
34
- }),
35
- )
36
- return stringifyHtmlAst(htmlAst)
37
- }
38
-
39
- const globalsInjectorOnJsEntryPoints = (urlInfo) => {
40
- if (!urlInfo.data.isEntryPoint && !urlInfo.data.isWebWorkerEntryPoint) {
41
- return null
42
- }
43
- const magicSource = createMagicSource(urlInfo.content)
44
- magicSource.append(
45
- generateClientCodeForGlobals({
46
- globals,
47
- isWebWorker: isWebWorkerUrlInfo(urlInfo),
48
- }),
49
- )
50
- return magicSource.toContentAndSourcemap()
51
- }
52
-
53
14
  return {
54
15
  name: "jsenv:inject_globals",
55
16
  appliesDuring: "*",
56
17
  transformUrlContent: {
57
- html: globalInjectorOnHtmlEntryPoint,
58
- js_classic: globalsInjectorOnJsEntryPoints,
59
- js_module: globalsInjectorOnJsEntryPoints,
18
+ html: injectGlobals,
19
+ js_classic: injectGlobals,
20
+ js_module: injectGlobals,
60
21
  },
61
22
  }
62
23
  }
63
24
 
25
+ export const injectGlobals = (urlInfo, globals) => {
26
+ if (urlInfo.type === "html") {
27
+ return globalInjectorOnHtmlEntryPoint(urlInfo, globals)
28
+ }
29
+ if (urlInfo.type === "js_classic" || urlInfo.type === "js_module") {
30
+ return globalsInjectorOnJsEntryPoints(urlInfo, globals)
31
+ }
32
+ throw new Error(`cannot inject globals into "${urlInfo.type}"`)
33
+ }
34
+
35
+ const globalInjectorOnHtmlEntryPoint = async (urlInfo, globals) => {
36
+ if (!urlInfo.data.isEntryPoint) {
37
+ return null
38
+ }
39
+ // ideally we would inject an importmap but browser support is too low
40
+ // (even worse for worker/service worker)
41
+ // so for now we inject code into entry points
42
+ const htmlAst = parseHtmlString(urlInfo.content, {
43
+ storeOriginalPositions: false,
44
+ })
45
+ const clientCode = generateClientCodeForGlobals({
46
+ globals,
47
+ isWebWorker: false,
48
+ })
49
+ injectScriptAsEarlyAsPossible(
50
+ htmlAst,
51
+ createHtmlNode({
52
+ "tagName": "script",
53
+ "textContent": clientCode,
54
+ "injected-by": "jsenv:inject_globals",
55
+ }),
56
+ )
57
+ return stringifyHtmlAst(htmlAst)
58
+ }
59
+
60
+ const globalsInjectorOnJsEntryPoints = async (urlInfo, globals) => {
61
+ if (!urlInfo.data.isEntryPoint && !urlInfo.data.isWebWorkerEntryPoint) {
62
+ return null
63
+ }
64
+ const clientCode = generateClientCodeForGlobals({
65
+ globals,
66
+ isWebWorker: isWebWorkerUrlInfo(urlInfo),
67
+ })
68
+ const magicSource = createMagicSource(urlInfo.content)
69
+ magicSource.prepend(clientCode)
70
+ return magicSource.toContentAndSourcemap()
71
+ }
72
+
64
73
  const generateClientCodeForGlobals = ({ isWebWorker = false, globals }) => {
65
74
  const globalName = isWebWorker ? "self" : "window"
66
75
  return `Object.assign(${globalName}, ${JSON.stringify(globals, null, " ")});`
@@ -35,10 +35,7 @@ export const jsenvPluginDataUrls = () => {
35
35
  }
36
36
  return (async () => {
37
37
  const urlInfo = context.urlGraph.getUrlInfo(reference.url)
38
- await context.cook({
39
- reference,
40
- urlInfo,
41
- })
38
+ await context.cook(urlInfo, { reference })
42
39
  if (urlInfo.originalContent === urlInfo.content) {
43
40
  return reference.generatedUrl
44
41
  }
@@ -54,9 +54,8 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
54
54
  contentType: "text/css",
55
55
  content: textNode.value,
56
56
  })
57
- await context.cook({
57
+ await context.cook(inlineStyleUrlInfo, {
58
58
  reference: inlineStyleReference,
59
- urlInfo: inlineStyleUrlInfo,
60
59
  })
61
60
  setHtmlNodeGeneratedText(node, {
62
61
  generatedText: inlineStyleUrlInfo.content,
@@ -77,7 +76,7 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
77
76
  // - we want to avoid cooking twice a script during build
78
77
  const generatedBy = getHtmlNodeAttributeByName(node, "generated-by")
79
78
  if (generatedBy) {
80
- if (generatedBy.value === "jsenv:script_type_module_as_classic") {
79
+ if (generatedBy.value === "jsenv:as_js_classic_html") {
81
80
  if (!analyzeConvertedScripts) {
82
81
  return
83
82
  }
@@ -135,9 +134,8 @@ export const jsenvPluginHtmlInlineContent = ({ analyzeConvertedScripts }) => {
135
134
  content: textNode.value,
136
135
  })
137
136
 
138
- await context.cook({
137
+ await context.cook(inlineScriptUrlInfo, {
139
138
  reference: inlineScriptReference,
140
- urlInfo: inlineScriptUrlInfo,
141
139
  })
142
140
  setHtmlNodeGeneratedText(node, {
143
141
  generatedText: inlineScriptUrlInfo.content,
@@ -25,10 +25,7 @@ export const jsenvPluginInlineQueryParam = () => {
25
25
  }
26
26
  return (async () => {
27
27
  const urlInfo = context.urlGraph.getUrlInfo(reference.url)
28
- await context.cook({
29
- reference,
30
- urlInfo,
31
- })
28
+ await context.cook(urlInfo, { reference })
32
29
  const specifier = DataUrl.stringify({
33
30
  mediaType: urlInfo.contentType,
34
31
  base64Flag: true,
@@ -49,10 +49,7 @@ export const jsenvPluginJsInlineContent = ({ allowEscapeForVersioning }) => {
49
49
  inlineUrlInfo.jsQuote = quote
50
50
  inlineReference.escape = (value) =>
51
51
  JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote })
52
- await context.cook({
53
- reference: inlineReference,
54
- urlInfo: inlineUrlInfo,
55
- })
52
+ await context.cook(inlineUrlInfo, { reference: inlineReference })
56
53
  magicSource.replace({
57
54
  start: inlineContentInfo.start,
58
55
  end: inlineContentInfo.end,
@@ -138,6 +138,10 @@ const jsenvPluginNodeModulesVersionInUrls = ({
138
138
  return null
139
139
  }
140
140
  const packageVersion = readPackageJson(packageUrl).version
141
+ if (!packageVersion) {
142
+ // example where it happens: https://github.com/babel/babel/blob/2ce56e832c2dd7a7ed92c89028ba929f874c2f5c/packages/babel-runtime/helpers/esm/package.json#L2
143
+ return null
144
+ }
141
145
  return {
142
146
  v: packageVersion,
143
147
  }
@@ -44,7 +44,10 @@ export const getCorePlugins = ({
44
44
  }
45
45
  return [
46
46
  jsenvPluginUrlAnalysis(),
47
- jsenvPluginTranspilation(transpilation),
47
+ jsenvPluginTranspilation({
48
+ rootDirectoryUrl,
49
+ ...transpilation,
50
+ }),
48
51
  ...(htmlSupervisor
49
52
  ? [
50
53
  jsenvPluginHtmlSupervisor({