@jsenv/core 27.0.0-alpha.83 → 27.0.0-alpha.86

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 (62) hide show
  1. package/dist/html/explorer.html +1 -1
  2. package/dist/js/event_source_client.js +3 -3
  3. package/dist/js/s.js +2 -2
  4. package/dist/main.js +503 -417
  5. package/dist/s.js +2 -2
  6. package/dist/s.js.map +2 -1
  7. package/package.json +7 -3
  8. package/src/build/build.js +5 -8
  9. package/src/build/build_urls_generator.js +1 -2
  10. package/src/build/inject_global_version_mappings.js +4 -4
  11. package/src/build/inject_service_worker_urls.js +2 -2
  12. package/src/build/resync_ressource_hints.js +17 -18
  13. package/src/build/start_build_server.js +5 -1
  14. package/src/build/version_generator.js +60 -0
  15. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  16. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +2 -3
  17. package/src/dev/plugins/toolbar/client/util/fetching.js +1 -1
  18. package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -3
  19. package/src/dev/start_dev_server.js +5 -1
  20. package/src/execute/runtimes/browsers/from_playwright.js +2 -2
  21. package/src/execute/runtimes/node/node_process.js +2 -2
  22. package/src/helpers/command/command.js +73 -0
  23. package/src/helpers/worker_reload.js +4 -3
  24. package/src/omega/compat/runtime_compat.js +2 -1
  25. package/src/omega/kitchen.js +4 -1
  26. package/src/omega/server/user_agent.js +2 -1
  27. package/src/omega/url_graph/sort_by_dependencies.js +27 -0
  28. package/src/omega/url_graph/url_info_transformations.js +24 -14
  29. package/src/plugins/autoreload/dev_sse/client/reload.js +6 -3
  30. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +3 -3
  31. package/src/plugins/bundling/css/bundle_css.js +4 -4
  32. package/src/plugins/bundling/js_module/bundle_js_module.js +86 -67
  33. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +2 -2
  34. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +4 -5
  35. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +62 -74
  36. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +10 -6
  37. package/src/plugins/import_meta_hot/html_hot_dependencies.js +9 -15
  38. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +3 -3
  39. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +2 -2
  40. package/src/plugins/importmap/jsenv_plugin_importmap.js +25 -27
  41. package/src/plugins/inject_globals/inject_globals.js +4 -4
  42. package/src/plugins/inline/jsenv_plugin_data_urls.js +1 -1
  43. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +41 -43
  44. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +4 -4
  45. package/src/plugins/minification/css/minify_css.js +1 -1
  46. package/src/plugins/transpilation/as_js_classic/client/s.js +2 -2
  47. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +2 -4
  48. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +45 -67
  49. package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +2 -3
  50. package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +3 -4
  51. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +1 -1
  52. package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +2 -3
  53. package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +2 -3
  54. package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +1 -1
  55. package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +1 -1
  56. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +2 -1
  57. package/src/plugins/url_analysis/css/css_urls.js +2 -3
  58. package/src/plugins/url_analysis/html/html_urls.js +98 -113
  59. package/src/plugins/url_analysis/js/js_urls.js +3 -2
  60. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +10 -6
  61. package/src/test/coverage/empty_coverage_factory.js +1 -1
  62. package/src/test/coverage/file_by_file_coverage.js +1 -2
@@ -1,10 +1,9 @@
1
1
  import { pathToFileURL } from "node:url"
2
-
3
- import { injectImport } from "@jsenv/utils/js_ast/babel_utils.js"
2
+ import { injectJsImport } from "@jsenv/ast"
4
3
  import {
5
4
  getBabelHelperFileUrl,
6
5
  babelHelperNameFromUrl,
7
- } from "@jsenv/babel-plugins/main.js"
6
+ } from "@jsenv/babel-plugins"
8
7
 
9
8
  // named import approach found here:
10
9
  // https://github.com/rollup/rollup-plugin-babel/blob/18e4232a450f320f44c651aa8c495f21c74d59ac/src/helperPlugin.js#L1
@@ -37,7 +36,7 @@ export const babelPluginBabelHelpersAsJsenvImports = (
37
36
  return undefined
38
37
  }
39
38
  const babelHelperImportSpecifier = getBabelHelperFileUrl(name)
