1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = mergeChunkMetadata;
|
15 |
|
16 | function mergeChunkMetadata(
|
17 | arr /*: Array<ClientChunkMetadata> */
|
18 | ) /*: ClientChunkMetadata */ {
|
19 | const base = {
|
20 | fileManifest: new Map(),
|
21 | urlMap: new Map(),
|
22 | criticalPaths: [],
|
23 | criticalIds: [],
|
24 | chunks: new Map(),
|
25 | runtimeChunkIds: new Set(),
|
26 | initialChunkIds: new Set(),
|
27 | };
|
28 | arr = arr.reverse();
|
29 |
|
30 | return arr.reduce((acc, item) => {
|
31 | for (let [key, val] of item.fileManifest) {
|
32 | if (acc.fileManifest.has(key)) {
|
33 | let set = acc.fileManifest.get(key);
|
34 | for (let el of val) {
|
35 |
|
36 | set.add(el);
|
37 | }
|
38 | } else {
|
39 | acc.fileManifest.set(key, val);
|
40 | }
|
41 | }
|
42 | for (let [key, val] of item.urlMap) {
|
43 | acc.urlMap.set(key, val);
|
44 | }
|
45 | for (let [key, val] of item.chunks) {
|
46 | acc.chunks.set(key, val);
|
47 | }
|
48 | for (let val of item.runtimeChunkIds) {
|
49 | acc.runtimeChunkIds.add(val);
|
50 | }
|
51 | for (let val of item.initialChunkIds) {
|
52 | acc.initialChunkIds.add(val);
|
53 | }
|
54 | for (let path of item.criticalPaths) {
|
55 | if (!acc.criticalPaths.includes(path)) {
|
56 | acc.criticalPaths.push(path);
|
57 | }
|
58 | }
|
59 | for (let id of item.criticalIds) {
|
60 | if (!acc.criticalIds.includes(id)) {
|
61 | acc.criticalIds.push(id);
|
62 | }
|
63 | }
|
64 | return acc;
|
65 | }, base);
|
66 | }
|