metro 0.72.1 → 0.72.3
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 +23 -21
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js +3 -2
- package/src/DeltaBundler/Serializers/baseBytecodeBundle.js.flow +2 -1
- package/src/DeltaBundler/Serializers/helpers/bytecode.js +2 -2
- package/src/DeltaBundler/Serializers/helpers/bytecode.js.flow +2 -1
- package/src/DeltaBundler/Worker.js +0 -1
- package/src/DeltaBundler/Worker.js.flow +0 -1
- package/src/DeltaBundler/graphOperations.js +6 -6
- package/src/DeltaBundler/graphOperations.js.flow +5 -5
- package/src/DeltaBundler.js.flow +1 -1
- package/src/HmrServer.js +9 -5
- package/src/HmrServer.js.flow +9 -4
- package/src/IncrementalBundler.js +16 -4
- package/src/IncrementalBundler.js.flow +17 -4
- package/src/ModuleGraph/node-haste/HasteFS.js +0 -1
- package/src/ModuleGraph/node-haste/HasteFS.js.flow +0 -1
- package/src/ModuleGraph/node-haste/Package.js.flow +5 -5
- package/src/ModuleGraph/node-haste/node-haste.js +8 -4
- package/src/ModuleGraph/node-haste/node-haste.js.flow +21 -14
- package/src/ModuleGraph/output/reverse-dependency-map-references.js +1 -2
- package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +0 -1
- package/src/ModuleGraph/output/util.js +2 -4
- package/src/ModuleGraph/output/util.js.flow +1 -2
- package/src/ModuleGraph/types.flow.js.flow +28 -6
- package/src/Server/MultipartResponse.js +10 -12
- package/src/Server/MultipartResponse.js.flow +97 -0
- package/src/Server.js +100 -48
- package/src/Server.js.flow +118 -49
- package/src/index.flow.js +16 -8
- package/src/index.flow.js.flow +14 -8
- package/src/index.js +0 -1
- package/src/index.js.flow +0 -1
- package/src/lib/CountingSet.js +0 -1
- package/src/lib/CountingSet.js.flow +0 -1
- package/src/lib/RamBundleParser.js +1 -0
- package/src/lib/RamBundleParser.js.flow +1 -0
- package/src/lib/TerminalReporter.js +22 -24
- package/src/lib/TerminalReporter.js.flow +20 -24
- package/src/lib/bundleToBytecode.js +3 -2
- package/src/lib/bundleToBytecode.js.flow +2 -2
- package/src/lib/getGraphId.js +16 -3
- package/src/lib/getGraphId.js.flow +10 -10
- package/src/lib/getPrependedScripts.js +13 -5
- package/src/lib/getPrependedScripts.js.flow +6 -1
- package/src/lib/parseCustomResolverOptions.js +26 -0
- package/src/lib/parseCustomResolverOptions.js.flow +38 -0
- package/src/lib/parseOptionsFromUrl.js +3 -0
- package/src/lib/parseOptionsFromUrl.js.flow +2 -0
- package/src/lib/splitBundleOptions.js +3 -0
- package/src/lib/splitBundleOptions.js.flow +3 -0
- package/src/lib/transformHelpers.js +27 -13
- package/src/lib/transformHelpers.js.flow +27 -7
- package/src/node-haste/DependencyGraph/ModuleResolution.js +18 -2
- package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +5 -0
- package/src/node-haste/DependencyGraph.js +34 -9
- package/src/node-haste/DependencyGraph.js.flow +49 -11
- package/src/node-haste/Module.js +1 -0
- package/src/node-haste/Module.js.flow +1 -0
- package/src/node-haste/Package.js +0 -1
- package/src/node-haste/Package.js.flow +0 -1
- package/src/shared/output/bundle.js +0 -1
- package/src/shared/output/bundle.js.flow +0 -1
- package/src/shared/types.flow.js.flow +7 -0
|
@@ -11,6 +11,8 @@ var _metroFileMap = require("metro-file-map");
|
|
|
11
11
|
*
|
|
12
12
|
* @format
|
|
13
13
|
*/
|
|
14
|
+
const canonicalize = require("metro-core/src/canonicalize");
|
|
15
|
+
|
|
14
16
|
const createHasteMap = require("./DependencyGraph/createHasteMap");
|
|
15
17
|
|
|
16
18
|
const { ModuleResolver } = require("./DependencyGraph/ModuleResolution");
|
|
@@ -34,8 +36,9 @@ const nullthrows = require("nullthrows");
|
|
|
34
36
|
const path = require("path");
|
|
35
37
|
|
|
36
38
|
const { DuplicateHasteCandidatesError } = _metroFileMap.ModuleMap;
|
|
39
|
+
const NULL_PLATFORM = Symbol();
|
|
37
40
|
|
|
38
|
-
function
|
|
41
|
+
function getOrCreateMap(map, field) {
|
|
39
42
|
let subMap = map.get(field);
|
|
40
43
|
|
|
41
44
|
if (!subMap) {
|
|
@@ -218,22 +221,43 @@ class DependencyGraph extends EventEmitter {
|
|
|
218
221
|
from,
|
|
219
222
|
to,
|
|
220
223
|
platform,
|
|
224
|
+
resolverOptions, // TODO: Fold assumeFlatNodeModules into resolverOptions and add to graphId
|
|
221
225
|
{ assumeFlatNodeModules } = {
|
|
222
226
|
assumeFlatNodeModules: false,
|
|
223
227
|
}
|
|
224
228
|
) {
|
|
229
|
+
var _JSON$stringify, _resolverOptions$cust;
|
|
230
|
+
|
|
225
231
|
const isSensitiveToOriginFolder = // Resolution is always relative to the origin folder unless we assume a flat node_modules
|
|
226
232
|
!assumeFlatNodeModules || // Path requests are resolved relative to the origin folder
|
|
227
233
|
to.includes("/") ||
|
|
228
234
|
to === "." ||
|
|
229
235
|
to === ".." || // Preserve standard assumptions under node_modules
|
|
230
|
-
from.includes(path.sep + "node_modules" + path.sep);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
236
|
+
from.includes(path.sep + "node_modules" + path.sep); // Compound key for the resolver cache
|
|
237
|
+
|
|
238
|
+
const resolverOptionsKey =
|
|
239
|
+
(_JSON$stringify = JSON.stringify(
|
|
240
|
+
(_resolverOptions$cust = resolverOptions.customResolverOptions) !==
|
|
241
|
+
null && _resolverOptions$cust !== void 0
|
|
242
|
+
? _resolverOptions$cust
|
|
243
|
+
: {},
|
|
244
|
+
canonicalize
|
|
245
|
+
)) !== null && _JSON$stringify !== void 0
|
|
246
|
+
? _JSON$stringify
|
|
247
|
+
: "";
|
|
248
|
+
const originKey = isSensitiveToOriginFolder ? path.dirname(from) : "";
|
|
249
|
+
const targetKey = to;
|
|
250
|
+
const platformKey =
|
|
251
|
+
platform !== null && platform !== void 0 ? platform : NULL_PLATFORM; // Traverse the resolver cache, which is a tree of maps
|
|
252
|
+
|
|
253
|
+
const mapByResolverOptions = this._resolutionCache;
|
|
254
|
+
const mapByOrigin = getOrCreateMap(
|
|
255
|
+
mapByResolverOptions,
|
|
256
|
+
resolverOptionsKey
|
|
234
257
|
);
|
|
235
|
-
const
|
|
236
|
-
|
|
258
|
+
const mapByTarget = getOrCreateMap(mapByOrigin, originKey);
|
|
259
|
+
const mapByPlatform = getOrCreateMap(mapByTarget, targetKey);
|
|
260
|
+
let modulePath = mapByPlatform.get(platformKey);
|
|
237
261
|
|
|
238
262
|
if (!modulePath) {
|
|
239
263
|
try {
|
|
@@ -241,7 +265,8 @@ class DependencyGraph extends EventEmitter {
|
|
|
241
265
|
this._moduleCache.getModule(from),
|
|
242
266
|
to,
|
|
243
267
|
true,
|
|
244
|
-
platform
|
|
268
|
+
platform,
|
|
269
|
+
resolverOptions
|
|
245
270
|
).path;
|
|
246
271
|
} catch (error) {
|
|
247
272
|
if (error instanceof DuplicateHasteCandidatesError) {
|
|
@@ -260,7 +285,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
260
285
|
}
|
|
261
286
|
}
|
|
262
287
|
|
|
263
|
-
mapByPlatform.set(
|
|
288
|
+
mapByPlatform.set(platformKey, modulePath);
|
|
264
289
|
return modulePath;
|
|
265
290
|
}
|
|
266
291
|
|
|
@@ -15,6 +15,7 @@ import type Module from './Module';
|
|
|
15
15
|
|
|
16
16
|
import {ModuleMap as MetroFileMapModuleMap} from 'metro-file-map';
|
|
17
17
|
|
|
18
|
+
const canonicalize = require('metro-core/src/canonicalize');
|
|
18
19
|
const createHasteMap = require('./DependencyGraph/createHasteMap');
|
|
19
20
|
const {ModuleResolver} = require('./DependencyGraph/ModuleResolution');
|
|
20
21
|
const ModuleCache = require('./ModuleCache');
|
|
@@ -28,13 +29,16 @@ const {
|
|
|
28
29
|
const {InvalidPackageError} = require('metro-resolver');
|
|
29
30
|
const nullthrows = require('nullthrows');
|
|
30
31
|
const path = require('path');
|
|
32
|
+
import type {ResolverInputOptions} from '../shared/types.flow';
|
|
31
33
|
|
|
32
34
|
const {DuplicateHasteCandidatesError} = MetroFileMapModuleMap;
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
const NULL_PLATFORM = Symbol();
|
|
37
|
+
|
|
38
|
+
function getOrCreateMap<T>(
|
|
39
|
+
map: Map<string | symbol, Map<string | symbol, T>>,
|
|
36
40
|
field: string,
|
|
37
|
-
): Map<string, T> {
|
|
41
|
+
): Map<string | symbol, T> {
|
|
38
42
|
let subMap = map.get(field);
|
|
39
43
|
if (!subMap) {
|
|
40
44
|
subMap = new Map();
|
|
@@ -51,7 +55,23 @@ class DependencyGraph extends EventEmitter {
|
|
|
51
55
|
_moduleCache: ModuleCache;
|
|
52
56
|
_moduleMap: MetroFileMapModuleMap;
|
|
53
57
|
_moduleResolver: ModuleResolver<Module, Package>;
|
|
54
|
-
_resolutionCache: Map<
|
|
58
|
+
_resolutionCache: Map<
|
|
59
|
+
// Custom resolver options
|
|
60
|
+
string | symbol,
|
|
61
|
+
Map<
|
|
62
|
+
// Origin folder
|
|
63
|
+
string | symbol,
|
|
64
|
+
Map<
|
|
65
|
+
// Dependency name
|
|
66
|
+
string | symbol,
|
|
67
|
+
Map<
|
|
68
|
+
// Platform
|
|
69
|
+
string | symbol,
|
|
70
|
+
string,
|
|
71
|
+
>,
|
|
72
|
+
>,
|
|
73
|
+
>,
|
|
74
|
+
>;
|
|
55
75
|
_readyPromise: Promise<void>;
|
|
56
76
|
|
|
57
77
|
constructor(
|
|
@@ -241,7 +261,10 @@ class DependencyGraph extends EventEmitter {
|
|
|
241
261
|
resolveDependency(
|
|
242
262
|
from: string,
|
|
243
263
|
to: string,
|
|
244
|
-
platform: string,
|
|
264
|
+
platform: string | null,
|
|
265
|
+
resolverOptions: ResolverInputOptions,
|
|
266
|
+
|
|
267
|
+
// TODO: Fold assumeFlatNodeModules into resolverOptions and add to graphId
|
|
245
268
|
{assumeFlatNodeModules}: {assumeFlatNodeModules: boolean} = {
|
|
246
269
|
assumeFlatNodeModules: false,
|
|
247
270
|
},
|
|
@@ -255,12 +278,26 @@ class DependencyGraph extends EventEmitter {
|
|
|
255
278
|
to === '..' ||
|
|
256
279
|
// Preserve standard assumptions under node_modules
|
|
257
280
|
from.includes(path.sep + 'node_modules' + path.sep);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
281
|
+
|
|
282
|
+
// Compound key for the resolver cache
|
|
283
|
+
const resolverOptionsKey =
|
|
284
|
+
JSON.stringify(
|
|
285
|
+
resolverOptions.customResolverOptions ?? {},
|
|
286
|
+
canonicalize,
|
|
287
|
+
) ?? '';
|
|
288
|
+
const originKey = isSensitiveToOriginFolder ? path.dirname(from) : '';
|
|
289
|
+
const targetKey = to;
|
|
290
|
+
const platformKey = platform ?? NULL_PLATFORM;
|
|
291
|
+
|
|
292
|
+
// Traverse the resolver cache, which is a tree of maps
|
|
293
|
+
const mapByResolverOptions = this._resolutionCache;
|
|
294
|
+
const mapByOrigin = getOrCreateMap(
|
|
295
|
+
mapByResolverOptions,
|
|
296
|
+
resolverOptionsKey,
|
|
261
297
|
);
|
|
262
|
-
const
|
|
263
|
-
|
|
298
|
+
const mapByTarget = getOrCreateMap(mapByOrigin, originKey);
|
|
299
|
+
const mapByPlatform = getOrCreateMap(mapByTarget, targetKey);
|
|
300
|
+
let modulePath = mapByPlatform.get(platformKey);
|
|
264
301
|
|
|
265
302
|
if (!modulePath) {
|
|
266
303
|
try {
|
|
@@ -269,6 +306,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
269
306
|
to,
|
|
270
307
|
true,
|
|
271
308
|
platform,
|
|
309
|
+
resolverOptions,
|
|
272
310
|
).path;
|
|
273
311
|
} catch (error) {
|
|
274
312
|
if (error instanceof DuplicateHasteCandidatesError) {
|
|
@@ -285,7 +323,7 @@ class DependencyGraph extends EventEmitter {
|
|
|
285
323
|
}
|
|
286
324
|
}
|
|
287
325
|
|
|
288
|
-
mapByPlatform.set(
|
|
326
|
+
mapByPlatform.set(platformKey, modulePath);
|
|
289
327
|
return modulePath;
|
|
290
328
|
}
|
|
291
329
|
|
package/src/node-haste/Module.js
CHANGED
|
@@ -21,6 +21,7 @@ class Module {
|
|
|
21
21
|
_moduleCache: ModuleCache;
|
|
22
22
|
_sourceCode: ?string;
|
|
23
23
|
|
|
24
|
+
// $FlowFixMe[missing-local-annot]
|
|
24
25
|
constructor(file: string, moduleCache: ModuleCache) {
|
|
25
26
|
if (!isAbsolutePath(file)) {
|
|
26
27
|
throw new Error('Expected file to be absolute path but got ' + file);
|
|
@@ -23,6 +23,7 @@ import type {
|
|
|
23
23
|
CustomTransformOptions,
|
|
24
24
|
MinifierOptions,
|
|
25
25
|
} from 'metro-transform-worker';
|
|
26
|
+
import type {CustomResolverOptions} from 'metro-resolver';
|
|
26
27
|
|
|
27
28
|
type BundleType =
|
|
28
29
|
| 'bundle'
|
|
@@ -41,6 +42,7 @@ type MetroSourceMapOrMappings =
|
|
|
41
42
|
|
|
42
43
|
export type BundleOptions = {
|
|
43
44
|
bundleType: BundleType,
|
|
45
|
+
+customResolverOptions: CustomResolverOptions,
|
|
44
46
|
customTransformOptions: CustomTransformOptions,
|
|
45
47
|
dev: boolean,
|
|
46
48
|
entryFile: string,
|
|
@@ -61,6 +63,10 @@ export type BundleOptions = {
|
|
|
61
63
|
...
|
|
62
64
|
};
|
|
63
65
|
|
|
66
|
+
export type ResolverInputOptions = $ReadOnly<{
|
|
67
|
+
customResolverOptions?: CustomResolverOptions,
|
|
68
|
+
}>;
|
|
69
|
+
|
|
64
70
|
export type SerializerOptions = {
|
|
65
71
|
+sourceMapUrl: ?string,
|
|
66
72
|
+sourceUrl: ?string,
|
|
@@ -77,6 +83,7 @@ export type GraphOptions = {
|
|
|
77
83
|
// Stricter representation of BundleOptions.
|
|
78
84
|
export type SplitBundleOptions = {
|
|
79
85
|
+entryFile: string,
|
|
86
|
+
+resolverOptions: ResolverInputOptions,
|
|
80
87
|
+transformOptions: TransformInputOptions,
|
|
81
88
|
+serializerOptions: SerializerOptions,
|
|
82
89
|
+graphOptions: GraphOptions,
|