40
- const helper = injectImport({
39
+ const helper = injectJsImport({
41
40
  programPath: file.path,
42
41
  from: getImportSpecifier(babelHelperImportSpecifier),
43
42
  nameHint: `_${name}`,
@@ -1,4 +1,4 @@
1
- import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
1
+ import { applyBabelPlugins } from "@jsenv/ast"
2
2
 
3
3
  import { RUNTIME_COMPAT } from "@jsenv/core/src/omega/compat/runtime_compat.js"
4
4
  import { getBaseBabelPluginStructure } from "./helpers/babel_plugin_structure.js"
@@ -1,6 +1,5 @@
1
1
  import { pathToFileURL } from "node:url"
2
-
3
- import { injectImport } from "@jsenv/utils/js_ast/babel_utils.js"
2
+ import { injectJsImport } from "@jsenv/ast"
4
3
 
5
4
  export const babelPluginNewStylesheetAsJsenvImport = (
6
5
  babel,
@@ -85,7 +84,7 @@ export const babelPluginNewStylesheetAsJsenvImport = (
85
84
  },
86
85
  })
87
86
  if (usesNewStylesheet) {
88
- injectImport({
87
+ injectJsImport({
89
88
  programPath,
90
89
  from: getImportSpecifier(newStylesheetClientFileUrl),
91
90
  sideEffect: true,
@@ -1,6 +1,5 @@
1
1
  import { pathToFileURL } from "node:url"
2
-
3
- import { injectImport } from "@jsenv/utils/js_ast/babel_utils.js"
2
+ import { injectJsImport } from "@jsenv/ast"
4
3
 
5
4
  export const babelPluginRegeneratorRuntimeAsJsenvImport = (
6
5
  babel,
@@ -22,7 +21,7 @@ export const babelPluginRegeneratorRuntimeAsJsenvImport = (
22
21
  }
23
22
  const { node } = path
24
23
  if (node.name === "regeneratorRuntime") {
25
- injectImport({
24
+ injectJsImport({
26
25
  programPath: path.scope.getProgramParent().path,
27
26
  from: getImportSpecifier(regeneratorRuntimeClientFileUrl),
28
27
  sideEffect: true,
@@ -1,4 +1,4 @@
1
- import { transpileWithParcel } from "@jsenv/utils/css_ast/parcel_css.js"
1
+ import { transpileWithParcel } from "@jsenv/ast"
2
2
 
3
3
  // https://github.com/parcel-bundler/parcel-css
4
4
  export const jsenvPluginCssParcel = () => {
@@ -12,7 +12,7 @@
12
12
 
13
13
  import { urlToFilename, injectQueryParams } from "@jsenv/urls"
14
14
 
15
- import { JS_QUOTES } from "@jsenv/utils/string/js_quotes.js"
15
+ import { JS_QUOTES } from "@jsenv/utils/src/string/js_quotes.js"
16
16
 
17
17
  export const jsenvPluginImportAssertions = () => {
18
18
  const updateReference = (reference, searchParam) => {
@@ -1,4 +1,5 @@
1
- import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
1
+ import { applyBabelPlugins } from "@jsenv/ast"
2
+
2
3
  import { requireBabelPlugin } from "./babel/require_babel_plugin.js"
3
4
 
4
5
  export const jsenvPluginTopLevelAwait = () => {
@@ -2,9 +2,8 @@
2
2
  * https://github.com/parcel-bundler/parcel/blob/v2/packages/transformers/css/src/CSSTransformer.js
3
3
  */
4
4
 
5
- import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
6
- import { applyPostCss } from "@jsenv/utils/css_ast/apply_post_css.js"
7
- import { postCssPluginUrlVisitor } from "@jsenv/utils/css_ast/postcss_plugin_url_visitor.js"
5
+ import { createMagicSource } from "@jsenv/sourcemap"
6
+ import { applyPostCss, postCssPluginUrlVisitor } from "@jsenv/ast"
8
7
 
9
8
  export const parseAndTransformCssUrls = async (urlInfo, context) => {
10
9
  const actions = []
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  parseHtmlString,
3
+ visitHtmlNodes,
4
+ getHtmlNodeAttribute,
5
+ getHtmlNodePosition,
6
+ setHtmlNodeAttributes,
7
+ getHtmlNodeAttributePosition,
8
+ parseSrcSet,
3
9
  stringifyHtmlAst,
4
- getHtmlNodeAttributeByName,
5
- htmlNodePosition,
6
- visitHtmlAst,
7
- } from "@jsenv/utils/html_ast/html_ast.js"
8
- import { htmlAttributeSrcSet } from "@jsenv/utils/html_ast/html_attribute_src_set.js"
10
+ } from "@jsenv/ast"
9
11
 
10
12
  export const parseAndTransformHtmlUrls = async (urlInfo, context) => {
11
13
  const url = urlInfo.originalUrl
@@ -26,9 +28,12 @@ export const parseAndTransformHtmlUrls = async (urlInfo, context) => {
26
28
  column,
27
29
  originalLine,
28
30
  originalColumn,
31
+ node,
32
+ attributeName,
29
33
  specifier,
30
- attribute,
31
34
  }) => {
35
+ const { crossorigin, integrity } = readFetchMetas(node)
36
+
32
37
  const isRessourceHint = [
33
38
  "preconnect",
34
39
  "dns-prefetch",
@@ -45,9 +50,15 @@ export const parseAndTransformHtmlUrls = async (urlInfo, context) => {
45
50
  specifierLine: line,
46
51
  specifierColumn: column,
47
52
  isRessourceHint,
53
+ crossorigin,
54
+ integrity,
48
55
  })
49
56
  actions.push(async () => {
50
- attribute.value = await referenceUtils.readGeneratedSpecifier(reference)
57
+ setHtmlNodeAttributes(node, {
58
+ [attributeName]: await referenceUtils.readGeneratedSpecifier(
59
+ reference,
60
+ ),
61
+ })
51
62
  })
52
63
  },
53
64
  })
@@ -60,25 +71,39 @@ export const parseAndTransformHtmlUrls = async (urlInfo, context) => {
60
71
  }
61
72
  }
62
73
 
74
+ const crossOriginCompatibleTagNames = ["script", "link", "img", "source"]
75
+ const integrityCompatibleTagNames = ["script", "link", "img", "source"]
76
+ const readFetchMetas = (node) => {
77
+ const meta = {}
78
+ if (crossOriginCompatibleTagNames.includes(node.nodeName)) {
79
+ const crossorigin = getHtmlNodeAttribute(node, "crossorigin") !== undefined
80
+ meta.crossorigin = crossorigin
81
+ }
82
+ if (integrityCompatibleTagNames.includes(node.nodeName)) {
83
+ const integrity = getHtmlNodeAttribute(node, "integrity")
84
+ meta.integrity = integrity
85
+ }
86
+ return meta
87
+ }
88
+
63
89
  const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
64
90
  const addDependency = ({
65
91
  type,
66
92
  subtype,
67
93
  expectedType,
68
94
  node,
69
- attribute,
95
+ attributeName,
70
96
  specifier,
71
97
  }) => {
72
- const generatedFromInlineContent = Boolean(
73
- getHtmlNodeAttributeByName(node, "generated-from-inline-content"),
74
- )
98
+ const generatedFromInlineContent =
99
+ getHtmlNodeAttribute(node, "generated-from-inline-content") !== undefined
75
100
  let position
76
101
  if (generatedFromInlineContent) {
77
102
  // when generated from inline content,
78
103
  // line, column is not "src" nor "generated-from-src" but "original-position"
79
- position = htmlNodePosition.readNodePosition(node)
104
+ position = getHtmlNodePosition(node)
80
105
  } else {
81
- position = htmlNodePosition.readAttributePosition(node, attribute.name)
106
+ position = getHtmlNodeAttributePosition(node, attributeName)
82
107
  }
83
108
  const {
84
109
  line,
@@ -93,18 +118,61 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
93
118
  column,
94
119
  // originalLine, originalColumn
95
120
  specifier,
96
- attribute,
97
- // injected:Boolean(getHtmlNodeAttributeByName(node, "injected-by"))
98
- // srcGeneratedFromInlineContent
99
- ...readFetchMetas(node),
121
+ node,
122
+ attributeName,
100
123
  })
101
124
  }
102
- const visitors = {
125
+ const visitAttributeAsUrlSpecifier = ({ node, attributeName, ...rest }) => {
126
+ const value = getHtmlNodeAttribute(node, attributeName)
127
+ if (value) {
128
+ const generatedBy = getHtmlNodeAttribute(node, "generated-by")
129
+ if (generatedBy !== undefined) {
130
+ // during build the importmap is inlined
131
+ // and shoud not be considered as a dependency anymore
132
+ return
133
+ }
134
+ addDependency({
135
+ ...rest,
136
+ node,
137
+ attributeName,
138
+ specifier:
139
+ attributeName === "generated-from-src" ||
140
+ attributeName === "generated-from-href"
141
+ ? new URL(value, url).href
142
+ : value,
143
+ })
144
+ } else if (attributeName === "src") {
145
+ visitAttributeAsUrlSpecifier({
146
+ ...rest,
147
+ node,
148
+ attributeName: "generated-from-src",
149
+ })
150
+ } else if (attributeName === "href") {
151
+ visitAttributeAsUrlSpecifier({
152
+ ...rest,
153
+ node,
154
+ attributeName: "generated-from-href",
155
+ })
156
+ }
157
+ }
158
+ const visitSrcset = ({ type, node }) => {
159
+ const srcset = getHtmlNodeAttribute(node, "srcset")
160
+ if (srcset) {
161
+ const srcCandidates = parseSrcSet(srcset)
162
+ srcCandidates.forEach((srcCandidate) => {
163
+ addDependency({
164
+ type,
165
+ node,
166
+ attributeName: "srcset",
167
+ specifier: srcCandidate.specifier,
168
+ })
169
+ })
170
+ }
171
+ }
172
+ visitHtmlNodes(htmlAst, {
103
173
  link: (node) => {
104
- const relAttribute = getHtmlNodeAttributeByName(node, "rel")
105
- const rel = relAttribute ? relAttribute.value : undefined
106
- const typeAttribute = getHtmlNodeAttributeByName(node, "type")
107
- const type = typeAttribute ? typeAttribute.value : undefined
174
+ const rel = getHtmlNodeAttribute(node, "rel")
175
+ const type = getHtmlNodeAttribute(node, "type")
108
176
  visitAttributeAsUrlSpecifier({
109
177
  type: "link_href",
110
178
  subtype: rel,
@@ -120,15 +188,16 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
120
188
  },
121
189
  // style: () => {},
122
190
  script: (node) => {
123
- const typeAttributeNode = getHtmlNodeAttributeByName(node, "type")
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]
124
198
  visitAttributeAsUrlSpecifier({
125
199
  type: "script_src",
126
- expectedType: {
127
- "undefined": "js_classic",
128
- "text/javascript": "js_classic",
129
- "module": "js_module",
130
- "importmap": "importmap",
131
- }[typeAttributeNode ? typeAttributeNode.value : undefined],
200
+ expectedType,
132
201
  node,
133
202
  attributeName: "src",
134
203
  })
@@ -184,89 +253,5 @@ const visitHtmlUrls = ({ url, htmlAst, onUrl }) => {
184
253
  attributeName: "href",
185
254
  })
186
255
  },
187
- }
188
- const visitAttributeAsUrlSpecifier = ({
189
- type,
190
- subtype,
191
- expectedType,
192
- node,
193
- attributeName,
194
- }) => {
195
- const attribute = getHtmlNodeAttributeByName(node, attributeName)
196
- const value = attribute ? attribute.value : undefined
197
- if (value) {
198
- const generatedBy = getHtmlNodeAttributeByName(node, "generated-by")
199
- if (generatedBy) {
200
- // during build the importmap is inlined
201
- // and shoud not be considered as a dependency anymore
202
- return
203
- }
204
- addDependency({
205
- type,
206
- subtype,
207
- expectedType,
208
- node,
209
- attribute,
210
- specifier:
211
- attributeName === "generated-from-src" ||
212
- attributeName === "generated-from-href"
213
- ? new URL(value, url).href
214
- : value,
215
- })
216
- } else if (attributeName === "src") {
217
- visitAttributeAsUrlSpecifier({
218
- type,
219
- subtype,
220
- expectedType,
221
- node,
222
- attributeName: "generated-from-src",
223
- })
224
- } else if (attributeName === "href") {
225
- visitAttributeAsUrlSpecifier({
226
- type,
227
- subtype,
228
- expectedType,
229
- node,
230
- attributeName: "generated-from-href",
231
- })
232
- }
233
- }
234
- const visitSrcset = ({ type, node }) => {
235
- const srcsetAttribute = getHtmlNodeAttributeByName(node, "srcset")
236
- const srcset = srcsetAttribute ? srcsetAttribute.value : undefined
237
- if (srcset) {
238
- const srcCandidates = htmlAttributeSrcSet.parse(srcset)
239
- srcCandidates.forEach((srcCandidate) => {
240
- addDependency({
241
- type,
242
- node,
243
- attribute: srcsetAttribute,
244
- specifier: srcCandidate.specifier,
245
- })
246
- })
247
- }
248
- }
249
- visitHtmlAst(htmlAst, (node) => {
250
- const visitor = visitors[node.nodeName]
251
- if (visitor) {
252
- visitor(node)
253
- }
254
256
  })
255
257
  }
256
-
257
- const crossOriginCompatibleTagNames = ["script", "link", "img", "source"]
258
- const integrityCompatibleTagNames = ["script", "link", "img", "source"]
259
- const readFetchMetas = (node) => {
260
- const meta = {}
261
- if (crossOriginCompatibleTagNames.includes(node.nodeName)) {
262
- const crossoriginAttribute = getHtmlNodeAttributeByName(node, "crossorigin")
263
- meta.crossorigin = crossoriginAttribute
264
- ? crossoriginAttribute.value
265
- : undefined
266
- }
267
- if (integrityCompatibleTagNames.includes(node.nodeName)) {
268
- const integrityAttribute = getHtmlNodeAttributeByName(node, "integrity")
269
- meta.integrity = integrityAttribute ? integrityAttribute.value : undefined
270
- }
271
- return meta
272
- }
@@ -1,5 +1,6 @@
1
- import { parseJsUrls } from "@jsenv/utils/js_ast/parse_js_urls.js"
2
- import { createMagicSource } from "@jsenv/utils/sourcemap/magic_source.js"
1
+ import { createMagicSource } from "@jsenv/sourcemap"
2
+ import { parseJsUrls } from "@jsenv/ast"
3
+
3
4
  import { isWebWorkerUrlInfo } from "@jsenv/core/src/omega/web_workers.js"
4
5
 
5
6
  export const parseAndTransformJsUrls = async (urlInfo, context) => {
@@ -6,7 +6,11 @@ import { parseAndTransformCssUrls } from "./css/css_urls.js"
6
6
  import { parseAndTransformJsUrls } from "./js/js_urls.js"
7
7
  import { parseAndTransformWebmanifestUrls } from "./webmanifest/webmanifest_urls.js"
8
8
 
9
- export const jsenvPluginUrlAnalysis = ({ rootDirectoryUrl, include }) => {
9
+ export const jsenvPluginUrlAnalysis = ({
10
+ rootDirectoryUrl,
11
+ include,
12
+ supportedProtocols = ["file:", "data:", "virtual:", "http:", "https:"],
13
+ }) => {
10
14
  let getIncludeInfo = () => undefined
11
15
  if (include) {
12
16
  const associations = URL_META.resolveAssociations(
@@ -43,11 +47,11 @@ export const jsenvPluginUrlAnalysis = ({ rootDirectoryUrl, include }) => {
43
47
  reference.shouldHandle = false
44
48
  return
45
49
  }
46
- if (reference.url.startsWith("data:")) {
47
- reference.shouldHandle = true
48
- return
49
- }
50
- if (reference.url.startsWith("file:")) {
50
+ const { protocol } = new URL(reference.url)
51
+ const protocolIsSupported = supportedProtocols.some(
52
+ (supportedProtocol) => protocol === supportedProtocol,
53
+ )
54
+ if (protocolIsSupported) {
51
55
  reference.shouldHandle = true
52
56
  return
53
57
  }
@@ -1,7 +1,7 @@
1
1
  import { readFile } from "@jsenv/filesystem"
2
2
  import { resolveUrl } from "@jsenv/urls"
3
3
  import { Abort } from "@jsenv/abort"
4
- import { applyBabelPlugins } from "@jsenv/utils/js_ast/apply_babel_plugins.js"
4
+ import { applyBabelPlugins } from "@jsenv/ast"
5
5
 
6
6
  import { requireFromJsenv } from "@jsenv/core/src/require_from_jsenv.js"
7
7
  import { babelPluginInstrument } from "./babel_plugin_instrument.js"
@@ -2,7 +2,6 @@ import {
2
2
  urlToRelativeUrl,
3
3
  fileSystemPathToUrl,
4
4
  isFileSystemPath,
5
- resolveUrl,
6
5
  } from "@jsenv/urls"
7
6
 
8
7
  export const normalizeFileByFileCoveragePaths = (
@@ -15,7 +14,7 @@ export const normalizeFileByFileCoveragePaths = (
15
14
  const { path } = fileCoverage
16
15
  const url = isFileSystemPath(path)
17
16
  ? fileSystemPathToUrl(path)
18
- : resolveUrl(path, rootDirectoryUrl)
17
+ : new URL(path, rootDirectoryUrl).href
19
18
  const relativeUrl = urlToRelativeUrl(url, rootDirectoryUrl)
20
19
  fileByFileNormalized[`./${relativeUrl}`] = {
21
20
  ...fileCoverage,