@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.
- 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 +17 -17
- 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
|
@@ -3,45 +3,29 @@
|
|
|
3
3
|
* to provide "serverEvents" used by other plugins
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
parseHtmlString,
|
|
8
|
-
stringifyHtmlAst,
|
|
9
|
-
injectHtmlNodeAsEarlyAsPossible,
|
|
10
|
-
createHtmlNode,
|
|
11
|
-
} from "@jsenv/ast";
|
|
12
|
-
|
|
13
6
|
const serverEventsClientFileUrl = new URL(
|
|
14
7
|
"./client/server_events_client.js",
|
|
15
8
|
import.meta.url,
|
|
16
9
|
).href;
|
|
17
10
|
|
|
18
|
-
export const jsenvPluginServerEventsClientInjection = () => {
|
|
11
|
+
export const jsenvPluginServerEventsClientInjection = ({ logs = true }) => {
|
|
19
12
|
return {
|
|
20
13
|
name: "jsenv:server_events_client_injection",
|
|
21
14
|
appliesDuring: "*",
|
|
22
15
|
transformUrlContent: {
|
|
23
|
-
html: (
|
|
24
|
-
const htmlAst = parseHtmlString(htmlUrlInfo.content);
|
|
25
|
-
const [serverEventsClientFileReference] = context.referenceUtils.inject(
|
|
26
|
-
{
|
|
27
|
-
type: "script",
|
|
28
|
-
subtype: "js_module",
|
|
29
|
-
expectedType: "js_module",
|
|
30
|
-
specifier: serverEventsClientFileUrl,
|
|
31
|
-
},
|
|
32
|
-
);
|
|
33
|
-
injectHtmlNodeAsEarlyAsPossible(
|
|
34
|
-
htmlAst,
|
|
35
|
-
createHtmlNode({
|
|
36
|
-
tagName: "script",
|
|
37
|
-
type: "module",
|
|
38
|
-
src: serverEventsClientFileReference.generatedSpecifier,
|
|
39
|
-
}),
|
|
40
|
-
"jsenv:server_events",
|
|
41
|
-
);
|
|
42
|
-
const htmlModified = stringifyHtmlAst(htmlAst);
|
|
16
|
+
html: () => {
|
|
43
17
|
return {
|
|
44
|
-
|
|
18
|
+
scriptInjections: [
|
|
19
|
+
{
|
|
20
|
+
src: serverEventsClientFileUrl,
|
|
21
|
+
setup: {
|
|
22
|
+
name: "window.__server_events__.setup",
|
|
23
|
+
param: {
|
|
24
|
+
logs,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
45
29
|
};
|
|
46
30
|
},
|
|
47
31
|
},
|
|
@@ -5,7 +5,7 @@ export const jsenvPluginVersionSearchParam = () => {
|
|
|
5
5
|
redirectReference: (reference) => {
|
|
6
6
|
// "v" search param goal is to enable long-term cache
|
|
7
7
|
// for server response headers
|
|
8
|
-
// it is also used by
|
|
8
|
+
// it is also used by hot to bypass browser cache
|
|
9
9
|
// this goal is achieved when we reach this part of the code
|
|
10
10
|
// We get rid of this params so that urlGraph and other parts of the code
|
|
11
11
|
// recognize the url (it is not considered as a different url)
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
// https://github.com/rollup/rollup/blob/19e50af3099c2f627451a45a84e2fa90d20246d5/src/utils/FileEmitter.ts#L47
|
|
4
|
-
// https://github.com/rollup/rollup/blob/5a5391971d695c808eed0c5d7d2c6ccb594fc689/src/Chunk.ts#L870
|
|
5
|
-
export const createVersionGenerator = () => {
|
|
6
|
-
const hash = createHash("sha256");
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
augmentWithContent: (content) => {
|
|
10
|
-
hash.update(content);
|
|
11
|
-
},
|
|
12
|
-
augment: (value) => {
|
|
13
|
-
hash.update(value);
|
|
14
|
-
},
|
|
15
|
-
generate: () => {
|
|
16
|
-
return hash.digest("hex").slice(0, 8);
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
export const createUrlGraphLoader = (context) => {
|
|
2
|
-
const promises = [];
|
|
3
|
-
const promiseMap = new Map();
|
|
4
|
-
const load = (
|
|
5
|
-
urlInfo,
|
|
6
|
-
dishContext,
|
|
7
|
-
{ ignoreRessourceHint = true, ignoreDynamicImport = false } = {},
|
|
8
|
-
) => {
|
|
9
|
-
const promiseFromData = promiseMap.get(urlInfo);
|
|
10
|
-
if (promiseFromData) return promiseFromData;
|
|
11
|
-
const promise = (async () => {
|
|
12
|
-
await context.cook(urlInfo, {
|
|
13
|
-
cookDuringCook: load,
|
|
14
|
-
...dishContext,
|
|
15
|
-
});
|
|
16
|
-
loadReferencedUrlInfos(urlInfo, {
|
|
17
|
-
ignoreRessourceHint,
|
|
18
|
-
ignoreDynamicImport,
|
|
19
|
-
});
|
|
20
|
-
})();
|
|
21
|
-
promises.push(promise);
|
|
22
|
-
promiseMap.set(urlInfo, promise);
|
|
23
|
-
return promise;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const loadReferencedUrlInfos = (
|
|
27
|
-
urlInfo,
|
|
28
|
-
{ ignoreRessourceHint, ignoreDynamicImport },
|
|
29
|
-
) => {
|
|
30
|
-
const { references } = urlInfo;
|
|
31
|
-
references.forEach((reference) => {
|
|
32
|
-
// we don't cook resource hints
|
|
33
|
-
// because they might refer to resource that will be modified during build
|
|
34
|
-
// It also means something else have to reference that url in order to cook it
|
|
35
|
-
// so that the preload is deleted by "resync_resource_hints.js" otherwise
|
|
36
|
-
if (ignoreRessourceHint && reference.isResourceHint) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (ignoreDynamicImport && reference.subtype === "import_dynamic") {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// we use reference.generatedUrl to mimic what a browser would do:
|
|
43
|
-
// do a fetch to the specifier as found in the file
|
|
44
|
-
const referencedUrlInfo = context.urlGraph.reuseOrCreateUrlInfo(
|
|
45
|
-
reference.generatedUrl,
|
|
46
|
-
);
|
|
47
|
-
load(referencedUrlInfo, {
|
|
48
|
-
reference,
|
|
49
|
-
ignoreRessourceHint,
|
|
50
|
-
ignoreDynamicImport,
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const getAllLoadDonePromise = async (operation) => {
|
|
56
|
-
const waitAll = async () => {
|
|
57
|
-
if (operation) {
|
|
58
|
-
operation.throwIfAborted();
|
|
59
|
-
}
|
|
60
|
-
if (promises.length === 0) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const promisesToWait = promises.slice();
|
|
64
|
-
promises.length = 0;
|
|
65
|
-
await Promise.all(promisesToWait);
|
|
66
|
-
await waitAll();
|
|
67
|
-
};
|
|
68
|
-
await waitAll();
|
|
69
|
-
promiseMap.clear();
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
load,
|
|
74
|
-
loadReferencedUrlInfos,
|
|
75
|
-
getAllLoadDonePromise,
|
|
76
|
-
};
|
|
77
|
-
};
|
package/src/kitchen/url_graph.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
import { urlToRelativeUrl } from "@jsenv/urls";
|
|
2
|
-
|
|
3
|
-
import { urlSpecifierEncoding } from "./url_specifier_encoding.js";
|
|
4
|
-
|
|
5
|
-
export const createUrlGraph = ({ name = "anonymous" } = {}) => {
|
|
6
|
-
const createUrlInfoCallbackRef = { current: () => {} };
|
|
7
|
-
const prunedUrlInfosCallbackRef = { current: () => {} };
|
|
8
|
-
|
|
9
|
-
const urlInfoMap = new Map();
|
|
10
|
-
const getUrlInfo = (url) => urlInfoMap.get(url);
|
|
11
|
-
const deleteUrlInfo = (url) => {
|
|
12
|
-
const urlInfo = urlInfoMap.get(url);
|
|
13
|
-
if (urlInfo) {
|
|
14
|
-
urlInfoMap.delete(url);
|
|
15
|
-
urlInfo.dependencies.forEach((dependencyUrl) => {
|
|
16
|
-
getUrlInfo(dependencyUrl).dependents.delete(url);
|
|
17
|
-
});
|
|
18
|
-
if (urlInfo.sourcemapReference) {
|
|
19
|
-
deleteUrlInfo(urlInfo.sourcemapReference.url);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const reuseOrCreateUrlInfo = (url) => {
|
|
24
|
-
const existingUrlInfo = getUrlInfo(url);
|
|
25
|
-
if (existingUrlInfo) return existingUrlInfo;
|
|
26
|
-
const urlInfo = createUrlInfo(url);
|
|
27
|
-
urlInfoMap.set(url, urlInfo);
|
|
28
|
-
createUrlInfoCallbackRef.current(urlInfo);
|
|
29
|
-
return urlInfo;
|
|
30
|
-
};
|
|
31
|
-
const getParentIfInline = (urlInfo) => {
|
|
32
|
-
return urlInfo.isInline ? getUrlInfo(urlInfo.inlineUrlSite.url) : urlInfo;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const inferReference = (specifier, parentUrl) => {
|
|
36
|
-
const parentUrlInfo = getUrlInfo(parentUrl);
|
|
37
|
-
if (!parentUrlInfo) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const seen = [];
|
|
41
|
-
const search = (urlInfo) => {
|
|
42
|
-
const firstReferenceFound = urlInfo.references.find((reference) => {
|
|
43
|
-
return urlSpecifierEncoding.decode(reference) === specifier;
|
|
44
|
-
});
|
|
45
|
-
if (firstReferenceFound) {
|
|
46
|
-
return firstReferenceFound;
|
|
47
|
-
}
|
|
48
|
-
for (const dependencyUrl of parentUrlInfo.dependencies) {
|
|
49
|
-
if (seen.includes(dependencyUrl)) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
seen.push(dependencyUrl);
|
|
53
|
-
const dependencyUrlInfo = getUrlInfo(dependencyUrl);
|
|
54
|
-
if (dependencyUrlInfo.isInline) {
|
|
55
|
-
const firstRef = search(dependencyUrlInfo);
|
|
56
|
-
if (firstRef) {
|
|
57
|
-
return firstRef;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
};
|
|
63
|
-
return search(parentUrlInfo);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const updateReferences = (urlInfo, references) => {
|
|
67
|
-
const setOfDependencyUrls = new Set();
|
|
68
|
-
const setOfImplicitUrls = new Set();
|
|
69
|
-
references.forEach((reference) => {
|
|
70
|
-
if (reference.isResourceHint) {
|
|
71
|
-
// resource hint are a special kind of reference.
|
|
72
|
-
// They are a sort of weak reference to an url.
|
|
73
|
-
// We ignore them so that url referenced only by resource hints
|
|
74
|
-
// have url.dependents.size === 0 and can be considered as not used
|
|
75
|
-
// It means html won't consider url referenced solely
|
|
76
|
-
// by <link> as dependency and it's fine
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const dependencyUrl = reference.url;
|
|
80
|
-
setOfDependencyUrls.add(dependencyUrl);
|
|
81
|
-
// an implicit reference do not appear in the file but the non explicited file
|
|
82
|
-
// have an impact on it
|
|
83
|
-
// -> package.json on import resolution for instance
|
|
84
|
-
// in that case:
|
|
85
|
-
// - file depends on the implicit file (it must autoreload if package.json is modified)
|
|
86
|
-
// - cache validity for the file depends on the implicit file (it must be re-cooked if package.json is modified)
|
|
87
|
-
if (reference.isImplicit) {
|
|
88
|
-
setOfImplicitUrls.add(dependencyUrl);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
setOfDependencyUrls.forEach((dependencyUrl) => {
|
|
92
|
-
urlInfo.dependencies.add(dependencyUrl);
|
|
93
|
-
const dependencyUrlInfo = reuseOrCreateUrlInfo(dependencyUrl);
|
|
94
|
-
dependencyUrlInfo.dependents.add(urlInfo.url);
|
|
95
|
-
});
|
|
96
|
-
setOfImplicitUrls.forEach((implicitUrl) => {
|
|
97
|
-
urlInfo.implicitUrls.add(implicitUrl);
|
|
98
|
-
if (urlInfo.isInline) {
|
|
99
|
-
const parentUrlInfo = getUrlInfo(urlInfo.inlineUrlSite.url);
|
|
100
|
-
parentUrlInfo.implicitUrls.add(implicitUrl);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
const prunedUrlInfos = [];
|
|
104
|
-
const pruneDependency = (urlInfo, urlToClean) => {
|
|
105
|
-
urlInfo.dependencies.delete(urlToClean);
|
|
106
|
-
const dependencyUrlInfo = getUrlInfo(urlToClean);
|
|
107
|
-
if (!dependencyUrlInfo) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
dependencyUrlInfo.dependents.delete(urlInfo.url);
|
|
111
|
-
if (dependencyUrlInfo.dependents.size === 0) {
|
|
112
|
-
dependencyUrlInfo.dependencies.forEach((dependencyUrl) => {
|
|
113
|
-
pruneDependency(dependencyUrlInfo, dependencyUrl);
|
|
114
|
-
});
|
|
115
|
-
prunedUrlInfos.push(dependencyUrlInfo);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
urlInfo.dependencies.forEach((dependencyUrl) => {
|
|
119
|
-
if (!setOfDependencyUrls.has(dependencyUrl)) {
|
|
120
|
-
pruneDependency(urlInfo, dependencyUrl);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
if (prunedUrlInfos.length) {
|
|
124
|
-
prunedUrlInfos.forEach((prunedUrlInfo) => {
|
|
125
|
-
prunedUrlInfo.modifiedTimestamp = Date.now();
|
|
126
|
-
if (prunedUrlInfo.isInline) {
|
|
127
|
-
// should we always delete?
|
|
128
|
-
deleteUrlInfo(prunedUrlInfo.url);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
prunedUrlInfosCallbackRef.current(prunedUrlInfos, urlInfo);
|
|
132
|
-
}
|
|
133
|
-
urlInfo.implicitUrls.forEach((implicitUrl) => {
|
|
134
|
-
if (!setOfDependencyUrls.has(implicitUrl)) {
|
|
135
|
-
let implicitUrlComesFromInlineContent = false;
|
|
136
|
-
for (const dependencyUrl of urlInfo.dependencies) {
|
|
137
|
-
const dependencyUrlInfo = getUrlInfo(dependencyUrl);
|
|
138
|
-
if (
|
|
139
|
-
dependencyUrlInfo.isInline &&
|
|
140
|
-
dependencyUrlInfo.implicitUrls.has(implicitUrl)
|
|
141
|
-
) {
|
|
142
|
-
implicitUrlComesFromInlineContent = true;
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (!implicitUrlComesFromInlineContent) {
|
|
147
|
-
urlInfo.implicitUrls.delete(implicitUrl);
|
|
148
|
-
}
|
|
149
|
-
if (urlInfo.isInline) {
|
|
150
|
-
const parentUrlInfo = getUrlInfo(urlInfo.inlineUrlSite.url);
|
|
151
|
-
parentUrlInfo.implicitUrls.delete(implicitUrl);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
urlInfo.references = references;
|
|
156
|
-
return urlInfo;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const considerModified = (urlInfo, modifiedTimestamp = Date.now()) => {
|
|
160
|
-
const seen = [];
|
|
161
|
-
const iterate = (urlInfo) => {
|
|
162
|
-
if (seen.includes(urlInfo.url)) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
seen.push(urlInfo.url);
|
|
166
|
-
urlInfo.modifiedTimestamp = modifiedTimestamp;
|
|
167
|
-
urlInfo.originalContentEtag = undefined;
|
|
168
|
-
urlInfo.contentEtag = undefined;
|
|
169
|
-
urlInfo.dependents.forEach((dependentUrl) => {
|
|
170
|
-
const dependentUrlInfo = getUrlInfo(dependentUrl);
|
|
171
|
-
const { hotAcceptDependencies = [] } = dependentUrlInfo.data;
|
|
172
|
-
if (!hotAcceptDependencies.includes(urlInfo.url)) {
|
|
173
|
-
iterate(dependentUrlInfo);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
urlInfo.dependencies.forEach((dependencyUrl) => {
|
|
177
|
-
const dependencyUrlInfo = getUrlInfo(dependencyUrl);
|
|
178
|
-
if (dependencyUrlInfo.isInline) {
|
|
179
|
-
iterate(dependencyUrlInfo);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
iterate(urlInfo);
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const getEntryPoints = () => {
|
|
187
|
-
const entryPoints = [];
|
|
188
|
-
urlInfoMap.forEach((urlInfo) => {
|
|
189
|
-
if (urlInfo.isEntryPoint) {
|
|
190
|
-
entryPoints.push(urlInfo);
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
return entryPoints;
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
const hasDependent = (urlInfo) => {
|
|
197
|
-
for (const dependentUrl of urlInfo.dependents) {
|
|
198
|
-
const dependentUrlInfo = getUrlInfo(dependentUrl);
|
|
199
|
-
for (const reference of dependentUrlInfo.references) {
|
|
200
|
-
if (reference.url === urlInfo.url) {
|
|
201
|
-
if (
|
|
202
|
-
!reference.isInline &&
|
|
203
|
-
reference.next &&
|
|
204
|
-
reference.next.isInline
|
|
205
|
-
) {
|
|
206
|
-
// the url info was inlined, an other reference is required
|
|
207
|
-
// to consider the non-inlined urlInfo as used
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return false;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const isUsed = (urlInfo) => {
|
|
218
|
-
// nothing uses this url anymore
|
|
219
|
-
// - versioning update inline content
|
|
220
|
-
// - file converted for import assertion or js_classic conversion
|
|
221
|
-
// - urlInfo for a file that is now inlined
|
|
222
|
-
if (urlInfo.isEntryPoint) {
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
// if (urlInfo.type === "sourcemap") {
|
|
226
|
-
// return true;
|
|
227
|
-
// }
|
|
228
|
-
// check if there is a valid reference to this urlInfo
|
|
229
|
-
if (hasDependent(urlInfo)) {
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
return false;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
return {
|
|
236
|
-
name,
|
|
237
|
-
createUrlInfoCallbackRef,
|
|
238
|
-
prunedUrlInfosCallbackRef,
|
|
239
|
-
|
|
240
|
-
urlInfoMap,
|
|
241
|
-
reuseOrCreateUrlInfo,
|
|
242
|
-
getUrlInfo,
|
|
243
|
-
deleteUrlInfo,
|
|
244
|
-
getParentIfInline,
|
|
245
|
-
getEntryPoints,
|
|
246
|
-
hasDependent,
|
|
247
|
-
isUsed,
|
|
248
|
-
|
|
249
|
-
inferReference,
|
|
250
|
-
updateReferences,
|
|
251
|
-
considerModified,
|
|
252
|
-
|
|
253
|
-
toObject: () => {
|
|
254
|
-
const data = {};
|
|
255
|
-
urlInfoMap.forEach((urlInfo) => {
|
|
256
|
-
data[urlInfo.url] = urlInfo;
|
|
257
|
-
});
|
|
258
|
-
return data;
|
|
259
|
-
},
|
|
260
|
-
toJSON: (rootDirectoryUrl) => {
|
|
261
|
-
const data = {};
|
|
262
|
-
urlInfoMap.forEach((urlInfo) => {
|
|
263
|
-
const dependencyUrls = Array.from(urlInfo.dependencies);
|
|
264
|
-
if (dependencyUrls.length) {
|
|
265
|
-
const relativeUrl = urlToRelativeUrl(urlInfo.url, rootDirectoryUrl);
|
|
266
|
-
data[relativeUrl] = dependencyUrls.map((dependencyUrl) =>
|
|
267
|
-
urlToRelativeUrl(dependencyUrl, rootDirectoryUrl),
|
|
268
|
-
);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
return data;
|
|
272
|
-
},
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
const createUrlInfo = (url) => {
|
|
277
|
-
const urlInfo = {
|
|
278
|
-
error: null,
|
|
279
|
-
modifiedTimestamp: 0,
|
|
280
|
-
originalContentEtag: null,
|
|
281
|
-
contentEtag: null,
|
|
282
|
-
isWatched: false,
|
|
283
|
-
isValid: () => false,
|
|
284
|
-
data: {}, // plugins can put whatever they want here
|
|
285
|
-
references: [],
|
|
286
|
-
dependencies: new Set(),
|
|
287
|
-
dependents: new Set(),
|
|
288
|
-
implicitUrls: new Set(),
|
|
289
|
-
type: undefined, // "html", "css", "js_classic", "js_module", "importmap", "sourcemap", "json", "webmanifest", ...
|
|
290
|
-
subtype: undefined, // "worker", "service_worker", "shared_worker" for js, otherwise undefined
|
|
291
|
-
typeHint: undefined,
|
|
292
|
-
subtypeHint: undefined,
|
|
293
|
-
contentType: "", // "text/html", "text/css", "text/javascript", "application/json", ...
|
|
294
|
-
url,
|
|
295
|
-
originalUrl: undefined,
|
|
296
|
-
filename: "",
|
|
297
|
-
isEntryPoint: false,
|
|
298
|
-
originalContent: undefined,
|
|
299
|
-
originalContentAst: undefined,
|
|
300
|
-
content: undefined,
|
|
301
|
-
contentAst: undefined,
|
|
302
|
-
contentFinalized: false,
|
|
303
|
-
|
|
304
|
-
sourcemap: null,
|
|
305
|
-
sourcemapReference: null,
|
|
306
|
-
sourcemapIsWrong: false,
|
|
307
|
-
|
|
308
|
-
generatedUrl: null,
|
|
309
|
-
sourcemapGeneratedUrl: null,
|
|
310
|
-
injected: false,
|
|
311
|
-
|
|
312
|
-
isInline: false,
|
|
313
|
-
inlineUrlSite: null,
|
|
314
|
-
jsQuote: null, // maybe move to inlineUrlSite?
|
|
315
|
-
|
|
316
|
-
timing: {},
|
|
317
|
-
headers: {},
|
|
318
|
-
debug: false,
|
|
319
|
-
};
|
|
320
|
-
// Object.preventExtensions(urlInfo) // useful to ensure all properties are declared here
|
|
321
|
-
return urlInfo;
|
|
322
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export const jsenvPluginHmr = () => {
|
|
2
|
-
return {
|
|
3
|
-
name: "jsenv:hmr",
|
|
4
|
-
appliesDuring: "dev",
|
|
5
|
-
redirectReference: (reference) => {
|
|
6
|
-
if (!reference.searchParams.has("hmr")) {
|
|
7
|
-
reference.data.hmr = false;
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
reference.data.hmr = true;
|
|
11
|
-
const urlObject = new URL(reference.url);
|
|
12
|
-
// "hmr" search param goal is to mark url as enabling hmr:
|
|
13
|
-
// this goal is achieved when we reach this part of the code
|
|
14
|
-
// We get rid of this params so that urlGraph and other parts of the code
|
|
15
|
-
// recognize the url (it is not considered as a different url)
|
|
16
|
-
urlObject.searchParams.delete("hmr");
|
|
17
|
-
urlObject.searchParams.delete("v");
|
|
18
|
-
return urlObject.href;
|
|
19
|
-
},
|
|
20
|
-
transformReferenceSearchParams: (reference, context) => {
|
|
21
|
-
if (reference.isImplicit) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
if (context.reference && !context.reference.data.hmr) {
|
|
25
|
-
// parent do not use hmr search param
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
if (!context.reference && !reference.data.hmr) {
|
|
29
|
-
// entry point do not use hmr search param
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
const urlInfo = context.urlGraph.getUrlInfo(reference.url);
|
|
33
|
-
if (!urlInfo.modifiedTimestamp) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
hmr: "",
|
|
38
|
-
v: urlInfo.modifiedTimestamp,
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const urlTypeFromReference = (reference, context) => {
|
|
2
|
-
if (reference.type === "sourcemap_comment") {
|
|
3
|
-
return "sourcemap";
|
|
4
|
-
}
|
|
5
|
-
if (reference.injected) {
|
|
6
|
-
return reference.expectedType;
|
|
7
|
-
}
|
|
8
|
-
const parentUrlInfo = context.urlGraph.getUrlInfo(reference.parentUrl);
|
|
9
|
-
if (parentUrlInfo) {
|
|
10
|
-
return parentUrlInfo.type;
|
|
11
|
-
}
|
|
12
|
-
return "entry_point";
|
|
13
|
-
};
|