@jsenv/core 27.0.0-alpha.63 → 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 (39) hide show
  1. package/dist/html_supervisor_installer.js +1 -1
  2. package/dist/html_supervisor_installer.js.map +2 -2
  3. package/dist/s.js +626 -0
  4. package/dist/s.js.map +207 -0
  5. package/main.js +1 -0
  6. package/package.json +6 -6
  7. package/src/build/build.js +23 -8
  8. package/src/build/inject_global_version_mappings.js +18 -5
  9. package/src/build/start_build_server.js +38 -29
  10. package/src/dev/start_dev_server.js +1 -1
  11. package/src/execute/runtimes/browsers/from_playwright.js +10 -0
  12. package/src/execute/runtimes/node/node_process.js +8 -0
  13. package/src/omega/kitchen.js +52 -134
  14. package/src/omega/server/file_service.js +34 -17
  15. package/src/omega/url_graph/url_graph_load.js +10 -17
  16. package/src/omega/url_graph/url_info_transformations.js +1 -4
  17. package/src/omega/url_graph.js +6 -2
  18. package/src/omega/url_specifier_encoding.js +59 -0
  19. package/src/plugins/html_supervisor/client/html_supervisor_installer.js +1 -1
  20. package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -4
  21. package/src/plugins/inject_globals/jsenv_plugin_inject_globals.js +51 -42
  22. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -4
  23. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +3 -5
  24. package/src/plugins/inline/jsenv_plugin_inline_query_param.js +1 -4
  25. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -4
  26. package/src/plugins/node_esm_resolution/jsenv_plugin_node_esm_resolution.js +4 -0
  27. package/src/plugins/plugins.js +4 -1
  28. package/src/plugins/transpilation/as_js_classic/client/s.js +362 -807
  29. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +28 -12
  30. package/src/plugins/transpilation/as_js_classic/{jsenv_plugin_workers_type_module_as_classic.js → jsenv_plugin_as_js_classic_workers.js} +2 -2
  31. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_script_type_module_as_classic.js +165 -133
  32. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +5 -2
  33. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -2
  34. package/src/plugins/transpilation/jsenv_plugin_transpilation.js +4 -1
  35. package/src/test/execute_plan.js +32 -13
  36. package/src/test/execute_test_plan.js +2 -0
  37. package/src/test/logs_file_execution.js +47 -38
  38. package/src/plugins/transpilation/as_js_classic/client/s.js.md +0 -1
  39. package/src/plugins/transpilation/fetch_original_url_info.js +0 -30
@@ -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({