@jsenv/core 24.6.4 → 25.0.0-alpha.2
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_91c5a3b8.js} +137 -26
- package/dist/browser_runtime/browser_runtime_91c5a3b8.js.map +1089 -0
- 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_7ad5faa6.html} +119 -26
- package/dist/compile_proxy/{compile_proxy.html__inline__20-9e168143.js.map → compile_proxy_e3b0c442_809f35f7.js.map} +6 -6
- package/dist/event_source_client/asset-manifest.json +2 -1
- package/dist/event_source_client/{event_source_client-9f14c8b9.js → event_source_client_80644aee.js} +2 -2
- package/dist/event_source_client/{event_source_client-9f14c8b9.js.map → event_source_client_80644aee.js.map} +4 -3
- package/dist/redirector/asset-manifest.json +2 -1
- package/dist/redirector/{redirector.html__inline__15-3a34a156.js.map → redirector_e3b0c442_e391410e.js.map} +6 -6
- package/dist/redirector/{redirector-b6ad84bf.html → redirector_eb92e8a7.html} +119 -26
- 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.main2_6c1b3d82.js.map} +8 -8
- package/dist/toolbar/{toolbar-1fbf8dcb.html → toolbar_04ba410c.html} +129 -36
- 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_4a48bc53.js} +3 -3
- package/dist/toolbar_injector/{toolbar_injector-997dbaa0.js.map → toolbar_injector_4a48bc53.js.map} +2 -2
- package/package.json +5 -4
- package/readme.md +24 -91
- package/src/buildProject.js +42 -27
- package/src/dev_server.js +8 -2
- package/src/execute.js +7 -1
- package/src/executeTestPlan.js +17 -0
- package/src/internal/browser_feature_detection/browser_feature_detection.js +18 -25
- package/src/internal/browser_runtime/browser_runtime.js +2 -2
- package/src/internal/browser_runtime/createBrowserRuntime.js +1 -1
- package/src/internal/browser_runtime/displayErrorInDocument.js +2 -0
- package/src/internal/browser_runtime/displayErrorNotification.js +1 -1
- package/src/internal/building/buildUsingRollup.js +12 -15
- 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 +210 -216
- package/src/internal/building/rollup_plugin_jsenv.js +530 -365
- package/src/internal/building/url_loader.js +8 -145
- package/src/internal/building/url_versioning.js +220 -0
- package/src/internal/compiling/compileHtml.js +8 -1
- package/src/internal/compiling/createCompiledFileService.js +28 -40
- package/src/internal/compiling/html_source_file_service.js +66 -51
- package/src/internal/compiling/js-compilation-service/babel_plugin_systemjs_prepend.js +23 -0
- package/src/internal/compiling/js-compilation-service/jsenvTransform.js +16 -12
- package/src/internal/compiling/js-compilation-service/transformJs.js +2 -0
- package/src/internal/compiling/jsenvCompilerForHtml.js +43 -44
- package/src/internal/compiling/jsenvCompilerForImportmap.js +15 -76
- package/src/internal/compiling/jsenvCompilerForJavaScript.js +9 -0
- package/src/internal/compiling/startCompileServer.js +29 -5
- package/src/internal/dev_server/event_source_client/livereload_preference.js +1 -1
- package/src/internal/dev_server/toolbar/compilation/toolbar.compilation.js +9 -9
- package/src/internal/executing/executePlan.js +6 -0
- package/src/internal/generateGroupMap/{jsenvBabelPluginCompatMap.js → babel_plugins_compatibility.js} +0 -0
- package/src/internal/generateGroupMap/{featuresCompatMap.js → features_compatibility.js} +9 -1
- package/src/internal/generateGroupMap/generateGroupMap.js +6 -35
- package/src/internal/generateGroupMap/one_runtime_compat.js +9 -12
- package/src/internal/generateGroupMap/runtime_compat.js +10 -15
- package/src/internal/generateGroupMap/runtime_compat_composition.js +2 -2
- package/src/internal/generateGroupMap/shake_babel_plugin_map.js +21 -0
- package/src/internal/import-resolution/importmap_default.js +52 -0
- package/src/internal/node_feature_detection/node_feature_detection.js +25 -19
- package/src/internal/runtime/s.js +101 -6
- package/src/internal/unevalException.js +1 -1
- package/src/jsenvServiceWorkerFinalizer.js +10 -9
- package/dist/browser_runtime/browser_runtime-bb0e3aa4.js.map +0 -1067
- 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/generateGroupMap/jsenvPluginCompatMap.js +0 -1
- package/src/internal/import-resolution/importmap-default.js +0 -34
- 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,12 +108,13 @@ export const createRessourceBuilder = (
|
|
|
119
108
|
})
|
|
120
109
|
}
|
|
121
110
|
|
|
122
|
-
const createReferenceFoundInJsModule =
|
|
111
|
+
const createReferenceFoundInJsModule = ({
|
|
123
112
|
referenceLabel,
|
|
124
113
|
jsUrl,
|
|
125
114
|
jsLine,
|
|
126
115
|
jsColumn,
|
|
127
116
|
isImportAssertion,
|
|
117
|
+
isJsModule,
|
|
128
118
|
|
|
129
119
|
contentTypeExpected,
|
|
130
120
|
ressourceSpecifier,
|
|
@@ -142,11 +132,8 @@ export const createRessourceBuilder = (
|
|
|
142
132
|
|
|
143
133
|
contentType,
|
|
144
134
|
bufferBeforeBuild,
|
|
135
|
+
isJsModule,
|
|
145
136
|
})
|
|
146
|
-
if (!reference) {
|
|
147
|
-
return null
|
|
148
|
-
}
|
|
149
|
-
await reference.ressource.getReadyPromise()
|
|
150
137
|
return reference
|
|
151
138
|
}
|
|
152
139
|
|
|
@@ -154,19 +141,40 @@ export const createRessourceBuilder = (
|
|
|
154
141
|
const urlToWait = Object.keys(ressourceMap).filter(
|
|
155
142
|
(url) => ressourceMap[url].isEntryPoint,
|
|
156
143
|
)
|
|
157
|
-
|
|
144
|
+
await Promise.all(
|
|
158
145
|
urlToWait.map(async (url) => {
|
|
159
146
|
const ressource = ressourceMap[url]
|
|
160
147
|
await ressource.getReadyPromise()
|
|
161
148
|
return ressource
|
|
162
149
|
}),
|
|
163
150
|
)
|
|
151
|
+
|
|
152
|
+
// compute all asset fileName
|
|
153
|
+
Object.keys(ressourceMap).forEach((key) => {
|
|
154
|
+
const ressource = ressourceMap[key]
|
|
155
|
+
if (ressource.isExternal || ressource.isJsModule || ressource.fileName) {
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
if (ressource.isPlaceholder && !ressource.buildRelativeUrl) {
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
if (!ressource.buildRelativeUrl) {
|
|
162
|
+
if (ressource.isPlaceholder) {
|
|
163
|
+
// placeholder not filled, that's ok
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
if (ressource.references.every((ref) => ref.isRessourceHint)) {
|
|
167
|
+
// ressource hint never used, the ressource can be ignored
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
ressource.fileName = asFileNameWithoutHash(ressource.buildRelativeUrl)
|
|
172
|
+
})
|
|
164
173
|
}
|
|
165
174
|
|
|
166
175
|
const ressourceMap = {}
|
|
167
176
|
const ressourceRedirectionMap = {}
|
|
168
177
|
const createReference = ({
|
|
169
|
-
referenceShouldNotEmitChunk,
|
|
170
178
|
isRessourceHint,
|
|
171
179
|
isImportAssertion,
|
|
172
180
|
contentTypeExpected,
|
|
@@ -183,32 +191,34 @@ export const createRessourceBuilder = (
|
|
|
183
191
|
isSourcemap,
|
|
184
192
|
isInline,
|
|
185
193
|
isPlaceholder,
|
|
186
|
-
|
|
194
|
+
|
|
187
195
|
urlVersioningDisabled,
|
|
188
196
|
|
|
189
197
|
fromRollup,
|
|
190
198
|
}) => {
|
|
191
|
-
const existingRessourceForReference = findRessourceByUrl(referenceUrl)
|
|
192
199
|
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: "",
|
|
200
|
+
if (referenceUrl) {
|
|
201
|
+
const existingRessourceForReference = findRessourceByUrl(referenceUrl)
|
|
202
|
+
if (existingRessourceForReference) {
|
|
203
|
+
ressourceImporter = existingRessourceForReference
|
|
204
|
+
} else {
|
|
205
|
+
const referenceOriginalUrl = asOriginalServerUrl(referenceUrl)
|
|
206
|
+
if (referenceOriginalUrl) {
|
|
207
|
+
ressourceImporter = findRessourceByUrl(referenceOriginalUrl)
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
210
|
}
|
|
211
|
+
if (!ressourceImporter) {
|
|
212
|
+
// happens only for entry points?
|
|
213
|
+
// in that case the importer is theoric
|
|
214
|
+
// see "getCallerLocation()" in createReferenceForEntryPoint
|
|
215
|
+
ressourceImporter = {
|
|
216
|
+
url: referenceUrl,
|
|
217
|
+
isEntryPoint: false,
|
|
218
|
+
isJsModule: true,
|
|
219
|
+
bufferAfterBuild: "",
|
|
220
|
+
}
|
|
221
|
+
}
|
|
212
222
|
|
|
213
223
|
const shouldBeIgnoredWarning = referenceShouldBeIgnoredWarning({
|
|
214
224
|
isJsModule,
|
|
@@ -244,6 +254,9 @@ export const createRessourceBuilder = (
|
|
|
244
254
|
if (ressourceUrlResolution.isServiceWorker) {
|
|
245
255
|
isServiceWorker = true
|
|
246
256
|
}
|
|
257
|
+
if (ressourceUrlResolution.isJsModule) {
|
|
258
|
+
isJsModule = true
|
|
259
|
+
}
|
|
247
260
|
ressourceUrl = ressourceUrlResolution.url
|
|
248
261
|
} else {
|
|
249
262
|
ressourceUrl = ressourceUrlResolution
|
|
@@ -263,23 +276,6 @@ export const createRessourceBuilder = (
|
|
|
263
276
|
// any hash in the url would mess up with filenames
|
|
264
277
|
ressourceUrl = removePotentialUrlHash(ressourceUrl)
|
|
265
278
|
|
|
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
279
|
const existingRessource = findRessourceByUrl(ressourceUrl)
|
|
284
280
|
let ressource
|
|
285
281
|
if (existingRessource) {
|
|
@@ -295,6 +291,7 @@ export const createRessourceBuilder = (
|
|
|
295
291
|
ressource = createRessource({
|
|
296
292
|
contentType,
|
|
297
293
|
ressourceUrl,
|
|
294
|
+
ressourceImporter,
|
|
298
295
|
bufferBeforeBuild,
|
|
299
296
|
|
|
300
297
|
isEntryPoint,
|
|
@@ -305,14 +302,14 @@ export const createRessourceBuilder = (
|
|
|
305
302
|
isPlaceholder,
|
|
306
303
|
isWorker,
|
|
307
304
|
isServiceWorker,
|
|
308
|
-
|
|
305
|
+
|
|
309
306
|
urlVersioningDisabled,
|
|
310
307
|
})
|
|
311
308
|
ressourceMap[ressourceUrl] = ressource
|
|
312
309
|
}
|
|
313
310
|
|
|
314
311
|
const reference = {
|
|
315
|
-
|
|
312
|
+
fromRollup,
|
|
316
313
|
isRessourceHint,
|
|
317
314
|
isImportAssertion,
|
|
318
315
|
contentTypeExpected,
|
|
@@ -335,26 +332,33 @@ export const createRessourceBuilder = (
|
|
|
335
332
|
}
|
|
336
333
|
|
|
337
334
|
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
|
-
)
|
|
335
|
+
if (fromRollup) {
|
|
336
|
+
if (ressourceImporter.isEntryPoint) {
|
|
337
|
+
// When HTML references JS, ressource builder has emitted the js chunk.
|
|
338
|
+
// so it already knows it exists and is part of references
|
|
339
|
+
// -> no need to push into reference (would incorrectly consider html references js twice)
|
|
340
|
+
// -> no need to log the js ressource (already logged during the HTML parsing)
|
|
341
|
+
return reference
|
|
342
|
+
}
|
|
343
|
+
if (ressource.isEntryPoint) {
|
|
344
|
+
// When rollup "loads" a js entry point, ressource builder is already aware of it
|
|
345
|
+
// because of "createReferenceForEntryPoint"
|
|
346
|
+
return reference
|
|
355
347
|
}
|
|
356
348
|
}
|
|
357
349
|
|
|
350
|
+
ressource.references.push(reference)
|
|
351
|
+
const effects = ressource.applyReferenceEffects(reference, { isJsModule })
|
|
352
|
+
if (loggerToLevels(logger).debug) {
|
|
353
|
+
logger.debug(
|
|
354
|
+
formatFoundReference({
|
|
355
|
+
reference,
|
|
356
|
+
referenceEffects: effects,
|
|
357
|
+
showReferenceSourceLocation,
|
|
358
|
+
shortenUrl,
|
|
359
|
+
}),
|
|
360
|
+
)
|
|
361
|
+
}
|
|
358
362
|
return reference
|
|
359
363
|
}
|
|
360
364
|
|
|
@@ -363,6 +367,7 @@ export const createRessourceBuilder = (
|
|
|
363
367
|
const createRessource = ({
|
|
364
368
|
contentType,
|
|
365
369
|
ressourceUrl,
|
|
370
|
+
ressourceImporter,
|
|
366
371
|
bufferBeforeBuild,
|
|
367
372
|
|
|
368
373
|
isEntryPoint = false,
|
|
@@ -374,13 +379,14 @@ export const createRessourceBuilder = (
|
|
|
374
379
|
isWorker = false,
|
|
375
380
|
isServiceWorker = false,
|
|
376
381
|
|
|
377
|
-
|
|
378
|
-
urlVersioningDisabled = isServiceWorker,
|
|
382
|
+
urlVersioningDisabled,
|
|
379
383
|
}) => {
|
|
380
384
|
const ressource = {
|
|
381
385
|
contentType,
|
|
382
386
|
url: ressourceUrl,
|
|
387
|
+
importer: ressourceImporter,
|
|
383
388
|
bufferBeforeBuild,
|
|
389
|
+
bufferAfterBuild: undefined,
|
|
384
390
|
firstStrongReference: null,
|
|
385
391
|
references: [],
|
|
386
392
|
|
|
@@ -394,10 +400,10 @@ export const createRessourceBuilder = (
|
|
|
394
400
|
isServiceWorker,
|
|
395
401
|
|
|
396
402
|
urlVersioningDisabled,
|
|
397
|
-
fileNamePattern,
|
|
398
403
|
|
|
399
|
-
relativeUrl:
|
|
400
|
-
|
|
404
|
+
relativeUrl: ressourceUrl.startsWith(compileServerOrigin)
|
|
405
|
+
? urlToRelativeUrl(ressourceUrl, compileServerOrigin)
|
|
406
|
+
: urlToRelativeUrl(ressourceUrl, buildDirectoryUrl),
|
|
401
407
|
}
|
|
402
408
|
|
|
403
409
|
ressource.usedPromise = new Promise((resolve) => {
|
|
@@ -494,7 +500,6 @@ export const createRessourceBuilder = (
|
|
|
494
500
|
isSourcemap = false,
|
|
495
501
|
isPlaceholder = false,
|
|
496
502
|
urlVersioningDisabled,
|
|
497
|
-
fileNamePattern,
|
|
498
503
|
}) => {
|
|
499
504
|
if (parsingDone) {
|
|
500
505
|
throw new Error(
|
|
@@ -519,7 +524,6 @@ export const createRessourceBuilder = (
|
|
|
519
524
|
isPlaceholder,
|
|
520
525
|
|
|
521
526
|
urlVersioningDisabled,
|
|
522
|
-
fileNamePattern,
|
|
523
527
|
})
|
|
524
528
|
|
|
525
529
|
if (dependencyReference) {
|
|
@@ -567,6 +571,10 @@ export const createRessourceBuilder = (
|
|
|
567
571
|
if (dependencyRessource.isPlaceholder) {
|
|
568
572
|
return
|
|
569
573
|
}
|
|
574
|
+
// don't keep waiting for ever in case ressource hint is never used
|
|
575
|
+
if (dependencyReference.isRessourceHint) {
|
|
576
|
+
return
|
|
577
|
+
}
|
|
570
578
|
await dependencyRessource.getReadyPromise()
|
|
571
579
|
}),
|
|
572
580
|
)
|
|
@@ -597,18 +605,12 @@ export const createRessourceBuilder = (
|
|
|
597
605
|
// }
|
|
598
606
|
// we don't yet know the exact importerBuildRelativeUrl but we can generate a fake one
|
|
599
607
|
// to ensure we resolve dependency against where the importer file will be
|
|
600
|
-
const importerBuildRelativeUrl =
|
|
601
|
-
ressource
|
|
602
|
-
{
|
|
603
|
-
lineBreakNormalization,
|
|
604
|
-
},
|
|
605
|
-
)
|
|
608
|
+
const importerBuildRelativeUrl =
|
|
609
|
+
urlVersioner.precomputeBuildRelativeUrl(ressource)
|
|
606
610
|
await transform({
|
|
607
611
|
buildDirectoryUrl,
|
|
608
612
|
precomputeBuildRelativeUrl: (ressource) =>
|
|
609
|
-
|
|
610
|
-
lineBreakNormalization,
|
|
611
|
-
}),
|
|
613
|
+
urlVersioner.precomputeBuildRelativeUrl(ressource),
|
|
612
614
|
getUrlRelativeToImporter: (referencedRessource) => {
|
|
613
615
|
const ressourceImporter = ressource
|
|
614
616
|
|
|
@@ -657,12 +659,8 @@ export const createRessourceBuilder = (
|
|
|
657
659
|
if (bufferAfterBuild !== undefined) {
|
|
658
660
|
ressource.bufferAfterBuild = bufferAfterBuild
|
|
659
661
|
if (buildRelativeUrl === undefined) {
|
|
660
|
-
ressource.buildRelativeUrl =
|
|
661
|
-
ressource
|
|
662
|
-
{
|
|
663
|
-
lineBreakNormalization,
|
|
664
|
-
},
|
|
665
|
-
)
|
|
662
|
+
ressource.buildRelativeUrl =
|
|
663
|
+
urlVersioner.computeBuildRelativeUrl(ressource)
|
|
666
664
|
}
|
|
667
665
|
}
|
|
668
666
|
|
|
@@ -677,7 +675,7 @@ export const createRessourceBuilder = (
|
|
|
677
675
|
!ressource.isInline &&
|
|
678
676
|
!ressource.isJsModule
|
|
679
677
|
) {
|
|
680
|
-
|
|
678
|
+
onAssetSourceUpdated({ ressource })
|
|
681
679
|
}
|
|
682
680
|
}
|
|
683
681
|
|
|
@@ -730,10 +728,6 @@ export const createRessourceBuilder = (
|
|
|
730
728
|
}
|
|
731
729
|
|
|
732
730
|
if (ressource.isJsModule) {
|
|
733
|
-
if (!isEmitChunkNeeded({ ressource, reference })) {
|
|
734
|
-
return effects
|
|
735
|
-
}
|
|
736
|
-
|
|
737
731
|
const jsModuleUrl = ressource.url
|
|
738
732
|
const rollupChunk = onJsModule({
|
|
739
733
|
ressource,
|
|
@@ -743,10 +737,12 @@ export const createRessourceBuilder = (
|
|
|
743
737
|
line: reference.referenceLine,
|
|
744
738
|
column: reference.referenceColumn,
|
|
745
739
|
})
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
740
|
+
if (rollupChunk) {
|
|
741
|
+
ressource.rollupReferenceId = rollupChunk.rollupReferenceId
|
|
742
|
+
effects.push(
|
|
743
|
+
`emit rollup chunk "${rollupChunk.fileName}" (${rollupChunk.rollupReferenceId})`,
|
|
744
|
+
)
|
|
745
|
+
}
|
|
750
746
|
return effects
|
|
751
747
|
}
|
|
752
748
|
|
|
@@ -755,12 +751,12 @@ export const createRessourceBuilder = (
|
|
|
755
751
|
return effects
|
|
756
752
|
}
|
|
757
753
|
|
|
758
|
-
const
|
|
759
|
-
|
|
754
|
+
const rollupAsset = onAsset({
|
|
755
|
+
ressource,
|
|
760
756
|
})
|
|
761
|
-
ressource.rollupReferenceId = rollupReferenceId
|
|
757
|
+
ressource.rollupReferenceId = rollupAsset.rollupReferenceId
|
|
762
758
|
effects.push(
|
|
763
|
-
`emit rollup asset "${
|
|
759
|
+
`emit rollup asset "${rollupAsset.fileName}" (${rollupAsset.rollupReferenceId})`,
|
|
764
760
|
)
|
|
765
761
|
return effects
|
|
766
762
|
}
|
|
@@ -777,82 +773,105 @@ export const createRessourceBuilder = (
|
|
|
777
773
|
return ressource
|
|
778
774
|
}
|
|
779
775
|
|
|
780
|
-
const rollupBuildEnd = ({
|
|
776
|
+
const rollupBuildEnd = ({
|
|
777
|
+
rollupResult,
|
|
778
|
+
useImportMapToMaximizeCacheReuse,
|
|
779
|
+
}) => {
|
|
780
|
+
const jsRessources = {}
|
|
781
|
+
|
|
781
782
|
Object.keys(ressourceMap).forEach((ressourceUrl) => {
|
|
782
783
|
const ressource = ressourceMap[ressourceUrl]
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
(
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
applyBuildEndEffects(ressource, { buildFileInfo, buildManifest })
|
|
792
|
-
const { rollupBuildDoneCallbacks } = ressource
|
|
793
|
-
rollupBuildDoneCallbacks.forEach((rollupBuildDoneCallback) => {
|
|
794
|
-
rollupBuildDoneCallback()
|
|
784
|
+
const rollupFileName = Object.keys(rollupResult).find((key) => {
|
|
785
|
+
const rollupFileInfo = rollupResult[key]
|
|
786
|
+
return (
|
|
787
|
+
rollupFileInfo.url === ressourceUrl ||
|
|
788
|
+
// asset
|
|
789
|
+
ressource.fileName === key ||
|
|
790
|
+
ressource.relativeUrl === key
|
|
791
|
+
)
|
|
795
792
|
})
|
|
793
|
+
if (rollupFileName) {
|
|
794
|
+
const rollupFileInfo = rollupResult[rollupFileName]
|
|
795
|
+
if (rollupFileInfo.type === "asset") {
|
|
796
|
+
ressource.fileName = rollupFileName
|
|
797
|
+
return
|
|
798
|
+
}
|
|
799
|
+
if (rollupFileInfo.type === "chunk") {
|
|
800
|
+
applyBuildEndEffects(ressource, {
|
|
801
|
+
rollupFileInfo,
|
|
802
|
+
rollupResult,
|
|
803
|
+
useImportMapToMaximizeCacheReuse,
|
|
804
|
+
})
|
|
805
|
+
const { rollupBuildDoneCallbacks } = ressource
|
|
806
|
+
rollupBuildDoneCallbacks.forEach((rollupBuildDoneCallback) => {
|
|
807
|
+
rollupBuildDoneCallback()
|
|
808
|
+
})
|
|
809
|
+
if (rollupFileInfo.type === "chunk") {
|
|
810
|
+
jsRessources[ressourceUrl] = ressource
|
|
811
|
+
}
|
|
812
|
+
return
|
|
813
|
+
}
|
|
814
|
+
}
|
|
796
815
|
})
|
|
816
|
+
return { jsRessources }
|
|
797
817
|
}
|
|
798
818
|
|
|
799
819
|
const applyBuildEndEffects = (
|
|
800
820
|
ressource,
|
|
801
|
-
{
|
|
802
|
-
buildFileInfo,
|
|
803
|
-
// buildManifest
|
|
804
|
-
},
|
|
821
|
+
{ rollupFileInfo, rollupResult, useImportMapToMaximizeCacheReuse },
|
|
805
822
|
) => {
|
|
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
|
-
)
|
|
831
|
-
}
|
|
823
|
+
const fileName = rollupFileInfo.fileName
|
|
824
|
+
let code = rollupFileInfo.code
|
|
825
|
+
ressource.contentType = "application/javascript"
|
|
832
826
|
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
ressource.
|
|
827
|
+
if (useImportMapToMaximizeCacheReuse) {
|
|
828
|
+
ressource.fileName = fileName
|
|
829
|
+
ressource.buildEnd(code)
|
|
830
|
+
} else {
|
|
831
|
+
ressource.fileName = asFileNameWithoutHash(fileName)
|
|
832
|
+
ressource.buildEnd(code, fileName)
|
|
839
833
|
}
|
|
840
|
-
ressource.fileName = fileName
|
|
841
|
-
ressource.buildEnd(
|
|
842
|
-
code,
|
|
843
|
-
// buildRelativeUrl
|
|
844
|
-
)
|
|
845
834
|
|
|
846
|
-
const map =
|
|
835
|
+
const map = rollupFileInfo.map
|
|
847
836
|
if (map) {
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
837
|
+
const sourcemapBuildRelativeUrl = `${ressource.buildRelativeUrl}.map`
|
|
838
|
+
const sourcemapRollupFileInfo = rollupResult[sourcemapBuildRelativeUrl]
|
|
839
|
+
if (!sourcemapRollupFileInfo) {
|
|
840
|
+
const ressourceBuildUrl = resolveUrl(
|
|
841
|
+
ressource.buildRelativeUrl,
|
|
842
|
+
buildDirectoryUrl,
|
|
843
|
+
)
|
|
844
|
+
const sourcemapBuildUrl = resolveUrl(
|
|
845
|
+
sourcemapBuildRelativeUrl,
|
|
846
|
+
buildDirectoryUrl,
|
|
847
|
+
)
|
|
848
|
+
const sourcemapAsString = JSON.stringify(rollupFileInfo.map, null, " ")
|
|
849
|
+
const sourcemapBuildUrlRelativeToFileBuildUrl = urlToRelativeUrl(
|
|
850
|
+
sourcemapBuildUrl,
|
|
851
|
+
ressourceBuildUrl,
|
|
852
|
+
)
|
|
853
|
+
const codeWithSourcemapComment = setJavaScriptSourceMappingUrl(
|
|
854
|
+
rollupFileInfo.code,
|
|
855
|
+
sourcemapBuildUrlRelativeToFileBuildUrl,
|
|
856
|
+
)
|
|
857
|
+
ressource.bufferAfterBuild = codeWithSourcemapComment
|
|
858
|
+
rollupFileInfo.code = codeWithSourcemapComment
|
|
859
|
+
const sourcemapReference = createReference({
|
|
860
|
+
referenceLabel: "js sourcemapping comment",
|
|
861
|
+
contentType: "application/octet-stream",
|
|
862
|
+
ressourceSpecifier: sourcemapBuildUrlRelativeToFileBuildUrl,
|
|
863
|
+
referenceUrl: ressourceBuildUrl,
|
|
864
|
+
referenceLine: codeWithSourcemapComment.split(/\r?\n/).length,
|
|
865
|
+
// ${"//#"} is to avoid a parser thinking there is a sourceMappingUrl for this file
|
|
866
|
+
referenceColumn: `${"//#"} sourceMappingURL=`.length + 1,
|
|
867
|
+
isSourcemap: true,
|
|
868
|
+
isPlaceholder: true,
|
|
869
|
+
})
|
|
870
|
+
sourcemapReference.ressource.buildEnd(
|
|
871
|
+
sourcemapAsString,
|
|
872
|
+
sourcemapBuildUrlRelativeToFileBuildUrl,
|
|
873
|
+
)
|
|
874
|
+
}
|
|
856
875
|
}
|
|
857
876
|
}
|
|
858
877
|
|
|
@@ -906,6 +925,9 @@ export const createRessourceBuilder = (
|
|
|
906
925
|
source: referenceSourceAsString,
|
|
907
926
|
}
|
|
908
927
|
|
|
928
|
+
if (!referenceRessource) {
|
|
929
|
+
return urlSite
|
|
930
|
+
}
|
|
909
931
|
if (!referenceRessource.isInline) {
|
|
910
932
|
return urlSite
|
|
911
933
|
}
|
|
@@ -953,6 +975,12 @@ export const createRessourceBuilder = (
|
|
|
953
975
|
}
|
|
954
976
|
}
|
|
955
977
|
|
|
978
|
+
const asFileNameWithoutHash = (fileName) => {
|
|
979
|
+
return fileName.replace(/_[a-z0-9]{8,}(\..*?)?$/, (_, afterHash = "") => {
|
|
980
|
+
return afterHash
|
|
981
|
+
})
|
|
982
|
+
}
|
|
983
|
+
|
|
956
984
|
// const preredirectUrlFromRessource = (ressource, ressourceRedirectionMap) => {
|
|
957
985
|
// const ressourceUrlPreRedirect = Object.keys(ressourceRedirectionMap).find(
|
|
958
986
|
// (urlPreRedirect) =>
|
|
@@ -961,26 +989,6 @@ export const createRessourceBuilder = (
|
|
|
961
989
|
// return ressourceUrlPreRedirect
|
|
962
990
|
// }
|
|
963
991
|
|
|
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
992
|
export const referenceToCodeForRollup = (reference) => {
|
|
985
993
|
const ressource = reference.ressource
|
|
986
994
|
if (ressource.isInline) {
|
|
@@ -1040,20 +1048,6 @@ const removePotentialUrlHash = (url) => {
|
|
|
1040
1048
|
return String(urlObject)
|
|
1041
1049
|
}
|
|
1042
1050
|
|
|
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
1051
|
/*
|
|
1058
1052
|
* We cannot reference js from asset (svg for example)
|
|
1059
1053
|
* that is because rollup awaits for html to be ready which waits
|