@jsenv/core 27.0.0-alpha.84 → 27.0.0-alpha.87

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 (50) hide show
  1. package/dist/html/explorer.html +1 -1
  2. package/dist/js/controllable_file.mjs +1 -1
  3. package/dist/js/event_source_client.js +3 -3
  4. package/dist/js/html_supervisor_installer.js +1 -1
  5. package/dist/js/s.js +2 -2
  6. package/dist/js/uneval.js +804 -0
  7. package/dist/main.js +11910 -1028
  8. package/dist/s.js +2 -2
  9. package/dist/s.js.map +1 -1
  10. package/package.json +17 -13
  11. package/src/build/build.js +2 -14
  12. package/src/build/inject_global_version_mappings.js +3 -3
  13. package/src/build/inject_service_worker_urls.js +1 -1
  14. package/src/build/resync_ressource_hints.js +17 -18
  15. package/src/build/version_generator.js +60 -0
  16. package/src/dev/plugins/explorer/client/explorer.html +1 -1
  17. package/src/dev/plugins/explorer/jsenv_plugin_explorer.js +1 -1
  18. package/src/dev/plugins/toolbar/jsenv_plugin_toolbar.js +3 -3
  19. package/src/omega/kitchen.js +2 -0
  20. package/src/plugins/autoreload/dev_sse/client/reload.js +6 -3
  21. package/src/plugins/autoreload/dev_sse/jsenv_plugin_dev_sse_client.js +3 -3
  22. package/src/plugins/bundling/css/bundle_css.js +1 -2
  23. package/src/plugins/bundling/js_module/bundle_js_module.js +85 -66
  24. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +1 -1
  25. package/src/plugins/file_urls/jsenv_plugin_file_urls.js +11 -3
  26. package/src/plugins/html_supervisor/jsenv_plugin_html_supervisor.js +62 -74
  27. package/src/plugins/http_urls/jsenv_plugin_http_urls.js +10 -6
  28. package/src/plugins/import_meta_hot/html_hot_dependencies.js +9 -15
  29. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +1 -2
  30. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +1 -1
  31. package/src/plugins/importmap/jsenv_plugin_importmap.js +24 -25
  32. package/src/plugins/inject_globals/inject_globals.js +3 -3
  33. package/src/plugins/inline/jsenv_plugin_html_inline_content.js +39 -41
  34. package/src/plugins/inline/jsenv_plugin_js_inline_content.js +1 -1
  35. package/src/plugins/minification/css/minify_css.js +1 -1
  36. package/src/plugins/transpilation/as_js_classic/client/s.js +2 -2
  37. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic.js +2 -2
  38. package/src/plugins/transpilation/as_js_classic/jsenv_plugin_as_js_classic_html.js +41 -63
  39. package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +2 -3
  40. package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +2 -2
  41. package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +1 -1
  42. package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +2 -2
  43. package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +2 -2
  44. package/src/plugins/transpilation/css_parcel/jsenv_plugin_css_parcel.js +1 -1
  45. package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +1 -1
  46. package/src/plugins/url_analysis/css/css_urls.js +1 -2
  47. package/src/plugins/url_analysis/html/html_urls.js +98 -113
  48. package/src/plugins/url_analysis/js/js_urls.js +1 -1
  49. package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +13 -6
  50. package/src/test/coverage/empty_coverage_factory.js +1 -1
@@ -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/src/html_ast/html_ast.js"
8
- import { htmlAttributeSrcSet } from "@jsenv/utils/src/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,5 @@
1
1
  import { createMagicSource } from "@jsenv/sourcemap"
2
- import { parseJsUrls } from "@jsenv/utils/src/js_ast/parse_js_urls.js"
2
+ import { parseJsUrls } from "@jsenv/ast"
3
3
 
4
4
  import { isWebWorkerUrlInfo } from "@jsenv/core/src/omega/web_workers.js"
5
5
 
@@ -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(
@@ -23,6 +27,9 @@ export const jsenvPluginUrlAnalysis = ({ rootDirectoryUrl, include }) => {
23
27
  name: "jsenv:url_analysis",
24
28
  appliesDuring: "*",
25
29
  redirectUrl: (reference) => {
30
+ if (reference.shouldHandle !== undefined) {
31
+ return
32
+ }
26
33
  if (
27
34
  reference.specifier[0] === "#" &&
28
35
  // For Html, css and in general "#" refer to a ressource in the page
@@ -43,11 +50,11 @@ export const jsenvPluginUrlAnalysis = ({ rootDirectoryUrl, include }) => {
43
50
  reference.shouldHandle = false
44
51
  return
45
52
  }
46
- if (reference.url.startsWith("data:")) {
47
- reference.shouldHandle = true
48
- return
49
- }
50
- if (reference.url.startsWith("file:")) {
53
+ const { protocol } = new URL(reference.url)
54
+ const protocolIsSupported = supportedProtocols.some(
55
+ (supportedProtocol) => protocol === supportedProtocol,
56
+ )
57
+ if (protocolIsSupported) {
51
58
  reference.shouldHandle = true
52
59
  return
53
60
  }
@@ -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/src/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"