@jsenv/core 36.3.0 → 37.0.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 (64) hide show
  1. package/dist/js/autoreload.js +6 -5
  2. package/dist/js/import_meta_hot.js +4 -4
  3. package/dist/js/server_events_client.js +422 -304
  4. package/dist/jsenv_core.js +3819 -3256
  5. package/package.json +18 -17
  6. package/src/build/build.js +342 -658
  7. package/src/build/build_urls_generator.js +8 -8
  8. package/src/build/build_versions_manager.js +495 -0
  9. package/src/build/version_mappings_injection.js +27 -16
  10. package/src/dev/file_service.js +80 -91
  11. package/src/dev/start_dev_server.js +5 -3
  12. package/src/kitchen/errors.js +16 -16
  13. package/src/kitchen/fetched_content_compliance.js +4 -8
  14. package/src/kitchen/kitchen.js +367 -939
  15. package/src/kitchen/prepend_content.js +13 -35
  16. package/src/kitchen/url_graph/references.js +713 -0
  17. package/src/kitchen/url_graph/sort_by_dependencies.js +2 -2
  18. package/src/kitchen/url_graph/url_content.js +96 -0
  19. package/src/kitchen/url_graph/url_graph.js +439 -0
  20. package/src/kitchen/url_graph/url_graph_report.js +6 -4
  21. package/src/kitchen/url_graph/url_graph_visitor.js +14 -12
  22. package/src/kitchen/url_graph/url_info_transformations.js +180 -184
  23. package/src/plugins/autoreload/client/autoreload.js +1 -0
  24. package/src/plugins/autoreload/client/reload.js +6 -6
  25. package/src/plugins/autoreload/jsenv_plugin_autoreload.js +2 -2
  26. package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +2 -2
  27. package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +84 -78
  28. package/src/plugins/autoreload/jsenv_plugin_hot_search_param.js +52 -0
  29. package/src/plugins/cache_control/jsenv_plugin_cache_control.js +1 -1
  30. package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +2 -2
  31. package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +3 -3
  32. package/src/plugins/import_meta_hot/client/import_meta_hot.js +4 -4
  33. package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +18 -20
  34. package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +2 -2
  35. package/src/plugins/importmap/jsenv_plugin_importmap.js +35 -37
  36. package/src/plugins/inlining/jsenv_plugin_inlining.js +1 -17
  37. package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +70 -50
  38. package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +72 -54
  39. package/src/plugins/plugin_controller.js +92 -27
  40. package/src/plugins/protocol_file/jsenv_plugin_protocol_file.js +18 -20
  41. package/src/plugins/reference_analysis/css/jsenv_plugin_css_reference_analysis.js +4 -5
  42. package/src/plugins/reference_analysis/data_urls/jsenv_plugin_data_urls_analysis.js +18 -16
  43. package/src/plugins/reference_analysis/directory/jsenv_plugin_directory_reference_analysis.js +13 -20
  44. package/src/plugins/reference_analysis/html/jsenv_plugin_html_reference_analysis.js +55 -72
  45. package/src/plugins/reference_analysis/js/jsenv_plugin_js_reference_analysis.js +33 -42
  46. package/src/plugins/reference_analysis/jsenv_plugin_reference_analysis.js +16 -7
  47. package/src/plugins/reference_analysis/webmanifest/jsenv_plugin_webmanifest_reference_analysis.js +4 -3
  48. package/src/plugins/resolution_node_esm/jsenv_plugin_node_esm_resolution.js +16 -6
  49. package/src/plugins/resolution_node_esm/node_esm_resolver.js +30 -24
  50. package/src/plugins/resolution_web/jsenv_plugin_web_resolution.js +8 -5
  51. package/src/plugins/ribbon/jsenv_plugin_ribbon.js +3 -3
  52. package/src/plugins/server_events/client/server_events_client.js +460 -15
  53. package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +13 -29
  54. package/src/plugins/version_search_param/jsenv_plugin_version_search_param.js +1 -1
  55. package/src/build/version_generator.js +0 -19
  56. package/src/kitchen/url_graph/url_graph_loader.js +0 -77
  57. package/src/kitchen/url_graph.js +0 -322
  58. package/src/plugins/autoreload/jsenv_plugin_hmr.js +0 -42
  59. package/src/plugins/resolution_node_esm/url_type_from_reference.js +0 -13
  60. package/src/plugins/server_events/client/connection_manager.js +0 -170
  61. package/src/plugins/server_events/client/event_source_connection.js +0 -83
  62. package/src/plugins/server_events/client/events_manager.js +0 -75
  63. package/src/plugins/server_events/client/web_socket_connection.js +0 -81
  64. /package/src/kitchen/{url_specifier_encoding.js → url_graph/url_specifier_encoding.js} +0 -0
