@jsenv/core 25.0.0-alpha.0 → 25.0.0-alpha.4
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 -2
- package/dist/browser_runtime/{browser_runtime_a8097085.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 -2
- package/dist/compile_proxy/{compile_proxy_e16d7de8.html → compile_proxy_7ad5faa6.html} +119 -26
- package/dist/compile_proxy/{compile_proxy_e3b0c442_9e168143.js.map → compile_proxy_e3b0c442_809f35f7.js.map} +6 -6
- package/dist/event_source_client/asset-manifest.json +2 -2
- package/dist/event_source_client/{event_source_client_620fbc2c.js → event_source_client_80644aee.js} +2 -2
- package/dist/event_source_client/{event_source_client_620fbc2c.js.map → event_source_client_80644aee.js.map} +4 -3
- package/dist/redirector/asset-manifest.json +2 -2
- package/dist/redirector/{redirector_e3b0c442_3a34a156.js.map → redirector_e3b0c442_e391410e.js.map} +6 -6
- package/dist/redirector/{redirector_2e0c8abe.html → redirector_eb92e8a7.html} +119 -26
- package/dist/toolbar/asset-manifest.json +2 -2
- package/dist/toolbar/{toolbar.main_a5ef2c60.js.map → toolbar.main_6c1b3d82.js.map} +8 -8
- package/dist/toolbar/{toolbar_412abb83.html → toolbar_f7b8a263.html} +127 -32
- package/dist/toolbar_injector/asset-manifest.json +3 -3
- package/dist/toolbar_injector/{toolbar_injector_4f9c19e5.js → toolbar_injector_49e4756e.js} +2 -2
- package/dist/toolbar_injector/{toolbar_injector_4f9c19e5.js.map → toolbar_injector_49e4756e.js.map} +2 -2
- package/package.json +5 -4
- package/readme.md +22 -89
- package/src/buildProject.js +37 -15
- 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 +3 -8
- package/src/internal/building/ressource_builder.js +35 -42
- package/src/internal/building/rollup_plugin_jsenv.js +226 -206
- package/src/internal/building/url_versioning.js +54 -42
- 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 +6 -10
- package/dist/browser_runtime/browser_runtime_a8097085.js.map +0 -1067
- package/src/internal/generateGroupMap/jsenvPluginCompatMap.js +0 -1
- package/src/internal/import-resolution/importmap-default.js +0 -34
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extname } from "node:path"
|
|
2
2
|
import MagicString from "magic-string"
|
|
3
|
-
import { normalizeImportMap } from "@jsenv/importmap"
|
|
3
|
+
import { composeTwoImportMaps, normalizeImportMap } from "@jsenv/importmap"
|
|
4
4
|
import { isSpecifierForNodeCoreModule } from "@jsenv/importmap/src/isSpecifierForNodeCoreModule.js"
|
|
5
5
|
import { createDetailedMessage, loggerToLogLevel } from "@jsenv/logger"
|
|
6
6
|
import {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
urlToMeta,
|
|
15
15
|
urlToBasename,
|
|
16
16
|
urlToFilename,
|
|
17
|
+
readFile,
|
|
17
18
|
} from "@jsenv/filesystem"
|
|
18
19
|
import { UNICODE } from "@jsenv/log"
|
|
19
20
|
|
|
@@ -26,6 +27,9 @@ import { createUrlLoader } from "@jsenv/core/src/internal/building/url_loader.js
|
|
|
26
27
|
import { stringifyUrlTrace } from "@jsenv/core/src/internal/building/url_trace.js"
|
|
27
28
|
import { sortObjectByPathnames } from "@jsenv/core/src/internal/building/sortObjectByPathnames.js"
|
|
28
29
|
import { jsenvHelpersDirectoryInfo } from "@jsenv/core/src/internal/jsenvInternalFiles.js"
|
|
30
|
+
import { createImportResolverForNode } from "@jsenv/core/src/internal/import-resolution/import-resolver-node.js"
|
|
31
|
+
import { createImportResolverForImportmap } from "@jsenv/core/src/internal/import-resolution/import-resolver-importmap.js"
|
|
32
|
+
import { getDefaultImportmap } from "@jsenv/core/src/internal/import-resolution/importmap_default.js"
|
|
29
33
|
|
|
30
34
|
import {
|
|
31
35
|
formatBuildStartLog,
|
|
@@ -44,9 +48,6 @@ import {
|
|
|
44
48
|
import { createUrlVersioner } from "./url_versioning.js"
|
|
45
49
|
import { visitImportReferences } from "./import_references.js"
|
|
46
50
|
|
|
47
|
-
import { createImportResolverForNode } from "../import-resolution/import-resolver-node.js"
|
|
48
|
-
import { createImportResolverForImportmap } from "../import-resolution/import-resolver-importmap.js"
|
|
49
|
-
import { getDefaultImportMap } from "../import-resolution/importmap-default.js"
|
|
50
51
|
import { createBuildStats } from "./build_stats.js"
|
|
51
52
|
|
|
52
53
|
export const createRollupPlugins = async ({
|
|
@@ -110,26 +111,19 @@ export const createRollupPlugins = async ({
|
|
|
110
111
|
const url = resolveUrl(key, projectDirectoryUrl)
|
|
111
112
|
entryPointUrls[url] = entryPoints[key]
|
|
112
113
|
})
|
|
113
|
-
const workerUrls =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
classicWorkerUrls[url] = classicWorkers[key]
|
|
127
|
-
})
|
|
128
|
-
const classicServiceWorkerUrls = {}
|
|
129
|
-
Object.keys(classicServiceWorkers).forEach((key) => {
|
|
130
|
-
const url = resolveUrl(key, projectDirectoryUrl)
|
|
131
|
-
classicServiceWorkerUrls[url] = classicServiceWorkers[key]
|
|
132
|
-
})
|
|
114
|
+
const workerUrls = workers.map((worker) =>
|
|
115
|
+
resolveUrl(worker, projectDirectoryUrl),
|
|
116
|
+
)
|
|
117
|
+
const serviceWorkerUrls = serviceWorkers.map((serviceWorker) =>
|
|
118
|
+
resolveUrl(serviceWorker, projectDirectoryUrl),
|
|
119
|
+
)
|
|
120
|
+
const classicWorkerUrls = classicWorkers.map((classicWorker) =>
|
|
121
|
+
resolveUrl(classicWorker, projectDirectoryUrl),
|
|
122
|
+
)
|
|
123
|
+
const classicServiceWorkerUrls = classicServiceWorkers.map(
|
|
124
|
+
(classicServiceWorker) =>
|
|
125
|
+
resolveUrl(classicServiceWorker, projectDirectoryUrl),
|
|
126
|
+
)
|
|
133
127
|
|
|
134
128
|
let ressourceBuilder
|
|
135
129
|
let importResolver
|
|
@@ -155,10 +149,6 @@ export const createRollupPlugins = async ({
|
|
|
155
149
|
|
|
156
150
|
const urlVersioner = createUrlVersioner({
|
|
157
151
|
entryPointUrls,
|
|
158
|
-
workerUrls,
|
|
159
|
-
classicWorkerUrls,
|
|
160
|
-
serviceWorkerUrls,
|
|
161
|
-
classicServiceWorkerUrls,
|
|
162
152
|
asOriginalUrl,
|
|
163
153
|
lineBreakNormalization,
|
|
164
154
|
})
|
|
@@ -192,14 +182,16 @@ export const createRollupPlugins = async ({
|
|
|
192
182
|
projectDirectoryUrl,
|
|
193
183
|
)
|
|
194
184
|
|
|
195
|
-
//
|
|
196
|
-
let
|
|
185
|
+
// Object mapping project relative urls to build relative urls
|
|
186
|
+
let buildMappings = {}
|
|
187
|
+
// Object mapping ressource names to build relative urls
|
|
188
|
+
let ressourceMappings = {}
|
|
197
189
|
|
|
198
190
|
const ressourcesReferencedByJs = []
|
|
199
191
|
const createImportMapForFilesUsedInJs = () => {
|
|
200
192
|
const topLevelMappings = {}
|
|
201
193
|
ressourcesReferencedByJs.sort(comparePathnames).forEach((ressourceName) => {
|
|
202
|
-
const buildRelativeUrl =
|
|
194
|
+
const buildRelativeUrl = ressourceMappings[ressourceName]
|
|
203
195
|
if (
|
|
204
196
|
ressourceName &&
|
|
205
197
|
buildRelativeUrl &&
|
|
@@ -213,12 +205,6 @@ export const createRollupPlugins = async ({
|
|
|
213
205
|
}
|
|
214
206
|
}
|
|
215
207
|
|
|
216
|
-
// an object where keys are build relative urls
|
|
217
|
-
// and values rollup chunk or asset
|
|
218
|
-
// we need this because we sometimes tell rollup
|
|
219
|
-
// that a file.fileName is something while it's not really this
|
|
220
|
-
// because of remapping
|
|
221
|
-
let buildMappings = {}
|
|
222
208
|
let rollupBuild
|
|
223
209
|
|
|
224
210
|
const EMPTY_CHUNK_URL = resolveUrl("__empty__", projectDirectoryUrl)
|
|
@@ -334,6 +320,7 @@ export const createRollupPlugins = async ({
|
|
|
334
320
|
: resolveUrl(chunk.fileName, buildDirectoryUrl),
|
|
335
321
|
code,
|
|
336
322
|
map,
|
|
323
|
+
module: format === "esmodule",
|
|
337
324
|
...(format === "global" ? { toplevel: false } : { toplevel: true }),
|
|
338
325
|
})
|
|
339
326
|
|
|
@@ -463,9 +450,21 @@ export const createRollupPlugins = async ({
|
|
|
463
450
|
)
|
|
464
451
|
importMapUrl = htmlCompiledUrl
|
|
465
452
|
fetchImportMap = () => {
|
|
466
|
-
const
|
|
467
|
-
const
|
|
468
|
-
|
|
453
|
+
const importmapFileUrl = asProjectUrl(importMapUrl)
|
|
454
|
+
const jsenvImportmap = getDefaultImportmap(importmapFileUrl, {
|
|
455
|
+
projectDirectoryUrl,
|
|
456
|
+
compileDirectoryUrl,
|
|
457
|
+
})
|
|
458
|
+
const htmlImportmap = JSON.parse(importMapInfoFromHtml.text)
|
|
459
|
+
const importmap = composeTwoImportMaps(
|
|
460
|
+
jsenvImportmap,
|
|
461
|
+
htmlImportmap,
|
|
462
|
+
)
|
|
463
|
+
const importmapNormalized = normalizeImportMap(
|
|
464
|
+
importmap,
|
|
465
|
+
importMapUrl,
|
|
466
|
+
)
|
|
467
|
+
return importmapNormalized
|
|
469
468
|
}
|
|
470
469
|
}
|
|
471
470
|
} else if (importMapFileRelativeUrl) {
|
|
@@ -488,16 +487,19 @@ export const createRollupPlugins = async ({
|
|
|
488
487
|
entryProjectRelativeUrl,
|
|
489
488
|
compileDirectoryUrl,
|
|
490
489
|
)
|
|
491
|
-
const
|
|
492
|
-
importMapFileUrl: entryCompileUrl,
|
|
490
|
+
const jsenvImportmap = getDefaultImportmap(entryCompileUrl, {
|
|
493
491
|
projectDirectoryUrl,
|
|
494
|
-
|
|
492
|
+
compileDirectoryUrl,
|
|
495
493
|
})
|
|
496
494
|
const entryCompileServerUrl = resolveUrl(
|
|
497
495
|
entryProjectRelativeUrl,
|
|
498
496
|
compileDirectoryServerUrl,
|
|
499
497
|
)
|
|
500
|
-
|
|
498
|
+
const importmapNormalized = normalizeImportMap(
|
|
499
|
+
jsenvImportmap,
|
|
500
|
+
entryCompileServerUrl,
|
|
501
|
+
)
|
|
502
|
+
return importmapNormalized
|
|
501
503
|
}
|
|
502
504
|
}
|
|
503
505
|
|
|
@@ -624,32 +626,27 @@ export const createRollupPlugins = async ({
|
|
|
624
626
|
}
|
|
625
627
|
|
|
626
628
|
const originalUrl = asOriginalUrl(projectUrl)
|
|
627
|
-
|
|
628
|
-
if (workerBuildRelativeUrl) {
|
|
629
|
+
if (workerUrls.includes(originalUrl)) {
|
|
629
630
|
return {
|
|
630
631
|
isWorker: true,
|
|
631
632
|
isJsModule: true,
|
|
632
633
|
url: ressourceUrl,
|
|
633
634
|
}
|
|
634
635
|
}
|
|
635
|
-
|
|
636
|
-
if (serviceWorkerBuildRelativeUrl) {
|
|
636
|
+
if (serviceWorkerUrls.includes(originalUrl)) {
|
|
637
637
|
return {
|
|
638
638
|
isServiceWorker: true,
|
|
639
639
|
isJsModule: true,
|
|
640
640
|
url: ressourceUrl,
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
|
-
|
|
644
|
-
if (classicWorkerBuildRelativeUrl) {
|
|
643
|
+
if (classicWorkerUrls.includes(originalUrl)) {
|
|
645
644
|
return {
|
|
646
645
|
isWorker: true,
|
|
647
646
|
url: ressourceUrl,
|
|
648
647
|
}
|
|
649
648
|
}
|
|
650
|
-
|
|
651
|
-
classicServiceWorkerUrls[originalUrl]
|
|
652
|
-
if (classicServiceWorkerBuildRelativeUrl) {
|
|
649
|
+
if (classicServiceWorkerUrls.includes(originalUrl)) {
|
|
653
650
|
return {
|
|
654
651
|
isServiceWorker: true,
|
|
655
652
|
url: ressourceUrl,
|
|
@@ -781,7 +778,7 @@ export const createRollupPlugins = async ({
|
|
|
781
778
|
}
|
|
782
779
|
},
|
|
783
780
|
|
|
784
|
-
async resolveId(specifier, importer, { custom }) {
|
|
781
|
+
async resolveId(specifier, importer, { custom = {} } = {}) {
|
|
785
782
|
if (specifier === EMPTY_CHUNK_URL) {
|
|
786
783
|
return specifier
|
|
787
784
|
}
|
|
@@ -819,7 +816,7 @@ export const createRollupPlugins = async ({
|
|
|
819
816
|
}
|
|
820
817
|
|
|
821
818
|
if (inlineModuleScripts.hasOwnProperty(specifier)) {
|
|
822
|
-
return specifier
|
|
819
|
+
return asRollupUrl(specifier)
|
|
823
820
|
}
|
|
824
821
|
|
|
825
822
|
const importUrl = await importResolver.resolveImport(
|
|
@@ -868,31 +865,28 @@ export const createRollupPlugins = async ({
|
|
|
868
865
|
|
|
869
866
|
resolveFileUrl: ({ referenceId, fileName }) => {
|
|
870
867
|
ressourcesReferencedByJs.push(fileName)
|
|
871
|
-
|
|
868
|
+
const getBuildRelativeUrl = () => {
|
|
869
|
+
const ressource = ressourceBuilder.findRessource((ressource) => {
|
|
870
|
+
return ressource.rollupReferenceId === referenceId
|
|
871
|
+
})
|
|
872
|
+
ressource.fileName = fileName
|
|
873
|
+
const buildRelativeUrl = ressource.buildRelativeUrl
|
|
874
|
+
return buildRelativeUrl
|
|
875
|
+
}
|
|
872
876
|
if (format === "esmodule") {
|
|
873
877
|
if (!node && useImportMapToMaximizeCacheReuse && urlVersioning) {
|
|
874
878
|
return `window.__resolveImportUrl__("./${fileName}", import.meta.url)`
|
|
875
879
|
}
|
|
876
|
-
return `new URL("${
|
|
880
|
+
return `new URL("${getBuildRelativeUrl()}", import.meta.url)`
|
|
877
881
|
}
|
|
878
882
|
if (format === "systemjs") {
|
|
879
883
|
return `new URL(System.resolve("./${fileName}", module.meta.url))`
|
|
880
884
|
}
|
|
881
885
|
if (format === "global") {
|
|
882
|
-
|
|
883
|
-
return ressource.rollupReferenceId === referenceId
|
|
884
|
-
})
|
|
885
|
-
ressource.fileName = fileName
|
|
886
|
-
const buildRelativeUrl = ressource.buildRelativeUrl
|
|
887
|
-
return `new URL("${buildRelativeUrl}", document.currentScript && document.currentScript.src || document.baseURI)`
|
|
886
|
+
return `new URL("${getBuildRelativeUrl()}", document.currentScript && document.currentScript.src || document.baseURI)`
|
|
888
887
|
}
|
|
889
888
|
if (format === "commonjs") {
|
|
890
|
-
|
|
891
|
-
return ressource.rollupReferenceId === referenceId
|
|
892
|
-
})
|
|
893
|
-
ressource.fileName = fileName
|
|
894
|
-
const buildRelativeUrl = ressource.buildRelativeUrl
|
|
895
|
-
return `new URL("${buildRelativeUrl}", "file:///" + __filename.replace(/\\/g, "/"))`
|
|
889
|
+
return `new URL("${getBuildRelativeUrl()}", "file:///" + __filename.replace(/\\/g, "/"))`
|
|
896
890
|
}
|
|
897
891
|
return null
|
|
898
892
|
},
|
|
@@ -973,12 +967,22 @@ export const createRollupPlugins = async ({
|
|
|
973
967
|
onReferenceWithImportMetaUrlPattern: async ({ importNode }) => {
|
|
974
968
|
const specifier = importNode.arguments[0].value
|
|
975
969
|
const { line, column } = importNode.loc.start
|
|
970
|
+
|
|
971
|
+
const { id } = normalizeRollupResolveReturnValue(
|
|
972
|
+
await this.resolve(specifier, url),
|
|
973
|
+
)
|
|
974
|
+
const ressourceUrl = asServerUrl(id)
|
|
975
|
+
const originalUrl = asOriginalUrl(ressourceUrl)
|
|
976
|
+
const isJsModule = Boolean(
|
|
977
|
+
workerUrls[originalUrl] || serviceWorkerUrls[originalUrl],
|
|
978
|
+
)
|
|
976
979
|
const reference = ressourceBuilder.createReferenceFoundInJsModule({
|
|
977
980
|
referenceLabel: "URL + import.meta.url",
|
|
978
981
|
jsUrl: url,
|
|
979
982
|
jsLine: line,
|
|
980
983
|
jsColumn: column,
|
|
981
|
-
ressourceSpecifier:
|
|
984
|
+
ressourceSpecifier: ressourceUrl,
|
|
985
|
+
isJsModule,
|
|
982
986
|
})
|
|
983
987
|
if (!reference) {
|
|
984
988
|
return
|
|
@@ -1270,45 +1274,65 @@ export const createRollupPlugins = async ({
|
|
|
1270
1274
|
return outputOptions
|
|
1271
1275
|
},
|
|
1272
1276
|
|
|
1277
|
+
async renderChunk(code, chunk) {
|
|
1278
|
+
const { facadeModuleId } = chunk
|
|
1279
|
+
if (!facadeModuleId) {
|
|
1280
|
+
// happens for inline module scripts for instance
|
|
1281
|
+
return null
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
const url = asOriginalUrl(facadeModuleId)
|
|
1285
|
+
if (workerUrls.includes(url) || serviceWorkerUrls.includes(url)) {
|
|
1286
|
+
const magicString = new MagicString(code)
|
|
1287
|
+
const systemjsCode = await readFile(
|
|
1288
|
+
new URL("../runtime/s.js", import.meta.url),
|
|
1289
|
+
)
|
|
1290
|
+
magicString.prepend(systemjsCode)
|
|
1291
|
+
code = magicString.toString()
|
|
1292
|
+
const map = magicString.generateMap({ hires: true })
|
|
1293
|
+
return {
|
|
1294
|
+
code,
|
|
1295
|
+
map,
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
return null
|
|
1300
|
+
},
|
|
1301
|
+
|
|
1273
1302
|
async generateBundle(outputOptions, rollupResult) {
|
|
1274
|
-
|
|
1275
|
-
|
|
1303
|
+
// it's important to do this to emit late asset
|
|
1304
|
+
rollupEmitFile = (...args) => this.emitFile(...args)
|
|
1305
|
+
rollupSetAssetSource = (...args) => this.setAssetSource(...args)
|
|
1276
1306
|
// To keep in mind: rollupResult object can be mutated by late asset emission
|
|
1277
1307
|
// however late chunk (js module) emission is not possible
|
|
1278
1308
|
// as rollup rightfully prevent late js emission
|
|
1279
1309
|
Object.keys(rollupResult).forEach((fileName) => {
|
|
1280
1310
|
const rollupFileInfo = rollupResult[fileName]
|
|
1281
|
-
|
|
1282
1311
|
// there is 3 types of file: "placeholder", "asset", "chunk"
|
|
1283
|
-
if (rollupFileInfo.type === "asset") {
|
|
1284
|
-
rollupAssetFileInfos[fileName] = rollupFileInfo
|
|
1285
|
-
return
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
1312
|
if (rollupFileInfo.type === "chunk") {
|
|
1289
1313
|
const { facadeModuleId } = rollupFileInfo
|
|
1290
1314
|
if (facadeModuleId === EMPTY_CHUNK_URL) {
|
|
1315
|
+
delete rollupResult[fileName]
|
|
1291
1316
|
return
|
|
1292
1317
|
}
|
|
1293
|
-
const fileCopy = { ...rollupFileInfo }
|
|
1294
1318
|
if (facadeModuleId) {
|
|
1295
|
-
|
|
1319
|
+
rollupFileInfo.url = asServerUrl(facadeModuleId)
|
|
1296
1320
|
} else {
|
|
1297
1321
|
const sourcePath =
|
|
1298
1322
|
rollupFileInfo.map.sources[rollupFileInfo.map.sources.length - 1]
|
|
1299
|
-
const fileBuildUrl = resolveUrl(
|
|
1300
|
-
rollupFileInfo.fileName,
|
|
1301
|
-
buildDirectoryUrl,
|
|
1302
|
-
)
|
|
1323
|
+
const fileBuildUrl = resolveUrl(fileName, buildDirectoryUrl)
|
|
1303
1324
|
const originalProjectUrl = resolveUrl(sourcePath, fileBuildUrl)
|
|
1304
|
-
|
|
1325
|
+
rollupFileInfo.url = asCompiledServerUrl(originalProjectUrl, {
|
|
1305
1326
|
projectDirectoryUrl,
|
|
1306
1327
|
compileServerOrigin,
|
|
1307
1328
|
compileDirectoryRelativeUrl,
|
|
1308
1329
|
})
|
|
1309
1330
|
}
|
|
1310
1331
|
|
|
1311
|
-
if (
|
|
1332
|
+
if (
|
|
1333
|
+
rollupFileInfo.url in inlineModuleScripts &&
|
|
1334
|
+
format === "systemjs"
|
|
1335
|
+
) {
|
|
1312
1336
|
const code = rollupFileInfo.code
|
|
1313
1337
|
const systemRegisterIndex = code.indexOf("System.register([")
|
|
1314
1338
|
const magicString = new MagicString(code)
|
|
@@ -1317,27 +1341,24 @@ export const createRollupPlugins = async ({
|
|
|
1317
1341
|
systemRegisterIndex + "System.register([".length,
|
|
1318
1342
|
`System.register("${fileName}", [`,
|
|
1319
1343
|
)
|
|
1320
|
-
|
|
1344
|
+
rollupFileInfo.code = magicString.toString()
|
|
1321
1345
|
}
|
|
1322
1346
|
|
|
1347
|
+
const jsRessource = ressourceBuilder.findRessource((ressource) => {
|
|
1348
|
+
return ressource.url === rollupFileInfo.url
|
|
1349
|
+
})
|
|
1323
1350
|
if (
|
|
1324
1351
|
isReferencedByJs({
|
|
1325
|
-
rollupFileInfo
|
|
1352
|
+
rollupFileInfo,
|
|
1326
1353
|
jsConcatenation,
|
|
1327
|
-
|
|
1354
|
+
jsRessource,
|
|
1328
1355
|
})
|
|
1329
1356
|
) {
|
|
1330
|
-
ressourcesReferencedByJs.push(
|
|
1357
|
+
ressourcesReferencedByJs.push(fileName)
|
|
1331
1358
|
}
|
|
1332
|
-
|
|
1333
|
-
rollupJsFileInfos[fileName] = fileCopy
|
|
1334
1359
|
}
|
|
1335
1360
|
})
|
|
1336
1361
|
|
|
1337
|
-
// it's important to do this to emit late asset
|
|
1338
|
-
rollupEmitFile = (...args) => this.emitFile(...args)
|
|
1339
|
-
rollupSetAssetSource = (...args) => this.setAssetSource(...args)
|
|
1340
|
-
|
|
1341
1362
|
// malheureusement rollup ne permet pas de savoir lorsqu'un chunk
|
|
1342
1363
|
// a fini d'etre résolu (parsing des imports statiques et dynamiques recursivement)
|
|
1343
1364
|
// donc lorsque le build se termine on va indiquer
|
|
@@ -1345,8 +1366,7 @@ export const createRollupPlugins = async ({
|
|
|
1345
1366
|
// et donc les assets peuvent connaitre le nom du chunk
|
|
1346
1367
|
// et mettre a jour leur dépendance vers ce fichier js
|
|
1347
1368
|
const { jsRessources } = ressourceBuilder.rollupBuildEnd({
|
|
1348
|
-
|
|
1349
|
-
rollupAssetFileInfos,
|
|
1369
|
+
rollupResult,
|
|
1350
1370
|
useImportMapToMaximizeCacheReuse,
|
|
1351
1371
|
})
|
|
1352
1372
|
Object.keys(jsRessources).forEach((ressourceUrl) => {
|
|
@@ -1354,9 +1374,9 @@ export const createRollupPlugins = async ({
|
|
|
1354
1374
|
if (jsRessource.isInline) {
|
|
1355
1375
|
buildInlineFileContents[jsRessource.buildRelativeUrl] =
|
|
1356
1376
|
jsRessource.bufferAfterBuild
|
|
1357
|
-
if (format === "systemjs") {
|
|
1358
|
-
|
|
1359
|
-
}
|
|
1377
|
+
// if (format === "systemjs") {
|
|
1378
|
+
// ressourcesReferencedByJs.push(jsRessource.fileName)
|
|
1379
|
+
// }
|
|
1360
1380
|
} else {
|
|
1361
1381
|
const originalProjectUrl = asOriginalUrl(ressourceUrl)
|
|
1362
1382
|
const originalProjectRelativeUrl = urlToRelativeUrl(
|
|
@@ -1366,10 +1386,8 @@ export const createRollupPlugins = async ({
|
|
|
1366
1386
|
buildMappings[originalProjectRelativeUrl] =
|
|
1367
1387
|
jsRessource.buildRelativeUrl
|
|
1368
1388
|
}
|
|
1369
|
-
|
|
1370
|
-
buildManifest[jsRessource.fileName] = jsRessource.buildRelativeUrl
|
|
1389
|
+
ressourceMappings[jsRessource.fileName] = jsRessource.buildRelativeUrl
|
|
1371
1390
|
})
|
|
1372
|
-
|
|
1373
1391
|
// wait for asset build relative urls
|
|
1374
1392
|
// to ensure the importmap will contain remappings for them
|
|
1375
1393
|
// (not sure this is required anymore)
|
|
@@ -1380,68 +1398,70 @@ export const createRollupPlugins = async ({
|
|
|
1380
1398
|
})
|
|
1381
1399
|
if (ressource && !ressource.isJsModule) {
|
|
1382
1400
|
await ressource.getReadyPromise()
|
|
1383
|
-
|
|
1401
|
+
ressourceMappings[ressourceName] = ressource.buildRelativeUrl
|
|
1384
1402
|
}
|
|
1385
1403
|
}),
|
|
1386
1404
|
)
|
|
1387
|
-
|
|
1388
1405
|
// wait html files to be emitted
|
|
1389
1406
|
await ressourceBuilder.getAllEntryPointsEmittedPromise()
|
|
1390
1407
|
onBundleEnd()
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
}
|
|
1408
|
+
|
|
1409
|
+
const jsModuleBuild = {}
|
|
1394
1410
|
const assetBuild = {}
|
|
1395
1411
|
Object.keys(rollupResult).forEach((fileName) => {
|
|
1396
|
-
const
|
|
1397
|
-
if (file.type !== "asset") {
|
|
1398
|
-
return
|
|
1399
|
-
}
|
|
1400
|
-
|
|
1401
|
-
const assetRessource = ressourceBuilder.findRessource(
|
|
1402
|
-
(ressource) =>
|
|
1403
|
-
// happens for import.meta.url pattern
|
|
1404
|
-
ressource.fileName === fileName ||
|
|
1405
|
-
// happens for sourcemap
|
|
1406
|
-
ressource.relativeUrl === fileName,
|
|
1407
|
-
)
|
|
1408
|
-
|
|
1409
|
-
// ignore potential useless assets which happens when:
|
|
1410
|
-
// - sourcemap re-emitted
|
|
1411
|
-
// - importmap re-emitted to have buildRelativeUrlMap
|
|
1412
|
-
if (assetRessource.shouldBeIgnored) {
|
|
1413
|
-
return
|
|
1414
|
-
}
|
|
1412
|
+
const rollupFileInfo = rollupResult[fileName]
|
|
1415
1413
|
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
// and import assertions are supported, the file is still converted to js module
|
|
1420
|
-
const isReferencedOnlyByImportAssertions =
|
|
1421
|
-
assetRessource.references.every((reference) => {
|
|
1422
|
-
return reference.isImportAssertion
|
|
1414
|
+
if (rollupFileInfo.type === "chunk") {
|
|
1415
|
+
const jsRessource = ressourceBuilder.findRessource((ressource) => {
|
|
1416
|
+
return ressource.url === rollupFileInfo.url
|
|
1423
1417
|
})
|
|
1424
|
-
|
|
1418
|
+
jsModuleBuild[jsRessource.buildRelativeUrl] = rollupFileInfo
|
|
1425
1419
|
return
|
|
1426
1420
|
}
|
|
1427
1421
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
file.source = assetRessource.bufferAfterBuild
|
|
1436
|
-
assetBuild[buildRelativeUrl] = file
|
|
1437
|
-
buildManifest[assetRessource.fileName] = buildRelativeUrl
|
|
1438
|
-
if (assetRessource.bufferBeforeBuild) {
|
|
1439
|
-
const originalProjectUrl = asOriginalUrl(assetRessource.url)
|
|
1440
|
-
const originalProjectRelativeUrl = urlToRelativeUrl(
|
|
1441
|
-
originalProjectUrl,
|
|
1442
|
-
projectDirectoryUrl,
|
|
1422
|
+
if (rollupFileInfo.type === "asset") {
|
|
1423
|
+
const assetRessource = ressourceBuilder.findRessource(
|
|
1424
|
+
(ressource) =>
|
|
1425
|
+
// happens for import.meta.url pattern
|
|
1426
|
+
ressource.fileName === fileName ||
|
|
1427
|
+
// happens for sourcemap
|
|
1428
|
+
ressource.relativeUrl === fileName,
|
|
1443
1429
|
)
|
|
1444
|
-
|
|
1430
|
+
// ignore potential useless assets which happens when:
|
|
1431
|
+
// - sourcemap re-emitted
|
|
1432
|
+
// - importmap re-emitted to have buildRelativeUrlMap
|
|
1433
|
+
if (assetRessource.shouldBeIgnored) {
|
|
1434
|
+
return
|
|
1435
|
+
}
|
|
1436
|
+
// Ignore file only referenced by import assertions
|
|
1437
|
+
// - if file is referenced by import assertion and html or import meta url
|
|
1438
|
+
// then source file is duplicated. If concatenation is disabled
|
|
1439
|
+
// and import assertions are supported, the file is still converted to js module
|
|
1440
|
+
const isReferencedOnlyByImportAssertions =
|
|
1441
|
+
assetRessource.references.every((reference) => {
|
|
1442
|
+
return reference.isImportAssertion
|
|
1443
|
+
})
|
|
1444
|
+
if (isReferencedOnlyByImportAssertions) {
|
|
1445
|
+
return
|
|
1446
|
+
}
|
|
1447
|
+
const buildRelativeUrl = assetRessource.buildRelativeUrl
|
|
1448
|
+
if (assetRessource.isInline) {
|
|
1449
|
+
buildInlineFileContents[buildRelativeUrl] = rollupFileInfo.source
|
|
1450
|
+
return
|
|
1451
|
+
}
|
|
1452
|
+
// in case sourcemap is mutated, we must not trust rollup but the asset builder source instead
|
|
1453
|
+
rollupFileInfo.source = assetRessource.bufferAfterBuild
|
|
1454
|
+
assetBuild[buildRelativeUrl] = rollupFileInfo
|
|
1455
|
+
ressourceMappings[assetRessource.fileName] = buildRelativeUrl
|
|
1456
|
+
if (assetRessource.bufferBeforeBuild) {
|
|
1457
|
+
const originalProjectUrl = asOriginalUrl(assetRessource.url)
|
|
1458
|
+
const originalProjectRelativeUrl = urlToRelativeUrl(
|
|
1459
|
+
originalProjectUrl,
|
|
1460
|
+
projectDirectoryUrl,
|
|
1461
|
+
)
|
|
1462
|
+
buildMappings[originalProjectRelativeUrl] = buildRelativeUrl
|
|
1463
|
+
}
|
|
1464
|
+
return
|
|
1445
1465
|
}
|
|
1446
1466
|
})
|
|
1447
1467
|
rollupBuild = {
|
|
@@ -1450,12 +1470,12 @@ export const createRollupPlugins = async ({
|
|
|
1450
1470
|
}
|
|
1451
1471
|
rollupBuild = sortObjectByPathnames(rollupBuild)
|
|
1452
1472
|
// fill "buildFileContents", "buildInlineFilesContents"
|
|
1453
|
-
// and update "
|
|
1454
|
-
// by ressourceBuilder.rollupBuildEnd
|
|
1455
|
-
Object.keys(rollupBuild).forEach((
|
|
1456
|
-
const rollupFileInfo = rollupBuild[
|
|
1473
|
+
// and update "buildMappings"
|
|
1474
|
+
// in case some ressource where inlined by ressourceBuilder.rollupBuildEnd
|
|
1475
|
+
Object.keys(rollupBuild).forEach((buildRelativeUrl) => {
|
|
1476
|
+
const rollupFileInfo = rollupBuild[buildRelativeUrl]
|
|
1457
1477
|
const ressource = ressourceBuilder.findRessource((ressource) => {
|
|
1458
|
-
if (ressource.buildRelativeUrl ===
|
|
1478
|
+
if (ressource.buildRelativeUrl === buildRelativeUrl) {
|
|
1459
1479
|
return true
|
|
1460
1480
|
}
|
|
1461
1481
|
if (ressource.url === rollupFileInfo.url) {
|
|
@@ -1464,7 +1484,11 @@ export const createRollupPlugins = async ({
|
|
|
1464
1484
|
return false
|
|
1465
1485
|
})
|
|
1466
1486
|
if (ressource.isInline) {
|
|
1467
|
-
|
|
1487
|
+
if (ressource.isJsModule) {
|
|
1488
|
+
delete jsModuleBuild[buildRelativeUrl]
|
|
1489
|
+
} else {
|
|
1490
|
+
delete assetBuild[buildRelativeUrl]
|
|
1491
|
+
}
|
|
1468
1492
|
const originalProjectUrl = asOriginalUrl(ressource.url)
|
|
1469
1493
|
const originalRelativeUrl = urlToRelativeUrl(
|
|
1470
1494
|
originalProjectUrl,
|
|
@@ -1479,22 +1503,18 @@ export const createRollupPlugins = async ({
|
|
|
1479
1503
|
}
|
|
1480
1504
|
})
|
|
1481
1505
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
serviceWorkerFinalizer,
|
|
1506
|
+
ressourceMappings = sortObjectByPathnames(ressourceMappings)
|
|
1507
|
+
buildMappings = sortObjectByPathnames(buildMappings)
|
|
1508
|
+
await visitServiceWorkers({
|
|
1486
1509
|
projectDirectoryUrl,
|
|
1487
|
-
|
|
1488
|
-
|
|
1510
|
+
serviceWorkerUrls,
|
|
1511
|
+
classicServiceWorkerUrls,
|
|
1512
|
+
serviceWorkerFinalizer,
|
|
1489
1513
|
buildMappings,
|
|
1490
|
-
|
|
1514
|
+
ressourceMappings,
|
|
1491
1515
|
buildFileContents,
|
|
1492
1516
|
lineBreakNormalization,
|
|
1493
|
-
minify,
|
|
1494
1517
|
})
|
|
1495
|
-
|
|
1496
|
-
buildManifest = sortObjectByPathnames(buildManifest)
|
|
1497
|
-
buildMappings = sortObjectByPathnames(buildMappings)
|
|
1498
1518
|
const buildDuration = Date.now() - buildStartMs
|
|
1499
1519
|
buildStats = createBuildStats({
|
|
1500
1520
|
buildFileContents,
|
|
@@ -1534,7 +1554,11 @@ export const createRollupPlugins = async ({
|
|
|
1534
1554
|
rollupBuild,
|
|
1535
1555
|
urlResponseBodyMap: urlLoader.getUrlResponseBodyMap(),
|
|
1536
1556
|
buildMappings,
|
|
1537
|
-
|
|
1557
|
+
ressourceMappings,
|
|
1558
|
+
// Object mapping build relative urls without hash to build relative urls
|
|
1559
|
+
buildManifest: createBuildManifest({
|
|
1560
|
+
buildFileContents,
|
|
1561
|
+
}),
|
|
1538
1562
|
buildImportMap: createImportMapForFilesUsedInJs(),
|
|
1539
1563
|
buildFileContents,
|
|
1540
1564
|
buildInlineFileContents,
|
|
@@ -1547,6 +1571,21 @@ export const createRollupPlugins = async ({
|
|
|
1547
1571
|
}
|
|
1548
1572
|
}
|
|
1549
1573
|
|
|
1574
|
+
const createBuildManifest = ({ buildFileContents }) => {
|
|
1575
|
+
const buildManifest = {}
|
|
1576
|
+
Object.keys(buildFileContents).forEach((buildRelativeUrl) => {
|
|
1577
|
+
const relativeUrlWithoutHash = asFileNameWithoutHash(buildRelativeUrl)
|
|
1578
|
+
buildManifest[relativeUrlWithoutHash] = buildRelativeUrl
|
|
1579
|
+
})
|
|
1580
|
+
return buildManifest
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
const asFileNameWithoutHash = (fileName) => {
|
|
1584
|
+
return fileName.replace(/_[a-z0-9]{8,}(\..*?)?$/, (_, afterHash = "") => {
|
|
1585
|
+
return afterHash
|
|
1586
|
+
})
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1550
1589
|
const prepareEntryPoints = async (
|
|
1551
1590
|
entryPoints,
|
|
1552
1591
|
{
|
|
@@ -1670,17 +1709,10 @@ const acceptsJsonContentType = ({ node, format }) => {
|
|
|
1670
1709
|
return false
|
|
1671
1710
|
}
|
|
1672
1711
|
|
|
1673
|
-
const isReferencedByJs = ({
|
|
1674
|
-
rollupFileInfo,
|
|
1675
|
-
jsConcatenation,
|
|
1676
|
-
ressourceBuilder,
|
|
1677
|
-
}) => {
|
|
1712
|
+
const isReferencedByJs = ({ rollupFileInfo, jsConcatenation, jsRessource }) => {
|
|
1678
1713
|
if (rollupFileInfo.isDynamicEntry) {
|
|
1679
1714
|
return true
|
|
1680
1715
|
}
|
|
1681
|
-
const jsRessource = ressourceBuilder.findRessource((ressource) => {
|
|
1682
|
-
return ressource.url === rollupFileInfo.url
|
|
1683
|
-
})
|
|
1684
1716
|
if (!jsConcatenation && rollupFileInfo.isEntry) {
|
|
1685
1717
|
return true
|
|
1686
1718
|
}
|
|
@@ -1693,50 +1725,38 @@ const isReferencedByJs = ({
|
|
|
1693
1725
|
return false
|
|
1694
1726
|
}
|
|
1695
1727
|
|
|
1696
|
-
const
|
|
1697
|
-
|
|
1698
|
-
|
|
1728
|
+
const visitServiceWorkers = async ({
|
|
1729
|
+
projectDirectoryUrl,
|
|
1730
|
+
serviceWorkerUrls,
|
|
1731
|
+
classicServiceWorkerUrls,
|
|
1699
1732
|
serviceWorkerFinalizer,
|
|
1700
1733
|
buildMappings,
|
|
1701
|
-
buildManifest,
|
|
1702
1734
|
buildFileContents,
|
|
1703
1735
|
lineBreakNormalization,
|
|
1704
1736
|
}) => {
|
|
1705
|
-
const
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
...serviceWorkerKeys,
|
|
1709
|
-
...classicServiceWorkerKeys,
|
|
1737
|
+
const allServiceWorkerUrls = [
|
|
1738
|
+
...serviceWorkerUrls,
|
|
1739
|
+
...classicServiceWorkerUrls,
|
|
1710
1740
|
]
|
|
1711
1741
|
|
|
1712
1742
|
await Promise.all(
|
|
1713
|
-
|
|
1714
|
-
const
|
|
1715
|
-
|
|
1716
|
-
|
|
1743
|
+
allServiceWorkerUrls.map(async (serviceWorkerUrl) => {
|
|
1744
|
+
const serviceWorkerRelativeUrl = urlToRelativeUrl(
|
|
1745
|
+
serviceWorkerUrl,
|
|
1746
|
+
projectDirectoryUrl,
|
|
1747
|
+
)
|
|
1748
|
+
const serviceWorkerBuildRelativeUrl =
|
|
1749
|
+
buildMappings[serviceWorkerRelativeUrl]
|
|
1717
1750
|
if (!serviceWorkerBuildRelativeUrl) {
|
|
1718
1751
|
throw new Error(
|
|
1719
|
-
`"${
|
|
1752
|
+
`"${serviceWorkerRelativeUrl}" service worker file missing in the build`,
|
|
1720
1753
|
)
|
|
1721
1754
|
}
|
|
1722
1755
|
|
|
1723
|
-
|
|
1724
|
-
if (serviceWorkerKeys.includes(projectRelativeUrl)) {
|
|
1725
|
-
let code = buildFileContents[serviceWorkerBuildRelativeUrl]
|
|
1726
|
-
code = await serviceWorkerFinalizer(code, {
|
|
1727
|
-
serviceWorkerBuildRelativeUrl,
|
|
1728
|
-
buildManifest,
|
|
1729
|
-
buildFileContents,
|
|
1730
|
-
lineBreakNormalization,
|
|
1731
|
-
})
|
|
1732
|
-
buildFileContents[serviceWorkerBuildRelativeUrl] = code
|
|
1733
|
-
}
|
|
1734
|
-
// "classic" service worker
|
|
1735
|
-
else {
|
|
1756
|
+
if (serviceWorkerFinalizer) {
|
|
1736
1757
|
let code = buildFileContents[serviceWorkerBuildRelativeUrl]
|
|
1737
1758
|
code = await serviceWorkerFinalizer(code, {
|
|
1738
1759
|
serviceWorkerBuildRelativeUrl,
|
|
1739
|
-
buildManifest,
|
|
1740
1760
|
buildFileContents,
|
|
1741
1761
|
lineBreakNormalization,
|
|
1742
1762
|
})
|