metro 0.70.2 → 0.71.1
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/package.json +22 -21
- package/src/Assets.js.flow +4 -4
- package/src/Bundler/util.js +1 -1
- package/src/Bundler/util.js.flow +2 -2
- package/src/Bundler.js +17 -10
- package/src/Bundler.js.flow +19 -14
- package/src/DeltaBundler/DeltaCalculator.js +13 -17
- package/src/DeltaBundler/DeltaCalculator.js.flow +15 -20
- package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +4 -4
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +6 -6
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +4 -4
- package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +2 -2
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +2 -2
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +2 -2
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
- package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -4
- package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
- package/src/DeltaBundler/Worker.flow.js +78 -0
- package/src/DeltaBundler/Worker.flow.js.flow +121 -0
- package/src/DeltaBundler/Worker.js +8 -66
- package/src/DeltaBundler/Worker.js.flow +8 -107
- package/src/DeltaBundler/WorkerFarm.js.flow +4 -4
- package/src/DeltaBundler/__fixtures__/hasteImpl.js +4 -0
- package/src/DeltaBundler/getTransformCacheKey.js.flow +2 -2
- package/src/DeltaBundler/graphOperations.js +634 -0
- package/src/DeltaBundler/graphOperations.js.flow +749 -0
- package/src/DeltaBundler/types.flow.js.flow +36 -30
- package/src/DeltaBundler.js +14 -6
- package/src/DeltaBundler.js.flow +14 -10
- package/src/HmrServer.js.flow +6 -6
- package/src/IncrementalBundler.js +1 -1
- package/src/IncrementalBundler.js.flow +8 -8
- package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
- package/src/ModuleGraph/node-haste/ModuleCache.js.flow +1 -1
- package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +2 -2
- package/src/ModuleGraph/node-haste/node-haste.js +4 -4
- package/src/ModuleGraph/node-haste/node-haste.js.flow +13 -7
- package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +2 -2
- package/src/ModuleGraph/output/plain-bundle.js.flow +2 -2
- package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +8 -8
- package/src/ModuleGraph/output/util.js.flow +2 -2
- package/src/ModuleGraph/types.flow.js.flow +37 -37
- package/src/ModuleGraph/worker/collectDependencies.js.flow +2 -2
- package/src/Server/symbolicate.js.flow +1 -1
- package/src/Server.js.flow +18 -18
- package/src/cli.js +5 -0
- package/src/cli.js.flow +5 -0
- package/src/commands/build.js +4 -3
- package/src/commands/build.js.flow +5 -3
- package/src/commands/serve.js +3 -3
- package/src/commands/serve.js.flow +5 -3
- package/src/index.flow.js +392 -0
- package/src/index.flow.js.flow +480 -0
- package/src/index.js +8 -366
- package/src/index.js.flow +8 -456
- package/src/lib/bundleToBytecode.js.flow +2 -2
- package/src/lib/bundleToString.js.flow +2 -2
- package/src/lib/getPreludeCode.js.flow +2 -2
- package/src/lib/transformHelpers.js.flow +2 -2
- package/src/node-haste/DependencyGraph/ModuleResolution.js +17 -4
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +20 -12
- package/src/node-haste/DependencyGraph/createHasteMap.js +79 -19
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +15 -14
- package/src/node-haste/DependencyGraph.js +31 -27
- package/src/node-haste/DependencyGraph.js.flow +43 -37
- package/src/node-haste/ModuleCache.js.flow +1 -1
- package/src/node-haste/lib/AssetPaths.js.flow +2 -2
- package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -2
- package/src/shared/output/RamBundle/as-indexed-file.js.flow +1 -1
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +2 -2
- package/src/shared/types.flow.js.flow +14 -14
- package/src/DeltaBundler/computeDelta.js +0 -42
- package/src/DeltaBundler/computeDelta.js.flow +0 -47
- package/src/DeltaBundler/traverseDependencies.js +0 -470
- package/src/DeltaBundler/traverseDependencies.js.flow +0 -565
- package/src/node-haste/DependencyGraph/types.js +0 -10
- package/src/node-haste/DependencyGraph/types.js.flow +0 -88
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
"use strict";
|
|
11
|
-
|
|
12
|
-
const nullthrows = require("nullthrows");
|
|
13
|
-
|
|
14
|
-
function getInternalOptions({
|
|
15
|
-
transform,
|
|
16
|
-
resolve,
|
|
17
|
-
onProgress,
|
|
18
|
-
experimentalImportBundleSupport,
|
|
19
|
-
shallow,
|
|
20
|
-
}) {
|
|
21
|
-
let numProcessed = 0;
|
|
22
|
-
let total = 0;
|
|
23
|
-
return {
|
|
24
|
-
experimentalImportBundleSupport,
|
|
25
|
-
transform,
|
|
26
|
-
resolve,
|
|
27
|
-
onDependencyAdd: () => onProgress && onProgress(numProcessed, ++total),
|
|
28
|
-
onDependencyAdded: () => onProgress && onProgress(++numProcessed, total),
|
|
29
|
-
shallow,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Dependency Traversal logic for the Delta Bundler. This method calculates
|
|
34
|
-
* the modules that should be included in the bundle by traversing the
|
|
35
|
-
* dependency graph.
|
|
36
|
-
* Instead of traversing the whole graph each time, it just calculates the
|
|
37
|
-
* difference between runs by only traversing the added/removed dependencies.
|
|
38
|
-
* To do so, it uses the passed passed graph dependencies and it mutates it.
|
|
39
|
-
* The paths parameter contains the absolute paths of the root files that the
|
|
40
|
-
* method should traverse. Normally, these paths should be the modified files
|
|
41
|
-
* since the last traversal.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
async function traverseDependencies(paths, graph, options) {
|
|
45
|
-
const delta = {
|
|
46
|
-
added: new Set(),
|
|
47
|
-
modified: new Set(),
|
|
48
|
-
deleted: new Set(),
|
|
49
|
-
inverseDependencies: new Map(),
|
|
50
|
-
};
|
|
51
|
-
const internalOptions = getInternalOptions(options);
|
|
52
|
-
|
|
53
|
-
for (const path of paths) {
|
|
54
|
-
// Only process the path if it's part of the dependency graph. It's possible
|
|
55
|
-
// that this method receives a path that is no longer part of it (e.g if a
|
|
56
|
-
// module gets removed from the dependency graph and just afterwards it gets
|
|
57
|
-
// modified), and we have to ignore these cases.
|
|
58
|
-
if (graph.dependencies.get(path)) {
|
|
59
|
-
delta.modified.add(path);
|
|
60
|
-
await traverseDependenciesForSingleFile(
|
|
61
|
-
path,
|
|
62
|
-
graph,
|
|
63
|
-
delta,
|
|
64
|
-
internalOptions
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const added = new Map();
|
|
70
|
-
const modified = new Map();
|
|
71
|
-
const deleted = new Set();
|
|
72
|
-
|
|
73
|
-
for (const path of delta.deleted) {
|
|
74
|
-
// If a dependency has been marked both as added and deleted, it means that
|
|
75
|
-
// this is a renamed file (or that dependency has been removed from one path
|
|
76
|
-
// but added back in a different path). In this case the addition and
|
|
77
|
-
// deletion "get cancelled".
|
|
78
|
-
if (!delta.added.has(path)) {
|
|
79
|
-
deleted.add(path);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
delta.modified.delete(path);
|
|
83
|
-
delta.added.delete(path);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
for (const path of delta.added) {
|
|
87
|
-
added.set(path, nullthrows(graph.dependencies.get(path)));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
for (const path of delta.modified) {
|
|
91
|
-
// Similarly to the above, a file can be marked as both added and modified
|
|
92
|
-
// when its path and dependencies have changed. In this case, we only
|
|
93
|
-
// consider the addition.
|
|
94
|
-
if (!delta.added.has(path)) {
|
|
95
|
-
modified.set(path, nullthrows(graph.dependencies.get(path)));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
added,
|
|
101
|
-
modified,
|
|
102
|
-
deleted,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async function initialTraverseDependencies(graph, options) {
|
|
107
|
-
const delta = {
|
|
108
|
-
added: new Set(),
|
|
109
|
-
modified: new Set(),
|
|
110
|
-
deleted: new Set(),
|
|
111
|
-
inverseDependencies: new Map(),
|
|
112
|
-
};
|
|
113
|
-
const internalOptions = getInternalOptions(options);
|
|
114
|
-
await Promise.all(
|
|
115
|
-
graph.entryPoints.map((path) =>
|
|
116
|
-
traverseDependenciesForSingleFile(path, graph, delta, internalOptions)
|
|
117
|
-
)
|
|
118
|
-
);
|
|
119
|
-
reorderGraph(graph, {
|
|
120
|
-
shallow: options.shallow,
|
|
121
|
-
});
|
|
122
|
-
return {
|
|
123
|
-
added: graph.dependencies,
|
|
124
|
-
modified: new Map(),
|
|
125
|
-
deleted: new Set(),
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function traverseDependenciesForSingleFile(path, graph, delta, options) {
|
|
130
|
-
options.onDependencyAdd();
|
|
131
|
-
await processModule(path, graph, delta, options);
|
|
132
|
-
options.onDependencyAdded();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function processModule(path, graph, delta, options) {
|
|
136
|
-
// Transform the file via the given option.
|
|
137
|
-
const result = await options.transform(path); // Get the absolute path of all sub-dependencies (some of them could have been
|
|
138
|
-
// moved but maintain the same relative path).
|
|
139
|
-
|
|
140
|
-
const currentDependencies = resolveDependencies(
|
|
141
|
-
path,
|
|
142
|
-
result.dependencies,
|
|
143
|
-
options
|
|
144
|
-
);
|
|
145
|
-
const previousModule = graph.dependencies.get(path) || {
|
|
146
|
-
inverseDependencies: delta.inverseDependencies.get(path) || new Set(),
|
|
147
|
-
path,
|
|
148
|
-
};
|
|
149
|
-
const previousDependencies = previousModule.dependencies || new Map(); // Update the module information.
|
|
150
|
-
|
|
151
|
-
const module = {
|
|
152
|
-
...previousModule,
|
|
153
|
-
dependencies: new Map(),
|
|
154
|
-
getSource: result.getSource,
|
|
155
|
-
output: result.output,
|
|
156
|
-
};
|
|
157
|
-
graph.dependencies.set(module.path, module);
|
|
158
|
-
|
|
159
|
-
for (const [relativePath, dependency] of currentDependencies) {
|
|
160
|
-
module.dependencies.set(relativePath, dependency);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
Array.from(previousDependencies.entries())
|
|
164
|
-
.filter(
|
|
165
|
-
([relativePath, dependency]) =>
|
|
166
|
-
!currentDependencies.has(relativePath) ||
|
|
167
|
-
nullthrows(currentDependencies.get(relativePath)).absolutePath !==
|
|
168
|
-
dependency.absolutePath
|
|
169
|
-
)
|
|
170
|
-
.forEach(([relativePath, dependency]) =>
|
|
171
|
-
removeDependency(module, dependency.absolutePath, graph, delta, new Set())
|
|
172
|
-
); // Check all the module dependencies and start traversing the tree from each
|
|
173
|
-
// added and removed dependency, to get all the modules that have to be added
|
|
174
|
-
// and removed from the dependency graph.
|
|
175
|
-
|
|
176
|
-
const promises = [];
|
|
177
|
-
|
|
178
|
-
for (const [relativePath, dependency] of currentDependencies) {
|
|
179
|
-
if (!options.shallow) {
|
|
180
|
-
if (
|
|
181
|
-
options.experimentalImportBundleSupport &&
|
|
182
|
-
dependency.data.data.asyncType != null
|
|
183
|
-
) {
|
|
184
|
-
graph.importBundleNames.add(dependency.absolutePath);
|
|
185
|
-
} else if (
|
|
186
|
-
!previousDependencies.has(relativePath) ||
|
|
187
|
-
nullthrows(previousDependencies.get(relativePath)).absolutePath !==
|
|
188
|
-
dependency.absolutePath
|
|
189
|
-
) {
|
|
190
|
-
promises.push(
|
|
191
|
-
addDependency(module, dependency.absolutePath, graph, delta, options)
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
try {
|
|
198
|
-
await Promise.all(promises);
|
|
199
|
-
} catch (err) {
|
|
200
|
-
// If there is an error, restore the previous dependency list.
|
|
201
|
-
// This ensures we don't skip over them during the next traversal attempt.
|
|
202
|
-
// $FlowFixMe[cannot-write]
|
|
203
|
-
module.dependencies = previousDependencies;
|
|
204
|
-
throw err;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return module;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async function addDependency(parentModule, path, graph, delta, options) {
|
|
211
|
-
// The new dependency was already in the graph, we don't need to do anything.
|
|
212
|
-
const existingModule = graph.dependencies.get(path);
|
|
213
|
-
|
|
214
|
-
if (existingModule) {
|
|
215
|
-
existingModule.inverseDependencies.add(parentModule.path);
|
|
216
|
-
return;
|
|
217
|
-
} // This module is being transformed at the moment in parallel, so we should
|
|
218
|
-
// only mark its parent as an inverse dependency.
|
|
219
|
-
|
|
220
|
-
const inverse = delta.inverseDependencies.get(path);
|
|
221
|
-
|
|
222
|
-
if (inverse) {
|
|
223
|
-
inverse.add(parentModule.path);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
delta.added.add(path);
|
|
228
|
-
delta.inverseDependencies.set(path, new Set([parentModule.path]));
|
|
229
|
-
options.onDependencyAdd();
|
|
230
|
-
const module = await processModule(path, graph, delta, options);
|
|
231
|
-
graph.dependencies.set(module.path, module);
|
|
232
|
-
module.inverseDependencies.add(parentModule.path);
|
|
233
|
-
options.onDependencyAdded();
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Recursively look up `inverseDependencies` until it is empty,
|
|
237
|
-
* returning a set of paths for the last module that does not have
|
|
238
|
-
* `inverseDependencies`.
|
|
239
|
-
*/
|
|
240
|
-
|
|
241
|
-
function getAllTopLevelInverseDependencies(
|
|
242
|
-
inverseDependencies,
|
|
243
|
-
graph,
|
|
244
|
-
currModule,
|
|
245
|
-
visited
|
|
246
|
-
) {
|
|
247
|
-
if (visited.has(currModule)) {
|
|
248
|
-
return new Set();
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
visited.add(currModule);
|
|
252
|
-
|
|
253
|
-
if (!inverseDependencies.size) {
|
|
254
|
-
return new Set([currModule]);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return Array.from(inverseDependencies)
|
|
258
|
-
.filter((inverseDep) => graph.dependencies.has(inverseDep))
|
|
259
|
-
.reduce((acc, inverseDep) => {
|
|
260
|
-
const mod = graph.dependencies.get(inverseDep);
|
|
261
|
-
|
|
262
|
-
if (!mod) {
|
|
263
|
-
return acc;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
getAllTopLevelInverseDependencies(
|
|
267
|
-
mod.inverseDependencies,
|
|
268
|
-
graph,
|
|
269
|
-
inverseDep,
|
|
270
|
-
visited
|
|
271
|
-
).forEach((x) => {
|
|
272
|
-
acc.add(x);
|
|
273
|
-
});
|
|
274
|
-
return acc;
|
|
275
|
-
}, new Set());
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Given `inverseDependencies`, tracing back inverse dependencies to
|
|
279
|
-
* see if it only leads back to `parentModule`.
|
|
280
|
-
*/
|
|
281
|
-
|
|
282
|
-
function canSafelyRemoveFromParentModule(
|
|
283
|
-
inverseDependencies,
|
|
284
|
-
parentModule,
|
|
285
|
-
graph,
|
|
286
|
-
canBeRemovedSafely,
|
|
287
|
-
delta
|
|
288
|
-
) {
|
|
289
|
-
const visited = new Set();
|
|
290
|
-
const topInverseDependencies = getAllTopLevelInverseDependencies(
|
|
291
|
-
inverseDependencies,
|
|
292
|
-
graph,
|
|
293
|
-
"", // current module name
|
|
294
|
-
visited
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
if (!topInverseDependencies.size) {
|
|
298
|
-
/**
|
|
299
|
-
* This happens when parentModule and inverseDependencies have a circular dependency.
|
|
300
|
-
* This will eventually become an empty set due to the `visited` Set being the
|
|
301
|
-
* base case for the recursive call.
|
|
302
|
-
*/
|
|
303
|
-
return true;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
const undeletedInverseDependencies = Array.from(
|
|
307
|
-
topInverseDependencies
|
|
308
|
-
).filter((x) => !delta.deleted.has(x));
|
|
309
|
-
/**
|
|
310
|
-
* We can only mark the `visited` Set of modules to be safely removable if
|
|
311
|
-
* 1. We do not have top a level module to compare with parentModule.
|
|
312
|
-
* This can happen when trying to see if we can safely remove from
|
|
313
|
-
* a module that was deleted. This is why we filtered them out with `delta.deleted`
|
|
314
|
-
* 2. We have one top module and it is parentModule
|
|
315
|
-
*/
|
|
316
|
-
|
|
317
|
-
const canSafelyRemove =
|
|
318
|
-
!undeletedInverseDependencies.length ||
|
|
319
|
-
(undeletedInverseDependencies.length === 1 &&
|
|
320
|
-
undeletedInverseDependencies[0] === parentModule);
|
|
321
|
-
|
|
322
|
-
if (canSafelyRemove) {
|
|
323
|
-
visited.forEach((mod) => {
|
|
324
|
-
canBeRemovedSafely.add(mod);
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return canSafelyRemove;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function removeDependency(
|
|
332
|
-
parentModule,
|
|
333
|
-
absolutePath,
|
|
334
|
-
graph,
|
|
335
|
-
delta, // We use `canBeRemovedSafely` set to keep track of visited
|
|
336
|
-
// module(s) that we're sure can be removed. This will skip expensive
|
|
337
|
-
// inverse dependency traversals.
|
|
338
|
-
canBeRemovedSafely = new Set()
|
|
339
|
-
) {
|
|
340
|
-
const module = graph.dependencies.get(absolutePath);
|
|
341
|
-
|
|
342
|
-
if (!module) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
module.inverseDependencies.delete(parentModule.path); // Even if there are modules still using parentModule, we want to ensure
|
|
347
|
-
// there is no circular dependency. Thus, we check if it can be safely removed
|
|
348
|
-
// by tracing back the inverseDependencies.
|
|
349
|
-
|
|
350
|
-
if (!canBeRemovedSafely.has(module.path)) {
|
|
351
|
-
if (
|
|
352
|
-
module.inverseDependencies.size &&
|
|
353
|
-
!canSafelyRemoveFromParentModule(
|
|
354
|
-
module.inverseDependencies,
|
|
355
|
-
module.path,
|
|
356
|
-
graph,
|
|
357
|
-
canBeRemovedSafely,
|
|
358
|
-
delta
|
|
359
|
-
)
|
|
360
|
-
) {
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
delta.deleted.add(module.path); // Now we need to iterate through the module dependencies in order to
|
|
366
|
-
// clean up everything (we cannot read the module because it may have
|
|
367
|
-
// been deleted).
|
|
368
|
-
|
|
369
|
-
Array.from(module.dependencies.values())
|
|
370
|
-
.filter(
|
|
371
|
-
(dependency) =>
|
|
372
|
-
!delta.deleted.has(dependency.absolutePath) &&
|
|
373
|
-
dependency.absolutePath !== parentModule.path
|
|
374
|
-
)
|
|
375
|
-
.forEach((dependency) =>
|
|
376
|
-
removeDependency(
|
|
377
|
-
module,
|
|
378
|
-
dependency.absolutePath,
|
|
379
|
-
graph,
|
|
380
|
-
delta,
|
|
381
|
-
canBeRemovedSafely
|
|
382
|
-
)
|
|
383
|
-
); // This module is not used anywhere else!! we can clear it from the bundle
|
|
384
|
-
|
|
385
|
-
graph.dependencies.delete(module.path);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function resolveDependencies(parentPath, dependencies, options) {
|
|
389
|
-
const resolve = (parentPath, result) => {
|
|
390
|
-
const relativePath = result.name;
|
|
391
|
-
|
|
392
|
-
try {
|
|
393
|
-
return [
|
|
394
|
-
relativePath,
|
|
395
|
-
{
|
|
396
|
-
absolutePath: options.resolve(parentPath, relativePath),
|
|
397
|
-
data: result,
|
|
398
|
-
},
|
|
399
|
-
];
|
|
400
|
-
} catch (error) {
|
|
401
|
-
// Ignore unavailable optional dependencies. They are guarded
|
|
402
|
-
// with a try-catch block and will be handled during runtime.
|
|
403
|
-
if (result.data.isOptional !== true) {
|
|
404
|
-
throw error;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
return undefined;
|
|
409
|
-
};
|
|
410
|
-
|
|
411
|
-
const resolved = dependencies.reduce((list, result) => {
|
|
412
|
-
const resolvedPath = resolve(parentPath, result);
|
|
413
|
-
|
|
414
|
-
if (resolvedPath) {
|
|
415
|
-
list.push(resolvedPath);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return list;
|
|
419
|
-
}, []);
|
|
420
|
-
return new Map(resolved);
|
|
421
|
-
}
|
|
422
|
-
/**
|
|
423
|
-
* Re-traverse the dependency graph in DFS order to reorder the modules and
|
|
424
|
-
* guarantee the same order between runs. This method mutates the passed graph.
|
|
425
|
-
*/
|
|
426
|
-
|
|
427
|
-
function reorderGraph(graph, options) {
|
|
428
|
-
const orderedDependencies = new Map();
|
|
429
|
-
graph.entryPoints.forEach((entryPoint) => {
|
|
430
|
-
const mainModule = graph.dependencies.get(entryPoint);
|
|
431
|
-
|
|
432
|
-
if (!mainModule) {
|
|
433
|
-
throw new ReferenceError("Module not registered in graph: " + entryPoint);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
reorderDependencies(graph, mainModule, orderedDependencies, options);
|
|
437
|
-
});
|
|
438
|
-
graph.dependencies = orderedDependencies;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function reorderDependencies(graph, module, orderedDependencies, options) {
|
|
442
|
-
if (module.path) {
|
|
443
|
-
if (orderedDependencies.has(module.path)) {
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
orderedDependencies.set(module.path, module);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
module.dependencies.forEach((dependency) => {
|
|
451
|
-
const path = dependency.absolutePath;
|
|
452
|
-
const childModule = graph.dependencies.get(path);
|
|
453
|
-
|
|
454
|
-
if (!childModule) {
|
|
455
|
-
if (dependency.data.data.asyncType != null || options.shallow) {
|
|
456
|
-
return;
|
|
457
|
-
} else {
|
|
458
|
-
throw new ReferenceError("Module not registered in graph: " + path);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
reorderDependencies(graph, childModule, orderedDependencies, options);
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
module.exports = {
|
|
467
|
-
initialTraverseDependencies,
|
|
468
|
-
traverseDependencies,
|
|
469
|
-
reorderGraph,
|
|
470
|
-
};
|