@@ -2,6 +2,22 @@ import { DATA_URL } from "@jsenv/urls";
2
2
  import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
3
3
 
4
4
  export const jsenvPluginDataUrlsAnalysis = () => {
5
+ const cookDataUrl = async (reference) => {
6
+ const urlInfo = reference.urlInfo;
7
+ await urlInfo.cook();
8
+ if (urlInfo.originalContent === urlInfo.content) {
9
+ return reference.generatedUrl;
10
+ }
11
+ const specifier = DATA_URL.stringify({
12
+ contentType: urlInfo.contentType,
13
+ base64Flag: urlInfo.data.base64Flag,
14
+ data: urlInfo.data.base64Flag
15
+ ? dataToBase64(urlInfo.content)
16
+ : String(urlInfo.content),
17
+ });
18
+ return specifier;
19
+ };
20
+
5
21
  return {
6
22
  name: "jsenv:data_urls_analysis",
7
23
  appliesDuring: "*",
@@ -11,28 +27,14 @@ export const jsenvPluginDataUrlsAnalysis = () => {
11
27
  }
12
28
  return reference.specifier;
13
29
  },
14
- formatReference: (reference, context) => {
30
+ formatReference: (reference) => {
15
31
  if (!reference.generatedUrl.startsWith("data:")) {
16
32
  return null;
17
33
  }
18
34
  if (reference.type === "sourcemap_comment") {
19
35
  return null;
20
36
  }
21
- return (async () => {
22
- const urlInfo = context.urlGraph.getUrlInfo(reference.url);
23
- await context.cook(urlInfo, { reference });
24
- if (urlInfo.originalContent === urlInfo.content) {
25
- return reference.generatedUrl;
26
- }
27
- const specifier = DATA_URL.stringify({
28
- contentType: urlInfo.contentType,
29
- base64Flag: urlInfo.data.base64Flag,
30
- data: urlInfo.data.base64Flag
31
- ? dataToBase64(urlInfo.content)
32
- : String(urlInfo.content),
33
- });
34
- return specifier;
35
- })();
37
+ return cookDataUrl(reference);
36
38
  },
37
39
  fetchUrlContent: (urlInfo) => {
38
40
  if (!urlInfo.url.startsWith("data:")) {
@@ -4,17 +4,15 @@ export const jsenvPluginDirectoryReferenceAnalysis = () => {
4
4
  return {
5
5
  name: "jsenv:directory_reference_analysis",
6
6
  transformUrlContent: {
7
- directory: (urlInfo, context) => {
8
- const originalDirectoryReference = findOriginalDirectoryReference(
9
- urlInfo,
10
- context,
11
- );
7
+ directory: (urlInfo) => {
8
+ const originalDirectoryReference =
9
+ findOriginalDirectoryReference(urlInfo);
12
10
  const directoryRelativeUrl = urlToRelativeUrl(
13
11
  urlInfo.url,
14
- context.rootDirectoryUrl,
12
+ urlInfo.context.rootDirectoryUrl,
15
13
  );
16
14
  JSON.parse(urlInfo.content).forEach((directoryEntryName) => {
17
- context.referenceUtils.found({
15
+ urlInfo.dependencies.found({
18
16
  type: "filesystem",
19
17
  subtype: "directory_entry",
20
18
  specifier: directoryEntryName,
@@ -28,24 +26,19 @@ export const jsenvPluginDirectoryReferenceAnalysis = () => {
28
26
  };
29
27
  };
30
28
 
31
- const findOriginalDirectoryReference = (urlInfo, context) => {
29
+ const findOriginalDirectoryReference = (urlInfo) => {
32
30
  const findNonFileSystemAncestor = (urlInfo) => {
33
- for (const dependentUrl of urlInfo.dependents) {
34
- const dependentUrlInfo = context.urlGraph.getUrlInfo(dependentUrl);
35
- if (dependentUrlInfo.type !== "directory") {
36
- return [dependentUrlInfo, urlInfo];
31
+ for (const referenceFromOther of urlInfo.referenceFromOthersSet) {
32
+ const urlInfoReferencingThisOne = referenceFromOther.ownerUrlInfo;
33
+ if (urlInfoReferencingThisOne.type !== "directory") {
34
+ return referenceFromOther;
37
35
  }
38
- const found = findNonFileSystemAncestor(dependentUrlInfo);
36
+ const found = findNonFileSystemAncestor(urlInfoReferencingThisOne);
39
37
  if (found) {
40
38
  return found;
41
39
  }
42
40
  }
43
- return [];
44
- };
45
- const [ancestor, child] = findNonFileSystemAncestor(urlInfo);
46
- if (!ancestor) {
47
41
  return null;
48
- }
49
- const ref = ancestor.references.find((ref) => ref.url === child.url);
50
- return ref;
42
+ };
43
+ return findNonFileSystemAncestor(urlInfo);
51
44
  };
@@ -23,8 +23,8 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
23
23
  name: "jsenv:html_reference_analysis",
24
24
  appliesDuring: "*",
25
25
  transformUrlContent: {
26
- html: (urlInfo, context) =>
27
- parseAndTransformHtmlReferences(urlInfo, context, {
26
+ html: (urlInfo) =>
27
+ parseAndTransformHtmlReferences(urlInfo, {
28
28
  inlineContent,
29
29
  inlineConvertedScript,
30
30
  }),
@@ -34,7 +34,6 @@ export const jsenvPluginHtmlReferenceAnalysis = ({
34
34
 
35
35
  const parseAndTransformHtmlReferences = async (
36
36
  urlInfo,
37
- context,
38
37
  { inlineContent, inlineConvertedScript },
39
38
  ) => {
40
39
  const content = urlInfo.content;
@@ -48,7 +47,7 @@ const parseAndTransformHtmlReferences = async (
48
47
  node,
49
48
  attributeName,
50
49
  attributeValue,
51
- { type, subtype, expectedType },
50
+ { type, subtype, expectedType, ...rest },
52
51
  ) => {
53
52
  let position;
54
53
  if (getHtmlNodeAttribute(node, "jsenv-cooked-by")) {
@@ -73,21 +72,39 @@ const parseAndTransformHtmlReferences = async (
73
72
  "preload",
74
73
  "modulepreload",
75
74
  ].includes(subtype);
76
- const [reference] = context.referenceUtils.found({
77
- node,
75
+ let attributeLocation = node.sourceCodeLocation.attrs[attributeName];
76
+ if (
77
+ !attributeLocation &&
78
+ attributeName === "href" &&
79
+ (node.tagName === "use" || node.tagName === "image")
80
+ ) {
81
+ attributeLocation = node.sourceCodeLocation.attrs["xlink:href"];
82
+ }
83
+ const attributeStart = attributeLocation.startOffset;
84
+ const attributeValueStart = urlInfo.content.indexOf(
85
+ attributeValue,
86
+ attributeStart + `${attributeName}=`.length,
87
+ );
88
+ const attributeValueEnd = attributeValueStart + attributeValue.length;
89
+ const reference = urlInfo.dependencies.found({
78
90
  type,
79
91
  subtype,
80
92
  expectedType,
81
93
  specifier: attributeValue,
82
94
  specifierLine: line,
83
95
  specifierColumn: column,
96
+ specifierStart: attributeValueStart,
97
+ specifierEnd: attributeValueEnd,
84
98
  isResourceHint,
99
+ isWeak: isResourceHint,
85
100
  crossorigin,
86
101
  integrity,
87
102
  debug,
103
+ astInfo: { node, attributeName },
104
+ ...rest,
88
105
  });
89
106
  actions.push(async () => {
90
- await context.referenceUtils.readGeneratedSpecifier(reference);
107
+ await reference.readGeneratedSpecifier();
91
108
  mutations.push(() => {
92
109
  setHtmlNodeAttributes(node, {
93
110
  [attributeName]: reference.generatedSpecifier,
@@ -143,23 +160,21 @@ const parseAndTransformHtmlReferences = async (
143
160
  columnEnd,
144
161
  });
145
162
  const debug = getHtmlNodeAttribute(node, "jsenv-debug") !== undefined;
146
- const [inlineReference, inlineUrlInfo] = context.referenceUtils.foundInline(
147
- {
148
- node,
149
- type,
150
- expectedType,
151
- isOriginalPosition: isOriginal,
152
- // we remove 1 to the line because imagine the following html:
153
- // <style>body { color: red; }</style>
154
- // -> content starts same line as <style> (same for <script>)
155
- specifierLine: line - 1,
156
- specifierColumn: column,
157
- specifier: inlineContentUrl,
158
- contentType,
159
- content: inlineContent,
160
- debug,
161
- },
162
- );
163
+ const inlineReference = urlInfo.dependencies.foundInline({
164
+ type,
165
+ expectedType,
166
+ isOriginalPosition: isOriginal,
167
+ // we remove 1 to the line because imagine the following html:
168
+ // <style>body { color: red; }</style>
169
+ // -> content starts same line as <style> (same for <script>)
170
+ specifierLine: line - 1,
171
+ specifierColumn: column,
172
+ specifier: inlineContentUrl,
173
+ contentType,
174
+ content: inlineContent,
175
+ debug,
176
+ astInfo: { node },
177
+ });
163
178
 
164
179
  const externalSpecifierAttributeName =
165
180
  type === "script"
@@ -174,27 +189,22 @@ const parseAndTransformHtmlReferences = async (
174
189
  );
175
190
  if (externalSpecifier) {
176
191
  // create an external ref
177
- // the goal is only to have the url in the graph (and in dependencies/implitic urls for reload)
192
+ // the goal is only to have the url in the graph (and in dependencies/implicit urls for reload)
178
193
  // not to consider the url is actually used (at least during build)
179
- // maybe we can just exlcude these urls in a special if during build, we'll see
194
+ // maybe we can just exclude these urls in a special if during build, we'll see
180
195
  const externalRef = createExternalReference(
181
196
  node,
182
197
  externalSpecifierAttributeName,
183
198
  externalSpecifier,
184
- { type, subtype, expectedType },
199
+ { type, subtype, expectedType, next: inlineReference },
185
200
  );
186
201
  inlineReference.prev = externalRef;
187
202
  inlineReference.original = externalRef;
188
- externalRef.next = inlineReference;
189
203
  }
190
204
  }
191
205
 
192
206
  actions.push(async () => {
193
- await cookInlineContent({
194
- context,
195
- inlineContentUrlInfo: inlineUrlInfo,
196
- inlineContentReference: inlineReference,
197
- });
207
+ await inlineReference.urlInfo.cook();
198
208
  mutations.push(() => {
199
209
  if (hotAccept) {
200
210
  removeHtmlNodeText(node);
@@ -202,7 +212,7 @@ const parseAndTransformHtmlReferences = async (
202
212
  "jsenv-cooked-by": "jsenv:html_inline_content_analysis",
203
213
  });
204
214
  } else {
205
- setHtmlNodeText(node, inlineUrlInfo.content, {
215
+ setHtmlNodeText(node, inlineReference.urlInfo.content, {
206
216
  indentation: false, // indentation would decrease stack trace precision
207
217
  });
208
218
  setHtmlNodeAttributes(node, {
@@ -242,7 +252,7 @@ const parseAndTransformHtmlReferences = async (
242
252
  });
243
253
  if (ref) {
244
254
  finalizeCallbacks.push(() => {
245
- ref.expectedType = decideLinkExpectedType(ref, context);
255
+ ref.expectedType = decideLinkExpectedType(ref, urlInfo);
246
256
  });
247
257
  }
248
258
  },
@@ -365,33 +375,6 @@ const parseAndTransformHtmlReferences = async (
365
375
  return stringifyHtmlAst(htmlAst);
366
376
  };
367
377
 
368
- const cookInlineContent = async ({
369
- context,
370
- inlineContentUrlInfo,
371
- inlineContentReference,
372
- }) => {
373
- try {
374
- await context.cook(inlineContentUrlInfo, {
375
- reference: inlineContentReference,
376
- });
377
- } catch (e) {
378
- if (e.code === "PARSE_ERROR") {
379
- // When something like <style> or <script> contains syntax error
380
- // the HTML in itself it still valid
381
- // keep the syntax error and continue with the HTML
382
- const messageStart =
383
- inlineContentUrlInfo.type === "css"
384
- ? `Syntax error on css declared inside <style>`
385
- : `Syntax error on js declared inside <script>`;
386
-
387
- context.logger.error(`${messageStart}: ${e.cause.reasonCode}
388
- ${e.traceMessage}`);
389
- } else {
390
- throw e;
391
- }
392
- }
393
- };
394
-
395
378
  const crossOriginCompatibleTagNames = ["script", "link", "img", "source"];
396
379
  const integrityCompatibleTagNames = ["script", "link", "img", "source"];
397
380
  const readFetchMetas = (node) => {
@@ -407,8 +390,8 @@ const readFetchMetas = (node) => {
407
390
  return meta;
408
391
  };
409
392
 
410
- const decideLinkExpectedType = (linkReference, context) => {
411
- const rel = getHtmlNodeAttribute(linkReference.node, "rel");
393
+ const decideLinkExpectedType = (linkReference, htmlUrlInfo) => {
394
+ const rel = getHtmlNodeAttribute(linkReference.astInfo.node, "rel");
412
395
  if (rel === "webmanifest") {
413
396
  return "webmanifest";
414
397
  }
@@ -420,7 +403,7 @@ const decideLinkExpectedType = (linkReference, context) => {
420
403
  }
421
404
  if (rel === "preload") {
422
405
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types/preload#what_types_of_content_can_be_preloaded
423
- const as = getHtmlNodeAttribute(linkReference.node, "as");
406
+ const as = getHtmlNodeAttribute(linkReference.astInfo.node, "as");
424
407
  if (as === "document") {
425
408
  return "html";
426
409
  }
@@ -428,13 +411,13 @@ const decideLinkExpectedType = (linkReference, context) => {
428
411
  return "css";
429
412
  }
430
413
  if (as === "script") {
431
- const firstScriptOnThisUrl = context.referenceUtils.find(
432
- (refCandidate) =>
433
- refCandidate.url === linkReference.url &&
434
- refCandidate.type === "script",
435
- );
436
- if (firstScriptOnThisUrl) {
437
- return firstScriptOnThisUrl.expectedType;
414
+ for (const referenceToOther of htmlUrlInfo.referenceToOthersSet) {
415
+ if (
416
+ referenceToOther.url === linkReference.url &&
417
+ referenceToOther.type === "script"
418
+ ) {
419
+ return referenceToOther.expectedType;
420
+ }
438
421
  }
439
422
  return undefined;
440
423
  }
@@ -6,24 +6,23 @@ import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
6
6
 
7
7
  import { isWebWorkerUrlInfo } from "@jsenv/core/src/kitchen/web_workers.js";
8
8
 
9
- export const jsenvPluginJsReferenceAnalysis = ({
10
- inlineContent,
11
- allowEscapeForVersioning,
12
- }) => {
9
+ export const jsenvPluginJsReferenceAnalysis = ({ inlineContent }) => {
13
10
  return [
14
11
  {
15
12
  name: "jsenv:js_reference_analysis",
16
13
  appliesDuring: "*",
17
14
  transformUrlContent: {
18
- js_classic: (urlInfo, context) =>
19
- parseAndTransformJsReferences(urlInfo, context, {
15
+ js_classic: (urlInfo) =>
16
+ parseAndTransformJsReferences(urlInfo, {
20
17
  inlineContent,
21
- allowEscapeForVersioning,
18
+ canUseTemplateLiterals:
19
+ urlInfo.context.isSupportedOnCurrentClients("template_literals"),
22
20
  }),
23
- js_module: (urlInfo, context) =>
24
- parseAndTransformJsReferences(urlInfo, context, {
21
+ js_module: (urlInfo) =>
22
+ parseAndTransformJsReferences(urlInfo, {
25
23
  inlineContent,
26
- allowEscapeForVersioning,
24
+ canUseTemplateLiterals:
25
+ urlInfo.context.isSupportedOnCurrentClients("template_literals"),
27
26
  }),
28
27
  },
29
28
  },
@@ -32,8 +31,7 @@ export const jsenvPluginJsReferenceAnalysis = ({
32
31
 
33
32
  const parseAndTransformJsReferences = async (
34
33
  urlInfo,
35
- context,
36
- { inlineContent, allowEscapeForVersioning },
34
+ { inlineContent, canUseTemplateLiterals },
37
35
  ) => {
38
36
  const magicSource = createMagicSource(urlInfo.content);
39
37
  const parallelActions = [];
@@ -49,36 +47,32 @@ const parseAndTransformJsReferences = async (
49
47
  columnEnd: inlineReferenceInfo.columnEnd,
50
48
  });
51
49
  let { quote } = inlineReferenceInfo;
52
- if (
53
- quote === "`" &&
54
- !context.isSupportedOnCurrentClients("template_literals")
55
- ) {
50
+ if (quote === "`" && !canUseTemplateLiterals) {
56
51
  // if quote is "`" and template literals are not supported
57
52
  // we'll use a regular string (single or double quote)
58
53
  // when rendering the string
59
54
  quote = JS_QUOTES.pickBest(inlineReferenceInfo.content);
60
55
  }
61
- const [inlineReference, inlineUrlInfo] = context.referenceUtils.foundInline(
62
- {
63
- type: "js_inline_content",
64
- subtype: inlineReferenceInfo.type, // "new_blob_first_arg", "new_inline_content_first_arg", "json_parse_first_arg"
65
- isOriginalPosition: urlInfo.content === urlInfo.originalContent,
66
- specifierLine: inlineReferenceInfo.line,
67
- specifierColumn: inlineReferenceInfo.column,
68
- specifier: inlineUrl,
69
- contentType: inlineReferenceInfo.contentType,
70
- content: inlineReferenceInfo.content,
71
- },
72
- );
56
+ const inlineReference = urlInfo.dependencies.foundInline({
57
+ type: "js_inline_content",
58
+ subtype: inlineReferenceInfo.type, // "new_blob_first_arg", "new_inline_content_first_arg", "json_parse_first_arg"
59
+ isOriginalPosition: urlInfo.content === urlInfo.originalContent,
60
+ specifierLine: inlineReferenceInfo.line,
61
+ specifierColumn: inlineReferenceInfo.column,
62
+ specifier: inlineUrl,
63
+ contentType: inlineReferenceInfo.contentType,
64
+ content: inlineReferenceInfo.content,
65
+ });
66
+ const inlineUrlInfo = inlineReference.urlInfo;
73
67
  inlineUrlInfo.jsQuote = quote;
74
- inlineReference.escape = (value) =>
75
- JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote });
68
+ inlineReference.escape = (value) => {
69
+ return JS_QUOTES.escapeSpecialChars(value.slice(1, -1), { quote });
70
+ };
76
71
 
77
72
  sequentialActions.push(async () => {
78
- await context.cook(inlineUrlInfo, { reference: inlineReference });
73
+ await inlineUrlInfo.cook();
79
74
  const replacement = JS_QUOTES.escapeSpecialChars(inlineUrlInfo.content, {
80
75
  quote,
81
- allowEscapeForVersioning,
82
76
  });
83
77
  magicSource.replace({
84
78
  start: inlineReferenceInfo.start,
@@ -94,8 +88,7 @@ const parseAndTransformJsReferences = async (
94
88
  ) {
95
89
  urlInfo.data.usesImport = true;
96
90
  }
97
- const [reference] = context.referenceUtils.found({
98
- node: externalReferenceInfo.node,
91
+ const reference = urlInfo.dependencies.found({
99
92
  type: externalReferenceInfo.type,
100
93
  subtype: externalReferenceInfo.subtype,
101
94
  expectedType: externalReferenceInfo.expectedType,
@@ -109,26 +102,24 @@ const parseAndTransformJsReferences = async (
109
102
  baseUrl: {
110
103
  "StringLiteral": externalReferenceInfo.baseUrl,
111
104
  "window.location": urlInfo.url,
112
- "window.origin": context.rootDirectoryUrl,
105
+ "window.origin": urlInfo.context.rootDirectoryUrl,
113
106
  "import.meta.url": urlInfo.url,
114
107
  "context.meta.url": urlInfo.url,
115
108
  "document.currentScript.src": urlInfo.url,
116
109
  }[externalReferenceInfo.baseUrlType],
117
- assert: externalReferenceInfo.assert,
118
- assertNode: externalReferenceInfo.assertNode,
119
- typePropertyNode: externalReferenceInfo.typePropertyNode,
110
+ importAttributes: externalReferenceInfo.importAttributes,
111
+ astInfo: externalReferenceInfo.astInfo,
120
112
  });
121
113
  parallelActions.push(async () => {
122
- const replacement = await context.referenceUtils.readGeneratedSpecifier(
123
- reference,
124
- );
114
+ await reference.readGeneratedSpecifier();
115
+ const replacement = reference.generatedSpecifier;
125
116
  magicSource.replace({
126
117
  start: externalReferenceInfo.start,
127
118
  end: externalReferenceInfo.end,
128
119
  replacement,
129
120
  });
130
121
  if (reference.mutation) {
131
- reference.mutation(magicSource);
122
+ reference.mutation(magicSource, urlInfo);
132
123
  }
133
124
  });
134
125
  };
@@ -10,7 +10,6 @@ export const jsenvPluginReferenceAnalysis = ({
10
10
  inlineContent = true,
11
11
  inlineConvertedScript = false,
12
12
  fetchInlineUrls = true,
13
- allowEscapeForVersioning = false,
14
13
  }) => {
15
14
  return [
16
15
  jsenvPluginDirectoryReferenceAnalysis(),
@@ -22,7 +21,6 @@ export const jsenvPluginReferenceAnalysis = ({
22
21
  jsenvPluginCssReferenceAnalysis(),
23
22
  jsenvPluginJsReferenceAnalysis({
24
23
  inlineContent,
25
- allowEscapeForVersioning,
26
24
  }),
27
25
  ...(inlineContent ? [jsenvPluginDataUrlsAnalysis()] : []),
28
26
  ...(inlineContent && fetchInlineUrls
@@ -36,15 +34,26 @@ const jsenvPluginInlineContentFetcher = () => {
36
34
  return {
37
35
  name: "jsenv:inline_content_fetcher",
38
36
  appliesDuring: "*",
39
- fetchUrlContent: (urlInfo) => {
37
+ fetchUrlContent: async (urlInfo) => {
40
38
  if (!urlInfo.isInline) {
41
39
  return null;
42
40
  }
41
+ const { firstReference } = urlInfo;
42
+ const { prev } = firstReference;
43
+ if (prev && !prev.isInline) {
44
+ // got inlined, cook original url
45
+ if (firstReference.content === undefined) {
46
+ const originalUrlInfo = prev.urlInfo;
47
+ await originalUrlInfo.cook();
48
+ firstReference.content = originalUrlInfo.content;
49
+ firstReference.contentType = originalUrlInfo.contentType;
50
+ }
51
+ }
52
+
43
53
  return {
44
- // we want to fetch the original content otherwise we might re-cook
45
- // content already cooked
46
- content: urlInfo.originalContent,
47
- contentType: urlInfo.contentType,
54
+ originalContent: urlInfo.originalContent,
55
+ content: firstReference.content,
56
+ contentType: firstReference.contentType,
48
57
  };
49
58
  },
50
59
  };
@@ -10,18 +10,19 @@ export const jsenvPluginWebmanifestReferenceAnalysis = () => {
10
10
  };
11
11
  };
12
12
 
13
- const parseAndTransformWebmanifestUrls = async (urlInfo, context) => {
13
+ const parseAndTransformWebmanifestUrls = async (urlInfo) => {
14
14
  const content = urlInfo.content;
15
15
  const manifest = JSON.parse(content);
16
16
  const actions = [];
17
17
  const { icons = [] } = manifest;
18
18
  icons.forEach((icon) => {
19
- const [reference] = context.referenceUtils.found({
19
+ const iconReference = urlInfo.dependencies.found({
20
20
  type: "webmanifest_icon_src",
21
21
  specifier: icon.src,
22
22
  });
23
23
  actions.push(async () => {
24
- icon.src = await context.referenceUtils.readGeneratedSpecifier(reference);
24
+ await iconReference.readGeneratedSpecifier();
25
+ icon.src = iconReference.generatedSpecifier;
25
26
  });
26
27
  });
27
28
 
@@ -1,4 +1,3 @@
1
- import { urlTypeFromReference } from "./url_type_from_reference.js";
2
1
  import { createNodeEsmResolver } from "./node_esm_resolver.js";
3
2
 
4
3
  export const jsenvPluginNodeEsmResolution = (resolutionConfig = {}) => {
@@ -45,18 +44,18 @@ export const jsenvPluginNodeEsmResolution = (resolutionConfig = {}) => {
45
44
  resolvers.js_module = nodeEsmResolverDefault;
46
45
  }
47
46
  if (resolvers.js_classic === undefined) {
48
- resolvers.js_classic = (reference, context) => {
47
+ resolvers.js_classic = (reference) => {
49
48
  if (reference.subtype === "self_import_scripts_arg") {
50
- return nodeEsmResolverDefault(reference, context);
49
+ return nodeEsmResolverDefault(reference);
51
50
  }
52
51
  return null;
53
52
  };
54
53
  }
55
54
  },
56
- resolveReference: (reference, context) => {
57
- const urlType = urlTypeFromReference(reference, context);
55
+ resolveReference: (reference) => {
56
+ const urlType = urlTypeFromReference(reference);
58
57
  const resolver = resolvers[urlType];
59
- return resolver ? resolver(reference, context) : null;
58
+ return resolver ? resolver(reference) : null;
60
59
  },
61
60
  // when specifier is prefixed by "file:///@ignore/"
62
61
  // we return an empty js module
@@ -72,3 +71,14 @@ export const jsenvPluginNodeEsmResolution = (resolutionConfig = {}) => {
72
71
  },
73
72
  };
74
73
  };
74
+
75
+ const urlTypeFromReference = (reference) => {
76
+ if (reference.type === "sourcemap_comment") {
77
+ return "sourcemap";
78
+ }
79
+ if (reference.injected) {
80
+ return reference.expectedType;
81
+ }
82
+
83
+ return reference.ownerUrlInfo.type;
84
+ };