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
package/src/Server.js
CHANGED
|
@@ -47,12 +47,12 @@ const transformHelpers = require("./lib/transformHelpers");
|
|
|
47
47
|
|
|
48
48
|
const parsePlatformFilePath = require("./node-haste/lib/parsePlatformFilePath");
|
|
49
49
|
|
|
50
|
-
const MultipartResponse = require("./Server/MultipartResponse");
|
|
51
|
-
|
|
52
50
|
const symbolicate = require("./Server/symbolicate");
|
|
53
51
|
|
|
54
52
|
const { codeFrameColumns } = require("@babel/code-frame");
|
|
55
53
|
|
|
54
|
+
const MultipartResponse = require("./Server/MultipartResponse");
|
|
55
|
+
|
|
56
56
|
const debug = require("debug")("Metro:Server");
|
|
57
57
|
|
|
58
58
|
const fs = require("graceful-fs");
|
|
@@ -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") {
|
|
@@ -496,7 +516,7 @@ class Server {
|
|
|
496
516
|
return;
|
|
497
517
|
}
|
|
498
518
|
|
|
499
|
-
const mres = MultipartResponse.
|
|
519
|
+
const mres = MultipartResponse.wrapIfSupported(req, res);
|
|
500
520
|
const buildID = this.getNewBuildID();
|
|
501
521
|
let onProgress = null;
|
|
502
522
|
let lastProgress = -1;
|
|
@@ -512,15 +532,17 @@ class Server {
|
|
|
512
532
|
// actually different and that have increased from the last one we sent.
|
|
513
533
|
|
|
514
534
|
if (currentProgress > lastProgress || totalFileCount < 10) {
|
|
515
|
-
mres
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
535
|
+
if (mres instanceof MultipartResponse) {
|
|
536
|
+
mres.writeChunk(
|
|
537
|
+
{
|
|
538
|
+
"Content-Type": "application/json",
|
|
539
|
+
},
|
|
540
|
+
JSON.stringify({
|
|
541
|
+
done: transformedFileCount,
|
|
542
|
+
total: totalFileCount,
|
|
543
|
+
})
|
|
544
|
+
);
|
|
545
|
+
} // The `uncork` called internally in Node via `promise.nextTick()` may not fire
|
|
524
546
|
// until all of the Promises are resolved because the microtask queue we're
|
|
525
547
|
// in could be starving the event loop. This can cause a bug where the progress
|
|
526
548
|
// is not actually sent in the response until after bundling is complete. This
|
|
@@ -566,6 +588,7 @@ class Server {
|
|
|
566
588
|
mres,
|
|
567
589
|
onProgress,
|
|
568
590
|
req,
|
|
591
|
+
resolverOptions,
|
|
569
592
|
serializerOptions,
|
|
570
593
|
transformOptions,
|
|
571
594
|
};
|
|
@@ -648,6 +671,7 @@ class Server {
|
|
|
648
671
|
graphId,
|
|
649
672
|
graphOptions,
|
|
650
673
|
onProgress,
|
|
674
|
+
resolverOptions,
|
|
651
675
|
serializerOptions,
|
|
652
676
|
transformOptions,
|
|
653
677
|
}) => {
|
|
@@ -657,15 +681,18 @@ class Server {
|
|
|
657
681
|
|
|
658
682
|
const { delta, revision } = await (revPromise != null
|
|
659
683
|
? this._bundler.updateGraph(await revPromise, false)
|
|
660
|
-
: this._bundler.initializeGraph(
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
684
|
+
: this._bundler.initializeGraph(
|
|
685
|
+
entryFile,
|
|
686
|
+
transformOptions,
|
|
687
|
+
resolverOptions,
|
|
688
|
+
{
|
|
689
|
+
onProgress,
|
|
690
|
+
shallow: graphOptions.shallow,
|
|
691
|
+
}
|
|
692
|
+
));
|
|
664
693
|
|
|
665
694
|
const serializer =
|
|
666
695
|
this._config.serializer.customSerializer ||
|
|
667
|
-
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by
|
|
668
|
-
* Flow's LTI update could not be added via codemod */
|
|
669
696
|
((...args) => bundleToString(baseJSBundle(...args)).code);
|
|
670
697
|
|
|
671
698
|
const bundle = await serializer(
|
|
@@ -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,
|