metro 0.71.1 → 0.72.0
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 -22
- package/src/Assets.js +3 -2
- package/src/Assets.js.flow +3 -2
- package/src/Bundler.js +0 -2
- package/src/Bundler.js.flow +1 -1
- package/src/DeltaBundler/DeltaCalculator.js +2 -0
- package/src/DeltaBundler/DeltaCalculator.js.flow +2 -0
- package/src/DeltaBundler/WorkerFarm.js.flow +2 -2
- package/src/DeltaBundler/graphOperations.js +50 -47
- package/src/DeltaBundler/graphOperations.js.flow +46 -52
- package/src/DeltaBundler/types.flow.js +6 -0
- package/src/DeltaBundler/types.flow.js.flow +12 -3
- package/src/DeltaBundler.js +0 -2
- package/src/DeltaBundler.js.flow +1 -1
- package/src/HmrServer.js +0 -2
- package/src/HmrServer.js.flow +1 -2
- package/src/ModuleGraph/node-haste/node-haste.flow.js +0 -1
- package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +1 -2
- package/src/ModuleGraph/node-haste/node-haste.js +12 -3
- package/src/ModuleGraph/node-haste/node-haste.js.flow +34 -7
- package/src/ModuleGraph/output/util.js +1 -0
- package/src/ModuleGraph/output/util.js.flow +3 -2
- package/src/ModuleGraph/silent-console.js +5 -4
- package/src/ModuleGraph/silent-console.js.flow +8 -4
- package/src/ModuleGraph/worker/collectDependencies.js +229 -33
- package/src/ModuleGraph/worker/collectDependencies.js.flow +250 -48
- package/src/Server.js +4 -0
- package/src/Server.js.flow +11 -2
- package/src/cli-utils.js.flow +1 -1
- package/src/commands/build.js +1 -2
- package/src/commands/build.js.flow +6 -9
- package/src/commands/dependencies.js +1 -1
- package/src/commands/serve.js +2 -1
- package/src/commands/serve.js.flow +7 -8
- package/src/index.flow.js +11 -8
- package/src/index.flow.js.flow +10 -7
- package/src/lib/CountingSet.js +116 -0
- package/src/lib/CountingSet.js.flow +126 -0
- package/src/lib/JsonReporter.js +0 -2
- package/src/lib/JsonReporter.js.flow +1 -1
- package/src/lib/getAppendScripts.js +10 -4
- package/src/lib/getAppendScripts.js.flow +6 -4
- package/src/lib/getPreludeCode.js +19 -1
- package/src/lib/getPreludeCode.js.flow +15 -0
- package/src/lib/getPrependedScripts.js +10 -2
- package/src/lib/getPrependedScripts.js.flow +11 -2
- package/src/lib/reporting.js +0 -2
- package/src/lib/reporting.js.flow +2 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js +8 -1
- package/src/node-haste/DependencyGraph/createHasteMap.js.flow +9 -2
- package/src/node-haste/DependencyGraph.js +2 -2
- package/src/node-haste/DependencyGraph.js.flow +4 -2
- package/src/shared/output/bundle.flow.js +67 -0
- package/src/shared/output/bundle.flow.js.flow +89 -0
- package/src/shared/output/bundle.js +8 -55
- package/src/shared/output/bundle.js.flow +8 -75
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "metro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.72.0",
|
|
4
4
|
"description": "🚇 The JavaScript bundler for React Native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": "src/cli.js",
|
|
@@ -31,27 +31,27 @@
|
|
|
31
31
|
"error-stack-parser": "^2.0.6",
|
|
32
32
|
"fs-extra": "^1.0.0",
|
|
33
33
|
"graceful-fs": "^4.2.4",
|
|
34
|
-
"hermes-parser": "0.
|
|
34
|
+
"hermes-parser": "0.8.0",
|
|
35
35
|
"image-size": "^0.6.0",
|
|
36
36
|
"invariant": "^2.2.4",
|
|
37
37
|
"jest-worker": "^27.2.0",
|
|
38
38
|
"lodash.throttle": "^4.1.1",
|
|
39
|
-
"metro-babel-transformer": "0.
|
|
40
|
-
"metro-cache": "0.
|
|
41
|
-
"metro-cache-key": "0.
|
|
42
|
-
"metro-config": "0.
|
|
43
|
-
"metro-core": "0.
|
|
44
|
-
"metro-file-map": "0.
|
|
45
|
-
"metro-hermes-compiler": "0.
|
|
46
|
-
"metro-inspector-proxy": "0.
|
|
47
|
-
"metro-minify-uglify": "0.
|
|
48
|
-
"metro-react-native-babel-preset": "0.
|
|
49
|
-
"metro-resolver": "0.
|
|
50
|
-
"metro-runtime": "0.
|
|
51
|
-
"metro-source-map": "0.
|
|
52
|
-
"metro-symbolicate": "0.
|
|
53
|
-
"metro-transform-plugins": "0.
|
|
54
|
-
"metro-transform-worker": "0.
|
|
39
|
+
"metro-babel-transformer": "0.72.0",
|
|
40
|
+
"metro-cache": "0.72.0",
|
|
41
|
+
"metro-cache-key": "0.72.0",
|
|
42
|
+
"metro-config": "0.72.0",
|
|
43
|
+
"metro-core": "0.72.0",
|
|
44
|
+
"metro-file-map": "0.72.0",
|
|
45
|
+
"metro-hermes-compiler": "0.72.0",
|
|
46
|
+
"metro-inspector-proxy": "0.72.0",
|
|
47
|
+
"metro-minify-uglify": "0.72.0",
|
|
48
|
+
"metro-react-native-babel-preset": "0.72.0",
|
|
49
|
+
"metro-resolver": "0.72.0",
|
|
50
|
+
"metro-runtime": "0.72.0",
|
|
51
|
+
"metro-source-map": "0.72.0",
|
|
52
|
+
"metro-symbolicate": "0.72.0",
|
|
53
|
+
"metro-transform-plugins": "0.72.0",
|
|
54
|
+
"metro-transform-worker": "0.72.0",
|
|
55
55
|
"mime-types": "^2.1.27",
|
|
56
56
|
"node-fetch": "^2.2.0",
|
|
57
57
|
"nullthrows": "^1.1.1",
|
|
@@ -70,10 +70,10 @@
|
|
|
70
70
|
"babel-jest": "^26.6.3",
|
|
71
71
|
"dedent": "^0.7.0",
|
|
72
72
|
"jest-snapshot": "^26.5.2",
|
|
73
|
-
"metro-babel-register": "0.
|
|
74
|
-
"metro-memory-fs": "0.
|
|
75
|
-
"metro-react-native-babel-preset": "0.
|
|
76
|
-
"metro-react-native-babel-transformer": "0.
|
|
73
|
+
"metro-babel-register": "0.72.0",
|
|
74
|
+
"metro-memory-fs": "0.72.0",
|
|
75
|
+
"metro-react-native-babel-preset": "0.72.0",
|
|
76
|
+
"metro-react-native-babel-transformer": "0.72.0",
|
|
77
77
|
"stack-trace": "^0.0.10"
|
|
78
78
|
},
|
|
79
79
|
"license": "MIT"
|
package/src/Assets.js
CHANGED
|
@@ -108,8 +108,9 @@ async function getAbsoluteAssetRecord(assetPath, platform = null) {
|
|
|
108
108
|
|
|
109
109
|
if (!record) {
|
|
110
110
|
throw new Error(
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
`Asset not found: ${assetPath} for platform: ${
|
|
112
|
+
platform !== null && platform !== void 0 ? platform : "(unspecified)"
|
|
113
|
+
}`
|
|
113
114
|
);
|
|
114
115
|
}
|
|
115
116
|
|
package/src/Assets.js.flow
CHANGED
|
@@ -154,8 +154,9 @@ async function getAbsoluteAssetRecord(
|
|
|
154
154
|
|
|
155
155
|
if (!record) {
|
|
156
156
|
throw new Error(
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
`Asset not found: ${assetPath} for platform: ${
|
|
158
|
+
platform ?? '(unspecified)'
|
|
159
|
+
}`,
|
|
159
160
|
);
|
|
160
161
|
}
|
|
161
162
|
|
package/src/Bundler.js
CHANGED
|
@@ -13,8 +13,6 @@ const Transformer = require("./DeltaBundler/Transformer");
|
|
|
13
13
|
|
|
14
14
|
const DependencyGraph = require("./node-haste/DependencyGraph");
|
|
15
15
|
|
|
16
|
-
const { EventEmitter } = require("events");
|
|
17
|
-
|
|
18
16
|
class Bundler {
|
|
19
17
|
constructor(config, options) {
|
|
20
18
|
this._depGraph = new DependencyGraph(config, options);
|
package/src/Bundler.js.flow
CHANGED
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
import type {TransformResultWithSource} from './DeltaBundler';
|
|
14
14
|
import type {TransformOptions} from './DeltaBundler/Worker';
|
|
15
15
|
import type {ConfigT} from 'metro-config/src/configTypes.flow';
|
|
16
|
+
import type EventEmitter from 'events';
|
|
16
17
|
|
|
17
18
|
const Transformer = require('./DeltaBundler/Transformer');
|
|
18
19
|
const DependencyGraph = require('./node-haste/DependencyGraph');
|
|
19
|
-
const {EventEmitter} = require('events');
|
|
20
20
|
|
|
21
21
|
export type BundlerOptions = $ReadOnly<{
|
|
22
22
|
hasReducedPerformance?: boolean,
|
|
@@ -130,6 +130,8 @@ class DeltaCalculator extends EventEmitter {
|
|
|
130
130
|
getGraph() {
|
|
131
131
|
return this._graph;
|
|
132
132
|
}
|
|
133
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
134
|
+
* LTI update could not be added via codemod */
|
|
133
135
|
|
|
134
136
|
_handleMultipleFileChanges = ({ eventsQueue }) => {
|
|
135
137
|
eventsQueue.forEach(this._handleFileChange);
|
|
@@ -158,6 +158,8 @@ class DeltaCalculator<T> extends EventEmitter {
|
|
|
158
158
|
return this._graph;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
|
|
162
|
+
* LTI update could not be added via codemod */
|
|
161
163
|
_handleMultipleFileChanges = ({eventsQueue}) => {
|
|
162
164
|
eventsQueue.forEach(this._handleFileChange);
|
|
163
165
|
};
|
|
@@ -136,7 +136,7 @@ class WorkerFarm {
|
|
|
136
136
|
return null;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
_formatGenericError(err, filename: string): TransformError {
|
|
139
|
+
_formatGenericError(err: any, filename: string): TransformError {
|
|
140
140
|
const error = new TransformError(`${filename}: ${err.message}`);
|
|
141
141
|
|
|
142
142
|
return Object.assign(error, {
|
|
@@ -145,7 +145,7 @@ class WorkerFarm {
|
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
_formatBabelError(err, filename: string): TransformError {
|
|
148
|
+
_formatBabelError(err: any, filename: string): TransformError {
|
|
149
149
|
const error = new TransformError(
|
|
150
150
|
`${err.type || 'Error'}${
|
|
151
151
|
err.message.includes(filename) ? '' : ' in ' + filename
|
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
*/
|
|
30
30
|
"use strict";
|
|
31
31
|
|
|
32
|
+
var _CountingSet = _interopRequireDefault(require("../lib/CountingSet"));
|
|
33
|
+
|
|
34
|
+
function _interopRequireDefault(obj) {
|
|
35
|
+
return obj && obj.__esModule ? obj : { default: obj };
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
const invariant = require("invariant");
|
|
33
39
|
|
|
34
40
|
const nullthrows = require("nullthrows"); // TODO: Convert to a Flow enum
|
|
@@ -181,7 +187,8 @@ async function processModule(path, graph, delta, options) {
|
|
|
181
187
|
options
|
|
182
188
|
);
|
|
183
189
|
const previousModule = graph.dependencies.get(path) || {
|
|
184
|
-
inverseDependencies:
|
|
190
|
+
inverseDependencies:
|
|
191
|
+
delta.earlyInverseDependencies.get(path) || new _CountingSet.default(),
|
|
185
192
|
path,
|
|
186
193
|
};
|
|
187
194
|
const previousDependencies = previousModule.dependencies || new Map(); // Update the module information.
|
|
@@ -194,8 +201,8 @@ async function processModule(path, graph, delta, options) {
|
|
|
194
201
|
};
|
|
195
202
|
graph.dependencies.set(module.path, module); // Diff dependencies (1/2): remove dependencies that have changed or been removed.
|
|
196
203
|
|
|
197
|
-
for (const [
|
|
198
|
-
const curDependency = currentDependencies.get(
|
|
204
|
+
for (const [key, prevDependency] of previousDependencies) {
|
|
205
|
+
const curDependency = currentDependencies.get(key);
|
|
199
206
|
|
|
200
207
|
if (
|
|
201
208
|
!curDependency ||
|
|
@@ -204,21 +211,14 @@ async function processModule(path, graph, delta, options) {
|
|
|
204
211
|
curDependency.data.data.asyncType !==
|
|
205
212
|
prevDependency.data.data.asyncType)
|
|
206
213
|
) {
|
|
207
|
-
removeDependency(
|
|
208
|
-
module,
|
|
209
|
-
relativePath,
|
|
210
|
-
prevDependency,
|
|
211
|
-
graph,
|
|
212
|
-
delta,
|
|
213
|
-
options
|
|
214
|
-
);
|
|
214
|
+
removeDependency(module, key, prevDependency, graph, delta, options);
|
|
215
215
|
}
|
|
216
216
|
} // Diff dependencies (2/2): add dependencies that have changed or been added.
|
|
217
217
|
|
|
218
218
|
const promises = [];
|
|
219
219
|
|
|
220
|
-
for (const [
|
|
221
|
-
const prevDependency = previousDependencies.get(
|
|
220
|
+
for (const [key, curDependency] of currentDependencies) {
|
|
221
|
+
const prevDependency = previousDependencies.get(key);
|
|
222
222
|
|
|
223
223
|
if (
|
|
224
224
|
!prevDependency ||
|
|
@@ -228,14 +228,7 @@ async function processModule(path, graph, delta, options) {
|
|
|
228
228
|
curDependency.data.data.asyncType)
|
|
229
229
|
) {
|
|
230
230
|
promises.push(
|
|
231
|
-
addDependency(
|
|
232
|
-
module,
|
|
233
|
-
relativePath,
|
|
234
|
-
curDependency,
|
|
235
|
-
graph,
|
|
236
|
-
delta,
|
|
237
|
-
options
|
|
238
|
-
)
|
|
231
|
+
addDependency(module, key, curDependency, graph, delta, options)
|
|
239
232
|
);
|
|
240
233
|
}
|
|
241
234
|
}
|
|
@@ -258,7 +251,7 @@ async function processModule(path, graph, delta, options) {
|
|
|
258
251
|
|
|
259
252
|
async function addDependency(
|
|
260
253
|
parentModule,
|
|
261
|
-
|
|
254
|
+
key,
|
|
262
255
|
dependency,
|
|
263
256
|
graph,
|
|
264
257
|
delta,
|
|
@@ -298,7 +291,7 @@ async function addDependency(
|
|
|
298
291
|
delta.modified.delete(path);
|
|
299
292
|
}
|
|
300
293
|
|
|
301
|
-
delta.earlyInverseDependencies.set(path, new
|
|
294
|
+
delta.earlyInverseDependencies.set(path, new _CountingSet.default());
|
|
302
295
|
options.onDependencyAdd();
|
|
303
296
|
module = await processModule(path, graph, delta, options);
|
|
304
297
|
options.onDependencyAdded();
|
|
@@ -316,18 +309,18 @@ async function addDependency(
|
|
|
316
309
|
// inverseDependencies and the other fields in the case of lazy edges.
|
|
317
310
|
// Not an optimal representation :(
|
|
318
311
|
|
|
319
|
-
parentModule.dependencies.set(
|
|
312
|
+
parentModule.dependencies.set(key, dependency);
|
|
320
313
|
}
|
|
321
314
|
|
|
322
315
|
function removeDependency(
|
|
323
316
|
parentModule,
|
|
324
|
-
|
|
317
|
+
key,
|
|
325
318
|
dependency,
|
|
326
319
|
graph,
|
|
327
320
|
delta,
|
|
328
321
|
options
|
|
329
322
|
) {
|
|
330
|
-
parentModule.dependencies.delete(
|
|
323
|
+
parentModule.dependencies.delete(key);
|
|
331
324
|
const { absolutePath } = dependency;
|
|
332
325
|
|
|
333
326
|
if (
|
|
@@ -359,38 +352,48 @@ function removeDependency(
|
|
|
359
352
|
}
|
|
360
353
|
|
|
361
354
|
function resolveDependencies(parentPath, dependencies, options) {
|
|
362
|
-
const
|
|
363
|
-
|
|
355
|
+
const maybeResolvedDeps = new Map();
|
|
356
|
+
|
|
357
|
+
for (const dep of dependencies) {
|
|
358
|
+
let resolvedDep;
|
|
364
359
|
|
|
365
360
|
try {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
data: result,
|
|
371
|
-
},
|
|
372
|
-
];
|
|
361
|
+
resolvedDep = {
|
|
362
|
+
absolutePath: options.resolve(parentPath, dep.name),
|
|
363
|
+
data: dep,
|
|
364
|
+
};
|
|
373
365
|
} catch (error) {
|
|
374
366
|
// Ignore unavailable optional dependencies. They are guarded
|
|
375
367
|
// with a try-catch block and will be handled during runtime.
|
|
376
|
-
if (
|
|
368
|
+
if (dep.data.isOptional !== true) {
|
|
377
369
|
throw error;
|
|
378
370
|
}
|
|
379
371
|
}
|
|
380
372
|
|
|
381
|
-
|
|
382
|
-
};
|
|
373
|
+
const key = dep.data.key;
|
|
383
374
|
|
|
384
|
-
|
|
385
|
-
|
|
375
|
+
if (maybeResolvedDeps.has(key)) {
|
|
376
|
+
throw new Error(
|
|
377
|
+
`resolveDependencies: Found duplicate dependency key '${key}' in ${parentPath}`
|
|
378
|
+
);
|
|
379
|
+
}
|
|
386
380
|
|
|
387
|
-
|
|
388
|
-
|
|
381
|
+
maybeResolvedDeps.set(key, resolvedDep);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const resolvedDeps = new Map(); // Return just the dependencies we successfully resolved.
|
|
385
|
+
// FIXME: This has a bad bug affecting all dependencies *after* an unresolved
|
|
386
|
+
// optional dependency. We'll need to propagate the nulls all the way to the
|
|
387
|
+
// serializer and the require() runtime to keep the dependency map from being
|
|
388
|
+
// desynced from the contents of the module.
|
|
389
|
+
|
|
390
|
+
for (const [key, resolvedDep] of maybeResolvedDeps) {
|
|
391
|
+
if (resolvedDep) {
|
|
392
|
+
resolvedDeps.set(key, resolvedDep);
|
|
389
393
|
}
|
|
394
|
+
}
|
|
390
395
|
|
|
391
|
-
|
|
392
|
-
}, []);
|
|
393
|
-
return new Map(resolved);
|
|
396
|
+
return resolvedDeps;
|
|
394
397
|
}
|
|
395
398
|
/**
|
|
396
399
|
* Re-traverse the dependency graph in DFS order to reorder the modules and
|
|
@@ -478,8 +481,8 @@ function markModuleInUse(module, graph) {
|
|
|
478
481
|
// Called when the reference count of a module has reached 0.
|
|
479
482
|
|
|
480
483
|
function releaseModule(module, graph, delta, options) {
|
|
481
|
-
for (const [
|
|
482
|
-
removeDependency(module,
|
|
484
|
+
for (const [key, dependency] of module.dependencies) {
|
|
485
|
+
removeDependency(module, key, dependency, graph, delta, options);
|
|
483
486
|
}
|
|
484
487
|
|
|
485
488
|
graph.privateState.gc.color.set(module.path, "black");
|
|
@@ -39,6 +39,8 @@ import type {
|
|
|
39
39
|
TransformResultDependency,
|
|
40
40
|
} from './types.flow';
|
|
41
41
|
|
|
42
|
+
import CountingSet from '../lib/CountingSet';
|
|
43
|
+
|
|
42
44
|
const invariant = require('invariant');
|
|
43
45
|
const nullthrows = require('nullthrows');
|
|
44
46
|
|
|
@@ -104,7 +106,7 @@ type Delta = $ReadOnly<{
|
|
|
104
106
|
|
|
105
107
|
// A place to temporarily track inverse dependencies for a module while it is
|
|
106
108
|
// being processed but has not been added to `graph.dependencies` yet.
|
|
107
|
-
earlyInverseDependencies: Map<string,
|
|
109
|
+
earlyInverseDependencies: Map<string, CountingSet<string>>,
|
|
108
110
|
}>;
|
|
109
111
|
|
|
110
112
|
type InternalOptions<T> = $ReadOnly<{
|
|
@@ -277,7 +279,8 @@ async function processModule<T>(
|
|
|
277
279
|
);
|
|
278
280
|
|
|
279
281
|
const previousModule = graph.dependencies.get(path) || {
|
|
280
|
-
inverseDependencies:
|
|
282
|
+
inverseDependencies:
|
|
283
|
+
delta.earlyInverseDependencies.get(path) || new CountingSet(),
|
|
281
284
|
path,
|
|
282
285
|
};
|
|
283
286
|
const previousDependencies = previousModule.dependencies || new Map();
|
|
@@ -292,8 +295,8 @@ async function processModule<T>(
|
|
|
292
295
|
graph.dependencies.set(module.path, module);
|
|
293
296
|
|
|
294
297
|
// Diff dependencies (1/2): remove dependencies that have changed or been removed.
|
|
295
|
-
for (const [
|
|
296
|
-
const curDependency = currentDependencies.get(
|
|
298
|
+
for (const [key, prevDependency] of previousDependencies) {
|
|
299
|
+
const curDependency = currentDependencies.get(key);
|
|
297
300
|
if (
|
|
298
301
|
!curDependency ||
|
|
299
302
|
curDependency.absolutePath !== prevDependency.absolutePath ||
|
|
@@ -301,21 +304,14 @@ async function processModule<T>(
|
|
|
301
304
|
curDependency.data.data.asyncType !==
|
|
302
305
|
prevDependency.data.data.asyncType)
|
|
303
306
|
) {
|
|
304
|
-
removeDependency(
|
|
305
|
-
module,
|
|
306
|
-
relativePath,
|
|
307
|
-
prevDependency,
|
|
308
|
-
graph,
|
|
309
|
-
delta,
|
|
310
|
-
options,
|
|
311
|
-
);
|
|
307
|
+
removeDependency(module, key, prevDependency, graph, delta, options);
|
|
312
308
|
}
|
|
313
309
|
}
|
|
314
310
|
|
|
315
311
|
// Diff dependencies (2/2): add dependencies that have changed or been added.
|
|
316
312
|
const promises = [];
|
|
317
|
-
for (const [
|
|
318
|
-
const prevDependency = previousDependencies.get(
|
|
313
|
+
for (const [key, curDependency] of currentDependencies) {
|
|
314
|
+
const prevDependency = previousDependencies.get(key);
|
|
319
315
|
if (
|
|
320
316
|
!prevDependency ||
|
|
321
317
|
prevDependency.absolutePath !== curDependency.absolutePath ||
|
|
@@ -324,14 +320,7 @@ async function processModule<T>(
|
|
|
324
320
|
curDependency.data.data.asyncType)
|
|
325
321
|
) {
|
|
326
322
|
promises.push(
|
|
327
|
-
addDependency(
|
|
328
|
-
module,
|
|
329
|
-
relativePath,
|
|
330
|
-
curDependency,
|
|
331
|
-
graph,
|
|
332
|
-
delta,
|
|
333
|
-
options,
|
|
334
|
-
),
|
|
323
|
+
addDependency(module, key, curDependency, graph, delta, options),
|
|
335
324
|
);
|
|
336
325
|
}
|
|
337
326
|
}
|
|
@@ -358,7 +347,7 @@ async function processModule<T>(
|
|
|
358
347
|
|
|
359
348
|
async function addDependency<T>(
|
|
360
349
|
parentModule: Module<T>,
|
|
361
|
-
|
|
350
|
+
key: string,
|
|
362
351
|
dependency: Dependency,
|
|
363
352
|
graph: Graph<T>,
|
|
364
353
|
delta: Delta,
|
|
@@ -397,7 +386,7 @@ async function addDependency<T>(
|
|
|
397
386
|
delta.added.add(path);
|
|
398
387
|
delta.modified.delete(path);
|
|
399
388
|
}
|
|
400
|
-
delta.earlyInverseDependencies.set(path, new
|
|
389
|
+
delta.earlyInverseDependencies.set(path, new CountingSet());
|
|
401
390
|
|
|
402
391
|
options.onDependencyAdd();
|
|
403
392
|
module = await processModule(path, graph, delta, options);
|
|
@@ -417,18 +406,18 @@ async function addDependency<T>(
|
|
|
417
406
|
// This means the parent's dependencies can get desynced from
|
|
418
407
|
// inverseDependencies and the other fields in the case of lazy edges.
|
|
419
408
|
// Not an optimal representation :(
|
|
420
|
-
parentModule.dependencies.set(
|
|
409
|
+
parentModule.dependencies.set(key, dependency);
|
|
421
410
|
}
|
|
422
411
|
|
|
423
412
|
function removeDependency<T>(
|
|
424
413
|
parentModule: Module<T>,
|
|
425
|
-
|
|
414
|
+
key: string,
|
|
426
415
|
dependency: Dependency,
|
|
427
416
|
graph: Graph<T>,
|
|
428
417
|
delta: Delta,
|
|
429
418
|
options: InternalOptions<T>,
|
|
430
419
|
): void {
|
|
431
|
-
parentModule.dependencies.delete(
|
|
420
|
+
parentModule.dependencies.delete(key);
|
|
432
421
|
|
|
433
422
|
const {absolutePath} = dependency;
|
|
434
423
|
|
|
@@ -463,37 +452,42 @@ function resolveDependencies<T>(
|
|
|
463
452
|
dependencies: $ReadOnlyArray<TransformResultDependency>,
|
|
464
453
|
options: InternalOptions<T>,
|
|
465
454
|
): Map<string, Dependency> {
|
|
466
|
-
const
|
|
467
|
-
|
|
455
|
+
const maybeResolvedDeps = new Map();
|
|
456
|
+
for (const dep of dependencies) {
|
|
457
|
+
let resolvedDep;
|
|
468
458
|
try {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
data: result,
|
|
474
|
-
},
|
|
475
|
-
];
|
|
459
|
+
resolvedDep = {
|
|
460
|
+
absolutePath: options.resolve(parentPath, dep.name),
|
|
461
|
+
data: dep,
|
|
462
|
+
};
|
|
476
463
|
} catch (error) {
|
|
477
464
|
// Ignore unavailable optional dependencies. They are guarded
|
|
478
465
|
// with a try-catch block and will be handled during runtime.
|
|
479
|
-
if (
|
|
466
|
+
if (dep.data.isOptional !== true) {
|
|
480
467
|
throw error;
|
|
481
468
|
}
|
|
482
469
|
}
|
|
483
|
-
|
|
484
|
-
|
|
470
|
+
const key = dep.data.key;
|
|
471
|
+
if (maybeResolvedDeps.has(key)) {
|
|
472
|
+
throw new Error(
|
|
473
|
+
`resolveDependencies: Found duplicate dependency key '${key}' in ${parentPath}`,
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
maybeResolvedDeps.set(key, resolvedDep);
|
|
477
|
+
}
|
|
485
478
|
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
479
|
+
const resolvedDeps = new Map();
|
|
480
|
+
// Return just the dependencies we successfully resolved.
|
|
481
|
+
// FIXME: This has a bad bug affecting all dependencies *after* an unresolved
|
|
482
|
+
// optional dependency. We'll need to propagate the nulls all the way to the
|
|
483
|
+
// serializer and the require() runtime to keep the dependency map from being
|
|
484
|
+
// desynced from the contents of the module.
|
|
485
|
+
for (const [key, resolvedDep] of maybeResolvedDeps) {
|
|
486
|
+
if (resolvedDep) {
|
|
487
|
+
resolvedDeps.set(key, resolvedDep);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return resolvedDeps;
|
|
497
491
|
}
|
|
498
492
|
|
|
499
493
|
/**
|
|
@@ -601,8 +595,8 @@ function releaseModule<T>(
|
|
|
601
595
|
delta: Delta,
|
|
602
596
|
options: InternalOptions<T>,
|
|
603
597
|
) {
|
|
604
|
-
for (const [
|
|
605
|
-
removeDependency(module,
|
|
598
|
+
for (const [key, dependency] of module.dependencies) {
|
|
599
|
+
removeDependency(module, key, dependency, graph, delta, options);
|
|
606
600
|
}
|
|
607
601
|
graph.privateState.gc.color.set(module.path, 'black');
|
|
608
602
|
if (!graph.privateState.gc.possibleCycleRoots.has(module.path)) {
|
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
|
|
13
14
|
import type {PrivateState} from './graphOperations';
|
|
14
15
|
import type {JsTransformOptions} from 'metro-transform-worker';
|
|
15
16
|
|
|
17
|
+
import CountingSet from '../lib/CountingSet';
|
|
18
|
+
|
|
16
19
|
export type MixedOutput = {
|
|
17
20
|
+data: mixed,
|
|
18
21
|
+type: string,
|
|
@@ -28,10 +31,13 @@ export type TransformResultDependency = {
|
|
|
28
31
|
+name: string,
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
|
-
* Extra data returned by the dependency extractor.
|
|
32
|
-
* blindly piped by Metro to the serializers.
|
|
34
|
+
* Extra data returned by the dependency extractor.
|
|
33
35
|
*/
|
|
34
36
|
+data: {
|
|
37
|
+
/**
|
|
38
|
+
* A locally unique key for this dependency within the current module.
|
|
39
|
+
*/
|
|
40
|
+
+key: string,
|
|
35
41
|
/**
|
|
36
42
|
* If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
|
|
37
43
|
*/
|
|
@@ -48,6 +54,9 @@ export type TransformResultDependency = {
|
|
|
48
54
|
+isOptional?: boolean,
|
|
49
55
|
|
|
50
56
|
+locs: $ReadOnlyArray<BabelSourceLocation>,
|
|
57
|
+
|
|
58
|
+
/** Context for requiring a collection of modules. */
|
|
59
|
+
+contextParams?: RequireContextParams,
|
|
51
60
|
},
|
|
52
61
|
};
|
|
53
62
|
|
|
@@ -58,7 +67,7 @@ export type Dependency = {
|
|
|
58
67
|
|
|
59
68
|
export type Module<T = MixedOutput> = {
|
|
60
69
|
+dependencies: Map<string, Dependency>,
|
|
61
|
-
+inverseDependencies:
|
|
70
|
+
+inverseDependencies: CountingSet<string>,
|
|
62
71
|
+output: $ReadOnlyArray<T>,
|
|
63
72
|
+path: string,
|
|
64
73
|
+getSource: () => Buffer,
|
package/src/DeltaBundler.js
CHANGED
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
const DeltaCalculator = require("./DeltaBundler/DeltaCalculator");
|
|
13
13
|
|
|
14
|
-
const { EventEmitter } = require("events");
|
|
15
|
-
|
|
16
14
|
/**
|
|
17
15
|
* `DeltaBundler` uses the `DeltaTransformer` to build bundle deltas. This
|
|
18
16
|
* module handles all the transformer instances so it can support multiple
|
package/src/DeltaBundler.js.flow
CHANGED
|
@@ -18,9 +18,9 @@ import type {
|
|
|
18
18
|
MixedOutput,
|
|
19
19
|
Options,
|
|
20
20
|
} from './DeltaBundler/types.flow';
|
|
21
|
+
import type EventEmitter from 'events';
|
|
21
22
|
|
|
22
23
|
const DeltaCalculator = require('./DeltaBundler/DeltaCalculator');
|
|
23
|
-
const {EventEmitter} = require('events');
|
|
24
24
|
|
|
25
25
|
export type {
|
|
26
26
|
DeltaResult,
|
package/src/HmrServer.js
CHANGED
|
@@ -11,8 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
const hmrJSBundle = require("./DeltaBundler/Serializers/hmrJSBundle");
|
|
13
13
|
|
|
14
|
-
const IncrementalBundler = require("./IncrementalBundler");
|
|
15
|
-
|
|
16
14
|
const GraphNotFoundError = require("./IncrementalBundler/GraphNotFoundError");
|
|
17
15
|
|
|
18
16
|
const RevisionNotFoundError = require("./IncrementalBundler/RevisionNotFoundError");
|
package/src/HmrServer.js.flow
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
import type {RevisionId} from './IncrementalBundler';
|
|
13
|
+
import type IncrementalBundler, {RevisionId} from './IncrementalBundler';
|
|
14
14
|
import type {ConfigT} from 'metro-config/src/configTypes.flow';
|
|
15
15
|
import type {
|
|
16
16
|
HmrClientMessage,
|
|
@@ -20,7 +20,6 @@ import type {
|
|
|
20
20
|
} from 'metro-runtime/src/modules/types.flow';
|
|
21
21
|
|
|
22
22
|
const hmrJSBundle = require('./DeltaBundler/Serializers/hmrJSBundle');
|
|
23
|
-
const IncrementalBundler = require('./IncrementalBundler');
|
|
24
23
|
const GraphNotFoundError = require('./IncrementalBundler/GraphNotFoundError');
|
|
25
24
|
const RevisionNotFoundError = require('./IncrementalBundler/RevisionNotFoundError');
|
|
26
25
|
const debounceAsyncQueue = require('./lib/debounceAsyncQueue');
|