@jsenv/core 36.3.0 → 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 +18 -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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { pathToFileURL } from "node:url";
|
|
2
|
-
import {
|
|
3
|
-
import { bufferToEtag } from "@jsenv/filesystem";
|
|
2
|
+
import { writeFileSync } from "@jsenv/filesystem";
|
|
4
3
|
import { urlToRelativeUrl, isFileSystemPath } from "@jsenv/urls";
|
|
5
4
|
import {
|
|
6
5
|
composeTwoSourcemaps,
|
|
@@ -8,6 +7,10 @@ import {
|
|
|
8
7
|
generateSourcemapFileUrl,
|
|
9
8
|
generateSourcemapDataUrl,
|
|
10
9
|
} from "@jsenv/sourcemap";
|
|
10
|
+
import {
|
|
11
|
+
defineGettersOnPropertiesDerivedFromOriginalContent,
|
|
12
|
+
defineGettersOnPropertiesDerivedFromContent,
|
|
13
|
+
} from "./url_content.js";
|
|
11
14
|
|
|
12
15
|
export const createUrlInfoTransformer = ({
|
|
13
16
|
logger,
|
|
@@ -15,9 +18,8 @@ export const createUrlInfoTransformer = ({
|
|
|
15
18
|
sourcemapsSourcesProtocol,
|
|
16
19
|
sourcemapsSourcesContent,
|
|
17
20
|
sourcemapsSourcesRelative,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
foundSourcemap,
|
|
21
|
+
outDirectoryUrl,
|
|
22
|
+
supervisor,
|
|
21
23
|
}) => {
|
|
22
24
|
if (sourcemapsSourcesProtocol === undefined) {
|
|
23
25
|
sourcemapsSourcesProtocol = "file:///";
|
|
@@ -66,80 +68,49 @@ export const createUrlInfoTransformer = ({
|
|
|
66
68
|
return sourcemap;
|
|
67
69
|
};
|
|
68
70
|
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
"contentEtag",
|
|
86
|
-
);
|
|
87
|
-
if (contentEtagDescriptor.value === undefined) {
|
|
88
|
-
defineVolaliteGetter(urlInfo, "contentEtag", () => {
|
|
89
|
-
if (urlInfo.content === urlInfo.originalContent) {
|
|
90
|
-
return urlInfo.originalContentEtag;
|
|
91
|
-
}
|
|
92
|
-
return getContentEtag(urlInfo.content);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
71
|
+
const resetContent = (urlInfo) => {
|
|
72
|
+
urlInfo.contentFinalized = false;
|
|
73
|
+
urlInfo.originalContent = undefined;
|
|
74
|
+
urlInfo.originalContentAst = undefined;
|
|
75
|
+
urlInfo.originalContentEtag = undefined;
|
|
76
|
+
urlInfo.contentAst = undefined;
|
|
77
|
+
urlInfo.contentEtag = undefined;
|
|
78
|
+
urlInfo.content = undefined;
|
|
79
|
+
urlInfo.sourcemap = null;
|
|
80
|
+
urlInfo.sourcemapIsWrong = null;
|
|
81
|
+
urlInfo.referenceToOthersSet.forEach((referenceToOther) => {
|
|
82
|
+
const referencedUrlInfo = referenceToOther.urlInfo;
|
|
83
|
+
if (referencedUrlInfo.isInline) {
|
|
84
|
+
referencedUrlInfo.deleteFromGraph();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
95
87
|
};
|
|
96
88
|
|
|
97
|
-
const
|
|
89
|
+
const setContent = async (
|
|
98
90
|
urlInfo,
|
|
91
|
+
content,
|
|
99
92
|
{
|
|
100
|
-
content,
|
|
101
93
|
contentAst, // most of the time will be undefined
|
|
102
94
|
contentEtag, // in practice it's always undefined
|
|
103
|
-
originalContent,
|
|
95
|
+
originalContent = content,
|
|
104
96
|
originalContentAst, // most of the time will be undefined
|
|
105
97
|
originalContentEtag, // in practice always undefined
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
sourcemap,
|
|
99
|
+
} = {},
|
|
108
100
|
) => {
|
|
109
|
-
urlInfo.contentFinalized = false;
|
|
110
101
|
urlInfo.originalContentAst = originalContentAst;
|
|
111
102
|
urlInfo.originalContentEtag = originalContentEtag;
|
|
112
103
|
if (originalContent !== urlInfo.originalContent) {
|
|
113
104
|
urlInfo.originalContent = originalContent;
|
|
114
105
|
}
|
|
115
|
-
|
|
116
|
-
urlInfo,
|
|
117
|
-
"originalContentAst",
|
|
118
|
-
);
|
|
119
|
-
if (originalContentAstDescriptor.value === undefined) {
|
|
120
|
-
defineVolaliteGetter(urlInfo, "originalContentAst", () => {
|
|
121
|
-
return getContentAst(
|
|
122
|
-
urlInfo.originalContent,
|
|
123
|
-
urlInfo.type,
|
|
124
|
-
urlInfo.url,
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
const originalContentEtagDescriptor = Object.getOwnPropertyDescriptor(
|
|
129
|
-
urlInfo,
|
|
130
|
-
"originalContentEtag",
|
|
131
|
-
);
|
|
132
|
-
if (originalContentEtagDescriptor.value === undefined) {
|
|
133
|
-
defineVolaliteGetter(urlInfo, "originalContentEtag", () => {
|
|
134
|
-
return bufferToEtag(Buffer.from(urlInfo.originalContent));
|
|
135
|
-
});
|
|
136
|
-
}
|
|
106
|
+
defineGettersOnPropertiesDerivedFromOriginalContent(urlInfo);
|
|
137
107
|
|
|
138
108
|
urlInfo.contentAst = contentAst;
|
|
139
109
|
urlInfo.contentEtag = contentEtag;
|
|
140
110
|
urlInfo.content = content;
|
|
141
111
|
defineGettersOnPropertiesDerivedFromContent(urlInfo);
|
|
142
112
|
|
|
113
|
+
urlInfo.sourcemap = sourcemap;
|
|
143
114
|
if (!sourcemapsEnabled) {
|
|
144
115
|
return;
|
|
145
116
|
}
|
|
@@ -151,9 +122,6 @@ export const createUrlInfoTransformer = ({
|
|
|
151
122
|
}
|
|
152
123
|
// sourcemap is a special kind of reference:
|
|
153
124
|
// It's a reference to a content generated dynamically the content itself.
|
|
154
|
-
// For this reason sourcemap are not added to urlInfo.references
|
|
155
|
-
// Instead they are stored into urlInfo.sourcemapReference
|
|
156
|
-
// create a placeholder reference for the sourcemap that will be generated
|
|
157
125
|
// when jsenv is done cooking the file
|
|
158
126
|
// during build it's urlInfo.url to be inside the build
|
|
159
127
|
// but otherwise it's generatedUrl to be inside .jsenv/ directory
|
|
@@ -163,49 +131,43 @@ export const createUrlInfoTransformer = ({
|
|
|
163
131
|
generatedUrlObject.searchParams.delete("as_js_classic");
|
|
164
132
|
const urlForSourcemap = generatedUrlObject.href;
|
|
165
133
|
urlInfo.sourcemapGeneratedUrl = generateSourcemapFileUrl(urlForSourcemap);
|
|
166
|
-
|
|
134
|
+
|
|
135
|
+
// case #1: already loaded during "load" hook
|
|
136
|
+
// - happens during build
|
|
137
|
+
// - happens for url converted during fetch (js_module_fallback for instance)
|
|
167
138
|
if (urlInfo.sourcemap) {
|
|
168
|
-
const [sourcemapReference, sourcemapUrlInfo] = injectSourcemapPlaceholder(
|
|
169
|
-
{
|
|
170
|
-
urlInfo,
|
|
171
|
-
specifier: urlInfo.sourcemapGeneratedUrl,
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
|
-
sourcemapUrlInfo.isInline = sourcemaps === "inline";
|
|
175
|
-
urlInfo.sourcemapReference = sourcemapReference;
|
|
176
139
|
urlInfo.sourcemap = normalizeSourcemap(urlInfo, urlInfo.sourcemap);
|
|
177
140
|
return;
|
|
178
141
|
}
|
|
179
|
-
|
|
142
|
+
|
|
143
|
+
// case #2: check for existing sourcemap for this content
|
|
180
144
|
const sourcemapFound = SOURCEMAP.readComment({
|
|
181
145
|
contentType: urlInfo.contentType,
|
|
182
146
|
content: urlInfo.content,
|
|
183
147
|
});
|
|
184
148
|
if (sourcemapFound) {
|
|
185
|
-
const { type, line, column, specifier } = sourcemapFound;
|
|
186
|
-
const
|
|
187
|
-
urlInfo,
|
|
149
|
+
const { type, subtype, line, column, specifier } = sourcemapFound;
|
|
150
|
+
const sourcemapReference = urlInfo.dependencies.found({
|
|
188
151
|
type,
|
|
152
|
+
subtype,
|
|
153
|
+
expectedType: "sourcemap",
|
|
189
154
|
specifier,
|
|
190
155
|
specifierLine: line,
|
|
191
156
|
specifierColumn: column,
|
|
192
157
|
});
|
|
193
158
|
try {
|
|
194
|
-
await
|
|
195
|
-
const sourcemapRaw = JSON.parse(
|
|
159
|
+
await sourcemapReference.urlInfo.cook();
|
|
160
|
+
const sourcemapRaw = JSON.parse(sourcemapReference.urlInfo.content);
|
|
196
161
|
const sourcemap = normalizeSourcemap(urlInfo, sourcemapRaw);
|
|
197
162
|
urlInfo.sourcemap = sourcemap;
|
|
163
|
+
return;
|
|
198
164
|
} catch (e) {
|
|
199
165
|
logger.error(`Error while handling existing sourcemap: ${e.message}`);
|
|
200
166
|
return;
|
|
201
167
|
}
|
|
202
|
-
} else {
|
|
203
|
-
const [, sourcemapUrlInfo] = injectSourcemapPlaceholder({
|
|
204
|
-
urlInfo,
|
|
205
|
-
specifier: urlInfo.sourcemapGeneratedUrl,
|
|
206
|
-
});
|
|
207
|
-
sourcemapUrlInfo.isInline = sourcemaps === "inline";
|
|
208
168
|
}
|
|
169
|
+
|
|
170
|
+
// case #3: will be injected once cooked
|
|
209
171
|
};
|
|
210
172
|
|
|
211
173
|
const applyTransformations = (urlInfo, transformations) => {
|
|
@@ -227,10 +189,11 @@ export const createUrlInfoTransformer = ({
|
|
|
227
189
|
if (contentType) {
|
|
228
190
|
urlInfo.contentType = contentType;
|
|
229
191
|
}
|
|
230
|
-
|
|
231
|
-
|
|
192
|
+
const contentModified = content && content !== urlInfo.content;
|
|
193
|
+
if (contentModified) {
|
|
232
194
|
urlInfo.contentAst = contentAst;
|
|
233
195
|
urlInfo.contentEtag = contentEtag;
|
|
196
|
+
urlInfo.content = content;
|
|
234
197
|
defineGettersOnPropertiesDerivedFromContent(urlInfo);
|
|
235
198
|
}
|
|
236
199
|
if (sourcemapsEnabled && sourcemap) {
|
|
@@ -255,115 +218,148 @@ export const createUrlInfoTransformer = ({
|
|
|
255
218
|
// "no sourcemap is better than wrong sourcemap"
|
|
256
219
|
urlInfo.sourcemapIsWrong = urlInfo.sourcemapIsWrong || sourcemapIsWrong;
|
|
257
220
|
}
|
|
221
|
+
if (contentModified && urlInfo.contentFinalized) {
|
|
222
|
+
applyContentEffects(urlInfo);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const applyContentEffects = (urlInfo) => {
|
|
227
|
+
applySourcemapOnContent(urlInfo);
|
|
228
|
+
writeInsideOutDirectory(urlInfo);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const writeInsideOutDirectory = (urlInfo) => {
|
|
232
|
+
// writing result inside ".jsenv" directory (debug purposes)
|
|
233
|
+
if (!outDirectoryUrl) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const { generatedUrl } = urlInfo;
|
|
237
|
+
if (!generatedUrl) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (!generatedUrl.startsWith("file:")) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (urlInfo.type === "directory") {
|
|
244
|
+
// no need to write the directory
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
// if (urlInfo.content === undefined) {
|
|
248
|
+
// // Some error might lead to urlInfo.content to be null
|
|
249
|
+
// // (error hapenning before urlInfo.content can be set, or 404 for instance)
|
|
250
|
+
// // in that case we can't write anything
|
|
251
|
+
// return;
|
|
252
|
+
// }
|
|
258
253
|
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
let contentIsInlined = urlInfo.isInline;
|
|
255
|
+
if (
|
|
256
|
+
contentIsInlined &&
|
|
257
|
+
supervisor &&
|
|
258
|
+
urlInfo.graph.getUrlInfo(urlInfo.inlineUrlSite.url).type === "html"
|
|
259
|
+
) {
|
|
260
|
+
contentIsInlined = false;
|
|
261
|
+
}
|
|
262
|
+
if (!contentIsInlined) {
|
|
263
|
+
writeFileSync(new URL(generatedUrl), urlInfo.content);
|
|
264
|
+
}
|
|
265
|
+
const { sourcemapGeneratedUrl, sourcemap } = urlInfo;
|
|
266
|
+
if (sourcemapGeneratedUrl && sourcemap) {
|
|
267
|
+
writeFileSync(
|
|
268
|
+
new URL(sourcemapGeneratedUrl),
|
|
269
|
+
JSON.stringify(sourcemap, null, " "),
|
|
270
|
+
);
|
|
261
271
|
}
|
|
262
272
|
};
|
|
263
273
|
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
274
|
+
const applySourcemapOnContent = (urlInfo) => {
|
|
275
|
+
if (!sourcemapsEnabled) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!urlInfo.sourcemap) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
if (urlInfo.generatedUrl.startsWith("data:")) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// during build this function can be called after the file is cooked
|
|
286
|
+
// - to update content and sourcemap after "optimize" hook
|
|
287
|
+
// - to inject versioning into the entry point content
|
|
288
|
+
// in this scenarion we don't want to inject sourcemap reference
|
|
289
|
+
// just update the content
|
|
290
|
+
|
|
291
|
+
let sourcemapReference = null;
|
|
292
|
+
for (const referenceToOther of urlInfo.referenceToOthersSet) {
|
|
293
|
+
if (referenceToOther.type === "sourcemap_comment") {
|
|
294
|
+
sourcemapReference = referenceToOther;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (!sourcemapReference) {
|
|
299
|
+
sourcemapReference = urlInfo.dependencies.inject({
|
|
300
|
+
trace: {
|
|
301
|
+
message: `sourcemap comment placeholder`,
|
|
302
|
+
url: urlInfo.url,
|
|
303
|
+
},
|
|
304
|
+
type: "sourcemap_comment",
|
|
305
|
+
subtype: urlInfo.contentType === "text/javascript" ? "js" : "css",
|
|
306
|
+
expectedType: "sourcemap",
|
|
307
|
+
specifier: urlInfo.sourcemapGeneratedUrl,
|
|
308
|
+
isInline: sourcemaps === "inline",
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
const sourcemapUrlInfo = sourcemapReference.urlInfo;
|
|
312
|
+
|
|
313
|
+
const sourcemap = urlInfo.sourcemap;
|
|
314
|
+
if (sourcemapsSourcesRelative) {
|
|
315
|
+
sourcemap.sources = sourcemap.sources.map((source) => {
|
|
316
|
+
const sourceRelative = urlToRelativeUrl(source, urlInfo.url);
|
|
317
|
+
return sourceRelative || ".";
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
if (sourcemapsSourcesProtocol !== "file:///") {
|
|
321
|
+
sourcemap.sources = sourcemap.sources.map((source) => {
|
|
322
|
+
if (source.startsWith("file:///")) {
|
|
323
|
+
return `${sourcemapsSourcesProtocol}${source.slice(
|
|
324
|
+
"file:///".length,
|
|
325
|
+
)}`;
|
|
313
326
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
327
|
+
return source;
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
sourcemapUrlInfo.contentType = "application/json";
|
|
331
|
+
sourcemapUrlInfo.content = JSON.stringify(sourcemap, null, " ");
|
|
332
|
+
|
|
333
|
+
if (!urlInfo.sourcemapIsWrong) {
|
|
334
|
+
if (sourcemaps === "inline") {
|
|
335
|
+
sourcemapReference.generatedSpecifier =
|
|
336
|
+
generateSourcemapDataUrl(sourcemap);
|
|
337
|
+
}
|
|
338
|
+
if (sourcemaps === "file" || sourcemaps === "inline") {
|
|
339
|
+
urlInfo.content = SOURCEMAP.writeComment({
|
|
340
|
+
contentType: urlInfo.contentType,
|
|
341
|
+
content: urlInfo.content,
|
|
342
|
+
specifier:
|
|
343
|
+
sourcemaps === "file" && sourcemapsSourcesRelative
|
|
344
|
+
? urlToRelativeUrl(sourcemapReference.url, urlInfo.url)
|
|
345
|
+
: sourcemapReference.generatedSpecifier,
|
|
346
|
+
});
|
|
317
347
|
}
|
|
318
348
|
}
|
|
319
349
|
};
|
|
320
350
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
351
|
+
const endTransformations = (urlInfo, transformations) => {
|
|
352
|
+
if (transformations) {
|
|
353
|
+
applyTransformations(urlInfo, transformations);
|
|
354
|
+
}
|
|
355
|
+
applyContentEffects(urlInfo);
|
|
356
|
+
urlInfo.contentFinalized = true;
|
|
325
357
|
};
|
|
326
|
-
};
|
|
327
358
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
writable: true,
|
|
334
|
-
value,
|
|
335
|
-
});
|
|
359
|
+
return {
|
|
360
|
+
resetContent,
|
|
361
|
+
setContent,
|
|
362
|
+
applyTransformations,
|
|
363
|
+
endTransformations,
|
|
336
364
|
};
|
|
337
|
-
|
|
338
|
-
Object.defineProperty(object, property, {
|
|
339
|
-
enumerable: true,
|
|
340
|
-
configurable: true,
|
|
341
|
-
get: () => {
|
|
342
|
-
const value = getter();
|
|
343
|
-
restore(value);
|
|
344
|
-
return value;
|
|
345
|
-
},
|
|
346
|
-
set: restore,
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
const getContentAst = (content, type, url) => {
|
|
351
|
-
if (type === "js_module") {
|
|
352
|
-
return parseJsWithAcorn({
|
|
353
|
-
js: content,
|
|
354
|
-
url,
|
|
355
|
-
isJsModule: true,
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
if (type === "js_classic") {
|
|
359
|
-
return parseJsWithAcorn({
|
|
360
|
-
js: content,
|
|
361
|
-
url,
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
return null;
|
|
365
|
-
};
|
|
366
|
-
|
|
367
|
-
const getContentEtag = (content) => {
|
|
368
|
-
return bufferToEtag(Buffer.from(content));
|
|
369
365
|
};
|
|
@@ -34,6 +34,7 @@ const reloader = {
|
|
|
34
34
|
value: [],
|
|
35
35
|
onchange: () => {},
|
|
36
36
|
add: (reloadMessage) => {
|
|
37
|
+
// console.debug("received reload message", reloadMessage);
|
|
37
38
|
reloader.changes.value.push(reloadMessage);
|
|
38
39
|
reloader.changes.onchange();
|
|
39
40
|
if (reloader.autoreload.enabled) {
|
|
@@ -37,14 +37,14 @@ export const getDOMNodesUsingUrl = (urlToReload) => {
|
|
|
37
37
|
Array.from(node.attributes).forEach((attribute) => {
|
|
38
38
|
copy.setAttribute(attribute.nodeName, attribute.nodeValue);
|
|
39
39
|
});
|
|
40
|
-
copy.src = injectQuery(node.src, {
|
|
40
|
+
copy.src = injectQuery(node.src, { hot: Date.now() });
|
|
41
41
|
if (node.parentNode) {
|
|
42
42
|
node.parentNode.replaceChild(copy, node);
|
|
43
43
|
} else {
|
|
44
44
|
document.body.appendChild(copy);
|
|
45
45
|
}
|
|
46
46
|
} else {
|
|
47
|
-
node[attributeName] = injectQuery(attribute, {
|
|
47
|
+
node[attributeName] = injectQuery(attribute, { hot: Date.now() });
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
});
|
|
@@ -92,7 +92,7 @@ export const getDOMNodesUsingUrl = (urlToReload) => {
|
|
|
92
92
|
srcCandidates.forEach((srcCandidate) => {
|
|
93
93
|
const url = new URL(srcCandidate.specifier, `${window.location.href}`);
|
|
94
94
|
if (shouldReloadUrl(url)) {
|
|
95
|
-
srcCandidate.specifier = injectQuery(url, {
|
|
95
|
+
srcCandidate.specifier = injectQuery(url, { hot: Date.now() });
|
|
96
96
|
}
|
|
97
97
|
});
|
|
98
98
|
nodes.push({
|
|
@@ -118,8 +118,8 @@ export const getDOMNodesUsingUrl = (urlToReload) => {
|
|
|
118
118
|
};
|
|
119
119
|
|
|
120
120
|
export const reloadJsImport = async (url) => {
|
|
121
|
-
const
|
|
122
|
-
const namespace = await import(
|
|
121
|
+
const urlWithHotSearchParam = injectQuery(url, { hot: Date.now() });
|
|
122
|
+
const namespace = await import(urlWithHotSearchParam);
|
|
123
123
|
return namespace;
|
|
124
124
|
};
|
|
125
125
|
|
|
@@ -127,7 +127,7 @@ export const reloadAllCss = () => {
|
|
|
127
127
|
const links = Array.from(document.getElementsByTagName("link"));
|
|
128
128
|
links.forEach((link) => {
|
|
129
129
|
if (link.rel === "stylesheet") {
|
|
130
|
-
link.href = injectQuery(link.href, {
|
|
130
|
+
link.href = injectQuery(link.href, { hot: Date.now() });
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
133
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsenvPluginHotSearchParam } from "./jsenv_plugin_hot_search_param.js";
|
|
2
2
|
import { jsenvPluginAutoreloadClient } from "./jsenv_plugin_autoreload_client.js";
|
|
3
3
|
import { jsenvPluginAutoreloadServer } from "./jsenv_plugin_autoreload_server.js";
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ export const jsenvPluginAutoreload = ({
|
|
|
7
7
|
clientFilesPruneCallbackList,
|
|
8
8
|
}) => {
|
|
9
9
|
return [
|
|
10
|
-
|
|
10
|
+
jsenvPluginHotSearchParam(),
|
|
11
11
|
jsenvPluginAutoreloadClient(),
|
|
12
12
|
jsenvPluginAutoreloadServer({
|
|
13
13
|
clientFileChangeCallbackList,
|
|
@@ -15,9 +15,9 @@ export const jsenvPluginAutoreloadClient = () => {
|
|
|
15
15
|
name: "jsenv:autoreload_client",
|
|
16
16
|
appliesDuring: "dev",
|
|
17
17
|
transformUrlContent: {
|
|
18
|
-
html: (htmlUrlInfo
|
|
18
|
+
html: (htmlUrlInfo) => {
|
|
19
19
|
const htmlAst = parseHtmlString(htmlUrlInfo.content);
|
|
20
|
-
const
|
|
20
|
+
const autoreloadClientReference = htmlUrlInfo.dependencies.inject({
|
|
21
21
|
type: "script",
|
|
22
22
|
subtype: "js_module",
|
|
23
23
|
expectedType: "js_module",
|