@jsenv/core 24.6.5 → 25.0.0-alpha.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/browser_runtime/asset-manifest.json +2 -1
- package/dist/browser_runtime/{browser_runtime-bb0e3aa4.js → browser_runtime_a8097085.js} +1 -1
- package/dist/browser_runtime/{browser_runtime-bb0e3aa4.js.map → browser_runtime_a8097085.js.map} +1 -1
- package/dist/build_manifest.js +6 -6
- package/dist/compile_proxy/asset-manifest.json +2 -1
- package/dist/compile_proxy/{compile_proxy-6eb67db4.html → compile_proxy_e16d7de8.html} +2 -2
- package/dist/compile_proxy/{compile_proxy.html__inline__20-9e168143.js.map → compile_proxy_e3b0c442_9e168143.js.map} +0 -0
- package/dist/event_source_client/asset-manifest.json +2 -1
- package/dist/event_source_client/{event_source_client-9f14c8b9.js → event_source_client_620fbc2c.js} +1 -1
- package/dist/event_source_client/{event_source_client-9f14c8b9.js.map → event_source_client_620fbc2c.js.map} +1 -1
- package/dist/redirector/asset-manifest.json +2 -1
- package/dist/redirector/{redirector-b6ad84bf.html → redirector_2e0c8abe.html} +2 -2
- package/dist/redirector/{redirector.html__inline__15-3a34a156.js.map → redirector_e3b0c442_3a34a156.js.map} +0 -0
- package/dist/toolbar/asset-manifest.json +11 -10
- package/dist/toolbar/assets/{compilation.css-209d68b4.map → compilation.css_e37c747b.map} +1 -1
- package/dist/toolbar/assets/{eventsource.css-38cd0a36.map → eventsource.css_c0c71e7b.map} +1 -1
- package/dist/toolbar/assets/{execution.css-0ebe522f.map → execution.css_f3377c10.map} +1 -1
- package/dist/toolbar/assets/{focus.css-3f9c156d.map → focus.css_896f3e45.map} +1 -1
- package/dist/toolbar/assets/{light-theme.css-78b19a80.map → light-theme.css_72a60fa3.map} +1 -1
- package/dist/toolbar/assets/{overflow-menu.css-d9688a1c.map → overflow-menu.css_2859d519.map} +1 -1
- package/dist/toolbar/assets/{settings.css-2b81b245.map → settings.css_61548139.map} +1 -1
- package/dist/toolbar/assets/{toolbar.main.css-846920e9.map → toolbar.main.css_269d7ce2.map} +9 -9
- package/dist/toolbar/assets/{tooltip.css-03395ee6.map → tooltip.css_a94a8bdd.map} +1 -1
- package/dist/toolbar/{toolbar.main-a5ef2c60.js.map → toolbar.main_a5ef2c60.js.map} +0 -0
- package/dist/toolbar/{toolbar-1fbf8dcb.html → toolbar_412abb83.html} +3 -5
- package/dist/toolbar_injector/asset-manifest.json +3 -2
- package/dist/toolbar_injector/assets/{jsenv-logo-188b9ca6.svg → jsenv-logo_188b9ca6.svg} +0 -0
- package/dist/toolbar_injector/{toolbar_injector-997dbaa0.js → toolbar_injector_4f9c19e5.js} +3 -3
- package/dist/toolbar_injector/{toolbar_injector-997dbaa0.js.map → toolbar_injector_4f9c19e5.js.map} +2 -2
- package/package.json +1 -1
- package/readme.md +2 -2
- package/src/buildProject.js +18 -16
- package/src/internal/building/buildUsingRollup.js +9 -7
- package/src/internal/building/build_logs.js +2 -2
- package/src/internal/building/build_stats.js +11 -1
- package/src/internal/building/html/parseHtmlRessource.js +2 -26
- package/src/internal/building/js/parseJsRessource.js +3 -2
- package/src/internal/building/json_module.js +11 -0
- package/src/internal/building/parseRessource.js +1 -1
- package/src/internal/building/ressource_builder.js +216 -215
- package/src/internal/building/rollup_plugin_jsenv.js +462 -306
- package/src/internal/building/url_loader.js +8 -145
- package/src/internal/building/url_versioning.js +226 -0
- package/src/internal/compiling/compileHtml.js +8 -1
- package/src/jsenvServiceWorkerFinalizer.js +7 -8
- package/src/internal/building/asset_url_versioning.js +0 -50
- package/src/internal/building/rollup_build_sourcemap.js +0 -54
- package/src/internal/building/url-versioning.js +0 -96
- package/src/internal/renderNamePattern.js +0 -6
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveUrl,
|
|
3
|
-
urlToRelativeUrl,
|
|
4
|
-
urlIsInsideOf,
|
|
5
|
-
urlToParentUrl,
|
|
6
|
-
urlToFilename,
|
|
7
|
-
} from "@jsenv/filesystem"
|
|
1
|
+
import { resolveUrl, urlToRelativeUrl, urlIsInsideOf } from "@jsenv/filesystem"
|
|
8
2
|
import { createLogger, loggerToLevels } from "@jsenv/logger"
|
|
9
3
|
|
|
10
4
|
import { setJavaScriptSourceMappingUrl } from "@jsenv/core/src/internal/sourceMappingURLUtils.js"
|
|
5
|
+
|
|
11
6
|
import { racePromises } from "../promise_race.js"
|
|
12
7
|
import { parseDataUrl } from "../dataUrl.utils.js"
|
|
13
|
-
|
|
14
8
|
import {
|
|
15
9
|
getRessourceAsBase64Url,
|
|
16
10
|
memoize,
|
|
@@ -19,7 +13,6 @@ import {
|
|
|
19
13
|
// formatDependenciesCollectedMessage,
|
|
20
14
|
checkContentType,
|
|
21
15
|
} from "./ressource_builder_util.js"
|
|
22
|
-
import { computeBuildRelativeUrlForRessource } from "./asset_url_versioning.js"
|
|
23
16
|
import { stringifyUrlSite } from "./url_trace.js"
|
|
24
17
|
|
|
25
18
|
export const createRessourceBuilder = (
|
|
@@ -33,11 +26,11 @@ export const createRessourceBuilder = (
|
|
|
33
26
|
asOriginalServerUrl,
|
|
34
27
|
urlToHumanUrl,
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
onAsset,
|
|
30
|
+
onAssetSourceUpdated,
|
|
38
31
|
onJsModule,
|
|
39
32
|
resolveRessourceUrl,
|
|
40
|
-
|
|
33
|
+
urlVersioner,
|
|
41
34
|
},
|
|
42
35
|
) => {
|
|
43
36
|
const logger = createLogger({ logLevel })
|
|
@@ -46,10 +39,8 @@ export const createRessourceBuilder = (
|
|
|
46
39
|
entryContentType,
|
|
47
40
|
entryUrl,
|
|
48
41
|
entryBuffer,
|
|
49
|
-
entryBuildRelativeUrl,
|
|
50
|
-
urlVersionningForEntryPoints,
|
|
51
42
|
}) => {
|
|
52
|
-
// The entry point is conceptually referenced by code passing "
|
|
43
|
+
// The entry point is conceptually referenced by code passing "entryPoints"
|
|
53
44
|
// to buildProject. So we analyse stack trace to put this function caller
|
|
54
45
|
// as the reference to this ressource file
|
|
55
46
|
// we store this info in reference.isProgrammatic
|
|
@@ -63,18 +54,16 @@ export const createRessourceBuilder = (
|
|
|
63
54
|
|
|
64
55
|
contentType: entryContentType,
|
|
65
56
|
bufferBeforeBuild: entryBuffer,
|
|
57
|
+
isJsModule: entryContentType === "application/javascript",
|
|
66
58
|
|
|
67
59
|
isEntryPoint: true,
|
|
68
|
-
|
|
69
|
-
// don't hash asset entry points
|
|
70
|
-
...(urlVersionningForEntryPoints
|
|
71
|
-
? {}
|
|
72
|
-
: {
|
|
73
|
-
urlVersioningDisabled: true,
|
|
74
|
-
fileNamePattern: entryBuildRelativeUrl,
|
|
75
|
-
}),
|
|
76
60
|
})
|
|
77
61
|
entryReference.isProgrammatic = true
|
|
62
|
+
if (entryReference.ressource.isJsModule) {
|
|
63
|
+
// no need to call getDependenciesAvailablePromise and so on
|
|
64
|
+
// rollup is handling js entries
|
|
65
|
+
return
|
|
66
|
+
}
|
|
78
67
|
|
|
79
68
|
await entryReference.ressource.getDependenciesAvailablePromise()
|
|
80
69
|
|
|
@@ -119,7 +108,7 @@ export const createRessourceBuilder = (
|
|
|
119
108
|
})
|
|
120
109
|
}
|
|
121
110
|
|
|
122
|
-
const createReferenceFoundInJsModule =
|
|
111
|
+
const createReferenceFoundInJsModule = ({
|
|
123
112
|
referenceLabel,
|
|
124
113
|
jsUrl,
|
|
125
114
|
jsLine,
|
|
@@ -143,10 +132,6 @@ export const createRessourceBuilder = (
|
|
|
143
132
|
contentType,
|
|
144
133
|
bufferBeforeBuild,
|
|
145
134
|
})
|
|
146
|
-
if (!reference) {
|
|
147
|
-
return null
|
|
148
|
-
}
|
|
149
|
-
await reference.ressource.getReadyPromise()
|
|
150
135
|
return reference
|
|
151
136
|
}
|
|
152
137
|
|
|
@@ -154,19 +139,40 @@ export const createRessourceBuilder = (
|
|
|
154
139
|
const urlToWait = Object.keys(ressourceMap).filter(
|
|
155
140
|
(url) => ressourceMap[url].isEntryPoint,
|
|
156
141
|
)
|
|
157
|
-
|
|
142
|
+
await Promise.all(
|
|
158
143
|
urlToWait.map(async (url) => {
|
|
159
144
|
const ressource = ressourceMap[url]
|
|
160
145
|
await ressource.getReadyPromise()
|
|
161
146
|
return ressource
|
|
162
147
|
}),
|
|
163
148
|
)
|
|
149
|
+
|
|
150
|
+
// compute all asset fileName
|
|
151
|
+
Object.keys(ressourceMap).forEach((key) => {
|
|
152
|
+
const ressource = ressourceMap[key]
|
|
153
|
+
if (ressource.isExternal || ressource.isJsModule || ressource.fileName) {
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
if (ressource.isPlaceholder && !ressource.buildRelativeUrl) {
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
if (!ressource.buildRelativeUrl) {
|
|
160
|
+
if (ressource.isPlaceholder) {
|
|
161
|
+
// placeholder not filled, that's ok
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
if (ressource.references.every((ref) => ref.isRessourceHint)) {
|
|
165
|
+
// ressource hint never used, the ressource can be ignored
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
ressource.fileName = asFileNameWithoutHash(ressource.buildRelativeUrl)
|
|
170
|
+
})
|
|
164
171
|
}
|
|
165
172
|
|
|
166
173
|
const ressourceMap = {}
|
|
167
174
|
const ressourceRedirectionMap = {}
|
|
168
175
|
const createReference = ({
|
|
169
|
-
referenceShouldNotEmitChunk,
|
|
170
176
|
isRessourceHint,
|
|
171
177
|
isImportAssertion,
|
|
172
178
|
contentTypeExpected,
|
|
@@ -183,32 +189,34 @@ export const createRessourceBuilder = (
|
|
|
183
189
|
isSourcemap,
|
|
184
190
|
isInline,
|
|
185
191
|
isPlaceholder,
|
|
186
|
-
|
|
192
|
+
|
|
187
193
|
urlVersioningDisabled,
|
|
188
194
|
|
|
189
195
|
fromRollup,
|
|
190
196
|
}) => {
|
|
191
|
-
const existingRessourceForReference = findRessourceByUrl(referenceUrl)
|
|
192
197
|
let ressourceImporter
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
// happens only for entry points?
|
|
202
|
-
// in that case the importer is theoric
|
|
203
|
-
// see "getCallerLocation()" in createReferenceForEntryPoint
|
|
204
|
-
ressourceImporter = {
|
|
205
|
-
url: referenceUrl,
|
|
206
|
-
isEntryPoint: false,
|
|
207
|
-
isJsModule: true,
|
|
208
|
-
bufferAfterBuild: "",
|
|
198
|
+
if (referenceUrl) {
|
|
199
|
+
const existingRessourceForReference = findRessourceByUrl(referenceUrl)
|
|
200
|
+
if (existingRessourceForReference) {
|
|
201
|
+
ressourceImporter = existingRessourceForReference
|
|
202
|
+
} else {
|
|
203
|
+
const referenceOriginalUrl = asOriginalServerUrl(referenceUrl)
|
|
204
|
+
if (referenceOriginalUrl) {
|
|
205
|
+
ressourceImporter = findRessourceByUrl(referenceOriginalUrl)
|
|
209
206
|
}
|
|
210
207
|
}
|
|
211
208
|
}
|
|
209
|
+
if (!ressourceImporter) {
|
|
210
|
+
// happens only for entry points?
|
|
211
|
+
// in that case the importer is theoric
|
|
212
|
+
// see "getCallerLocation()" in createReferenceForEntryPoint
|
|
213
|
+
ressourceImporter = {
|
|
214
|
+
url: referenceUrl,
|
|
215
|
+
isEntryPoint: false,
|
|
216
|
+
isJsModule: true,
|
|
217
|
+
bufferAfterBuild: "",
|
|
218
|
+
}
|
|
219
|
+
}
|
|
212
220
|
|
|
213
221
|
const shouldBeIgnoredWarning = referenceShouldBeIgnoredWarning({
|
|
214
222
|
isJsModule,
|
|
@@ -244,6 +252,9 @@ export const createRessourceBuilder = (
|
|
|
244
252
|
if (ressourceUrlResolution.isServiceWorker) {
|
|
245
253
|
isServiceWorker = true
|
|
246
254
|
}
|
|
255
|
+
if (ressourceUrlResolution.isJsModule) {
|
|
256
|
+
isJsModule = true
|
|
257
|
+
}
|
|
247
258
|
ressourceUrl = ressourceUrlResolution.url
|
|
248
259
|
} else {
|
|
249
260
|
ressourceUrl = ressourceUrlResolution
|
|
@@ -263,23 +274,6 @@ export const createRessourceBuilder = (
|
|
|
263
274
|
// any hash in the url would mess up with filenames
|
|
264
275
|
ressourceUrl = removePotentialUrlHash(ressourceUrl)
|
|
265
276
|
|
|
266
|
-
if (isInline && fileNamePattern === undefined) {
|
|
267
|
-
// inherit parent directory location because it's an inline file
|
|
268
|
-
fileNamePattern = () => {
|
|
269
|
-
const importerBuildRelativeUrl = precomputeBuildRelativeUrlForRessource(
|
|
270
|
-
ressourceImporter,
|
|
271
|
-
{
|
|
272
|
-
lineBreakNormalization,
|
|
273
|
-
},
|
|
274
|
-
)
|
|
275
|
-
const importerParentRelativeUrl = urlToRelativeUrl(
|
|
276
|
-
urlToParentUrl(resolveUrl(importerBuildRelativeUrl, "file://")),
|
|
277
|
-
"file://",
|
|
278
|
-
)
|
|
279
|
-
return `${importerParentRelativeUrl}[name]-[hash][extname]`
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
277
|
const existingRessource = findRessourceByUrl(ressourceUrl)
|
|
284
278
|
let ressource
|
|
285
279
|
if (existingRessource) {
|
|
@@ -295,6 +289,7 @@ export const createRessourceBuilder = (
|
|
|
295
289
|
ressource = createRessource({
|
|
296
290
|
contentType,
|
|
297
291
|
ressourceUrl,
|
|
292
|
+
ressourceImporter,
|
|
298
293
|
bufferBeforeBuild,
|
|
299
294
|
|
|
300
295
|
isEntryPoint,
|
|
@@ -305,14 +300,14 @@ export const createRessourceBuilder = (
|
|
|
305
300
|
isPlaceholder,
|
|
306
301
|
isWorker,
|
|
307
302
|
isServiceWorker,
|
|
308
|
-
|
|
303
|
+
|
|
309
304
|
urlVersioningDisabled,
|
|
310
305
|
})
|
|
311
306
|
ressourceMap[ressourceUrl] = ressource
|
|
312
307
|
}
|
|
313
308
|
|
|
314
309
|
const reference = {
|
|
315
|
-
|
|
310
|
+
fromRollup,
|
|
316
311
|
isRessourceHint,
|
|
317
312
|
isImportAssertion,
|
|
318
313
|
contentTypeExpected,
|
|
@@ -335,26 +330,33 @@ export const createRessourceBuilder = (
|
|
|
335
330
|
}
|
|
336
331
|
|
|
337
332
|
reference.ressource = ressource
|
|
338
|
-
if (fromRollup
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
referenceEffects: effects,
|
|
351
|
-
showReferenceSourceLocation,
|
|
352
|
-
shortenUrl,
|
|
353
|
-
}),
|
|
354
|
-
)
|
|
333
|
+
if (fromRollup) {
|
|
334
|
+
if (ressourceImporter.isEntryPoint) {
|
|
335
|
+
// When HTML references JS, ressource builder has emitted the js chunk.
|
|
336
|
+
// so it already knows it exists and is part of references
|
|
337
|
+
// -> no need to push into reference (would incorrectly consider html references js twice)
|
|
338
|
+
// -> no need to log the js ressource (already logged during the HTML parsing)
|
|
339
|
+
return reference
|
|
340
|
+
}
|
|
341
|
+
if (ressource.isEntryPoint) {
|
|
342
|
+
// When rollup "loads" a js entry point, ressource builder is already aware of it
|
|
343
|
+
// because of "createReferenceForEntryPoint"
|
|
344
|
+
return reference
|
|
355
345
|
}
|
|
356
346
|
}
|
|
357
347
|
|
|
348
|
+
ressource.references.push(reference)
|
|
349
|
+
const effects = ressource.applyReferenceEffects(reference, { isJsModule })
|
|
350
|
+
if (loggerToLevels(logger).debug) {
|
|
351
|
+
logger.debug(
|
|
352
|
+
formatFoundReference({
|
|
353
|
+
reference,
|
|
354
|
+
referenceEffects: effects,
|
|
355
|
+
showReferenceSourceLocation,
|
|
356
|
+
shortenUrl,
|
|
357
|
+
}),
|
|
358
|
+
)
|
|
359
|
+
}
|
|
358
360
|
return reference
|
|
359
361
|
}
|
|
360
362
|
|
|
@@ -363,6 +365,7 @@ export const createRessourceBuilder = (
|
|
|
363
365
|
const createRessource = ({
|
|
364
366
|
contentType,
|
|
365
367
|
ressourceUrl,
|
|
368
|
+
ressourceImporter,
|
|
366
369
|
bufferBeforeBuild,
|
|
367
370
|
|
|
368
371
|
isEntryPoint = false,
|
|
@@ -374,13 +377,14 @@ export const createRessourceBuilder = (
|
|
|
374
377
|
isWorker = false,
|
|
375
378
|
isServiceWorker = false,
|
|
376
379
|
|
|
377
|
-
|
|
378
|
-
urlVersioningDisabled = isServiceWorker,
|
|
380
|
+
urlVersioningDisabled,
|
|
379
381
|
}) => {
|
|
380
382
|
const ressource = {
|
|
381
383
|
contentType,
|
|
382
384
|
url: ressourceUrl,
|
|
385
|
+
importer: ressourceImporter,
|
|
383
386
|
bufferBeforeBuild,
|
|
387
|
+
bufferAfterBuild: undefined,
|
|
384
388
|
firstStrongReference: null,
|
|
385
389
|
references: [],
|
|
386
390
|
|
|
@@ -394,10 +398,10 @@ export const createRessourceBuilder = (
|
|
|
394
398
|
isServiceWorker,
|
|
395
399
|
|
|
396
400
|
urlVersioningDisabled,
|
|
397
|
-
fileNamePattern,
|
|
398
401
|
|
|
399
|
-
relativeUrl:
|
|
400
|
-
|
|
402
|
+
relativeUrl: ressourceUrl.startsWith(compileServerOrigin)
|
|
403
|
+
? urlToRelativeUrl(ressourceUrl, compileServerOrigin)
|
|
404
|
+
: urlToRelativeUrl(ressourceUrl, buildDirectoryUrl),
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
ressource.usedPromise = new Promise((resolve) => {
|
|
@@ -494,7 +498,6 @@ export const createRessourceBuilder = (
|
|
|
494
498
|
isSourcemap = false,
|
|
495
499
|
isPlaceholder = false,
|
|
496
500
|
urlVersioningDisabled,
|
|
497
|
-
fileNamePattern,
|
|
498
501
|
}) => {
|
|
499
502
|
if (parsingDone) {
|
|
500
503
|
throw new Error(
|
|
@@ -519,7 +522,6 @@ export const createRessourceBuilder = (
|
|
|
519
522
|
isPlaceholder,
|
|
520
523
|
|
|
521
524
|
urlVersioningDisabled,
|
|
522
|
-
fileNamePattern,
|
|
523
525
|
})
|
|
524
526
|
|
|
525
527
|
if (dependencyReference) {
|
|
@@ -567,6 +569,10 @@ export const createRessourceBuilder = (
|
|
|
567
569
|
if (dependencyRessource.isPlaceholder) {
|
|
568
570
|
return
|
|
569
571
|
}
|
|
572
|
+
// don't keep waiting for ever in case ressource hint is never used
|
|
573
|
+
if (dependencyReference.isRessourceHint) {
|
|
574
|
+
return
|
|
575
|
+
}
|
|
570
576
|
await dependencyRessource.getReadyPromise()
|
|
571
577
|
}),
|
|
572
578
|
)
|
|
@@ -597,18 +603,12 @@ export const createRessourceBuilder = (
|
|
|
597
603
|
// }
|
|
598
604
|
// we don't yet know the exact importerBuildRelativeUrl but we can generate a fake one
|
|
599
605
|
// to ensure we resolve dependency against where the importer file will be
|
|
600
|
-
const importerBuildRelativeUrl =
|
|
601
|
-
ressource
|
|
602
|
-
{
|
|
603
|
-
lineBreakNormalization,
|
|
604
|
-
},
|
|
605
|
-
)
|
|
606
|
+
const importerBuildRelativeUrl =
|
|
607
|
+
urlVersioner.precomputeBuildRelativeUrl(ressource)
|
|
606
608
|
await transform({
|
|
607
609
|
buildDirectoryUrl,
|
|
608
610
|
precomputeBuildRelativeUrl: (ressource) =>
|
|
609
|
-
|
|
610
|
-
lineBreakNormalization,
|
|
611
|
-
}),
|
|
611
|
+
urlVersioner.precomputeBuildRelativeUrl(ressource),
|
|
612
612
|
getUrlRelativeToImporter: (referencedRessource) => {
|
|
613
613
|
const ressourceImporter = ressource
|
|
614
614
|
|
|
@@ -657,12 +657,8 @@ export const createRessourceBuilder = (
|
|
|
657
657
|
if (bufferAfterBuild !== undefined) {
|
|
658
658
|
ressource.bufferAfterBuild = bufferAfterBuild
|
|
659
659
|
if (buildRelativeUrl === undefined) {
|
|
660
|
-
ressource.buildRelativeUrl =
|
|
661
|
-
ressource
|
|
662
|
-
{
|
|
663
|
-
lineBreakNormalization,
|
|
664
|
-
},
|
|
665
|
-
)
|
|
660
|
+
ressource.buildRelativeUrl =
|
|
661
|
+
urlVersioner.computeBuildRelativeUrl(ressource)
|
|
666
662
|
}
|
|
667
663
|
}
|
|
668
664
|
|
|
@@ -677,7 +673,7 @@ export const createRessourceBuilder = (
|
|
|
677
673
|
!ressource.isInline &&
|
|
678
674
|
!ressource.isJsModule
|
|
679
675
|
) {
|
|
680
|
-
|
|
676
|
+
onAssetSourceUpdated({ ressource })
|
|
681
677
|
}
|
|
682
678
|
}
|
|
683
679
|
|
|
@@ -730,10 +726,6 @@ export const createRessourceBuilder = (
|
|
|
730
726
|
}
|
|
731
727
|
|
|
732
728
|
if (ressource.isJsModule) {
|
|
733
|
-
if (!isEmitChunkNeeded({ ressource, reference })) {
|
|
734
|
-
return effects
|
|
735
|
-
}
|
|
736
|
-
|
|
737
729
|
const jsModuleUrl = ressource.url
|
|
738
730
|
const rollupChunk = onJsModule({
|
|
739
731
|
ressource,
|
|
@@ -743,10 +735,12 @@ export const createRessourceBuilder = (
|
|
|
743
735
|
line: reference.referenceLine,
|
|
744
736
|
column: reference.referenceColumn,
|
|
745
737
|
})
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
738
|
+
if (rollupChunk) {
|
|
739
|
+
ressource.rollupReferenceId = rollupChunk.rollupReferenceId
|
|
740
|
+
effects.push(
|
|
741
|
+
`emit rollup chunk "${rollupChunk.fileName}" (${rollupChunk.rollupReferenceId})`,
|
|
742
|
+
)
|
|
743
|
+
}
|
|
750
744
|
return effects
|
|
751
745
|
}
|
|
752
746
|
|
|
@@ -755,12 +749,12 @@ export const createRessourceBuilder = (
|
|
|
755
749
|
return effects
|
|
756
750
|
}
|
|
757
751
|
|
|
758
|
-
const
|
|
759
|
-
|
|
752
|
+
const rollupAsset = onAsset({
|
|
753
|
+
ressource,
|
|
760
754
|
})
|
|
761
|
-
ressource.rollupReferenceId = rollupReferenceId
|
|
755
|
+
ressource.rollupReferenceId = rollupAsset.rollupReferenceId
|
|
762
756
|
effects.push(
|
|
763
|
-
`emit rollup asset "${
|
|
757
|
+
`emit rollup asset "${rollupAsset.fileName}" (${rollupAsset.rollupReferenceId})`,
|
|
764
758
|
)
|
|
765
759
|
return effects
|
|
766
760
|
}
|
|
@@ -777,82 +771,114 @@ export const createRessourceBuilder = (
|
|
|
777
771
|
return ressource
|
|
778
772
|
}
|
|
779
773
|
|
|
780
|
-
const rollupBuildEnd = ({
|
|
774
|
+
const rollupBuildEnd = ({
|
|
775
|
+
rollupJsFileInfos,
|
|
776
|
+
rollupAssetFileInfos,
|
|
777
|
+
useImportMapToMaximizeCacheReuse,
|
|
778
|
+
}) => {
|
|
779
|
+
const jsRessources = {}
|
|
781
780
|
Object.keys(ressourceMap).forEach((ressourceUrl) => {
|
|
782
781
|
const ressource = ressourceMap[ressourceUrl]
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
const file = jsModuleBuild[buildRelativeUrlCandidate]
|
|
787
|
-
return file.url === ressourceUrl
|
|
788
|
-
},
|
|
789
|
-
)
|
|
790
|
-
const buildFileInfo = jsModuleBuild[buildRelativeUrl]
|
|
791
|
-
applyBuildEndEffects(ressource, { buildFileInfo, buildManifest })
|
|
792
|
-
const { rollupBuildDoneCallbacks } = ressource
|
|
793
|
-
rollupBuildDoneCallbacks.forEach((rollupBuildDoneCallback) => {
|
|
794
|
-
rollupBuildDoneCallback()
|
|
782
|
+
const jsModuleFileName = Object.keys(rollupJsFileInfos).find((key) => {
|
|
783
|
+
const rollupFileInfo = rollupJsFileInfos[key]
|
|
784
|
+
return rollupFileInfo.url === ressourceUrl
|
|
795
785
|
})
|
|
786
|
+
if (jsModuleFileName) {
|
|
787
|
+
const rollupFileInfo = rollupJsFileInfos[jsModuleFileName]
|
|
788
|
+
// We expect to find the ressource in the rollup build except when:
|
|
789
|
+
// - js was only preloaded/prefetched and never referenced afterwards
|
|
790
|
+
// - js was only referenced by other js
|
|
791
|
+
if (!rollupFileInfo) {
|
|
792
|
+
const referencedOnlyByRessourceHint = !ressource.firstStrongReference
|
|
793
|
+
if (referencedOnlyByRessourceHint) {
|
|
794
|
+
return
|
|
795
|
+
}
|
|
796
|
+
const referencedOnlyByRollup = ressource.references.every(
|
|
797
|
+
(ref) => ref.fromRollup,
|
|
798
|
+
)
|
|
799
|
+
if (referencedOnlyByRollup) {
|
|
800
|
+
// concatened by rollup
|
|
801
|
+
return
|
|
802
|
+
}
|
|
803
|
+
throw new Error(
|
|
804
|
+
`${shortenUrl(ressource.url)} cannot be found in the build info`,
|
|
805
|
+
)
|
|
806
|
+
}
|
|
807
|
+
applyBuildEndEffects(ressource, {
|
|
808
|
+
rollupFileInfo,
|
|
809
|
+
rollupAssetFileInfos,
|
|
810
|
+
useImportMapToMaximizeCacheReuse,
|
|
811
|
+
})
|
|
812
|
+
const { rollupBuildDoneCallbacks } = ressource
|
|
813
|
+
rollupBuildDoneCallbacks.forEach((rollupBuildDoneCallback) => {
|
|
814
|
+
rollupBuildDoneCallback()
|
|
815
|
+
})
|
|
816
|
+
jsRessources[ressourceUrl] = ressource
|
|
817
|
+
return
|
|
818
|
+
}
|
|
796
819
|
})
|
|
820
|
+
|
|
821
|
+
return { jsRessources }
|
|
797
822
|
}
|
|
798
823
|
|
|
799
824
|
const applyBuildEndEffects = (
|
|
800
825
|
ressource,
|
|
801
|
-
{
|
|
802
|
-
buildFileInfo,
|
|
803
|
-
// buildManifest
|
|
804
|
-
},
|
|
826
|
+
{ rollupFileInfo, rollupAssetFileInfos, useImportMapToMaximizeCacheReuse },
|
|
805
827
|
) => {
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
// If the module is not in the rollup build, that's an error except when
|
|
812
|
-
// rollup chunk was not emitted, which happens when:
|
|
813
|
-
// - js was only preloaded/prefetched and never referenced afterwards
|
|
814
|
-
// - js was only referenced by other js
|
|
815
|
-
if (!buildFileInfo) {
|
|
816
|
-
const referencedOnlyByRessourceHint = !ressource.firstStrongReference
|
|
817
|
-
if (referencedOnlyByRessourceHint) {
|
|
818
|
-
return
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
const referencedOnlyByOtherJs = ressource.references.every(
|
|
822
|
-
(ref) => ref.referenceShouldNotEmitChunk,
|
|
823
|
-
)
|
|
824
|
-
if (referencedOnlyByOtherJs) {
|
|
825
|
-
return
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
throw new Error(
|
|
829
|
-
`${shortenUrl(ressource.url)} cannot be found in the build info`,
|
|
830
|
-
)
|
|
828
|
+
const fileName = rollupFileInfo.fileName
|
|
829
|
+
let code = rollupFileInfo.code
|
|
830
|
+
if (rollupFileInfo.type === "chunk") {
|
|
831
|
+
ressource.contentType = "application/javascript"
|
|
831
832
|
}
|
|
832
833
|
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
ressource.
|
|
834
|
+
if (useImportMapToMaximizeCacheReuse) {
|
|
835
|
+
ressource.fileName = fileName
|
|
836
|
+
ressource.buildEnd(code)
|
|
837
|
+
} else {
|
|
838
|
+
ressource.fileName = asFileNameWithoutHash(fileName)
|
|
839
|
+
ressource.buildEnd(code, fileName)
|
|
839
840
|
}
|
|
840
|
-
ressource.fileName = fileName
|
|
841
|
-
ressource.buildEnd(
|
|
842
|
-
code,
|
|
843
|
-
// buildRelativeUrl
|
|
844
|
-
)
|
|
845
841
|
|
|
846
|
-
const map =
|
|
842
|
+
const map = rollupFileInfo.map
|
|
847
843
|
if (map) {
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
)
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
844
|
+
const sourcemapBuildRelativeUrl = `${ressource.buildRelativeUrl}.map`
|
|
845
|
+
const sourcemapRollupFileInfo =
|
|
846
|
+
rollupAssetFileInfos[sourcemapBuildRelativeUrl]
|
|
847
|
+
if (!sourcemapRollupFileInfo) {
|
|
848
|
+
const ressourceBuildUrl = resolveUrl(
|
|
849
|
+
ressource.buildRelativeUrl,
|
|
850
|
+
buildDirectoryUrl,
|
|
851
|
+
)
|
|
852
|
+
const sourcemapBuildUrl = resolveUrl(
|
|
853
|
+
sourcemapBuildRelativeUrl,
|
|
854
|
+
buildDirectoryUrl,
|
|
855
|
+
)
|
|
856
|
+
const sourcemapAsString = JSON.stringify(rollupFileInfo.map, null, " ")
|
|
857
|
+
const sourcemapBuildUrlRelativeToFileBuildUrl = urlToRelativeUrl(
|
|
858
|
+
sourcemapBuildUrl,
|
|
859
|
+
ressourceBuildUrl,
|
|
860
|
+
)
|
|
861
|
+
const codeWithSourcemapComment = setJavaScriptSourceMappingUrl(
|
|
862
|
+
rollupFileInfo.code,
|
|
863
|
+
sourcemapBuildUrlRelativeToFileBuildUrl,
|
|
864
|
+
)
|
|
865
|
+
ressource.bufferAfterBuild = codeWithSourcemapComment
|
|
866
|
+
rollupFileInfo.code = codeWithSourcemapComment
|
|
867
|
+
const sourcemapReference = createReference({
|
|
868
|
+
referenceLabel: "js sourcemapping comment",
|
|
869
|
+
contentType: "application/octet-stream",
|
|
870
|
+
ressourceSpecifier: sourcemapBuildUrlRelativeToFileBuildUrl,
|
|
871
|
+
referenceUrl: ressourceBuildUrl,
|
|
872
|
+
referenceLine: codeWithSourcemapComment.split(/\r?\n/).length,
|
|
873
|
+
// ${"//#"} is to avoid a parser thinking there is a sourceMappingUrl for this file
|
|
874
|
+
referenceColumn: `${"//#"} sourceMappingURL=`.length + 1,
|
|
875
|
+
isSourcemap: true,
|
|
876
|
+
})
|
|
877
|
+
sourcemapReference.ressource.buildEnd(
|
|
878
|
+
sourcemapAsString,
|
|
879
|
+
sourcemapBuildUrlRelativeToFileBuildUrl,
|
|
880
|
+
)
|
|
881
|
+
}
|
|
856
882
|
}
|
|
857
883
|
}
|
|
858
884
|
|
|
@@ -906,6 +932,9 @@ export const createRessourceBuilder = (
|
|
|
906
932
|
source: referenceSourceAsString,
|
|
907
933
|
}
|
|
908
934
|
|
|
935
|
+
if (!referenceRessource) {
|
|
936
|
+
return urlSite
|
|
937
|
+
}
|
|
909
938
|
if (!referenceRessource.isInline) {
|
|
910
939
|
return urlSite
|
|
911
940
|
}
|
|
@@ -953,6 +982,12 @@ export const createRessourceBuilder = (
|
|
|
953
982
|
}
|
|
954
983
|
}
|
|
955
984
|
|
|
985
|
+
const asFileNameWithoutHash = (fileName) => {
|
|
986
|
+
return fileName.replace(/_[a-z0-9]{8,}(\..*?)?$/, (_, afterHash = "") => {
|
|
987
|
+
return afterHash
|
|
988
|
+
})
|
|
989
|
+
}
|
|
990
|
+
|
|
956
991
|
// const preredirectUrlFromRessource = (ressource, ressourceRedirectionMap) => {
|
|
957
992
|
// const ressourceUrlPreRedirect = Object.keys(ressourceRedirectionMap).find(
|
|
958
993
|
// (urlPreRedirect) =>
|
|
@@ -961,26 +996,6 @@ export const createRessourceBuilder = (
|
|
|
961
996
|
// return ressourceUrlPreRedirect
|
|
962
997
|
// }
|
|
963
998
|
|
|
964
|
-
const precomputeBuildRelativeUrlForRessource = (
|
|
965
|
-
ressource,
|
|
966
|
-
{ bufferAfterBuild = "", lineBreakNormalization } = {},
|
|
967
|
-
) => {
|
|
968
|
-
if (ressource.buildRelativeUrl) {
|
|
969
|
-
return ressource.buildRelativeUrl
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
ressource.bufferAfterBuild = bufferAfterBuild
|
|
973
|
-
const precomputedBuildRelativeUrl = computeBuildRelativeUrlForRessource(
|
|
974
|
-
ressource,
|
|
975
|
-
{
|
|
976
|
-
lineBreakNormalization,
|
|
977
|
-
contentType: ressource.contentType,
|
|
978
|
-
},
|
|
979
|
-
)
|
|
980
|
-
ressource.bufferAfterBuild = undefined
|
|
981
|
-
return precomputedBuildRelativeUrl
|
|
982
|
-
}
|
|
983
|
-
|
|
984
999
|
export const referenceToCodeForRollup = (reference) => {
|
|
985
1000
|
const ressource = reference.ressource
|
|
986
1001
|
if (ressource.isInline) {
|
|
@@ -1040,20 +1055,6 @@ const removePotentialUrlHash = (url) => {
|
|
|
1040
1055
|
return String(urlObject)
|
|
1041
1056
|
}
|
|
1042
1057
|
|
|
1043
|
-
const isEmitChunkNeeded = ({ ressource, reference }) => {
|
|
1044
|
-
if (reference.referenceShouldNotEmitChunk) {
|
|
1045
|
-
// si la ressource est preload ou prefetch
|
|
1046
|
-
const isReferencedByRessourceHint = ressource.references.some(
|
|
1047
|
-
(ref) => ref.isRessourceHint,
|
|
1048
|
-
)
|
|
1049
|
-
if (isReferencedByRessourceHint) {
|
|
1050
|
-
return true
|
|
1051
|
-
}
|
|
1052
|
-
return false
|
|
1053
|
-
}
|
|
1054
|
-
return true
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
1058
|
/*
|
|
1058
1059
|
* We cannot reference js from asset (svg for example)
|
|
1059
1060
|
* that is because rollup awaits for html to be ready which waits
|