@jsenv/core 37.0.5 → 37.1.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 +23 -20
- package/dist/js/import_meta_hot.js +0 -1
- package/dist/jsenv_core.js +691 -591
- package/package.json +2 -2
- package/src/build/build.js +141 -154
- package/src/build/build_versions_manager.js +53 -56
- package/src/dev/file_service.js +68 -77
- package/src/dev/start_dev_server.js +2 -4
- package/src/helpers/event_emitter.js +18 -0
- package/src/kitchen/kitchen.js +4 -6
- package/src/kitchen/url_graph/references.js +29 -8
- package/src/kitchen/url_graph/url_content.js +9 -0
- package/src/kitchen/url_graph/url_graph.js +50 -57
- package/src/kitchen/url_graph/url_graph_report.js +62 -59
- package/src/kitchen/url_graph/url_graph_visitor.js +30 -0
- package/src/kitchen/url_graph/url_info_transformations.js +26 -26
- package/src/plugins/autoreload/client/autoreload.js +7 -7
- package/src/plugins/autoreload/client/reload.js +16 -13
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +4 -4
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +138 -96
- package/src/plugins/autoreload/jsenv_plugin_hot_search_param.js +43 -25
- package/src/plugins/import_meta_hot/client/import_meta_hot.js +0 -1
- package/src/plugins/plugins.js +3 -14
- package/src/plugins/resolution_node_esm/jsenv_plugin_node_esm_resolution.js +4 -0
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
lastReference &&
|
|
14
|
-
lastReference.original &&
|
|
15
|
-
lastReference.original.searchParams.has("hot")
|
|
16
|
-
) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
return false;
|
|
20
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
* When client wants to hot reload, it wants to be sure it can reach the server
|
|
3
|
+
* and bypass any cache. This is done thanks to "hot" search param
|
|
4
|
+
* being injected by the client: file.js?hot=Date.now()
|
|
5
|
+
* When it happens server must:
|
|
6
|
+
* 1. Consider it's a regular request to "file.js" and not a variation
|
|
7
|
+
* of it (not like file.js?as_js_classic that creates a separate urlInfo)
|
|
8
|
+
* -> This is done by redirectReference deleting the search param.
|
|
9
|
+
*
|
|
10
|
+
* 2. Inject ?hot= into all urls referenced by this one
|
|
11
|
+
* -> This is done by transformReferenceSearchParams
|
|
12
|
+
*/
|
|
21
13
|
|
|
14
|
+
export const jsenvPluginHotSearchParam = () => {
|
|
22
15
|
return {
|
|
23
16
|
name: "jsenv:hot_search_param",
|
|
24
17
|
appliesDuring: "dev",
|
|
@@ -32,20 +25,45 @@ export const jsenvPluginHotSearchParam = () => {
|
|
|
32
25
|
// We get rid of this params so that urlGraph and other parts of the code
|
|
33
26
|
// recognize the url (it is not considered as a different url)
|
|
34
27
|
urlObject.searchParams.delete("hot");
|
|
35
|
-
urlObject.searchParams.delete("v");
|
|
36
28
|
return urlObject.href;
|
|
37
29
|
},
|
|
38
30
|
transformReferenceSearchParams: (reference) => {
|
|
39
|
-
if (
|
|
31
|
+
if (reference.isImplicit) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (reference.original && reference.original.searchParams.has("hot")) {
|
|
35
|
+
return {
|
|
36
|
+
hot: reference.original.searchParams.get("hot"),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const request = reference.ownerUrlInfo.context.request;
|
|
40
|
+
const parentHotParam = request ? request.searchParams.get("hot") : null;
|
|
41
|
+
if (!parentHotParam) {
|
|
40
42
|
return null;
|
|
41
43
|
}
|
|
44
|
+
// At this stage the parent is using ?hot and we are going to decide if
|
|
45
|
+
// we propagate the search param to child.
|
|
42
46
|
const referencedUrlInfo = reference.urlInfo;
|
|
43
|
-
|
|
47
|
+
const { modifiedTimestamp, dereferencedTimestamp } = referencedUrlInfo;
|
|
48
|
+
if (!modifiedTimestamp && !dereferencedTimestamp) {
|
|
44
49
|
return null;
|
|
45
50
|
}
|
|
51
|
+
// The goal is to send an url that will bypass client (the browser) cache
|
|
52
|
+
// more precisely the runtime cache of js modules, but also any http cache
|
|
53
|
+
// that could prevent re-execution of js code
|
|
54
|
+
// In order to achieve this, this plugin inject ?hot=timestamp
|
|
55
|
+
// - The browser will likely not have it in cache
|
|
56
|
+
// and refetch lastest version from server + re-execute it
|
|
57
|
+
// - If the browser have it in cache, he will not get it from server
|
|
58
|
+
// We use the latest timestamp to ensure it's fresh
|
|
59
|
+
// The dereferencedTimestamp is needed because when a js module is re-referenced
|
|
60
|
+
// browser must re-execute it, even if the code is not modified
|
|
61
|
+
const latestTimestamp =
|
|
62
|
+
dereferencedTimestamp && modifiedTimestamp
|
|
63
|
+
? Math.max(dereferencedTimestamp, modifiedTimestamp)
|
|
64
|
+
: dereferencedTimestamp || modifiedTimestamp;
|
|
46
65
|
return {
|
|
47
|
-
hot:
|
|
48
|
-
v: referencedUrlInfo.modifiedTimestamp,
|
|
66
|
+
hot: latestTimestamp,
|
|
49
67
|
};
|
|
50
68
|
},
|
|
51
69
|
};
|
package/src/plugins/plugins.js
CHANGED
|
@@ -33,9 +33,7 @@ export const getCorePlugins = ({
|
|
|
33
33
|
transpilation = true,
|
|
34
34
|
inlining = true,
|
|
35
35
|
|
|
36
|
-
clientAutoreload
|
|
37
|
-
clientFileChangeCallbackList,
|
|
38
|
-
clientFilesPruneCallbackList,
|
|
36
|
+
clientAutoreload,
|
|
39
37
|
cacheControl,
|
|
40
38
|
scenarioPlaceholders = true,
|
|
41
39
|
ribbon = true,
|
|
@@ -46,9 +44,6 @@ export const getCorePlugins = ({
|
|
|
46
44
|
if (supervisor === true) {
|
|
47
45
|
supervisor = {};
|
|
48
46
|
}
|
|
49
|
-
if (clientAutoreload === true) {
|
|
50
|
-
clientAutoreload = {};
|
|
51
|
-
}
|
|
52
47
|
if (ribbon === true) {
|
|
53
48
|
ribbon = {};
|
|
54
49
|
}
|
|
@@ -85,14 +80,8 @@ export const getCorePlugins = ({
|
|
|
85
80
|
jsenvPluginNodeRuntime({ runtimeCompat }),
|
|
86
81
|
|
|
87
82
|
jsenvPluginImportMetaHot(),
|
|
88
|
-
...(clientAutoreload
|
|
89
|
-
? [
|
|
90
|
-
jsenvPluginAutoreload({
|
|
91
|
-
...clientAutoreload,
|
|
92
|
-
clientFileChangeCallbackList,
|
|
93
|
-
clientFilesPruneCallbackList,
|
|
94
|
-
}),
|
|
95
|
-
]
|
|
83
|
+
...(clientAutoreload && clientAutoreload.enabled
|
|
84
|
+
? [jsenvPluginAutoreload(clientAutoreload)]
|
|
96
85
|
: []),
|
|
97
86
|
...(cacheControl ? [jsenvPluginCacheControl(cacheControl)] : []),
|
|
98
87
|
...(ribbon ? [jsenvPluginRibbon({ rootDirectoryUrl, ...ribbon })] : []),
|
|
@@ -48,6 +48,10 @@ export const jsenvPluginNodeEsmResolution = (resolutionConfig = {}) => {
|
|
|
48
48
|
if (reference.subtype === "self_import_scripts_arg") {
|
|
49
49
|
return nodeEsmResolverDefault(reference);
|
|
50
50
|
}
|
|
51
|
+
if (reference.type === "js_import") {
|
|
52
|
+
// happens for ?as_js_module
|
|
53
|
+
return nodeEsmResolverDefault(reference);
|
|
54
|
+
}
|
|
51
55
|
return null;
|
|
52
56
|
};
|
|
53
57
|
}
|