@jsenv/core 35.0.3 → 35.0.5
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/html/explorer.html +107 -107
- package/dist/js/new_stylesheet.js +3 -0
- package/dist/js/s.js.map +3 -3
- package/package.json +2 -2
- package/src/build/build.js +589 -587
- package/src/build/build_urls_generator.js +44 -44
- package/src/build/graph_utils.js +14 -14
- package/src/build/jsenv_plugin_line_break_normalization.js +6 -6
- package/src/build/line_break_unix.js +11 -11
- package/src/build/start_build_server.js +37 -37
- package/src/build/version_generator.js +7 -7
- package/src/build/version_mappings_injection.js +23 -23
- package/src/dev/file_service.js +132 -132
- package/src/dev/start_dev_server.js +56 -56
- package/src/dev/user_agent.js +8 -8
- package/src/helpers/basic_fetch.js +24 -24
- package/src/helpers/command/command.js +28 -28
- package/src/helpers/lookup_package_directory.js +19 -16
- package/src/helpers/ping_server.js +17 -17
- package/src/helpers/require_from_jsenv.js +2 -2
- package/src/helpers/watch_source_files.js +9 -9
- package/src/helpers/web_url_converter.js +10 -10
- package/src/helpers/worker_reload.js +27 -27
- package/src/kitchen/compat/features_compatibility.js +1 -1
- package/src/kitchen/compat/runtime_compat.js +26 -24
- package/src/kitchen/errors.js +75 -75
- package/src/kitchen/fetched_content_compliance.js +8 -8
- package/src/kitchen/kitchen.js +251 -250
- package/src/kitchen/url_graph/sort_by_dependencies.js +17 -17
- package/src/kitchen/url_graph/url_graph_loader.js +30 -30
- package/src/kitchen/url_graph/url_graph_report.js +57 -57
- package/src/kitchen/url_graph/url_info_transformations.js +77 -77
- package/src/kitchen/url_graph.js +121 -121
- package/src/kitchen/url_specifier_encoding.js +21 -21
- package/src/kitchen/web_workers.js +5 -5
- package/src/main.js +3 -3
- package/src/plugins/autoreload/client/autoreload.js +96 -96
- package/src/plugins/autoreload/client/reload.js +56 -56
- package/src/plugins/autoreload/client/url_helpers.js +13 -13
- package/src/plugins/autoreload/jsenv_plugin_autoreload.js +5 -5
- package/src/plugins/autoreload/jsenv_plugin_autoreload_client.js +9 -9
- package/src/plugins/autoreload/jsenv_plugin_autoreload_server.js +61 -60
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +15 -15
- package/src/plugins/cache_control/jsenv_plugin_cache_control.js +5 -5
- package/src/plugins/commonjs_globals/jsenv_plugin_commonjs_globals.js +57 -57
- package/src/plugins/explorer/client/explorer.html +107 -107
- package/src/plugins/explorer/jsenv_plugin_explorer.js +20 -20
- package/src/plugins/file_urls/jsenv_plugin_file_urls.js +60 -60
- package/src/plugins/global_scenarios/jsenv_plugin_global_scenarios.js +5 -5
- package/src/plugins/http_urls/jsenv_plugin_http_urls.js +3 -3
- package/src/plugins/import_meta_hot/babel_plugin_metadata_import_meta_hot.js +35 -35
- package/src/plugins/import_meta_hot/client/import_meta_hot.js +26 -26
- package/src/plugins/import_meta_hot/html_hot_dependencies.js +43 -43
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +44 -40
- package/src/plugins/import_meta_scenarios/jsenv_plugin_import_meta_scenarios.js +35 -35
- package/src/plugins/import_meta_url/client/import_meta_url_browser.js +21 -21
- package/src/plugins/import_meta_url/client/import_meta_url_commonjs.mjs +3 -3
- package/src/plugins/importmap/jsenv_plugin_importmap.js +54 -54
- package/src/plugins/inline_content_analysis/client/inline_content.js +3 -3
- package/src/plugins/inline_content_analysis/jsenv_plugin_data_urls.js +26 -26
- package/src/plugins/inline_content_analysis/jsenv_plugin_html_inline_content_analysis.js +47 -47
- package/src/plugins/inline_content_analysis/jsenv_plugin_inline_content_analysis.js +9 -9
- package/src/plugins/inline_content_analysis/jsenv_plugin_js_inline_content_analysis.js +101 -101
- package/src/plugins/inlining/jsenv_plugin_inlining.js +9 -9
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +11 -11
- package/src/plugins/inlining/jsenv_plugin_inlining_into_html.js +48 -46
- package/src/plugins/node_runtime/jsenv_plugin_node_runtime.js +4 -4
- package/src/plugins/plugin_controller.js +124 -124
- package/src/plugins/plugins.js +27 -27
- package/src/plugins/ribbon/client/ribbon.js +6 -6
- package/src/plugins/ribbon/jsenv_plugin_ribbon.js +15 -15
- package/src/plugins/server_events/client/connection_manager.js +52 -52
- package/src/plugins/server_events/client/event_source_connection.js +36 -36
- package/src/plugins/server_events/client/events_manager.js +37 -37
- package/src/plugins/server_events/client/server_events_client.js +7 -7
- package/src/plugins/server_events/client/web_socket_connection.js +39 -39
- package/src/plugins/server_events/jsenv_plugin_server_events_client_injection.js +9 -9
- package/src/plugins/server_events/server_events_dispatcher.js +43 -43
- package/src/plugins/supervisor/client/supervisor.js +455 -450
- package/src/plugins/supervisor/html_supervisor_injection.js +64 -62
- package/src/plugins/supervisor/js_supervisor_injection.js +67 -67
- package/src/plugins/supervisor/jsenv_plugin_supervisor.js +54 -51
- package/src/plugins/transpilation/as_js_module/convert_js_classic_to_js_module.js +13 -13
- package/src/plugins/transpilation/as_js_module/jsenv_plugin_as_js_module.js +19 -19
- package/src/plugins/transpilation/babel/global_this/babel_plugin_global_this_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/global_this/client/global_this.js +8 -8
- package/src/plugins/transpilation/babel/helpers/babel_plugin_babel_helpers_as_jsenv_imports.js +16 -16
- package/src/plugins/transpilation/babel/helpers/babel_plugin_structure.js +36 -36
- package/src/plugins/transpilation/babel/helpers/babel_plugins_compatibility.js +3 -3
- package/src/plugins/transpilation/babel/jsenv_plugin_babel.js +24 -24
- package/src/plugins/transpilation/babel/new_stylesheet/babel_plugin_new_stylesheet_as_jsenv_import.js +44 -44
- package/src/plugins/transpilation/babel/new_stylesheet/client/new_stylesheet.js +166 -166
- package/src/plugins/transpilation/babel/regenerator_runtime/babel_plugin_regenerator_runtime_as_jsenv_import.js +10 -10
- package/src/plugins/transpilation/babel/require_babel_plugin.js +6 -6
- package/src/plugins/transpilation/css/jsenv_plugin_css_transpilation.js +20 -20
- package/src/plugins/transpilation/import_assertions/jsenv_plugin_import_assertions.js +62 -62
- package/src/plugins/transpilation/js_module_fallback/client/s.js +214 -209
- package/src/plugins/transpilation/js_module_fallback/convert_js_module_to_js_classic.js +45 -45
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_resolve.js +6 -6
- package/src/plugins/transpilation/js_module_fallback/helpers/babel_plugin_transform_import_meta_url.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/helpers-string.js +1 -1
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_conversion.js +32 -32
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback.js +17 -17
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_inside_html.js +63 -63
- package/src/plugins/transpilation/js_module_fallback/jsenv_plugin_js_module_fallback_on_workers.js +15 -15
- package/src/plugins/transpilation/jsenv_plugin_import_meta_resolve.js +20 -20
- package/src/plugins/transpilation/jsenv_plugin_top_level_await.js +23 -23
- package/src/plugins/transpilation/jsenv_plugin_transpilation.js +11 -11
- package/src/plugins/url_analysis/css/css_urls.js +12 -12
- package/src/plugins/url_analysis/html/html_urls.js +85 -85
- package/src/plugins/url_analysis/js/js_urls.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_reference_expected_types.js +16 -16
- package/src/plugins/url_analysis/jsenv_plugin_url_analysis.js +40 -40
- package/src/plugins/url_analysis/webmanifest/webmanifest_urls.js +12 -12
- package/src/plugins/url_resolution/jsenv_plugin_url_resolution.js +35 -35
- package/src/plugins/url_resolution/node_esm_resolver.js +26 -26
- package/src/plugins/url_version/jsenv_plugin_url_version.js +11 -11
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
urlIsInsideOf,
|
|
3
3
|
urlToRelativeUrl,
|
|
4
4
|
asUrlWithoutSearch,
|
|
5
|
-
} from "@jsenv/urls"
|
|
5
|
+
} from "@jsenv/urls";
|
|
6
6
|
|
|
7
7
|
export const jsenvPluginAutoreloadServer = ({
|
|
8
8
|
clientFileChangeCallbackList,
|
|
@@ -15,13 +15,13 @@ export const jsenvPluginAutoreloadServer = ({
|
|
|
15
15
|
reload: ({ sendServerEvent, rootDirectoryUrl, urlGraph }) => {
|
|
16
16
|
const formatUrlForClient = (url) => {
|
|
17
17
|
if (urlIsInsideOf(url, rootDirectoryUrl)) {
|
|
18
|
-
return urlToRelativeUrl(url, rootDirectoryUrl)
|
|
18
|
+
return urlToRelativeUrl(url, rootDirectoryUrl);
|
|
19
19
|
}
|
|
20
20
|
if (url.startsWith("file:")) {
|
|
21
|
-
return `/@fs/${url.slice("file:///".length)}
|
|
21
|
+
return `/@fs/${url.slice("file:///".length)}`;
|
|
22
22
|
}
|
|
23
|
-
return url
|
|
24
|
-
}
|
|
23
|
+
return url;
|
|
24
|
+
};
|
|
25
25
|
|
|
26
26
|
const notifyDeclined = ({ cause, reason, declinedBy }) => {
|
|
27
27
|
sendServerEvent({
|
|
@@ -29,22 +29,22 @@ export const jsenvPluginAutoreloadServer = ({
|
|
|
29
29
|
type: "full",
|
|
30
30
|
typeReason: reason,
|
|
31
31
|
declinedBy,
|
|
32
|
-
})
|
|
33
|
-
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
34
|
const notifyAccepted = ({ cause, reason, instructions }) => {
|
|
35
35
|
sendServerEvent({
|
|
36
36
|
cause,
|
|
37
37
|
type: "hot",
|
|
38
38
|
typeReason: reason,
|
|
39
39
|
hotInstructions: instructions,
|
|
40
|
-
})
|
|
41
|
-
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
42
|
const propagateUpdate = (firstUrlInfo) => {
|
|
43
43
|
if (!urlGraph.getUrlInfo(firstUrlInfo.url)) {
|
|
44
44
|
return {
|
|
45
45
|
declined: true,
|
|
46
46
|
reason: `url not in the url graph`,
|
|
47
|
-
}
|
|
47
|
+
};
|
|
48
48
|
}
|
|
49
49
|
const iterate = (urlInfo, seen) => {
|
|
50
50
|
if (urlInfo.data.hotAcceptSelf) {
|
|
@@ -61,48 +61,48 @@ export const jsenvPluginAutoreloadServer = ({
|
|
|
61
61
|
acceptedBy: formatUrlForClient(urlInfo.url),
|
|
62
62
|
},
|
|
63
63
|
],
|
|
64
|
-
}
|
|
64
|
+
};
|
|
65
65
|
}
|
|
66
|
-
const { dependents } = urlInfo
|
|
67
|
-
const instructions = []
|
|
66
|
+
const { dependents } = urlInfo;
|
|
67
|
+
const instructions = [];
|
|
68
68
|
for (const dependentUrl of dependents) {
|
|
69
|
-
const dependentUrlInfo = urlGraph.getUrlInfo(dependentUrl)
|
|
69
|
+
const dependentUrlInfo = urlGraph.getUrlInfo(dependentUrl);
|
|
70
70
|
if (dependentUrlInfo.data.hotDecline) {
|
|
71
71
|
return {
|
|
72
72
|
declined: true,
|
|
73
73
|
reason: `a dependent file declines hot reload`,
|
|
74
74
|
declinedBy: dependentUrl,
|
|
75
|
-
}
|
|
75
|
+
};
|
|
76
76
|
}
|
|
77
|
-
const { hotAcceptDependencies = [] } = dependentUrlInfo.data
|
|
77
|
+
const { hotAcceptDependencies = [] } = dependentUrlInfo.data;
|
|
78
78
|
if (hotAcceptDependencies.includes(urlInfo.url)) {
|
|
79
79
|
instructions.push({
|
|
80
80
|
type: dependentUrlInfo.type,
|
|
81
81
|
boundary: formatUrlForClient(dependentUrl),
|
|
82
82
|
acceptedBy: formatUrlForClient(urlInfo.url),
|
|
83
|
-
})
|
|
84
|
-
continue
|
|
83
|
+
});
|
|
84
|
+
continue;
|
|
85
85
|
}
|
|
86
86
|
if (seen.includes(dependentUrl)) {
|
|
87
87
|
return {
|
|
88
88
|
declined: true,
|
|
89
89
|
reason: "circular dependency",
|
|
90
90
|
declinedBy: formatUrlForClient(dependentUrl),
|
|
91
|
-
}
|
|
91
|
+
};
|
|
92
92
|
}
|
|
93
93
|
const dependentPropagationResult = iterate(dependentUrlInfo, [
|
|
94
94
|
...seen,
|
|
95
95
|
dependentUrl,
|
|
96
|
-
])
|
|
96
|
+
]);
|
|
97
97
|
if (dependentPropagationResult.accepted) {
|
|
98
|
-
instructions.push(...dependentPropagationResult.instructions)
|
|
99
|
-
continue
|
|
98
|
+
instructions.push(...dependentPropagationResult.instructions);
|
|
99
|
+
continue;
|
|
100
100
|
}
|
|
101
101
|
if (
|
|
102
102
|
// declined explicitely by an other file, it must decline the whole update
|
|
103
103
|
dependentPropagationResult.declinedBy
|
|
104
104
|
) {
|
|
105
|
-
return dependentPropagationResult
|
|
105
|
+
return dependentPropagationResult;
|
|
106
106
|
}
|
|
107
107
|
// declined by absence of boundary, we can keep searching
|
|
108
108
|
}
|
|
@@ -110,52 +110,53 @@ export const jsenvPluginAutoreloadServer = ({
|
|
|
110
110
|
return {
|
|
111
111
|
declined: true,
|
|
112
112
|
reason: `there is no file accepting hot reload while propagating update`,
|
|
113
|
-
}
|
|
113
|
+
};
|
|
114
114
|
}
|
|
115
115
|
return {
|
|
116
116
|
accepted: true,
|
|
117
117
|
reason: `${instructions.length} dependent file(s) accepts hot reload`,
|
|
118
118
|
instructions,
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const seen = []
|
|
122
|
-
return iterate(firstUrlInfo, seen)
|
|
123
|
-
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
const seen = [];
|
|
122
|
+
return iterate(firstUrlInfo, seen);
|
|
123
|
+
};
|
|
124
124
|
clientFileChangeCallbackList.push(({ url, event }) => {
|
|
125
125
|
const onUrlInfo = (urlInfo) => {
|
|
126
|
-
const relativeUrl = formatUrlForClient(urlInfo.url)
|
|
127
|
-
const hotUpdate = propagateUpdate(urlInfo)
|
|
126
|
+
const relativeUrl = formatUrlForClient(urlInfo.url);
|
|
127
|
+
const hotUpdate = propagateUpdate(urlInfo);
|
|
128
128
|
if (hotUpdate.declined) {
|
|
129
129
|
notifyDeclined({
|
|
130
130
|
cause: `${relativeUrl} ${event}`,
|
|
131
131
|
reason: hotUpdate.reason,
|
|
132
132
|
declinedBy: hotUpdate.declinedBy,
|
|
133
|
-
})
|
|
133
|
+
});
|
|
134
134
|
} else {
|
|
135
135
|
notifyAccepted({
|
|
136
136
|
cause: `${relativeUrl} ${event}`,
|
|
137
137
|
reason: hotUpdate.reason,
|
|
138
138
|
instructions: hotUpdate.instructions,
|
|
139
|
-
})
|
|
139
|
+
});
|
|
140
140
|
}
|
|
141
|
-
}
|
|
142
|
-
const exactUrlInfo = urlGraph.getUrlInfo(url)
|
|
141
|
+
};
|
|
142
|
+
const exactUrlInfo = urlGraph.getUrlInfo(url);
|
|
143
143
|
if (exactUrlInfo) {
|
|
144
|
-
onUrlInfo(exactUrlInfo)
|
|
144
|
+
onUrlInfo(exactUrlInfo);
|
|
145
145
|
}
|
|
146
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))
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
if (urlInfo === exactUrlInfo) return;
|
|
148
|
+
const urlWithoutSearch = asUrlWithoutSearch(urlInfo.url);
|
|
149
|
+
if (urlWithoutSearch !== url) return;
|
|
150
|
+
if (exactUrlInfo && exactUrlInfo.dependents.has(urlInfo.url))
|
|
151
|
+
return;
|
|
152
|
+
onUrlInfo(urlInfo);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
154
155
|
clientFilesPruneCallbackList.push((prunedUrlInfos, firstUrlInfo) => {
|
|
155
|
-
const mainHotUpdate = propagateUpdate(firstUrlInfo)
|
|
156
|
+
const mainHotUpdate = propagateUpdate(firstUrlInfo);
|
|
156
157
|
const cause = `following files are no longer referenced: ${prunedUrlInfos.map(
|
|
157
158
|
(prunedUrlInfo) => formatUrlForClient(prunedUrlInfo.url),
|
|
158
|
-
)}
|
|
159
|
+
)}`;
|
|
159
160
|
// now check if we can hot update the main resource
|
|
160
161
|
// then if we can hot update all dependencies
|
|
161
162
|
if (mainHotUpdate.declined) {
|
|
@@ -163,39 +164,39 @@ export const jsenvPluginAutoreloadServer = ({
|
|
|
163
164
|
cause,
|
|
164
165
|
reason: mainHotUpdate.reason,
|
|
165
166
|
declinedBy: mainHotUpdate.declinedBy,
|
|
166
|
-
})
|
|
167
|
-
return
|
|
167
|
+
});
|
|
168
|
+
return;
|
|
168
169
|
}
|
|
169
170
|
// main can hot update
|
|
170
|
-
let i = 0
|
|
171
|
-
const instructions = []
|
|
171
|
+
let i = 0;
|
|
172
|
+
const instructions = [];
|
|
172
173
|
while (i < prunedUrlInfos.length) {
|
|
173
|
-
const prunedUrlInfo = prunedUrlInfos[i++]
|
|
174
|
+
const prunedUrlInfo = prunedUrlInfos[i++];
|
|
174
175
|
if (prunedUrlInfo.data.hotDecline) {
|
|
175
176
|
notifyDeclined({
|
|
176
177
|
cause,
|
|
177
178
|
reason: `a pruned file declines hot reload`,
|
|
178
179
|
declinedBy: formatUrlForClient(prunedUrlInfo.url),
|
|
179
|
-
})
|
|
180
|
-
return
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
181
182
|
}
|
|
182
183
|
instructions.push({
|
|
183
184
|
type: "prune",
|
|
184
185
|
boundary: formatUrlForClient(prunedUrlInfo.url),
|
|
185
186
|
acceptedBy: formatUrlForClient(firstUrlInfo.url),
|
|
186
|
-
})
|
|
187
|
+
});
|
|
187
188
|
}
|
|
188
189
|
notifyAccepted({
|
|
189
190
|
cause,
|
|
190
191
|
reason: mainHotUpdate.reason,
|
|
191
192
|
instructions,
|
|
192
|
-
})
|
|
193
|
-
})
|
|
193
|
+
});
|
|
194
|
+
});
|
|
194
195
|
},
|
|
195
196
|
},
|
|
196
197
|
serve: (request, { rootDirectoryUrl, urlGraph }) => {
|
|
197
198
|
if (request.pathname === "/__graph__") {
|
|
198
|
-
const graphJson = JSON.stringify(urlGraph.toJSON(rootDirectoryUrl))
|
|
199
|
+
const graphJson = JSON.stringify(urlGraph.toJSON(rootDirectoryUrl));
|
|
199
200
|
return {
|
|
200
201
|
status: 200,
|
|
201
202
|
headers: {
|
|
@@ -203,9 +204,9 @@ export const jsenvPluginAutoreloadServer = ({
|
|
|
203
204
|
"content-length": Buffer.byteLength(graphJson),
|
|
204
205
|
},
|
|
205
206
|
body: graphJson,
|
|
206
|
-
}
|
|
207
|
+
};
|
|
207
208
|
}
|
|
208
|
-
return null
|
|
209
|
+
return null;
|
|
209
210
|
},
|
|
210
|
-
}
|
|
211
|
-
}
|
|
211
|
+
};
|
|
212
|
+
};
|
|
@@ -4,40 +4,40 @@ export const jsenvPluginHmr = () => {
|
|
|
4
4
|
appliesDuring: "dev",
|
|
5
5
|
redirectUrl: (reference) => {
|
|
6
6
|
if (!reference.searchParams.has("hmr")) {
|
|
7
|
-
reference.data.hmr = false
|
|
8
|
-
return null
|
|
7
|
+
reference.data.hmr = false;
|
|
8
|
+
return null;
|
|
9
9
|
}
|
|
10
|
-
reference.data.hmr = true
|
|
11
|
-
const urlObject = new URL(reference.url)
|
|
10
|
+
reference.data.hmr = true;
|
|
11
|
+
const urlObject = new URL(reference.url);
|
|
12
12
|
// "hmr" search param goal is to mark url as enabling hmr:
|
|
13
13
|
// this goal is achieved when we reach this part of the code
|
|
14
14
|
// We get rid of this params so that urlGraph and other parts of the code
|
|
15
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
|
|
16
|
+
urlObject.searchParams.delete("hmr");
|
|
17
|
+
urlObject.searchParams.delete("v");
|
|
18
|
+
return urlObject.href;
|
|
19
19
|
},
|
|
20
20
|
transformUrlSearchParams: (reference, context) => {
|
|
21
21
|
if (reference.type === "package_json") {
|
|
22
22
|
// maybe the if above shoulb be .isImplicit but it's just a detail anyway
|
|
23
|
-
return null
|
|
23
|
+
return null;
|
|
24
24
|
}
|
|
25
25
|
if (context.reference && !context.reference.data.hmr) {
|
|
26
26
|
// parent do not use hmr search param
|
|
27
|
-
return null
|
|
27
|
+
return null;
|
|
28
28
|
}
|
|
29
29
|
if (!context.reference && !reference.data.hmr) {
|
|
30
30
|
// entry point do not use hmr search param
|
|
31
|
-
return null
|
|
31
|
+
return null;
|
|
32
32
|
}
|
|
33
|
-
const urlInfo = context.urlGraph.getUrlInfo(reference.url)
|
|
33
|
+
const urlInfo = context.urlGraph.getUrlInfo(reference.url);
|
|
34
34
|
if (!urlInfo.modifiedTimestamp) {
|
|
35
|
-
return null
|
|
35
|
+
return null;
|
|
36
36
|
}
|
|
37
37
|
return {
|
|
38
38
|
hmr: "",
|
|
39
39
|
v: urlInfo.modifiedTimestamp,
|
|
40
|
-
}
|
|
40
|
+
};
|
|
41
41
|
},
|
|
42
|
-
}
|
|
43
|
-
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -15,11 +15,11 @@ export const jsenvPluginCacheControl = ({
|
|
|
15
15
|
headers: {
|
|
16
16
|
"cache-control": `private,max-age=${maxAge},immutable`,
|
|
17
17
|
},
|
|
18
|
-
}
|
|
18
|
+
};
|
|
19
19
|
}
|
|
20
|
-
return null
|
|
20
|
+
return null;
|
|
21
21
|
},
|
|
22
|
-
}
|
|
23
|
-
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
24
|
|
|
25
|
-
const SECONDS_IN_30_DAYS = 60 * 60 * 24 * 30
|
|
25
|
+
const SECONDS_IN_30_DAYS = 60 * 60 * 24 * 30;
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* - global
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { createMagicSource } from "@jsenv/sourcemap"
|
|
11
|
-
import { applyBabelPlugins } from "@jsenv/ast"
|
|
10
|
+
import { createMagicSource } from "@jsenv/sourcemap";
|
|
11
|
+
import { applyBabelPlugins } from "@jsenv/ast";
|
|
12
12
|
|
|
13
13
|
export const jsenvPluginCommonJsGlobals = () => {
|
|
14
14
|
const transformCommonJsGlobals = async (urlInfo, context) => {
|
|
@@ -17,9 +17,9 @@ export const jsenvPluginCommonJsGlobals = () => {
|
|
|
17
17
|
!urlInfo.content.includes("__filename") &&
|
|
18
18
|
!urlInfo.content.includes("__dirname")
|
|
19
19
|
) {
|
|
20
|
-
return null
|
|
20
|
+
return null;
|
|
21
21
|
}
|
|
22
|
-
const isJsModule = urlInfo.type === "js_module"
|
|
22
|
+
const isJsModule = urlInfo.type === "js_module";
|
|
23
23
|
const replaceMap = {
|
|
24
24
|
"process.env.NODE_ENV": `("${
|
|
25
25
|
context.dev ? "development" : "production"
|
|
@@ -31,7 +31,7 @@ export const jsenvPluginCommonJsGlobals = () => {
|
|
|
31
31
|
"__dirname": isJsModule
|
|
32
32
|
? `import.meta.url.slice('file:///'.length).replace(/[\\\/\\\\][^\\\/\\\\]*$/, '')`
|
|
33
33
|
: `new URL('./', document.currentScript.src).href`,
|
|
34
|
-
}
|
|
34
|
+
};
|
|
35
35
|
const { metadata } = await applyBabelPlugins({
|
|
36
36
|
babelPlugins: [
|
|
37
37
|
[
|
|
@@ -43,24 +43,24 @@ export const jsenvPluginCommonJsGlobals = () => {
|
|
|
43
43
|
],
|
|
44
44
|
],
|
|
45
45
|
urlInfo,
|
|
46
|
-
})
|
|
47
|
-
const { expressionPaths } = metadata
|
|
48
|
-
const keys = Object.keys(expressionPaths)
|
|
46
|
+
});
|
|
47
|
+
const { expressionPaths } = metadata;
|
|
48
|
+
const keys = Object.keys(expressionPaths);
|
|
49
49
|
if (keys.length === 0) {
|
|
50
|
-
return null
|
|
50
|
+
return null;
|
|
51
51
|
}
|
|
52
|
-
const magicSource = createMagicSource(urlInfo.content)
|
|
52
|
+
const magicSource = createMagicSource(urlInfo.content);
|
|
53
53
|
keys.forEach((key) => {
|
|
54
54
|
expressionPaths[key].forEach((path) => {
|
|
55
55
|
magicSource.replace({
|
|
56
56
|
start: path.node.start,
|
|
57
57
|
end: path.node.end,
|
|
58
58
|
replacement: replaceMap[key],
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
return magicSource.toContentAndSourcemap()
|
|
63
|
-
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return magicSource.toContentAndSourcemap();
|
|
63
|
+
};
|
|
64
64
|
|
|
65
65
|
return {
|
|
66
66
|
name: "jsenv:commonjs_globals",
|
|
@@ -69,8 +69,8 @@ export const jsenvPluginCommonJsGlobals = () => {
|
|
|
69
69
|
js_classic: transformCommonJsGlobals,
|
|
70
70
|
js_module: transformCommonJsGlobals,
|
|
71
71
|
},
|
|
72
|
-
}
|
|
73
|
-
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
74
|
|
|
75
75
|
// heavily inspired from https://github.com/jviide/babel-plugin-transform-replace-expressions
|
|
76
76
|
// last known commit: 57b608e0eeb8807db53d1c68292621dfafb5599c
|
|
@@ -78,9 +78,9 @@ const babelPluginMetadataExpressionPaths = (
|
|
|
78
78
|
babel,
|
|
79
79
|
{ replaceMap = {}, allowConflictingReplacements = false },
|
|
80
80
|
) => {
|
|
81
|
-
const { traverse, parse, types } = babel
|
|
82
|
-
const replacementMap = new Map()
|
|
83
|
-
const valueExpressionSet = new Set()
|
|
81
|
+
const { traverse, parse, types } = babel;
|
|
82
|
+
const replacementMap = new Map();
|
|
83
|
+
const valueExpressionSet = new Set();
|
|
84
84
|
|
|
85
85
|
return {
|
|
86
86
|
name: "metadata-replace",
|
|
@@ -89,94 +89,94 @@ const babelPluginMetadataExpressionPaths = (
|
|
|
89
89
|
// https://github.com/babel/babel/blob/d50e78d45b608f6e0f6cc33aeb22f5db5027b153/packages/babel-traverse/src/path/replacement.js#L93
|
|
90
90
|
const parseExpression = (value) => {
|
|
91
91
|
const expressionNode = parse(value, state.opts).program.body[0]
|
|
92
|
-
.expression
|
|
93
|
-
traverse.removeProperties(expressionNode)
|
|
94
|
-
return expressionNode
|
|
95
|
-
}
|
|
92
|
+
.expression;
|
|
93
|
+
traverse.removeProperties(expressionNode);
|
|
94
|
+
return expressionNode;
|
|
95
|
+
};
|
|
96
96
|
Object.keys(replaceMap).forEach((key) => {
|
|
97
|
-
const keyExpressionNode = parseExpression(key)
|
|
98
|
-
const candidateArray = replacementMap.get(keyExpressionNode.type) || []
|
|
99
|
-
const value = replaceMap[key]
|
|
100
|
-
const valueExpressionNode = parseExpression(value)
|
|
97
|
+
const keyExpressionNode = parseExpression(key);
|
|
98
|
+
const candidateArray = replacementMap.get(keyExpressionNode.type) || [];
|
|
99
|
+
const value = replaceMap[key];
|
|
100
|
+
const valueExpressionNode = parseExpression(value);
|
|
101
101
|
const equivalentKeyExpressionIndex = candidateArray.findIndex(
|
|
102
102
|
(candidate) =>
|
|
103
103
|
types.isNodesEquivalent(
|
|
104
104
|
candidate.keyExpressionNode,
|
|
105
105
|
keyExpressionNode,
|
|
106
106
|
),
|
|
107
|
-
)
|
|
107
|
+
);
|
|
108
108
|
if (
|
|
109
109
|
!allowConflictingReplacements &&
|
|
110
110
|
equivalentKeyExpressionIndex > -1
|
|
111
111
|
) {
|
|
112
112
|
throw new Error(
|
|
113
113
|
`Expressions ${candidateArray[equivalentKeyExpressionIndex].key} and ${key} conflict`,
|
|
114
|
-
)
|
|
114
|
+
);
|
|
115
115
|
}
|
|
116
116
|
const newCandidate = {
|
|
117
117
|
key,
|
|
118
118
|
value,
|
|
119
119
|
keyExpressionNode,
|
|
120
120
|
valueExpressionNode,
|
|
121
|
-
}
|
|
121
|
+
};
|
|
122
122
|
if (equivalentKeyExpressionIndex > -1) {
|
|
123
|
-
candidateArray[equivalentKeyExpressionIndex] = newCandidate
|
|
123
|
+
candidateArray[equivalentKeyExpressionIndex] = newCandidate;
|
|
124
124
|
} else {
|
|
125
|
-
candidateArray.push(newCandidate)
|
|
125
|
+
candidateArray.push(newCandidate);
|
|
126
126
|
}
|
|
127
|
-
replacementMap.set(keyExpressionNode.type, candidateArray)
|
|
128
|
-
})
|
|
127
|
+
replacementMap.set(keyExpressionNode.type, candidateArray);
|
|
128
|
+
});
|
|
129
129
|
replacementMap.forEach((candidateArray) => {
|
|
130
130
|
candidateArray.forEach((candidate) => {
|
|
131
|
-
valueExpressionSet.add(candidate.valueExpressionNode)
|
|
132
|
-
})
|
|
133
|
-
})
|
|
131
|
+
valueExpressionSet.add(candidate.valueExpressionNode);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
134
|
},
|
|
135
135
|
visitor: {
|
|
136
136
|
Program: (programPath, state) => {
|
|
137
|
-
const expressionPaths = {}
|
|
137
|
+
const expressionPaths = {};
|
|
138
138
|
programPath.traverse({
|
|
139
139
|
Expression(path) {
|
|
140
140
|
if (valueExpressionSet.has(path.node)) {
|
|
141
|
-
path.skip()
|
|
142
|
-
return
|
|
141
|
+
path.skip();
|
|
142
|
+
return;
|
|
143
143
|
}
|
|
144
|
-
const candidateArray = replacementMap.get(path.node.type)
|
|
144
|
+
const candidateArray = replacementMap.get(path.node.type);
|
|
145
145
|
if (!candidateArray) {
|
|
146
|
-
return
|
|
146
|
+
return;
|
|
147
147
|
}
|
|
148
148
|
const candidateFound = candidateArray.find((candidate) => {
|
|
149
149
|
return types.isNodesEquivalent(
|
|
150
150
|
candidate.keyExpressionNode,
|
|
151
151
|
path.node,
|
|
152
|
-
)
|
|
153
|
-
})
|
|
152
|
+
);
|
|
153
|
+
});
|
|
154
154
|
if (candidateFound) {
|
|
155
155
|
try {
|
|
156
156
|
types.validate(
|
|
157
157
|
path.parent,
|
|
158
158
|
path.key,
|
|
159
159
|
candidateFound.valueExpressionNode,
|
|
160
|
-
)
|
|
160
|
+
);
|
|
161
161
|
} catch (err) {
|
|
162
162
|
if (err instanceof TypeError) {
|
|
163
|
-
path.skip()
|
|
164
|
-
return
|
|
163
|
+
path.skip();
|
|
164
|
+
return;
|
|
165
165
|
}
|
|
166
|
-
throw err
|
|
166
|
+
throw err;
|
|
167
167
|
}
|
|
168
|
-
const paths = expressionPaths[candidateFound.key]
|
|
168
|
+
const paths = expressionPaths[candidateFound.key];
|
|
169
169
|
if (paths) {
|
|
170
|
-
expressionPaths[candidateFound.key] = [...paths, path]
|
|
170
|
+
expressionPaths[candidateFound.key] = [...paths, path];
|
|
171
171
|
} else {
|
|
172
|
-
expressionPaths[candidateFound.key] = [path]
|
|
172
|
+
expressionPaths[candidateFound.key] = [path];
|
|
173
173
|
}
|
|
174
|
-
return
|
|
174
|
+
return;
|
|
175
175
|
}
|
|
176
176
|
},
|
|
177
|
-
})
|
|
178
|
-
state.file.metadata.expressionPaths = expressionPaths
|
|
177
|
+
});
|
|
178
|
+
state.file.metadata.expressionPaths = expressionPaths;
|
|
179
179
|
},
|
|
180
180
|
},
|
|
181
|
-
}
|
|
182
|
-
}
|
|
181
|
+
};
|
|
182
|
+
};
|