metro 0.72.1 → 0.72.2
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.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/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/util.js +2 -4
- package/src/ModuleGraph/output/util.js.flow +1 -2
- package/src/ModuleGraph/types.flow.js.flow +28 -5
- package/src/Server.js +86 -34
- package/src/Server.js.flow +106 -36
- package/src/index.flow.js +16 -8
- package/src/index.flow.js.flow +14 -8
- package/src/lib/RamBundleParser.js +1 -0
- package/src/lib/RamBundleParser.js.flow +1 -0
- 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/shared/types.flow.js.flow +7 -0
|
@@ -117,11 +117,15 @@ export type OutputResult<M: MixedSourceMap> = {
|
|
|
117
117
|
map: M,
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
+
export type Replacements = $ReadOnly<{
|
|
121
|
+
[filename: string]: string | false,
|
|
122
|
+
}>;
|
|
123
|
+
|
|
120
124
|
export type PackageData = {
|
|
121
|
-
browser?:
|
|
125
|
+
browser?: Replacements | string,
|
|
122
126
|
main?: string,
|
|
123
127
|
name?: string,
|
|
124
|
-
'react-native'?:
|
|
128
|
+
'react-native'?: Replacements | string,
|
|
125
129
|
};
|
|
126
130
|
|
|
127
131
|
export type ResolveFn = (id: string, source: ?string) => string;
|
|
@@ -259,14 +263,27 @@ export type AssetContentsByPath = {
|
|
|
259
263
|
};
|
|
260
264
|
|
|
261
265
|
export type ResolvedCodeFile = {
|
|
262
|
-
|
|
266
|
+
codeFile: TransformedCodeFile,
|
|
263
267
|
/**
|
|
264
268
|
* Imagine we have a source file that contains a `require('foo')`. The library
|
|
265
269
|
* will resolve the path of the module `foo` and store it in this field along
|
|
266
270
|
* all the other dependencies. For example, it could be
|
|
267
271
|
* `{'foo': 'bar/foo.js', 'bar': 'node_modules/bar/index.js'}`.
|
|
268
272
|
*/
|
|
269
|
-
|
|
273
|
+
filePathsByDependencyName: {
|
|
274
|
+
[dependencyName: string]:
|
|
275
|
+
| string
|
|
276
|
+
|
|
277
|
+
// requireCond
|
|
278
|
+
| {
|
|
279
|
+
type: string,
|
|
280
|
+
condition: string,
|
|
281
|
+
modules: {
|
|
282
|
+
[string]: string | null,
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
...
|
|
286
|
+
},
|
|
270
287
|
};
|
|
271
288
|
|
|
272
289
|
export type LibraryBoundCodeFile = {
|
|
@@ -294,8 +311,14 @@ export type Library = {
|
|
|
294
311
|
* path it resolves to, ex. `beep/glo/foo.js`.
|
|
295
312
|
*/
|
|
296
313
|
export type ResolvedLibrary = {
|
|
297
|
-
+files: $ReadOnlyArray<ResolvedCodeFile
|
|
314
|
+
+files: $ReadOnlyArray<$DeepReadOnly<ResolvedCodeFile>>,
|
|
298
315
|
/* cannot be a Map because it's JSONified later on */
|
|
299
316
|
+assets: AssetContentsByPath,
|
|
300
317
|
+isPartiallyResolved?: boolean,
|
|
301
318
|
};
|
|
319
|
+
|
|
320
|
+
type DeepReadOnlyFn = (<T>(Array<T>) => $ReadOnlyArray<$DeepReadOnly<T>>) &
|
|
321
|
+
(<T: {}>(T) => $ReadOnly<$ObjMap<T, DeepReadOnlyFn>>) &
|
|
322
|
+
(<T>(T) => T);
|
|
323
|
+
|
|
324
|
+
type $DeepReadOnly<T> = $Call<DeepReadOnlyFn, T>;
|
package/src/Server.js
CHANGED
|
@@ -62,8 +62,6 @@ const {
|
|
|
62
62
|
Logger: { createActionStartEntry, createActionEndEntry, log },
|
|
63
63
|
} = require("metro-core");
|
|
64
64
|
|
|
65
|
-
const { VERSION: BYTECODE_VERSION } = require("metro-hermes-compiler");
|
|
66
|
-
|
|
67
65
|
const mime = require("mime-types");
|
|
68
66
|
|
|
69
67
|
const nullthrows = require("nullthrows");
|
|
@@ -77,6 +75,10 @@ const url = require("url");
|
|
|
77
75
|
const DELTA_ID_HEADER = "X-Metro-Delta-ID";
|
|
78
76
|
const FILES_CHANGED_COUNT_HEADER = "X-Metro-Files-Changed-Count";
|
|
79
77
|
|
|
78
|
+
function getBytecodeVersion() {
|
|
79
|
+
return require("metro-hermes-compiler").VERSION;
|
|
80
|
+
}
|
|
81
|
+
|
|
80
82
|
class Server {
|
|
81
83
|
constructor(config, options) {
|
|
82
84
|
this._config = config;
|
|
@@ -129,12 +131,14 @@ class Server {
|
|
|
129
131
|
entryFile,
|
|
130
132
|
graphOptions,
|
|
131
133
|
onProgress,
|
|
134
|
+
resolverOptions,
|
|
132
135
|
serializerOptions,
|
|
133
136
|
transformOptions,
|
|
134
137
|
} = splitBundleOptions(options);
|
|
135
138
|
const { prepend, graph } = await this._bundler.buildGraph(
|
|
136
139
|
entryFile,
|
|
137
140
|
transformOptions,
|
|
141
|
+
resolverOptions,
|
|
138
142
|
{
|
|
139
143
|
onProgress,
|
|
140
144
|
shallow: graphOptions.shallow,
|
|
@@ -147,8 +151,9 @@ class Server {
|
|
|
147
151
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
148
152
|
this._config.transformer.asyncRequireModulePath,
|
|
149
153
|
{
|
|
150
|
-
transformOptions,
|
|
151
154
|
relativeTo: "project",
|
|
155
|
+
resolverOptions,
|
|
156
|
+
transformOptions,
|
|
152
157
|
}
|
|
153
158
|
),
|
|
154
159
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
@@ -217,12 +222,14 @@ class Server {
|
|
|
217
222
|
entryFile,
|
|
218
223
|
graphOptions,
|
|
219
224
|
onProgress,
|
|
225
|
+
resolverOptions,
|
|
220
226
|
serializerOptions,
|
|
221
227
|
transformOptions,
|
|
222
228
|
} = splitBundleOptions(options);
|
|
223
229
|
const { prepend, graph } = await this._bundler.buildGraph(
|
|
224
230
|
entryFile,
|
|
225
231
|
transformOptions,
|
|
232
|
+
resolverOptions,
|
|
226
233
|
{
|
|
227
234
|
onProgress,
|
|
228
235
|
shallow: graphOptions.shallow,
|
|
@@ -235,8 +242,9 @@ class Server {
|
|
|
235
242
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
236
243
|
this._config.transformer.asyncRequireModulePath,
|
|
237
244
|
{
|
|
238
|
-
transformOptions,
|
|
239
245
|
relativeTo: "project",
|
|
246
|
+
resolverOptions,
|
|
247
|
+
transformOptions,
|
|
240
248
|
}
|
|
241
249
|
),
|
|
242
250
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
@@ -265,11 +273,12 @@ class Server {
|
|
|
265
273
|
}
|
|
266
274
|
|
|
267
275
|
async getAssets(options) {
|
|
268
|
-
const { entryFile,
|
|
276
|
+
const { entryFile, onProgress, resolverOptions, transformOptions } =
|
|
269
277
|
splitBundleOptions(options);
|
|
270
278
|
const dependencies = await this._bundler.getDependencies(
|
|
271
279
|
[entryFile],
|
|
272
280
|
transformOptions,
|
|
281
|
+
resolverOptions,
|
|
273
282
|
{
|
|
274
283
|
onProgress,
|
|
275
284
|
shallow: false,
|
|
@@ -285,10 +294,15 @@ class Server {
|
|
|
285
294
|
}
|
|
286
295
|
|
|
287
296
|
async getOrderedDependencyPaths(options) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
297
|
+
const {
|
|
298
|
+
entryFile,
|
|
299
|
+
onProgress,
|
|
300
|
+
resolverOptions,
|
|
301
|
+
transformOptions,
|
|
302
|
+
/* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an
|
|
303
|
+
* error found when Flow v0.122.0 was deployed. To see the error, delete
|
|
304
|
+
* this comment and run Flow. */
|
|
305
|
+
} = splitBundleOptions({
|
|
292
306
|
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
293
307
|
...options,
|
|
294
308
|
bundleType: "bundle",
|
|
@@ -296,6 +310,7 @@ class Server {
|
|
|
296
310
|
const { prepend, graph } = await this._bundler.buildGraph(
|
|
297
311
|
entryFile,
|
|
298
312
|
transformOptions,
|
|
313
|
+
resolverOptions,
|
|
299
314
|
{
|
|
300
315
|
onProgress,
|
|
301
316
|
shallow: false,
|
|
@@ -395,7 +410,7 @@ class Server {
|
|
|
395
410
|
return parseOptionsFromUrl(
|
|
396
411
|
url,
|
|
397
412
|
new Set(this._config.resolver.platforms),
|
|
398
|
-
|
|
413
|
+
getBytecodeVersion()
|
|
399
414
|
);
|
|
400
415
|
}
|
|
401
416
|
|
|
@@ -453,26 +468,31 @@ class Server {
|
|
|
453
468
|
delete: deleteFn,
|
|
454
469
|
finish,
|
|
455
470
|
}) {
|
|
456
|
-
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
|
|
457
|
-
* Flow's LTI update could not be added via codemod */
|
|
458
471
|
return async function requestProcessor(req, res, bundleOptions) {
|
|
459
|
-
const {
|
|
460
|
-
|
|
472
|
+
const {
|
|
473
|
+
entryFile,
|
|
474
|
+
graphOptions,
|
|
475
|
+
resolverOptions,
|
|
476
|
+
serializerOptions,
|
|
477
|
+
transformOptions,
|
|
478
|
+
} = splitBundleOptions(bundleOptions);
|
|
461
479
|
/**
|
|
462
480
|
* `entryFile` is relative to projectRoot, we need to use resolution function
|
|
463
481
|
* to find the appropriate file with supported extensions.
|
|
464
482
|
*/
|
|
465
483
|
|
|
466
484
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
467
|
-
transformOptions,
|
|
468
485
|
relativeTo: "server",
|
|
486
|
+
resolverOptions,
|
|
487
|
+
transformOptions,
|
|
469
488
|
});
|
|
470
489
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
471
|
-
shallow: graphOptions.shallow,
|
|
472
490
|
experimentalImportBundleSupport:
|
|
473
491
|
this._config.transformer.experimentalImportBundleSupport,
|
|
474
492
|
unstable_allowRequireContext:
|
|
475
493
|
this._config.transformer.unstable_allowRequireContext,
|
|
494
|
+
resolverOptions,
|
|
495
|
+
shallow: graphOptions.shallow,
|
|
476
496
|
}); // For resources that support deletion, handle the DELETE method.
|
|
477
497
|
|
|
478
498
|
if (deleteFn && req.method === "DELETE") {
|
|
@@ -566,6 +586,7 @@ class Server {
|
|
|
566
586
|
mres,
|
|
567
587
|
onProgress,
|
|
568
588
|
req,
|
|
589
|
+
resolverOptions,
|
|
569
590
|
serializerOptions,
|
|
570
591
|
transformOptions,
|
|
571
592
|
};
|
|
@@ -648,6 +669,7 @@ class Server {
|
|
|
648
669
|
graphId,
|
|
649
670
|
graphOptions,
|
|
650
671
|
onProgress,
|
|
672
|
+
resolverOptions,
|
|
651
673
|
serializerOptions,
|
|
652
674
|
transformOptions,
|
|
653
675
|
}) => {
|
|
@@ -657,10 +679,15 @@ class Server {
|
|
|
657
679
|
|
|
658
680
|
const { delta, revision } = await (revPromise != null
|
|
659
681
|
? this._bundler.updateGraph(await revPromise, false)
|
|
660
|
-
: this._bundler.initializeGraph(
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
682
|
+
: this._bundler.initializeGraph(
|
|
683
|
+
entryFile,
|
|
684
|
+
transformOptions,
|
|
685
|
+
resolverOptions,
|
|
686
|
+
{
|
|
687
|
+
onProgress,
|
|
688
|
+
shallow: graphOptions.shallow,
|
|
689
|
+
}
|
|
690
|
+
));
|
|
664
691
|
|
|
665
692
|
const serializer =
|
|
666
693
|
this._config.serializer.customSerializer ||
|
|
@@ -676,8 +703,9 @@ class Server {
|
|
|
676
703
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
677
704
|
this._config.transformer.asyncRequireModulePath,
|
|
678
705
|
{
|
|
679
|
-
transformOptions,
|
|
680
706
|
relativeTo: "project",
|
|
707
|
+
resolverOptions,
|
|
708
|
+
transformOptions,
|
|
681
709
|
}
|
|
682
710
|
),
|
|
683
711
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
@@ -770,6 +798,7 @@ class Server {
|
|
|
770
798
|
graphId,
|
|
771
799
|
graphOptions,
|
|
772
800
|
onProgress,
|
|
801
|
+
resolverOptions,
|
|
773
802
|
serializerOptions,
|
|
774
803
|
transformOptions,
|
|
775
804
|
}) => {
|
|
@@ -779,17 +808,23 @@ class Server {
|
|
|
779
808
|
|
|
780
809
|
const { delta, revision } = await (revPromise != null
|
|
781
810
|
? this._bundler.updateGraph(await revPromise, false)
|
|
782
|
-
: this._bundler.initializeGraph(
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
811
|
+
: this._bundler.initializeGraph(
|
|
812
|
+
entryFile,
|
|
813
|
+
transformOptions,
|
|
814
|
+
resolverOptions,
|
|
815
|
+
{
|
|
816
|
+
onProgress,
|
|
817
|
+
shallow: graphOptions.shallow,
|
|
818
|
+
}
|
|
819
|
+
));
|
|
786
820
|
const bundle = bundleToBytecode(
|
|
787
821
|
baseBytecodeBundle(entryFile, revision.prepend, revision.graph, {
|
|
788
822
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
789
823
|
this._config.transformer.asyncRequireModulePath,
|
|
790
824
|
{
|
|
791
|
-
transformOptions,
|
|
792
825
|
relativeTo: "project",
|
|
826
|
+
resolverOptions,
|
|
827
|
+
transformOptions,
|
|
793
828
|
}
|
|
794
829
|
),
|
|
795
830
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
@@ -886,6 +921,7 @@ class Server {
|
|
|
886
921
|
graphId,
|
|
887
922
|
graphOptions,
|
|
888
923
|
onProgress,
|
|
924
|
+
resolverOptions,
|
|
889
925
|
serializerOptions,
|
|
890
926
|
transformOptions,
|
|
891
927
|
}) => {
|
|
@@ -897,6 +933,7 @@ class Server {
|
|
|
897
933
|
({ revision } = await this._bundler.initializeGraph(
|
|
898
934
|
entryFile,
|
|
899
935
|
transformOptions,
|
|
936
|
+
resolverOptions,
|
|
900
937
|
{
|
|
901
938
|
onProgress,
|
|
902
939
|
shallow: graphOptions.shallow,
|
|
@@ -942,10 +979,16 @@ class Server {
|
|
|
942
979
|
};
|
|
943
980
|
},
|
|
944
981
|
|
|
945
|
-
build: async ({
|
|
982
|
+
build: async ({
|
|
983
|
+
entryFile,
|
|
984
|
+
onProgress,
|
|
985
|
+
resolverOptions,
|
|
986
|
+
transformOptions,
|
|
987
|
+
}) => {
|
|
946
988
|
const dependencies = await this._bundler.getDependencies(
|
|
947
989
|
[entryFile],
|
|
948
990
|
transformOptions,
|
|
991
|
+
resolverOptions,
|
|
949
992
|
{
|
|
950
993
|
onProgress,
|
|
951
994
|
shallow: false,
|
|
@@ -1077,14 +1120,15 @@ class Server {
|
|
|
1077
1120
|
const options = parseOptionsFromUrl(
|
|
1078
1121
|
reqUrl,
|
|
1079
1122
|
new Set(this._config.resolver.platforms),
|
|
1080
|
-
|
|
1123
|
+
getBytecodeVersion()
|
|
1081
1124
|
);
|
|
1082
1125
|
const {
|
|
1083
1126
|
entryFile,
|
|
1084
|
-
transformOptions,
|
|
1085
|
-
serializerOptions,
|
|
1086
1127
|
graphOptions,
|
|
1087
1128
|
onProgress,
|
|
1129
|
+
resolverOptions,
|
|
1130
|
+
serializerOptions,
|
|
1131
|
+
transformOptions,
|
|
1088
1132
|
} = splitBundleOptions(options);
|
|
1089
1133
|
/**
|
|
1090
1134
|
* `entryFile` is relative to projectRoot, we need to use resolution function
|
|
@@ -1092,15 +1136,17 @@ class Server {
|
|
|
1092
1136
|
*/
|
|
1093
1137
|
|
|
1094
1138
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
1095
|
-
transformOptions,
|
|
1096
1139
|
relativeTo: "server",
|
|
1140
|
+
resolverOptions,
|
|
1141
|
+
transformOptions,
|
|
1097
1142
|
});
|
|
1098
1143
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
1099
|
-
shallow: graphOptions.shallow,
|
|
1100
1144
|
experimentalImportBundleSupport:
|
|
1101
1145
|
this._config.transformer.experimentalImportBundleSupport,
|
|
1102
1146
|
unstable_allowRequireContext:
|
|
1103
1147
|
this._config.transformer.unstable_allowRequireContext,
|
|
1148
|
+
resolverOptions,
|
|
1149
|
+
shallow: graphOptions.shallow,
|
|
1104
1150
|
});
|
|
1105
1151
|
let revision;
|
|
1106
1152
|
|
|
@@ -1110,6 +1156,7 @@ class Server {
|
|
|
1110
1156
|
({ revision } = await this._bundler.initializeGraph(
|
|
1111
1157
|
resolvedEntryFilePath,
|
|
1112
1158
|
transformOptions,
|
|
1159
|
+
resolverOptions,
|
|
1113
1160
|
{
|
|
1114
1161
|
onProgress,
|
|
1115
1162
|
shallow: graphOptions.shallow,
|
|
@@ -1133,10 +1180,14 @@ class Server {
|
|
|
1133
1180
|
);
|
|
1134
1181
|
}
|
|
1135
1182
|
|
|
1136
|
-
async _resolveRelativePath(
|
|
1183
|
+
async _resolveRelativePath(
|
|
1184
|
+
filePath,
|
|
1185
|
+
{ relativeTo, resolverOptions, transformOptions }
|
|
1186
|
+
) {
|
|
1137
1187
|
const resolutionFn = await transformHelpers.getResolveDependencyFn(
|
|
1138
1188
|
this._bundler.getBundler(),
|
|
1139
|
-
transformOptions.platform
|
|
1189
|
+
transformOptions.platform,
|
|
1190
|
+
resolverOptions
|
|
1140
1191
|
);
|
|
1141
1192
|
const rootDir =
|
|
1142
1193
|
relativeTo === "server"
|
|
@@ -1158,6 +1209,7 @@ class Server {
|
|
|
1158
1209
|
}
|
|
1159
1210
|
|
|
1160
1211
|
static DEFAULT_GRAPH_OPTIONS = {
|
|
1212
|
+
customResolverOptions: Object.create(null),
|
|
1161
1213
|
customTransformOptions: Object.create(null),
|
|
1162
1214
|
dev: true,
|
|
1163
1215
|
hot: false,
|