@jsenv/core 36.3.1 → 37.0.1

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 +17 -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
@@ -1,8 +1,4 @@
1
- import {
2
- urlIsInsideOf,
3
- urlToRelativeUrl,
4
- asUrlWithoutSearch,
5
- } from "@jsenv/urls";
1
+ import { urlIsInsideOf, urlToRelativeUrl } from "@jsenv/urls";
6
2
 
7
3
  export const jsenvPluginAutoreloadServer = ({
8
4
  clientFileChangeCallbackList,
@@ -12,27 +8,26 @@ export const jsenvPluginAutoreloadServer = ({
12
8
  name: "jsenv:autoreload_server",
13
9
  appliesDuring: "dev",
14
10
  serverEvents: {
15
- reload: ({ sendServerEvent, rootDirectoryUrl, urlGraph }) => {
11
+ reload: (serverEventInfo) => {
16
12
  const formatUrlForClient = (url) => {
17
- if (urlIsInsideOf(url, rootDirectoryUrl)) {
18
- return urlToRelativeUrl(url, rootDirectoryUrl);
13
+ if (urlIsInsideOf(url, serverEventInfo.rootDirectoryUrl)) {
14
+ return urlToRelativeUrl(url, serverEventInfo.rootDirectoryUrl);
19
15
  }
20
16
  if (url.startsWith("file:")) {
21
17
  return `/@fs/${url.slice("file:///".length)}`;
22
18
  }
23
19
  return url;
24
20
  };
25
-
26
- const notifyDeclined = ({ cause, reason, declinedBy }) => {
27
- sendServerEvent({
21
+ const notifyFullReload = ({ cause, reason, declinedBy }) => {
22
+ serverEventInfo.sendServerEvent({
28
23
  cause,
29
24
  type: "full",
30
25
  typeReason: reason,
31
26
  declinedBy,
32
27
  });
33
28
  };
34
- const notifyAccepted = ({ cause, reason, instructions }) => {
35
- sendServerEvent({
29
+ const notifyPartialReload = ({ cause, reason, instructions }) => {
30
+ serverEventInfo.sendServerEvent({
36
31
  cause,
37
32
  type: "hot",
38
33
  typeReason: reason,
@@ -40,7 +35,7 @@ export const jsenvPluginAutoreloadServer = ({
40
35
  });
41
36
  };
42
37
  const propagateUpdate = (firstUrlInfo) => {
43
- if (!urlGraph.getUrlInfo(firstUrlInfo.url)) {
38
+ if (!serverEventInfo.kitchen.graph.getUrlInfo(firstUrlInfo.url)) {
44
39
  return {
45
40
  declined: true,
46
41
  reason: `url not in the url graph`,
@@ -63,37 +58,40 @@ export const jsenvPluginAutoreloadServer = ({
63
58
  ],
64
59
  };
65
60
  }
66
- const { dependents } = urlInfo;
67
61
  const instructions = [];
68
- for (const dependentUrl of dependents) {
69
- const dependentUrlInfo = urlGraph.getUrlInfo(dependentUrl);
70
- if (dependentUrlInfo.data.hotDecline) {
62
+ for (const referenceFromOther of urlInfo.referenceFromOthersSet) {
63
+ if (referenceFromOther.isImplicit && referenceFromOther.isWeak) {
64
+ continue;
65
+ }
66
+ const urlInfoReferencingThisOne = referenceFromOther.ownerUrlInfo;
67
+ if (urlInfoReferencingThisOne.data.hotDecline) {
71
68
  return {
72
69
  declined: true,
73
70
  reason: `a dependent file declines hot reload`,
74
- declinedBy: dependentUrl,
71
+ declinedBy: urlInfoReferencingThisOne.url,
75
72
  };
76
73
  }
77
- const { hotAcceptDependencies = [] } = dependentUrlInfo.data;
74
+ const { hotAcceptDependencies = [] } =
75
+ urlInfoReferencingThisOne.data;
78
76
  if (hotAcceptDependencies.includes(urlInfo.url)) {
79
77
  instructions.push({
80
- type: dependentUrlInfo.type,
81
- boundary: formatUrlForClient(dependentUrl),
78
+ type: urlInfoReferencingThisOne.type,
79
+ boundary: formatUrlForClient(urlInfoReferencingThisOne.url),
82
80
  acceptedBy: formatUrlForClient(urlInfo.url),
83
81
  });
84
82
  continue;
85
83
  }
86
- if (seen.includes(dependentUrl)) {
84
+ if (seen.includes(urlInfoReferencingThisOne.url)) {
87
85
  return {
88
86
  declined: true,
89
87
  reason: "circular dependency",
90
- declinedBy: formatUrlForClient(dependentUrl),
88
+ declinedBy: formatUrlForClient(urlInfoReferencingThisOne.url),
91
89
  };
92
90
  }
93
- const dependentPropagationResult = iterate(dependentUrlInfo, [
94
- ...seen,
95
- dependentUrl,
96
- ]);
91
+ const dependentPropagationResult = iterate(
92
+ urlInfoReferencingThisOne,
93
+ [...seen, urlInfoReferencingThisOne.url],
94
+ );
97
95
  if (dependentPropagationResult.accepted) {
98
96
  instructions.push(...dependentPropagationResult.instructions);
99
97
  continue;
@@ -123,57 +121,61 @@ export const jsenvPluginAutoreloadServer = ({
123
121
  };
124
122
  clientFileChangeCallbackList.push(({ url, event }) => {
125
123
  const onUrlInfo = (urlInfo) => {
124
+ if (!urlInfo.isUsed()) {
125
+ return false;
126
+ }
126
127
  const relativeUrl = formatUrlForClient(urlInfo.url);
127
128
  const hotUpdate = propagateUpdate(urlInfo);
128
129
  if (hotUpdate.declined) {
129
- notifyDeclined({
130
+ notifyFullReload({
130
131
  cause: `${relativeUrl} ${event}`,
131
132
  reason: hotUpdate.reason,
132
133
  declinedBy: hotUpdate.declinedBy,
133
134
  });
134
- } else {
135
- notifyAccepted({
136
- cause: `${relativeUrl} ${event}`,
137
- reason: hotUpdate.reason,
138
- instructions: hotUpdate.instructions,
139
- });
135
+ return true;
140
136
  }
137
+ notifyPartialReload({
138
+ cause: `${relativeUrl} ${event}`,
139
+ reason: hotUpdate.reason,
140
+ instructions: hotUpdate.instructions,
141
+ });
142
+ return true;
141
143
  };
142
- const exactUrlInfo = urlGraph.getUrlInfo(url);
143
- if (exactUrlInfo) {
144
- onUrlInfo(exactUrlInfo);
145
- }
146
- urlGraph.urlInfoMap.forEach((urlInfo) => {
147
- if (urlInfo === exactUrlInfo) return;
148
- const urlWithoutSearch = asUrlWithoutSearch(urlInfo.url);
149
- if (urlWithoutSearch !== url) return;
150
- if (exactUrlInfo && exactUrlInfo.dependents.has(urlInfo.url))
144
+
145
+ const urlInfo = serverEventInfo.kitchen.graph.getUrlInfo(url);
146
+ if (urlInfo) {
147
+ if (onUrlInfo(urlInfo)) {
151
148
  return;
152
- onUrlInfo(urlInfo);
153
- });
154
- });
155
- clientFilesPruneCallbackList.push((prunedUrlInfos, firstUrlInfo) => {
156
- const mainHotUpdate = propagateUpdate(firstUrlInfo);
157
- const cause = `following files are no longer referenced: ${prunedUrlInfos.map(
158
- (prunedUrlInfo) => formatUrlForClient(prunedUrlInfo.url),
159
- )}`;
160
- // now check if we can hot update the main resource
161
- // then if we can hot update all dependencies
162
- if (mainHotUpdate.declined) {
163
- notifyDeclined({
164
- cause,
165
- reason: mainHotUpdate.reason,
166
- declinedBy: mainHotUpdate.declinedBy,
167
- });
168
- return;
149
+ }
150
+ for (const searchParamVariant of urlInfo.searchParamVariantSet) {
151
+ if (onUrlInfo(searchParamVariant)) {
152
+ return;
153
+ }
154
+ }
169
155
  }
170
- // main can hot update
171
- let i = 0;
172
- const instructions = [];
173
- while (i < prunedUrlInfos.length) {
174
- const prunedUrlInfo = prunedUrlInfos[i++];
156
+ });
157
+ clientFilesPruneCallbackList.push(
158
+ (prunedUrlInfo, lastReferenceFromOther) => {
159
+ const parentHotUpdate = propagateUpdate(
160
+ lastReferenceFromOther.ownerUrlInfo,
161
+ );
162
+ const cause = `following file is no longer referenced: ${formatUrlForClient(
163
+ prunedUrlInfo.url,
164
+ )}`;
165
+ // now check if we can hot update the parent resource
166
+ // then if we can hot update all dependencies
167
+ if (parentHotUpdate.declined) {
168
+ notifyFullReload({
169
+ cause,
170
+ reason: parentHotUpdate.reason,
171
+ declinedBy: parentHotUpdate.declinedBy,
172
+ });
173
+ return;
174
+ }
175
+ // parent can hot update
176
+ const instructions = [];
175
177
  if (prunedUrlInfo.data.hotDecline) {
176
- notifyDeclined({
178
+ notifyFullReload({
177
179
  cause,
178
180
  reason: `a pruned file declines hot reload`,
179
181
  declinedBy: formatUrlForClient(prunedUrlInfo.url),
@@ -183,20 +185,24 @@ export const jsenvPluginAutoreloadServer = ({
183
185
  instructions.push({
184
186
  type: "prune",
185
187
  boundary: formatUrlForClient(prunedUrlInfo.url),
186
- acceptedBy: formatUrlForClient(firstUrlInfo.url),
188
+ acceptedBy: formatUrlForClient(
189
+ lastReferenceFromOther.ownerUrlInfo.url,
190
+ ),
187
191
  });
188
- }
189
- notifyAccepted({
190
- cause,
191
- reason: mainHotUpdate.reason,
192
- instructions,
193
- });
194
- });
192
+ notifyPartialReload({
193
+ cause,
194
+ reason: parentHotUpdate.reason,
195
+ instructions,
196
+ });
197
+ },
198
+ );
195
199
  },
196
200
  },
197
- serve: (request, { rootDirectoryUrl, urlGraph }) => {
198
- if (request.pathname === "/__graph__") {
199
- const graphJson = JSON.stringify(urlGraph.toJSON(rootDirectoryUrl));
201
+ serve: (serveInfo) => {
202
+ if (serveInfo.request.pathname === "/__graph__") {
203
+ const graphJson = JSON.stringify(
204
+ serveInfo.kitchen.graph.toJSON(serveInfo.rootDirectoryUrl),
205
+ );
200
206
  return {
201
207
  status: 200,
202
208
  headers: {
@@ -0,0 +1,52 @@
1
+ export const jsenvPluginHotSearchParam = () => {
2
+ const shouldInjectHotSearchParam = (reference) => {
3
+ if (reference.isImplicit) {
4
+ return false;
5
+ }
6
+ if (reference.original && reference.original.searchParams.has("hot")) {
7
+ return true;
8
+ }
9
+ // parent is using ?hot -> propagate
10
+ const { ownerUrlInfo } = reference;
11
+ const lastReference = ownerUrlInfo.context.reference;
12
+ if (
13
+ lastReference &&
14
+ lastReference.original &&
15
+ lastReference.original.searchParams.has("hot")
16
+ ) {
17
+ return true;
18
+ }
19
+ return false;
20
+ };
21
+
22
+ return {
23
+ name: "jsenv:hot_search_param",
24
+ appliesDuring: "dev",
25
+ redirectReference: (reference) => {
26
+ if (!reference.searchParams.has("hot")) {
27
+ return null;
28
+ }
29
+ const urlObject = new URL(reference.url);
30
+ // "hot" search param goal is to invalide url in browser cache:
31
+ // this goal is achieved when we reach this part of the code
32
+ // We get rid of this params so that urlGraph and other parts of the code
33
+ // recognize the url (it is not considered as a different url)
34
+ urlObject.searchParams.delete("hot");
35
+ urlObject.searchParams.delete("v");
36
+ return urlObject.href;
37
+ },
38
+ transformReferenceSearchParams: (reference) => {
39
+ if (!shouldInjectHotSearchParam(reference)) {
40
+ return null;
41
+ }
42
+ const referencedUrlInfo = reference.urlInfo;
43
+ if (!referencedUrlInfo.modifiedTimestamp) {
44
+ return null;
45
+ }
46
+ return {
47
+ hot: "",
48
+ v: referencedUrlInfo.modifiedTimestamp,
49
+ };
50
+ },
51
+ };
52
+ };
@@ -9,7 +9,7 @@ export const jsenvPluginCacheControl = ({
9
9
  if (
10
10
  versionedUrls &&
11
11
  reference.searchParams.has("v") &&
12
- !reference.searchParams.has("hmr")
12
+ !reference.searchParams.has("hot")
13
13
  ) {
14
14
  return {
15
15
  headers: {
@@ -11,7 +11,7 @@ import { createMagicSource } from "@jsenv/sourcemap";
11
11
  import { applyBabelPlugins } from "@jsenv/ast";
12
12
 
13
13
  export const jsenvPluginCommonJsGlobals = () => {
14
- const transformCommonJsGlobals = async (urlInfo, context) => {
14
+ const transformCommonJsGlobals = async (urlInfo) => {
15
15
  if (
16
16
  !urlInfo.content.includes("process.env.NODE_ENV") &&
17
17
  !urlInfo.content.includes("__filename") &&
@@ -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
- context.dev ? "development" : "production"
25
+ urlInfo.context.dev ? "development" : "production"
26
26
  }")`,
27
27
  "global": "globalThis",
28
28
  "__filename": isJsModule
@@ -8,10 +8,10 @@
8
8
  import { replacePlaceholders } from "@jsenv/plugin-placeholders";
9
9
 
10
10
  export const jsenvPluginGlobalScenarios = () => {
11
- const transformIfNeeded = (urlInfo, context) => {
11
+ const transformIfNeeded = (urlInfo) => {
12
12
  return replacePlaceholders(urlInfo, {
13
- __DEV__: context.dev,
14
- __BUILD__: context.build,
13
+ __DEV__: urlInfo.context.dev,
14
+ __BUILD__: urlInfo.context.build,
15
15
  });
16
16
  };
17
17
 
@@ -7,7 +7,7 @@ export const urlHotMetas = {};
7
7
 
8
8
  export const createImportMetaHot = (importMetaUrl) => {
9
9
  const data = {};
10
- const url = asUrlWithoutHmrQuery(importMetaUrl);
10
+ const url = asUrlWithoutHotSearchParam(importMetaUrl);
11
11
 
12
12
  return {
13
13
  data,
@@ -71,10 +71,10 @@ const addUrlMeta = (url, meta) => {
71
71
  };
72
72
  };
73
73
 
74
- const asUrlWithoutHmrQuery = (url) => {
74
+ const asUrlWithoutHotSearchParam = (url) => {
75
75
  const urlObject = new URL(url);
76
- if (urlObject.searchParams.has("hmr")) {
77
- urlObject.searchParams.delete("hmr");
76
+ if (urlObject.searchParams.has("hot")) {
77
+ urlObject.searchParams.delete("hot");
78
78
  urlObject.searchParams.delete("v");
79
79
  return urlObject.href;
80
80
  }
@@ -14,9 +14,9 @@ export const jsenvPluginImportMetaHot = () => {
14
14
  name: "jsenv:import_meta_hot",
15
15
  appliesDuring: "*",
16
16
  transformUrlContent: {
17
- html: (htmlUrlInfo, context) => {
17
+ html: (htmlUrlInfo) => {
18
18
  // during build we don't really care to parse html hot dependencies
19
- if (context.build) {
19
+ if (htmlUrlInfo.context.build) {
20
20
  return;
21
21
  }
22
22
  const htmlAst = parseHtmlString(htmlUrlInfo.content);
@@ -25,18 +25,20 @@ export const jsenvPluginImportMetaHot = () => {
25
25
  htmlUrlInfo.data.hotAcceptSelf = false;
26
26
  htmlUrlInfo.data.hotAcceptDependencies = hotReferences.map(
27
27
  ({ type, specifier }) => {
28
- const existingReference = context.referenceUtils.find(
29
- (existingReference) => {
30
- return (
31
- existingReference.type === type &&
32
- existingReference.specifier === specifier
33
- );
34
- },
35
- );
28
+ let existingReference = null;
29
+ for (const referenceToOther of htmlUrlInfo.referenceToOthersSet) {
30
+ if (
31
+ referenceToOther.type === type &&
32
+ referenceToOther.specifier === specifier
33
+ ) {
34
+ existingReference = referenceToOther;
35
+ break;
36
+ }
37
+ }
36
38
  if (existingReference) {
37
39
  return existingReference.url;
38
40
  }
39
- const [reference] = context.referenceUtils.found({
41
+ const reference = htmlUrlInfo.dependencies.found({
40
42
  type,
41
43
  specifier,
42
44
  });
@@ -49,7 +51,7 @@ export const jsenvPluginImportMetaHot = () => {
49
51
  cssUrlInfo.data.hotAcceptSelf = false;
50
52
  cssUrlInfo.data.hotAcceptDependencies = [];
51
53
  },
52
- js_module: async (urlInfo, context) => {
54
+ js_module: async (urlInfo) => {
53
55
  if (!urlInfo.content.includes("import.meta.hot")) {
54
56
  return null;
55
57
  }
@@ -72,14 +74,10 @@ export const jsenvPluginImportMetaHot = () => {
72
74
  if (importMetaHotPaths.length === 0) {
73
75
  return null;
74
76
  }
75
- if (context.build) {
77
+ if (urlInfo.context.build) {
76
78
  return removeImportMetaHots(urlInfo, importMetaHotPaths);
77
79
  }
78
- return injectImportMetaHot(
79
- urlInfo,
80
- context,
81
- importMetaHotClientFileUrl,
82
- );
80
+ return injectImportMetaHot(urlInfo, importMetaHotClientFileUrl);
83
81
  },
84
82
  },
85
83
  };
@@ -101,8 +99,8 @@ const removeImportMetaHots = (urlInfo, importMetaHotPaths) => {
101
99
  // better sourcemap than doing the equivalent with babel
102
100
  // I suspect it's because I was doing injectAstAfterImport(programPath, ast.program.body[0])
103
101
  // which is likely not well supported by babel
104
- const injectImportMetaHot = (urlInfo, context, importMetaHotClientFileUrl) => {
105
- const [importMetaHotClientFileReference] = context.referenceUtils.inject({
102
+ const injectImportMetaHot = (urlInfo, importMetaHotClientFileUrl) => {
103
+ const importMetaHotClientFileReference = urlInfo.dependencies.inject({
106
104
  parentUrl: urlInfo.url,
107
105
  type: "js_import",
108
106
  expectedType: "js_module",
@@ -16,7 +16,7 @@ export const jsenvPluginImportMetaScenarios = () => {
16
16
  name: "jsenv:import_meta_scenario",
17
17
  appliesDuring: "*",
18
18
  transformUrlContent: {
19
- js_module: async (urlInfo, context) => {
19
+ js_module: async (urlInfo) => {
20
20
  if (
21
21
  !urlInfo.content.includes("import.meta.dev") &&
22
22
  !urlInfo.content.includes("import.meta.test") &&
@@ -36,7 +36,7 @@ export const jsenvPluginImportMetaScenarios = () => {
36
36
  const replace = (path, value) => {
37
37
  replacements.push({ path, value });
38
38
  };
39
- if (context.build) {
39
+ if (urlInfo.context.build) {
40
40
  // during build ensure replacement for tree-shaking
41
41
  dev.forEach((path) => {
42
42
  replace(path, "undefined");
@@ -66,7 +66,7 @@ export const jsenvPluginImportmap = () => {
66
66
  let fromMapping = false;
67
67
  const result = resolveImport({
68
68
  specifier: reference.specifier,
69
- importer: reference.parentUrl,
69
+ importer: reference.ownerUrlInfo.url,
70
70
  importMap: finalImportmap,
71
71
  onImportMapping: () => {
72
72
  fromMapping = true;
@@ -90,7 +90,7 @@ export const jsenvPluginImportmap = () => {
90
90
  },
91
91
  },
92
92
  transformUrlContent: {
93
- html: async (htmlUrlInfo, context) => {
93
+ html: async (htmlUrlInfo) => {
94
94
  const htmlAst = parseHtmlString(htmlUrlInfo.content);
95
95
  const importmap = findHtmlNode(htmlAst, (node) => {
96
96
  if (node.nodeName !== "script") {
@@ -119,8 +119,8 @@ export const jsenvPluginImportmap = () => {
119
119
  lineEnd,
120
120
  columnEnd,
121
121
  });
122
- const [inlineImportmapReference, inlineImportmapUrlInfo] =
123
- context.referenceUtils.foundInline({
122
+ const inlineImportmapReference = htmlUrlInfo.dependencies.foundInline(
123
+ {
124
124
  type: "script",
125
125
  isOriginalPosition: isOriginal,
126
126
  specifierLine: line - 1,
@@ -128,10 +128,10 @@ export const jsenvPluginImportmap = () => {
128
128
  specifier: inlineImportmapUrl,
129
129
  contentType: "application/importmap+json",
130
130
  content: htmlNodeText,
131
- });
132
- await context.cook(inlineImportmapUrlInfo, {
133
- reference: inlineImportmapReference,
134
- });
131
+ },
132
+ );
133
+ const inlineImportmapUrlInfo = inlineImportmapReference.urlInfo;
134
+ await inlineImportmapUrlInfo.cook();
135
135
  setHtmlNodeText(importmap, inlineImportmapUrlInfo.content, {
136
136
  indentation: "auto",
137
137
  });
@@ -149,33 +149,18 @@ export const jsenvPluginImportmap = () => {
149
149
  // We must precook the importmap to know its content and inline it into the HTML
150
150
  // In this situation the ref to the importmap was already discovered
151
151
  // when parsing the HTML
152
- const importmapReference = context.referenceUtils.find(
153
- (ref) => ref.generatedSpecifier === src,
154
- );
155
- const importmapUrlInfo = context.urlGraph.getUrlInfo(
156
- importmapReference.url,
157
- );
158
- await context.cook(importmapUrlInfo, {
159
- reference: importmapReference,
160
- });
161
- onHtmlImportmapParsed(
162
- JSON.parse(importmapUrlInfo.content),
163
- htmlUrlInfo.url,
164
- );
165
- setHtmlNodeText(importmap, importmapUrlInfo.content, {
166
- indentation: "auto",
167
- });
168
- setHtmlNodeAttributes(importmap, {
169
- "src": undefined,
170
- "jsenv-inlined-by": "jsenv:importmap",
171
- "inlined-from-src": src,
172
- });
173
-
152
+ let importmapReference = null;
153
+ for (const referenceToOther of htmlUrlInfo.referenceToOthersSet) {
154
+ if (referenceToOther.generatedSpecifier === src) {
155
+ importmapReference = referenceToOther;
156
+ break;
157
+ }
158
+ }
174
159
  const { line, column, lineEnd, columnEnd, isOriginal } =
175
160
  getHtmlNodePosition(importmap, {
176
161
  preferOriginal: true,
177
162
  });
178
- const inlineImportmapUrl = generateInlineContentUrl({
163
+ const importmapInlineUrl = generateInlineContentUrl({
179
164
  url: htmlUrlInfo.url,
180
165
  extension: ".importmap",
181
166
  line,
@@ -183,13 +168,26 @@ export const jsenvPluginImportmap = () => {
183
168
  lineEnd,
184
169
  columnEnd,
185
170
  });
186
- context.referenceUtils.becomesInline(importmapReference, {
187
- specifierLine: line - 1,
188
- specifierColumn: column,
171
+ const importmapReferenceInlined = importmapReference.inline({
172
+ line: line - 1,
173
+ column,
189
174
  isOriginal,
190
- specifier: inlineImportmapUrl,
175
+ specifier: importmapInlineUrl,
191
176
  contentType: "application/importmap+json",
192
- content: importmapUrlInfo.content,
177
+ });
178
+ const importmapInlineUrlInfo = importmapReferenceInlined.urlInfo;
179
+ await importmapInlineUrlInfo.cook();
180
+ onHtmlImportmapParsed(
181
+ JSON.parse(importmapInlineUrlInfo.content),
182
+ htmlUrlInfo.url,
183
+ );
184
+ setHtmlNodeText(importmap, importmapInlineUrlInfo.content, {
185
+ indentation: "auto",
186
+ });
187
+ setHtmlNodeAttributes(importmap, {
188
+ "src": undefined,
189
+ "jsenv-inlined-by": "jsenv:importmap",
190
+ "inlined-from-src": src,
193
191
  });
194
192
  };
195
193
 
@@ -207,7 +205,7 @@ export const jsenvPluginImportmap = () => {
207
205
  // by "formatReferencedUrl" making the importmap presence useless.
208
206
  // In dev/test we keep importmap into the HTML to see it even if useless
209
207
  // Duing build we get rid of it
210
- if (context.build) {
208
+ if (htmlUrlInfo.context.build) {
211
209
  removeHtmlNode(importmap);
212
210
  }
213
211
  return {
@@ -2,21 +2,5 @@ import { jsenvPluginInliningAsDataUrl } from "./jsenv_plugin_inlining_as_data_ur
2
2
  import { jsenvPluginInliningIntoHtml } from "./jsenv_plugin_inlining_into_html.js";
3
3
 
4
4
  export const jsenvPluginInlining = () => {
5
- return [
6
- {
7
- name: "jsenv:inlining",
8
- appliesDuring: "*",
9
- redirectReference: (reference) => {
10
- const { searchParams } = reference;
11
- if (searchParams.has("inline")) {
12
- const urlObject = new URL(reference.url);
13
- urlObject.searchParams.delete("inline");
14
- return urlObject.href;
15
- }
16
- return null;
17
- },
18
- },
19
- jsenvPluginInliningAsDataUrl(),
20
- jsenvPluginInliningIntoHtml(),
21
- ];
5
+ return [jsenvPluginInliningAsDataUrl(), jsenvPluginInliningIntoHtml()];
22
6
  };