metro 0.80.4 → 0.80.6
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 +16 -17
- package/src/Assets.js +0 -35
- package/src/Bundler/util.js +1 -29
- package/src/Bundler.js +1 -20
- package/src/DeltaBundler/DeltaCalculator.js +0 -86
- package/src/DeltaBundler/Graph.js +0 -197
- package/src/DeltaBundler/Serializers/baseJSBundle.js +0 -13
- package/src/DeltaBundler/Serializers/getAllFiles.js +0 -11
- package/src/DeltaBundler/Serializers/getAssets.js +0 -11
- package/src/DeltaBundler/Serializers/getExplodedSourceMap.js +0 -11
- package/src/DeltaBundler/Serializers/getRamBundleInfo.js +0 -18
- package/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js +0 -11
- package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +0 -11
- package/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js +0 -14
- package/src/DeltaBundler/Serializers/helpers/js.js +0 -21
- package/src/DeltaBundler/Serializers/helpers/processModules.js +0 -11
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +0 -23
- package/src/DeltaBundler/Serializers/sourceMapGenerator.js +0 -16
- package/src/DeltaBundler/Serializers/sourceMapObject.js +0 -11
- package/src/DeltaBundler/Serializers/sourceMapString.js +0 -11
- package/src/DeltaBundler/Transformer.js +0 -30
- package/src/DeltaBundler/Worker.flow.js +0 -26
- package/src/DeltaBundler/Worker.flow.js.flow +2 -2
- package/src/DeltaBundler/Worker.js +0 -14
- package/src/DeltaBundler/WorkerFarm.js +1 -21
- package/src/DeltaBundler/__fixtures__/hasteImpl.js +0 -14
- package/src/DeltaBundler/buildSubgraph.js +0 -24
- package/src/DeltaBundler/getTransformCacheKey.js +0 -13
- package/src/DeltaBundler/getTransformCacheKey.js.flow +1 -1
- package/src/DeltaBundler/mergeDeltas.js +0 -11
- package/src/DeltaBundler/types.flow.js +0 -11
- package/src/DeltaBundler.js +0 -21
- package/src/HmrServer.js +8 -39
- package/src/HmrServer.js.flow +8 -6
- package/src/IncrementalBundler/GraphNotFoundError.js +0 -11
- package/src/IncrementalBundler/ResourceNotFoundError.js +0 -11
- package/src/IncrementalBundler/RevisionNotFoundError.js +0 -11
- package/src/IncrementalBundler.js +0 -23
- package/src/ModuleGraph/test-helpers.js +0 -17
- package/src/ModuleGraph/worker/JsFileWrapping.js +1 -22
- package/src/ModuleGraph/worker/collectDependencies.js +1 -94
- package/src/ModuleGraph/worker/generateImportNames.js +0 -15
- package/src/Server/MultipartResponse.js +0 -13
- package/src/Server/symbolicate.js +2 -36
- package/src/Server.js +6 -83
- package/src/cli/parseKeyValueParamArray.js +0 -11
- package/src/cli-utils.js +0 -11
- package/src/cli.js +0 -13
- package/src/commands/build.js +0 -15
- package/src/commands/dependencies.js +1 -19
- package/src/commands/serve.js +0 -19
- package/src/index.flow.js +0 -31
- package/src/index.js +0 -14
- package/src/integration_tests/basic_bundle/AssetRegistry.js +0 -10
- package/src/integration_tests/basic_bundle/Bar.js +0 -10
- package/src/integration_tests/basic_bundle/ErrorBundle.js +0 -12
- package/src/integration_tests/basic_bundle/Foo.js +0 -10
- package/src/integration_tests/basic_bundle/TestBigInt.js +0 -12
- package/src/integration_tests/basic_bundle/TestBundle.js +0 -11
- package/src/integration_tests/basic_bundle/TestPolyfill.js +0 -10
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js +0 -14
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js +0 -14
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js +0 -14
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js +1 -15
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js +0 -13
- package/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js +0 -16
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js +0 -14
- package/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js +0 -13
- package/src/integration_tests/basic_bundle/import-export/export-1.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-2.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-3.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-4.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-5.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-6.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-null.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/export-primitive-default.js +0 -10
- package/src/integration_tests/basic_bundle/import-export/index.js +0 -10
- package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js +0 -10
- package/src/integration_tests/basic_bundle/polyfill.js +0 -12
- package/src/integration_tests/basic_bundle/require-context/conflict.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/empty.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/matching.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/mode-eager.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/mode-lazy.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/mode-sync.js +0 -11
- package/src/integration_tests/basic_bundle/require-context/subdir/a.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/subdir/b.js +0 -9
- package/src/integration_tests/basic_bundle/require-context/subdir/c.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js +0 -10
- package/src/integration_tests/basic_bundle/require-context/utils.js +0 -10
- package/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js +0 -15
- package/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js +0 -10
- package/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js +0 -10
- package/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js +0 -15
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js +0 -10
- package/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js +0 -10
- package/src/integration_tests/execBundle.js +0 -11
- package/src/integration_tests/metro.config.js +0 -10
- package/src/lib/BatchProcessor.js +0 -23
- package/src/lib/CountingSet.js +0 -35
- package/src/lib/JsonReporter.js +0 -17
- package/src/lib/RamBundleParser.js +0 -23
- package/src/lib/TerminalReporter.js +0 -68
- package/src/lib/bundleToString.js +1 -19
- package/src/lib/contextModule.js +1 -31
- package/src/lib/contextModuleTemplates.js +0 -36
- package/src/lib/countLines.js +0 -11
- package/src/lib/createModuleIdFactory.js +0 -11
- package/src/lib/createWebsocketServer.js +0 -24
- package/src/lib/debounceAsyncQueue.js +0 -13
- package/src/lib/formatBundlingError.js +0 -14
- package/src/lib/getAppendScripts.js +0 -11
- package/src/lib/getGraphId.js +0 -11
- package/src/lib/getMaxWorkers.js +0 -11
- package/src/lib/getPreludeCode.js +0 -18
- package/src/lib/getPrependedScripts.js +0 -13
- package/src/lib/logToConsole.js +0 -18
- package/src/lib/parseCustomResolverOptions.js +0 -11
- package/src/lib/parseCustomTransformOptions.js +0 -12
- package/src/lib/parseOptionsFromUrl.js +1 -17
- package/src/lib/relativizeSourceMap.js +0 -12
- package/src/lib/reporting.js +0 -30
- package/src/lib/splitBundleOptions.js +0 -14
- package/src/lib/transformHelpers.js +0 -20
- package/src/node-haste/DependencyGraph/ModuleResolution.js +5 -64
- package/src/node-haste/DependencyGraph/createFileMap.js +0 -16
- package/src/node-haste/DependencyGraph.js +6 -46
- package/src/node-haste/DependencyGraph.js.flow +7 -4
- package/src/node-haste/Module.js +0 -11
- package/src/node-haste/ModuleCache.js +0 -20
- package/src/node-haste/Package.js +0 -11
- package/src/node-haste/lib/AssetPaths.js +0 -16
- package/src/node-haste/lib/parsePlatformFilePath.js +0 -16
- package/src/shared/output/RamBundle/as-assets.js +6 -29
- package/src/shared/output/RamBundle/as-indexed-file.js +0 -44
- package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js +0 -13
- package/src/shared/output/RamBundle/magic-number.js +0 -11
- package/src/shared/output/RamBundle/util.js +1 -17
- package/src/shared/output/RamBundle/write-sourcemap.js +0 -12
- package/src/shared/output/RamBundle.js +0 -14
- package/src/shared/output/bundle.flow.js +0 -13
- package/src/shared/output/bundle.flow.js.flow +1 -1
- package/src/shared/output/bundle.js +0 -14
- package/src/shared/output/meta.js +0 -11
- package/src/shared/output/unbundle.js +0 -13
- package/src/shared/output/writeFile.js +0 -11
- package/src/shared/types.flow.js +0 -11
|
@@ -10,42 +10,8 @@ var _buildSubgraph = require("./buildSubgraph");
|
|
|
10
10
|
function _interopRequireDefault(obj) {
|
|
11
11
|
return obj && obj.__esModule ? obj : { default: obj };
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
15
|
-
*
|
|
16
|
-
* This source code is licensed under the MIT license found in the
|
|
17
|
-
* LICENSE file in the root directory of this source tree.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @format
|
|
21
|
-
* @oncall react_native
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Portions of this code are based on the Synchronous Cycle Collection
|
|
26
|
-
* algorithm described in:
|
|
27
|
-
*
|
|
28
|
-
* David F. Bacon and V. T. Rajan. 2001. Concurrent Cycle Collection in
|
|
29
|
-
* Reference Counted Systems. In Proceedings of the 15th European Conference on
|
|
30
|
-
* Object-Oriented Programming (ECOOP '01). Springer-Verlag, Berlin,
|
|
31
|
-
* Heidelberg, 207–235.
|
|
32
|
-
*
|
|
33
|
-
* Notable differences from the algorithm in the paper:
|
|
34
|
-
* 1. Our implementation uses the inverseDependencies set (which we already
|
|
35
|
-
* have to maintain) instead of a separate refcount variable. A module's
|
|
36
|
-
* reference count is equal to the size of its inverseDependencies set, plus
|
|
37
|
-
* 1 if it's an entry point of the graph.
|
|
38
|
-
* 2. We keep the "root buffer" (possibleCycleRoots) free of duplicates by
|
|
39
|
-
* making it a Set, instead of storing a "buffered" flag on each node.
|
|
40
|
-
* 3. On top of tracking edges between nodes, we also count references between
|
|
41
|
-
* nodes and entries in the importBundleNodes set.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
13
|
const invariant = require("invariant");
|
|
45
14
|
const nullthrows = require("nullthrows");
|
|
46
|
-
|
|
47
|
-
// TODO: Convert to a Flow enum
|
|
48
|
-
|
|
49
15
|
function getInternalOptions({ transform, resolve, onProgress, lazy, shallow }) {
|
|
50
16
|
let numProcessed = 0;
|
|
51
17
|
let total = 0;
|
|
@@ -65,31 +31,15 @@ function isWeakOrLazy(dependency, options) {
|
|
|
65
31
|
class Graph {
|
|
66
32
|
dependencies = new Map();
|
|
67
33
|
#importBundleNodes = new Map();
|
|
68
|
-
|
|
69
|
-
/// GC state for nodes in the graph (this.dependencies)
|
|
70
34
|
#gc = {
|
|
71
35
|
color: new Map(),
|
|
72
36
|
possibleCycleRoots: new Set(),
|
|
73
37
|
};
|
|
74
|
-
|
|
75
|
-
/** Resolved context parameters from `require.context`. */
|
|
76
38
|
#resolvedContexts = new Map();
|
|
77
39
|
constructor(options) {
|
|
78
40
|
this.entryPoints = options.entryPoints;
|
|
79
41
|
this.transformOptions = options.transformOptions;
|
|
80
42
|
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Dependency Traversal logic for the Delta Bundler. This method calculates
|
|
84
|
-
* the modules that should be included in the bundle by traversing the
|
|
85
|
-
* dependency graph.
|
|
86
|
-
* Instead of traversing the whole graph each time, it just calculates the
|
|
87
|
-
* difference between runs by only traversing the added/removed dependencies.
|
|
88
|
-
* To do so, it uses the passed graph dependencies and it mutates it.
|
|
89
|
-
* The paths parameter contains the absolute paths of the root files that the
|
|
90
|
-
* method should traverse. Normally, these paths should be the modified files
|
|
91
|
-
* since the last traversal.
|
|
92
|
-
*/
|
|
93
43
|
async traverseDependencies(paths, options) {
|
|
94
44
|
const internalOptions = getInternalOptions(options);
|
|
95
45
|
const modifiedPathsInBaseGraph = new Set(
|
|
@@ -99,16 +49,10 @@ class Graph {
|
|
|
99
49
|
const delta = await this._buildDelta(
|
|
100
50
|
modifiedPathsInBaseGraph,
|
|
101
51
|
internalOptions,
|
|
102
|
-
// Traverse new or modified paths
|
|
103
52
|
(absolutePath) =>
|
|
104
53
|
!this.dependencies.has(absolutePath) ||
|
|
105
54
|
allModifiedPaths.has(absolutePath)
|
|
106
55
|
);
|
|
107
|
-
|
|
108
|
-
// If we have errors we might need to roll back any changes - take
|
|
109
|
-
// snapshots of all modified modules at the base state. We'll also snapshot
|
|
110
|
-
// unmodified modules that become unreachable as they are released, so that
|
|
111
|
-
// we have everything we need to restore the graph to base.
|
|
112
56
|
if (delta.errors.size > 0) {
|
|
113
57
|
for (const modified of modifiedPathsInBaseGraph) {
|
|
114
58
|
delta.baseModuleData.set(
|
|
@@ -117,48 +61,28 @@ class Graph {
|
|
|
117
61
|
);
|
|
118
62
|
}
|
|
119
63
|
}
|
|
120
|
-
|
|
121
|
-
// Commit changes in a subtractive pass and then an additive pass - this
|
|
122
|
-
// ensures that any errors encountered on the additive pass would also be
|
|
123
|
-
// encountered on a fresh build (implying legitimate errors in the graph,
|
|
124
|
-
// rather than an error in a module that's no longer reachable).
|
|
125
64
|
for (const modified of modifiedPathsInBaseGraph) {
|
|
126
|
-
// Skip this module if it has errors. Hopefully it will be removed -
|
|
127
|
-
// if not, we'll throw during the additive pass.
|
|
128
65
|
if (delta.errors.has(modified)) {
|
|
129
66
|
continue;
|
|
130
67
|
}
|
|
131
68
|
const module = this.dependencies.get(modified);
|
|
132
|
-
// The module may have already been released from the graph - we'll readd
|
|
133
|
-
// it if necessary later.
|
|
134
69
|
if (module == null) {
|
|
135
70
|
continue;
|
|
136
71
|
}
|
|
137
|
-
// Process the transform result and dependency removals. This should
|
|
138
|
-
// never encounter an error.
|
|
139
72
|
this._recursivelyCommitModule(modified, delta, internalOptions, {
|
|
140
73
|
onlyRemove: true,
|
|
141
74
|
});
|
|
142
75
|
}
|
|
143
|
-
|
|
144
|
-
// Ensure we have released any unreachable modules before the additive
|
|
145
|
-
// pass.
|
|
146
76
|
this._collectCycles(delta, internalOptions);
|
|
147
|
-
|
|
148
|
-
// Additive pass - any errors we encounter here should be thrown after
|
|
149
|
-
// rolling back the commit.
|
|
150
77
|
try {
|
|
151
78
|
for (const modified of modifiedPathsInBaseGraph) {
|
|
152
79
|
const module = this.dependencies.get(modified);
|
|
153
|
-
// The module may have already been released from the graph (it may yet
|
|
154
|
-
// be readded via another dependency).
|
|
155
80
|
if (module == null) {
|
|
156
81
|
continue;
|
|
157
82
|
}
|
|
158
83
|
this._recursivelyCommitModule(modified, delta, internalOptions);
|
|
159
84
|
}
|
|
160
85
|
} catch (error) {
|
|
161
|
-
// Roll back to base before re-throwing.
|
|
162
86
|
const rollbackDelta = {
|
|
163
87
|
added: delta.added,
|
|
164
88
|
deleted: delta.deleted,
|
|
@@ -169,26 +93,16 @@ class Graph {
|
|
|
169
93
|
};
|
|
170
94
|
for (const modified of modifiedPathsInBaseGraph) {
|
|
171
95
|
const module = this.dependencies.get(modified);
|
|
172
|
-
// The module may have already been released from the graph (it may yet
|
|
173
|
-
// be readded via another dependency).
|
|
174
96
|
if (module == null) {
|
|
175
97
|
continue;
|
|
176
98
|
}
|
|
177
|
-
// Set the module and descendants back to base state.
|
|
178
99
|
this._recursivelyCommitModule(modified, rollbackDelta, internalOptions);
|
|
179
100
|
}
|
|
180
|
-
// Collect cycles again after rolling back. There's no need if we're
|
|
181
|
-
// not rolling back, because we have not removed any edges.
|
|
182
101
|
this._collectCycles(delta, internalOptions);
|
|
183
|
-
|
|
184
|
-
// Cheap check to validate the rollback.
|
|
185
102
|
invariant(
|
|
186
103
|
rollbackDelta.added.size === 0 && rollbackDelta.deleted.size === 0,
|
|
187
104
|
"attempted to roll back a graph commit but there were still changes"
|
|
188
105
|
);
|
|
189
|
-
|
|
190
|
-
// Re-throw the transform or resolution error originally seen by
|
|
191
|
-
// `buildSubgraph`.
|
|
192
106
|
throw error;
|
|
193
107
|
}
|
|
194
108
|
const added = new Map();
|
|
@@ -221,19 +135,13 @@ class Graph {
|
|
|
221
135
|
this.#gc.possibleCycleRoots.clear();
|
|
222
136
|
this.#importBundleNodes.clear();
|
|
223
137
|
for (const path of this.entryPoints) {
|
|
224
|
-
// Each entry point implicitly has a refcount of 1, so mark them all black.
|
|
225
138
|
this.#gc.color.set(path, "black");
|
|
226
139
|
}
|
|
227
140
|
const delta = await this._buildDelta(this.entryPoints, internalOptions);
|
|
228
141
|
if (delta.errors.size > 0) {
|
|
229
|
-
// If we encountered any errors during traversal, throw one of them.
|
|
230
|
-
// Since errors are encountered in a non-deterministic order, even on
|
|
231
|
-
// fresh builds, it's valid to arbitrarily pick the first.
|
|
232
142
|
throw delta.errors.values().next().value;
|
|
233
143
|
}
|
|
234
144
|
for (const path of this.entryPoints) {
|
|
235
|
-
// We have already thrown on userland errors in the delta, so any error
|
|
236
|
-
// encountered here would be exceptional and fatal.
|
|
237
145
|
this._recursivelyCommitModule(path, delta, internalOptions);
|
|
238
146
|
}
|
|
239
147
|
this.reorderGraph({
|
|
@@ -303,22 +211,14 @@ class Graph {
|
|
|
303
211
|
...transformResult,
|
|
304
212
|
dependencies: new Map(previousDependencies),
|
|
305
213
|
};
|
|
306
|
-
|
|
307
|
-
// Update the module information.
|
|
308
214
|
this.dependencies.set(nextModule.path, nextModule);
|
|
309
215
|
if (previousModule == null) {
|
|
310
|
-
// If the module is not currently in the graph, it is either new or was
|
|
311
|
-
// released earlier in the commit.
|
|
312
216
|
if (delta.deleted.has(path)) {
|
|
313
|
-
// Mark the addition by clearing a prior deletion.
|
|
314
217
|
delta.deleted.delete(path);
|
|
315
218
|
} else {
|
|
316
|
-
// Mark the addition in the added set.
|
|
317
219
|
delta.added.add(path);
|
|
318
220
|
}
|
|
319
221
|
}
|
|
320
|
-
|
|
321
|
-
// Diff dependencies (1/3): remove dependencies that have changed or been removed.
|
|
322
222
|
let dependenciesRemoved = false;
|
|
323
223
|
for (const [key, prevDependency] of previousDependencies) {
|
|
324
224
|
const curDependency = currentDependencies.get(key);
|
|
@@ -330,8 +230,6 @@ class Graph {
|
|
|
330
230
|
this._removeDependency(nextModule, key, prevDependency, delta, options);
|
|
331
231
|
}
|
|
332
232
|
}
|
|
333
|
-
|
|
334
|
-
// Diff dependencies (2/3): add dependencies that have changed or been added.
|
|
335
233
|
let dependenciesAdded = false;
|
|
336
234
|
if (!commitOptions.onlyRemove) {
|
|
337
235
|
for (const [key, curDependency] of currentDependencies) {
|
|
@@ -352,9 +250,6 @@ class Graph {
|
|
|
352
250
|
}
|
|
353
251
|
}
|
|
354
252
|
}
|
|
355
|
-
|
|
356
|
-
// Diff dependencies (3/3): detect changes in the ordering of dependency
|
|
357
|
-
// keys, which must be committed even if no other changes were made.
|
|
358
253
|
const previousDependencyKeys = [...previousDependencies.keys()];
|
|
359
254
|
const dependencyKeysChangedOrReordered =
|
|
360
255
|
currentDependencies.size !== previousDependencies.size ||
|
|
@@ -368,25 +263,13 @@ class Graph {
|
|
|
368
263
|
!dependenciesAdded &&
|
|
369
264
|
!dependencyKeysChangedOrReordered
|
|
370
265
|
) {
|
|
371
|
-
// We have not operated on nextModule, so restore previousModule
|
|
372
|
-
// to aid diffing. Don't add this path to delta.touched.
|
|
373
266
|
this.dependencies.set(previousModule.path, previousModule);
|
|
374
267
|
return previousModule;
|
|
375
268
|
}
|
|
376
269
|
delta.touched.add(path);
|
|
377
|
-
|
|
378
|
-
// Replace dependencies with the correctly-ordered version, matching the
|
|
379
|
-
// transform output. Because this assignment does not add or remove edges,
|
|
380
|
-
// it does NOT invalidate any of the garbage collection state.
|
|
381
|
-
|
|
382
|
-
// A subtractive pass only partially commits modules, so our dependencies
|
|
383
|
-
// are not generally complete yet. We'll address ordering in the next pass
|
|
384
|
-
// after processing additions.
|
|
385
270
|
if (commitOptions.onlyRemove) {
|
|
386
271
|
return nextModule;
|
|
387
272
|
}
|
|
388
|
-
|
|
389
|
-
// Catch obvious errors with a cheap assertion.
|
|
390
273
|
invariant(
|
|
391
274
|
nextModule.dependencies.size === currentDependencies.size,
|
|
392
275
|
"Failed to add the correct dependencies"
|
|
@@ -403,27 +286,16 @@ class Graph {
|
|
|
403
286
|
options
|
|
404
287
|
) {
|
|
405
288
|
const path = dependency.absolutePath;
|
|
406
|
-
|
|
407
|
-
// The module may already exist, in which case we just need to update some
|
|
408
|
-
// bookkeeping instead of adding a new node to the graph.
|
|
409
289
|
let module = this.dependencies.get(path);
|
|
410
290
|
if (options.shallow) {
|
|
411
|
-
// Don't add a node for the module if the graph is shallow (single-module).
|
|
412
291
|
} else if (dependency.data.data.asyncType === "weak") {
|
|
413
|
-
// Exclude weak dependencies from the bundle.
|
|
414
292
|
} else if (options.lazy && dependency.data.data.asyncType != null) {
|
|
415
|
-
// Don't add a node for the module if we are traversing async dependencies
|
|
416
|
-
// lazily (and this is an async dependency). Instead, record it in
|
|
417
|
-
// importBundleNodes.
|
|
418
293
|
this._incrementImportBundleReference(dependency, parentModule);
|
|
419
294
|
} else {
|
|
420
295
|
if (!module) {
|
|
421
296
|
try {
|
|
422
297
|
module = this._recursivelyCommitModule(path, delta, options);
|
|
423
298
|
} catch (error) {
|
|
424
|
-
// If we couldn't add this module but it was added to the graph
|
|
425
|
-
// before failing on a sub-dependency, it may be orphaned. Mark it as
|
|
426
|
-
// a possible garbage root.
|
|
427
299
|
const module = this.dependencies.get(path);
|
|
428
300
|
if (module) {
|
|
429
301
|
if (module.inverseDependencies.size > 0) {
|
|
@@ -435,38 +307,26 @@ class Graph {
|
|
|
435
307
|
throw error;
|
|
436
308
|
}
|
|
437
309
|
}
|
|
438
|
-
|
|
439
|
-
// We either added a new node to the graph, or we're updating an existing one.
|
|
440
310
|
module.inverseDependencies.add(parentModule.path);
|
|
441
311
|
this._markModuleInUse(module);
|
|
442
312
|
}
|
|
443
313
|
if (requireContext) {
|
|
444
314
|
this.#resolvedContexts.set(path, requireContext);
|
|
445
315
|
} else {
|
|
446
|
-
// This dependency may have existed previously as a require.context -
|
|
447
|
-
// clean it up.
|
|
448
316
|
this.#resolvedContexts.delete(path);
|
|
449
317
|
}
|
|
450
|
-
|
|
451
|
-
// Update the parent's dependency map unless we failed to add a dependency.
|
|
452
|
-
// This means the parent's dependencies can get desynced from
|
|
453
|
-
// inverseDependencies and the other fields in the case of lazy edges.
|
|
454
|
-
// Not an optimal representation :(
|
|
455
318
|
parentModule.dependencies.set(key, dependency);
|
|
456
319
|
}
|
|
457
320
|
_removeDependency(parentModule, key, dependency, delta, options) {
|
|
458
321
|
parentModule.dependencies.delete(key);
|
|
459
322
|
const { absolutePath } = dependency;
|
|
460
323
|
if (dependency.data.data.asyncType === "weak") {
|
|
461
|
-
// Weak dependencies are excluded from the bundle.
|
|
462
324
|
return;
|
|
463
325
|
}
|
|
464
326
|
const module = this.dependencies.get(absolutePath);
|
|
465
327
|
if (options.lazy && dependency.data.data.asyncType != null) {
|
|
466
328
|
this._decrementImportBundleReference(dependency, parentModule);
|
|
467
329
|
} else if (module) {
|
|
468
|
-
// Decrement inverseDependencies only if the dependency is not async,
|
|
469
|
-
// mirroring the increment conditions in _addDependency.
|
|
470
330
|
module.inverseDependencies.delete(parentModule.path);
|
|
471
331
|
}
|
|
472
332
|
if (!module) {
|
|
@@ -476,18 +336,11 @@ class Graph {
|
|
|
476
336
|
module.inverseDependencies.size > 0 ||
|
|
477
337
|
this.entryPoints.has(absolutePath)
|
|
478
338
|
) {
|
|
479
|
-
// The reference count has decreased, but not to zero.
|
|
480
|
-
// NOTE: Each entry point implicitly has a refcount of 1.
|
|
481
339
|
this._markAsPossibleCycleRoot(module);
|
|
482
340
|
} else {
|
|
483
|
-
// The reference count has decreased to zero.
|
|
484
341
|
this._releaseModule(module, delta, options);
|
|
485
342
|
}
|
|
486
343
|
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Collect a list of context modules which include a given file.
|
|
490
|
-
*/
|
|
491
344
|
markModifiedContextModules(filePath, modifiedPaths) {
|
|
492
345
|
for (const [absolutePath, context] of this.#resolvedContexts) {
|
|
493
346
|
if (
|
|
@@ -498,21 +351,10 @@ class Graph {
|
|
|
498
351
|
}
|
|
499
352
|
}
|
|
500
353
|
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Gets the list of modules affected by the deletion of a given file. The
|
|
504
|
-
* caller is expected to mark these modules as modified in the next call to
|
|
505
|
-
* traverseDependencies. Note that the list may contain duplicates.
|
|
506
|
-
*/
|
|
507
354
|
*getModifiedModulesForDeletedPath(filePath) {
|
|
508
355
|
yield* this.dependencies.get(filePath)?.inverseDependencies ?? [];
|
|
509
356
|
yield* this.#importBundleNodes.get(filePath)?.inverseDependencies ?? [];
|
|
510
357
|
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Re-traverse the dependency graph in DFS order to reorder the modules and
|
|
514
|
-
* guarantee the same order between runs. This method mutates the passed graph.
|
|
515
|
-
*/
|
|
516
358
|
reorderGraph(options) {
|
|
517
359
|
const orderedDependencies = new Map();
|
|
518
360
|
this.entryPoints.forEach((entryPoint) => {
|
|
@@ -549,10 +391,6 @@ class Graph {
|
|
|
549
391
|
this._reorderDependencies(childModule, orderedDependencies, options);
|
|
550
392
|
});
|
|
551
393
|
}
|
|
552
|
-
|
|
553
|
-
/** Garbage collection functions */
|
|
554
|
-
|
|
555
|
-
// Add an entry to importBundleNodes (or record an inverse dependency of an existing one)
|
|
556
394
|
_incrementImportBundleReference(dependency, parentModule) {
|
|
557
395
|
const { absolutePath } = dependency;
|
|
558
396
|
const importBundleNode = this.#importBundleNodes.get(absolutePath) ?? {
|
|
@@ -561,8 +399,6 @@ class Graph {
|
|
|
561
399
|
importBundleNode.inverseDependencies.add(parentModule.path);
|
|
562
400
|
this.#importBundleNodes.set(absolutePath, importBundleNode);
|
|
563
401
|
}
|
|
564
|
-
|
|
565
|
-
// Decrease the reference count of an entry in importBundleNodes (and delete it if necessary)
|
|
566
402
|
_decrementImportBundleReference(dependency, parentModule) {
|
|
567
403
|
const { absolutePath } = dependency;
|
|
568
404
|
const importBundleNode = nullthrows(
|
|
@@ -577,14 +413,9 @@ class Graph {
|
|
|
577
413
|
this.#importBundleNodes.delete(absolutePath);
|
|
578
414
|
}
|
|
579
415
|
}
|
|
580
|
-
|
|
581
|
-
// Mark a module as in use (ref count >= 1)
|
|
582
416
|
_markModuleInUse(module) {
|
|
583
417
|
this.#gc.color.set(module.path, "black");
|
|
584
418
|
}
|
|
585
|
-
|
|
586
|
-
// Iterate "children" of the given module - i.e. non-weak / async
|
|
587
|
-
// dependencies having a corresponding inverse dependency.
|
|
588
419
|
*_children(module, options) {
|
|
589
420
|
for (const dependency of module.dependencies.values()) {
|
|
590
421
|
if (isWeakOrLazy(dependency, options)) {
|
|
@@ -613,19 +444,11 @@ class Graph {
|
|
|
613
444
|
unstable_transformResultKey,
|
|
614
445
|
};
|
|
615
446
|
}
|
|
616
|
-
|
|
617
|
-
// Delete an unreachable module (and its outbound edges) from the graph
|
|
618
|
-
// immediately.
|
|
619
|
-
// Called when the reference count of a module has reached 0.
|
|
620
447
|
_releaseModule(module, delta, options) {
|
|
621
448
|
if (
|
|
622
449
|
!delta.updatedModuleData.has(module.path) &&
|
|
623
450
|
!delta.baseModuleData.has(module.path)
|
|
624
451
|
) {
|
|
625
|
-
// Before releasing a module, take a snapshot of the data we might need
|
|
626
|
-
// to reintroduce it to the graph later in this commit. As it is not
|
|
627
|
-
// already present in updatedModuleData we can infer it has not been modified,
|
|
628
|
-
// so the transform output and dependencies we copy here are current.
|
|
629
452
|
delta.baseModuleData.set(module.path, this._moduleSnapshot(module));
|
|
630
453
|
}
|
|
631
454
|
for (const [key, dependency] of module.dependencies) {
|
|
@@ -634,37 +457,24 @@ class Graph {
|
|
|
634
457
|
this.#gc.color.set(module.path, "black");
|
|
635
458
|
this._freeModule(module, delta);
|
|
636
459
|
}
|
|
637
|
-
|
|
638
|
-
// Delete an unreachable module from the graph.
|
|
639
460
|
_freeModule(module, delta) {
|
|
640
461
|
if (delta.added.has(module.path)) {
|
|
641
|
-
// Mark the deletion by clearing a prior addition.
|
|
642
462
|
delta.added.delete(module.path);
|
|
643
463
|
} else {
|
|
644
|
-
// Mark the deletion in the deleted set.
|
|
645
464
|
delta.deleted.add(module.path);
|
|
646
465
|
}
|
|
647
|
-
|
|
648
|
-
// This module is not used anywhere else! We can clear it from the bundle.
|
|
649
|
-
// Clean up all the state associated with this module in order to correctly
|
|
650
|
-
// re-add it if we encounter it again.
|
|
651
466
|
this.dependencies.delete(module.path);
|
|
652
467
|
this.#gc.possibleCycleRoots.delete(module.path);
|
|
653
468
|
this.#gc.color.delete(module.path);
|
|
654
469
|
this.#resolvedContexts.delete(module.path);
|
|
655
470
|
}
|
|
656
|
-
|
|
657
|
-
// Mark a module as a possible cycle root
|
|
658
471
|
_markAsPossibleCycleRoot(module) {
|
|
659
472
|
if (this.#gc.color.get(module.path) !== "purple") {
|
|
660
473
|
this.#gc.color.set(module.path, "purple");
|
|
661
474
|
this.#gc.possibleCycleRoots.add(module.path);
|
|
662
475
|
}
|
|
663
476
|
}
|
|
664
|
-
|
|
665
|
-
// Collect any unreachable cycles in the graph.
|
|
666
477
|
_collectCycles(delta, options) {
|
|
667
|
-
// Mark recursively from roots (trial deletion)
|
|
668
478
|
for (const path of this.#gc.possibleCycleRoots) {
|
|
669
479
|
const module = nullthrows(this.dependencies.get(path));
|
|
670
480
|
const color = nullthrows(this.#gc.color.get(path));
|
|
@@ -681,12 +491,10 @@ class Graph {
|
|
|
681
491
|
}
|
|
682
492
|
}
|
|
683
493
|
}
|
|
684
|
-
// Scan recursively from roots (undo unsuccessful trial deletions)
|
|
685
494
|
for (const path of this.#gc.possibleCycleRoots) {
|
|
686
495
|
const module = nullthrows(this.dependencies.get(path));
|
|
687
496
|
this._scan(module, options);
|
|
688
497
|
}
|
|
689
|
-
// Collect recursively from roots (free unreachable cycles)
|
|
690
498
|
for (const path of this.#gc.possibleCycleRoots) {
|
|
691
499
|
this.#gc.possibleCycleRoots.delete(path);
|
|
692
500
|
const module = nullthrows(this.dependencies.get(path));
|
|
@@ -698,7 +506,6 @@ class Graph {
|
|
|
698
506
|
if (color !== "gray") {
|
|
699
507
|
this.#gc.color.set(module.path, "gray");
|
|
700
508
|
for (const childModule of this._children(module, options)) {
|
|
701
|
-
// The inverse dependency will be restored during the scan phase if this module remains live.
|
|
702
509
|
childModule.inverseDependencies.delete(module.path);
|
|
703
510
|
this._markGray(childModule, options);
|
|
704
511
|
}
|
|
@@ -723,7 +530,6 @@ class Graph {
|
|
|
723
530
|
_scanBlack(module, options) {
|
|
724
531
|
this.#gc.color.set(module.path, "black");
|
|
725
532
|
for (const childModule of this._children(module, options)) {
|
|
726
|
-
// The inverse dependency must have been deleted during the mark phase.
|
|
727
533
|
childModule.inverseDependencies.add(module.path);
|
|
728
534
|
const childColor = nullthrows(this.#gc.color.get(childModule.path));
|
|
729
535
|
if (childColor !== "black") {
|
|
@@ -737,7 +543,6 @@ class Graph {
|
|
|
737
543
|
this.#gc.color.set(module.path, "black");
|
|
738
544
|
for (const dependency of module.dependencies.values()) {
|
|
739
545
|
const childModule = this.dependencies.get(dependency.absolutePath);
|
|
740
|
-
// The child may already have been collected.
|
|
741
546
|
if (childModule) {
|
|
742
547
|
this._collectWhite(childModule, delta);
|
|
743
548
|
}
|
|
@@ -745,8 +550,6 @@ class Graph {
|
|
|
745
550
|
this._freeModule(module, delta);
|
|
746
551
|
}
|
|
747
552
|
}
|
|
748
|
-
|
|
749
|
-
/** End of garbage collection functions */
|
|
750
553
|
}
|
|
751
554
|
exports.Graph = Graph;
|
|
752
555
|
function dependenciesEqual(a, b, options) {
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const getAppendScripts = require("../../lib/getAppendScripts");
|
|
@@ -26,8 +15,6 @@ function baseJSBundle(entryPoint, preModules, graph, options) {
|
|
|
26
15
|
serverRoot: options.serverRoot,
|
|
27
16
|
sourceUrl: options.sourceUrl,
|
|
28
17
|
};
|
|
29
|
-
|
|
30
|
-
// Do not prepend polyfills or the require runtime when only modules are requested
|
|
31
18
|
if (options.modulesOnly) {
|
|
32
19
|
preModules = [];
|
|
33
20
|
}
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const { getAssetFiles } = require("../../Assets");
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const { getAssetData } = require("../../Assets");
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const { getJsOutput, isJsModule } = require("./helpers/js");
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const { createRamBundleGroups } = require("../../Bundler/util");
|
|
@@ -85,10 +74,6 @@ async function getRamBundleInfo(entryPoint, pre, graph, options) {
|
|
|
85
74
|
startupModules,
|
|
86
75
|
};
|
|
87
76
|
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Returns the options needed to create a RAM bundle.
|
|
91
|
-
*/
|
|
92
77
|
async function _getRamOptions(
|
|
93
78
|
entryFile,
|
|
94
79
|
options,
|
|
@@ -108,9 +93,6 @@ async function _getRamOptions(
|
|
|
108
93
|
hot: true,
|
|
109
94
|
platform: options.platform,
|
|
110
95
|
},
|
|
111
|
-
/* $FlowFixMe(>=0.99.0 site=react_native_fb) This comment suppresses an
|
|
112
|
-
* error found when Flow v0.99 was deployed. To see the error, delete this
|
|
113
|
-
* comment and run Flow. */
|
|
114
96
|
async (x) => Array.from(getDependencies)
|
|
115
97
|
);
|
|
116
98
|
return {
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
function getInlineSourceMappingURL(sourceMap) {
|
|
@@ -1,14 +1,3 @@
|
|
|
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
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
const { getJsOutput } = require("./js");
|
|
@@ -1,21 +1,7 @@
|
|
|
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
|
-
* @oncall react_native
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
"use strict";
|
|
13
2
|
|
|
14
3
|
function getTransitiveDependencies(path, graph) {
|
|
15
4
|
const dependencies = _getDeps(path, graph, new Set());
|
|
16
|
-
|
|
17
|
-
// Remove the main entry point, since this method only returns the
|
|
18
|
-
// dependencies.
|
|
19
5
|
dependencies.delete(path);
|
|
20
6
|
return dependencies;
|
|
21
7
|
}
|