@jsenv/core 36.3.1 → 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.
- package/dist/js/autoreload.js +6 -5
- package/dist/js/import_meta_hot.js +4 -4
- package/dist/js/server_events_client.js +422 -304
- package/dist/jsenv_core.js +3819 -3256
- package/package.json +16 -16
- package/src/build/build.js +342 -658
- package/src/build/build_urls_generator.js +8 -8
- package/src/build/build_versions_manager.js +495 -0
- package/src/build/version_mappings_injection.js +27 -16
- package/src/dev/file_service.js +80 -91
- package/src/dev/start_dev_server.js +5 -3
- package/src/kitchen/errors.js +16 -16
- package/src/kitchen/fetched_content_compliance.js +4 -8
- package/src/kitchen/kitchen.js +367 -939
- package/src/kitchen/prepend_content.js +13 -35
- package/src/kitchen/url_graph/references.js +713 -0
- package/src/kitchen/url_graph/sort_by_dependencies.js +2 -2
- package/src/kitchen/url_graph/url_content.js +96 -0
- package/src/kitchen/url_graph/url_graph.js +439 -0
- package/src/kitchen/url_graph/url_graph_report.js +6 -4
- package/src/kitchen/url_graph/url_graph_visitor.js +14 -12
- package/src/kitchen/url_graph/url_info_transformations.js +180 -184
- package/src/plugins/autoreload/client/autoreload.js +1 -0
- package/src/plugins/autoreload/client/reload.js +6 -6
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +2 -2
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +2 -2
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +84 -78
- package/src/plugins/autoreload/jsenv_plugin_hot_search_param.js +52 -0
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +1 -1
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +2 -2
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +3 -3
- package/src/plugins/import_meta_hot/client/import_meta_hot.js +4 -4
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +18 -20
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +2 -2
- package/src/plugins/importmap/jsenv_plugin_importmap.js +35 -37
- package/src/plugins/inlining/jsenv_plugin_inlining.js +1 -17
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +70 -50
- package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +72 -54
- package/src/plugins/plugin_controller.js +92 -27
- package/src/plugins/protocol_file/jsenv_plugin_protocol_file.js +18 -20
- package/src/plugins/reference_analysis/css/jsenv_plugin_css_reference_analysis.js +4 -5
- package/src/plugins/reference_analysis/data_urls/jsenv_plugin_data_urls_analysis.js +18 -16
- package/src/plugins/reference_analysis/directory/jsenv_plugin_directory_reference_analysis.js +13 -20
- package/src/plugins/reference_analysis/html/jsenv_plugin_html_reference_analysis.js +55 -72
- package/src/plugins/reference_analysis/js/jsenv_plugin_js_reference_analysis.js +33 -42
- package/src/plugins/reference_analysis/jsenv_plugin_reference_analysis.js +16 -7
- package/src/plugins/reference_analysis/webmanifest/jsenv_plugin_webmanifest_reference_analysis.js +4 -3
- package/src/plugins/resolution_node_esm/jsenv_plugin_node_esm_resolution.js +16 -6
- package/src/plugins/resolution_node_esm/node_esm_resolver.js +30 -24
- package/src/plugins/resolution_web/jsenv_plugin_web_resolution.js +8 -5
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +3 -3
- package/src/plugins/server_events/client/server_events_client.js +460 -15
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +13 -29
- package/src/plugins/version_search_param/jsenv_plugin_version_search_param.js +1 -1
- package/src/build/version_generator.js +0 -19
- package/src/kitchen/url_graph/url_graph_loader.js +0 -77
- package/src/kitchen/url_graph.js +0 -322
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +0 -42
- package/src/plugins/resolution_node_esm/url_type_from_reference.js +0 -13
- package/src/plugins/server_events/client/connection_manager.js +0 -170
- package/src/plugins/server_events/client/event_source_connection.js +0 -83
- package/src/plugins/server_events/client/events_manager.js +0 -75
- package/src/plugins/server_events/client/web_socket_connection.js +0 -81
- /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: (
|
|
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
|
-
|
|
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
|
|
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 (!
|
|
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
|
|
69
|
-
|
|
70
|
-
|
|
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:
|
|
71
|
+
declinedBy: urlInfoReferencingThisOne.url,
|
|
75
72
|
};
|
|
76
73
|
}
|
|
77
|
-
const { hotAcceptDependencies = [] } =
|
|
74
|
+
const { hotAcceptDependencies = [] } =
|
|
75
|
+
urlInfoReferencingThisOne.data;
|
|
78
76
|
if (hotAcceptDependencies.includes(urlInfo.url)) {
|
|
79
77
|
instructions.push({
|
|
80
|
-
type:
|
|
81
|
-
boundary: formatUrlForClient(
|
|
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(
|
|
84
|
+
if (seen.includes(urlInfoReferencingThisOne.url)) {
|
|
87
85
|
return {
|
|
88
86
|
declined: true,
|
|
89
87
|
reason: "circular dependency",
|
|
90
|
-
declinedBy: formatUrlForClient(
|
|
88
|
+
declinedBy: formatUrlForClient(urlInfoReferencingThisOne.url),
|
|
91
89
|
};
|
|
92
90
|
}
|
|
93
|
-
const dependentPropagationResult = iterate(
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
130
|
+
notifyFullReload({
|
|
130
131
|
cause: `${relativeUrl} ${event}`,
|
|
131
132
|
reason: hotUpdate.reason,
|
|
132
133
|
declinedBy: hotUpdate.declinedBy,
|
|
133
134
|
});
|
|
134
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
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(
|
|
188
|
+
acceptedBy: formatUrlForClient(
|
|
189
|
+
lastReferenceFromOther.ownerUrlInfo.url,
|
|
190
|
+
),
|
|
187
191
|
});
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
192
|
+
notifyPartialReload({
|
|
193
|
+
cause,
|
|
194
|
+
reason: parentHotUpdate.reason,
|
|
195
|
+
instructions,
|
|
196
|
+
});
|
|
197
|
+
},
|
|
198
|
+
);
|
|
195
199
|
},
|
|
196
200
|
},
|
|
197
|
-
serve: (
|
|
198
|
-
if (request.pathname === "/__graph__") {
|
|
199
|
-
const graphJson = JSON.stringify(
|
|
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
|
+
};
|
|
@@ -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
|
|
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
|
|
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 =
|
|
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
|
|
74
|
+
const asUrlWithoutHotSearchParam = (url) => {
|
|
75
75
|
const urlObject = new URL(url);
|
|
76
|
-
if (urlObject.searchParams.has("
|
|
77
|
-
urlObject.searchParams.delete("
|
|
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
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
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
|
|
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,
|
|
105
|
-
const
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
123
|
-
|
|
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
|
-
|
|
133
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
171
|
+
const importmapReferenceInlined = importmapReference.inline({
|
|
172
|
+
line: line - 1,
|
|
173
|
+
column,
|
|
189
174
|
isOriginal,
|
|
190
|
-
specifier:
|
|
175
|
+
specifier: importmapInlineUrl,
|
|
191
176
|
contentType: "application/importmap+json",
|
|
192
|
-
|
|
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
|
};
|