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
package/src/Server.js.flow
CHANGED
|
@@ -26,6 +26,7 @@ import type {Reporter} from './lib/reporting';
|
|
|
26
26
|
import type {
|
|
27
27
|
BundleOptions,
|
|
28
28
|
GraphOptions,
|
|
29
|
+
ResolverInputOptions,
|
|
29
30
|
SplitBundleOptions,
|
|
30
31
|
} from './shared/types.flow';
|
|
31
32
|
import type {IncomingMessage, ServerResponse} from 'http';
|
|
@@ -36,6 +37,8 @@ import type {
|
|
|
36
37
|
ActionStartLogEntry,
|
|
37
38
|
LogEntry,
|
|
38
39
|
} from 'metro-core/src/Logger';
|
|
40
|
+
import type {CustomResolverOptions} from 'metro-resolver/src/types';
|
|
41
|
+
import type {CustomTransformOptions} from 'metro-transform-worker';
|
|
39
42
|
|
|
40
43
|
const {getAsset} = require('./Assets');
|
|
41
44
|
const baseBytecodeBundle = require('./DeltaBundler/Serializers/baseBytecodeBundle');
|
|
@@ -66,7 +69,7 @@ const {
|
|
|
66
69
|
Logger,
|
|
67
70
|
Logger: {createActionStartEntry, createActionEndEntry, log},
|
|
68
71
|
} = require('metro-core');
|
|
69
|
-
|
|
72
|
+
|
|
70
73
|
const mime = require('mime-types');
|
|
71
74
|
const nullthrows = require('nullthrows');
|
|
72
75
|
const path = require('path');
|
|
@@ -115,6 +118,10 @@ export type ServerOptions = $ReadOnly<{
|
|
|
115
118
|
const DELTA_ID_HEADER = 'X-Metro-Delta-ID';
|
|
116
119
|
const FILES_CHANGED_COUNT_HEADER = 'X-Metro-Files-Changed-Count';
|
|
117
120
|
|
|
121
|
+
function getBytecodeVersion() {
|
|
122
|
+
return require('metro-hermes-compiler').VERSION;
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
class Server {
|
|
119
126
|
_bundler: IncrementalBundler;
|
|
120
127
|
_config: ConfigT;
|
|
@@ -178,6 +185,7 @@ class Server {
|
|
|
178
185
|
entryFile,
|
|
179
186
|
graphOptions,
|
|
180
187
|
onProgress,
|
|
188
|
+
resolverOptions,
|
|
181
189
|
serializerOptions,
|
|
182
190
|
transformOptions,
|
|
183
191
|
} = splitBundleOptions(options);
|
|
@@ -185,6 +193,7 @@ class Server {
|
|
|
185
193
|
const {prepend, graph} = await this._bundler.buildGraph(
|
|
186
194
|
entryFile,
|
|
187
195
|
transformOptions,
|
|
196
|
+
resolverOptions,
|
|
188
197
|
{
|
|
189
198
|
onProgress,
|
|
190
199
|
shallow: graphOptions.shallow,
|
|
@@ -196,7 +205,11 @@ class Server {
|
|
|
196
205
|
const bundleOptions = {
|
|
197
206
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
198
207
|
this._config.transformer.asyncRequireModulePath,
|
|
199
|
-
{
|
|
208
|
+
{
|
|
209
|
+
relativeTo: 'project',
|
|
210
|
+
resolverOptions,
|
|
211
|
+
transformOptions,
|
|
212
|
+
},
|
|
200
213
|
),
|
|
201
214
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
202
215
|
createModuleId: this._createModuleId,
|
|
@@ -255,6 +268,7 @@ class Server {
|
|
|
255
268
|
entryFile,
|
|
256
269
|
graphOptions,
|
|
257
270
|
onProgress,
|
|
271
|
+
resolverOptions,
|
|
258
272
|
serializerOptions,
|
|
259
273
|
transformOptions,
|
|
260
274
|
} = splitBundleOptions(options);
|
|
@@ -262,6 +276,7 @@ class Server {
|
|
|
262
276
|
const {prepend, graph} = await this._bundler.buildGraph(
|
|
263
277
|
entryFile,
|
|
264
278
|
transformOptions,
|
|
279
|
+
resolverOptions,
|
|
265
280
|
{onProgress, shallow: graphOptions.shallow},
|
|
266
281
|
);
|
|
267
282
|
|
|
@@ -270,7 +285,11 @@ class Server {
|
|
|
270
285
|
return await getRamBundleInfo(entryPoint, prepend, graph, {
|
|
271
286
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
272
287
|
this._config.transformer.asyncRequireModulePath,
|
|
273
|
-
{
|
|
288
|
+
{
|
|
289
|
+
relativeTo: 'project',
|
|
290
|
+
resolverOptions,
|
|
291
|
+
transformOptions,
|
|
292
|
+
},
|
|
274
293
|
),
|
|
275
294
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
276
295
|
createModuleId: this._createModuleId,
|
|
@@ -295,12 +314,13 @@ class Server {
|
|
|
295
314
|
}
|
|
296
315
|
|
|
297
316
|
async getAssets(options: BundleOptions): Promise<$ReadOnlyArray<AssetData>> {
|
|
298
|
-
const {entryFile,
|
|
317
|
+
const {entryFile, onProgress, resolverOptions, transformOptions} =
|
|
299
318
|
splitBundleOptions(options);
|
|
300
319
|
|
|
301
320
|
const dependencies = await this._bundler.getDependencies(
|
|
302
321
|
[entryFile],
|
|
303
322
|
transformOptions,
|
|
323
|
+
resolverOptions,
|
|
304
324
|
{onProgress, shallow: false},
|
|
305
325
|
);
|
|
306
326
|
|
|
@@ -320,10 +340,15 @@ class Server {
|
|
|
320
340
|
+platform: string,
|
|
321
341
|
...
|
|
322
342
|
}): Promise<Array<string>> {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
343
|
+
const {
|
|
344
|
+
entryFile,
|
|
345
|
+
onProgress,
|
|
346
|
+
resolverOptions,
|
|
347
|
+
transformOptions,
|
|
348
|
+
/* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an
|
|
349
|
+
* error found when Flow v0.122.0 was deployed. To see the error, delete
|
|
350
|
+
* this comment and run Flow. */
|
|
351
|
+
} = splitBundleOptions({
|
|
327
352
|
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
328
353
|
...options,
|
|
329
354
|
bundleType: 'bundle',
|
|
@@ -332,6 +357,7 @@ class Server {
|
|
|
332
357
|
const {prepend, graph} = await this._bundler.buildGraph(
|
|
333
358
|
entryFile,
|
|
334
359
|
transformOptions,
|
|
360
|
+
resolverOptions,
|
|
335
361
|
{onProgress, shallow: false},
|
|
336
362
|
);
|
|
337
363
|
|
|
@@ -445,7 +471,7 @@ class Server {
|
|
|
445
471
|
return parseOptionsFromUrl(
|
|
446
472
|
url,
|
|
447
473
|
new Set(this._config.resolver.platforms),
|
|
448
|
-
|
|
474
|
+
getBytecodeVersion(),
|
|
449
475
|
);
|
|
450
476
|
}
|
|
451
477
|
|
|
@@ -522,30 +548,36 @@ class Server {
|
|
|
522
548
|
res: ServerResponse,
|
|
523
549
|
bundleOptions: BundleOptions,
|
|
524
550
|
) => Promise<void> {
|
|
525
|
-
/* $FlowFixMe[missing-this-annot] The 'this' type annotation(s) required by
|
|
526
|
-
* Flow's LTI update could not be added via codemod */
|
|
527
551
|
return async function requestProcessor(
|
|
552
|
+
this: Server,
|
|
528
553
|
req: IncomingMessage,
|
|
529
554
|
res: ServerResponse,
|
|
530
555
|
bundleOptions: BundleOptions,
|
|
531
556
|
): Promise<void> {
|
|
532
|
-
const {
|
|
533
|
-
|
|
557
|
+
const {
|
|
558
|
+
entryFile,
|
|
559
|
+
graphOptions,
|
|
560
|
+
resolverOptions,
|
|
561
|
+
serializerOptions,
|
|
562
|
+
transformOptions,
|
|
563
|
+
} = splitBundleOptions(bundleOptions);
|
|
534
564
|
|
|
535
565
|
/**
|
|
536
566
|
* `entryFile` is relative to projectRoot, we need to use resolution function
|
|
537
567
|
* to find the appropriate file with supported extensions.
|
|
538
568
|
*/
|
|
539
569
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
540
|
-
transformOptions,
|
|
541
570
|
relativeTo: 'server',
|
|
571
|
+
resolverOptions,
|
|
572
|
+
transformOptions,
|
|
542
573
|
});
|
|
543
574
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
544
|
-
shallow: graphOptions.shallow,
|
|
545
575
|
experimentalImportBundleSupport:
|
|
546
576
|
this._config.transformer.experimentalImportBundleSupport,
|
|
547
577
|
unstable_allowRequireContext:
|
|
548
578
|
this._config.transformer.unstable_allowRequireContext,
|
|
579
|
+
resolverOptions,
|
|
580
|
+
shallow: graphOptions.shallow,
|
|
549
581
|
});
|
|
550
582
|
|
|
551
583
|
// For resources that support deletion, handle the DELETE method.
|
|
@@ -639,6 +671,7 @@ class Server {
|
|
|
639
671
|
mres,
|
|
640
672
|
onProgress,
|
|
641
673
|
req,
|
|
674
|
+
resolverOptions,
|
|
642
675
|
serializerOptions,
|
|
643
676
|
transformOptions,
|
|
644
677
|
};
|
|
@@ -736,6 +769,7 @@ class Server {
|
|
|
736
769
|
graphId,
|
|
737
770
|
graphOptions,
|
|
738
771
|
onProgress,
|
|
772
|
+
resolverOptions,
|
|
739
773
|
serializerOptions,
|
|
740
774
|
transformOptions,
|
|
741
775
|
}) => {
|
|
@@ -743,10 +777,15 @@ class Server {
|
|
|
743
777
|
|
|
744
778
|
const {delta, revision} = await (revPromise != null
|
|
745
779
|
? this._bundler.updateGraph(await revPromise, false)
|
|
746
|
-
: this._bundler.initializeGraph(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
780
|
+
: this._bundler.initializeGraph(
|
|
781
|
+
entryFile,
|
|
782
|
+
transformOptions,
|
|
783
|
+
resolverOptions,
|
|
784
|
+
{
|
|
785
|
+
onProgress,
|
|
786
|
+
shallow: graphOptions.shallow,
|
|
787
|
+
},
|
|
788
|
+
));
|
|
750
789
|
|
|
751
790
|
const serializer =
|
|
752
791
|
this._config.serializer.customSerializer ||
|
|
@@ -761,7 +800,11 @@ class Server {
|
|
|
761
800
|
{
|
|
762
801
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
763
802
|
this._config.transformer.asyncRequireModulePath,
|
|
764
|
-
{
|
|
803
|
+
{
|
|
804
|
+
relativeTo: 'project',
|
|
805
|
+
resolverOptions,
|
|
806
|
+
transformOptions,
|
|
807
|
+
},
|
|
765
808
|
),
|
|
766
809
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
767
810
|
createModuleId: this._createModuleId,
|
|
@@ -859,6 +902,7 @@ class Server {
|
|
|
859
902
|
graphId,
|
|
860
903
|
graphOptions,
|
|
861
904
|
onProgress,
|
|
905
|
+
resolverOptions,
|
|
862
906
|
serializerOptions,
|
|
863
907
|
transformOptions,
|
|
864
908
|
}) => {
|
|
@@ -866,16 +910,25 @@ class Server {
|
|
|
866
910
|
|
|
867
911
|
const {delta, revision} = await (revPromise != null
|
|
868
912
|
? this._bundler.updateGraph(await revPromise, false)
|
|
869
|
-
: this._bundler.initializeGraph(
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
913
|
+
: this._bundler.initializeGraph(
|
|
914
|
+
entryFile,
|
|
915
|
+
transformOptions,
|
|
916
|
+
resolverOptions,
|
|
917
|
+
{
|
|
918
|
+
onProgress,
|
|
919
|
+
shallow: graphOptions.shallow,
|
|
920
|
+
},
|
|
921
|
+
));
|
|
873
922
|
|
|
874
923
|
const bundle = bundleToBytecode(
|
|
875
924
|
baseBytecodeBundle(entryFile, revision.prepend, revision.graph, {
|
|
876
925
|
asyncRequireModulePath: await this._resolveRelativePath(
|
|
877
926
|
this._config.transformer.asyncRequireModulePath,
|
|
878
|
-
{
|
|
927
|
+
{
|
|
928
|
+
relativeTo: 'project',
|
|
929
|
+
resolverOptions,
|
|
930
|
+
transformOptions,
|
|
931
|
+
},
|
|
879
932
|
),
|
|
880
933
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
881
934
|
createModuleId: this._createModuleId,
|
|
@@ -971,6 +1024,7 @@ class Server {
|
|
|
971
1024
|
graphId,
|
|
972
1025
|
graphOptions,
|
|
973
1026
|
onProgress,
|
|
1027
|
+
resolverOptions,
|
|
974
1028
|
serializerOptions,
|
|
975
1029
|
transformOptions,
|
|
976
1030
|
}) => {
|
|
@@ -980,6 +1034,7 @@ class Server {
|
|
|
980
1034
|
({revision} = await this._bundler.initializeGraph(
|
|
981
1035
|
entryFile,
|
|
982
1036
|
transformOptions,
|
|
1037
|
+
resolverOptions,
|
|
983
1038
|
{onProgress, shallow: graphOptions.shallow},
|
|
984
1039
|
));
|
|
985
1040
|
} else {
|
|
@@ -1020,10 +1075,16 @@ class Server {
|
|
|
1020
1075
|
bundler: 'delta',
|
|
1021
1076
|
};
|
|
1022
1077
|
},
|
|
1023
|
-
build: async ({
|
|
1078
|
+
build: async ({
|
|
1079
|
+
entryFile,
|
|
1080
|
+
onProgress,
|
|
1081
|
+
resolverOptions,
|
|
1082
|
+
transformOptions,
|
|
1083
|
+
}) => {
|
|
1024
1084
|
const dependencies = await this._bundler.getDependencies(
|
|
1025
1085
|
[entryFile],
|
|
1026
1086
|
transformOptions,
|
|
1087
|
+
resolverOptions,
|
|
1027
1088
|
{onProgress, shallow: false},
|
|
1028
1089
|
);
|
|
1029
1090
|
|
|
@@ -1144,15 +1205,16 @@ class Server {
|
|
|
1144
1205
|
const options = parseOptionsFromUrl(
|
|
1145
1206
|
reqUrl,
|
|
1146
1207
|
new Set(this._config.resolver.platforms),
|
|
1147
|
-
|
|
1208
|
+
getBytecodeVersion(),
|
|
1148
1209
|
);
|
|
1149
1210
|
|
|
1150
1211
|
const {
|
|
1151
1212
|
entryFile,
|
|
1152
|
-
transformOptions,
|
|
1153
|
-
serializerOptions,
|
|
1154
1213
|
graphOptions,
|
|
1155
1214
|
onProgress,
|
|
1215
|
+
resolverOptions,
|
|
1216
|
+
serializerOptions,
|
|
1217
|
+
transformOptions,
|
|
1156
1218
|
} = splitBundleOptions(options);
|
|
1157
1219
|
|
|
1158
1220
|
/**
|
|
@@ -1160,16 +1222,18 @@ class Server {
|
|
|
1160
1222
|
* to find the appropriate file with supported extensions.
|
|
1161
1223
|
*/
|
|
1162
1224
|
const resolvedEntryFilePath = await this._resolveRelativePath(entryFile, {
|
|
1163
|
-
transformOptions,
|
|
1164
1225
|
relativeTo: 'server',
|
|
1226
|
+
resolverOptions,
|
|
1227
|
+
transformOptions,
|
|
1165
1228
|
});
|
|
1166
1229
|
|
|
1167
1230
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
1168
|
-
shallow: graphOptions.shallow,
|
|
1169
1231
|
experimentalImportBundleSupport:
|
|
1170
1232
|
this._config.transformer.experimentalImportBundleSupport,
|
|
1171
1233
|
unstable_allowRequireContext:
|
|
1172
1234
|
this._config.transformer.unstable_allowRequireContext,
|
|
1235
|
+
resolverOptions,
|
|
1236
|
+
shallow: graphOptions.shallow,
|
|
1173
1237
|
});
|
|
1174
1238
|
let revision;
|
|
1175
1239
|
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
@@ -1177,6 +1241,7 @@ class Server {
|
|
|
1177
1241
|
({revision} = await this._bundler.initializeGraph(
|
|
1178
1242
|
resolvedEntryFilePath,
|
|
1179
1243
|
transformOptions,
|
|
1244
|
+
resolverOptions,
|
|
1180
1245
|
{onProgress, shallow: graphOptions.shallow},
|
|
1181
1246
|
));
|
|
1182
1247
|
} else {
|
|
@@ -1199,16 +1264,19 @@ class Server {
|
|
|
1199
1264
|
async _resolveRelativePath(
|
|
1200
1265
|
filePath: string,
|
|
1201
1266
|
{
|
|
1202
|
-
transformOptions,
|
|
1203
1267
|
relativeTo,
|
|
1268
|
+
resolverOptions,
|
|
1269
|
+
transformOptions,
|
|
1204
1270
|
}: $ReadOnly<{
|
|
1205
|
-
transformOptions: TransformInputOptions,
|
|
1206
1271
|
relativeTo: 'project' | 'server',
|
|
1272
|
+
resolverOptions: ResolverInputOptions,
|
|
1273
|
+
transformOptions: TransformInputOptions,
|
|
1207
1274
|
}>,
|
|
1208
1275
|
): Promise<string> {
|
|
1209
1276
|
const resolutionFn = await transformHelpers.getResolveDependencyFn(
|
|
1210
1277
|
this._bundler.getBundler(),
|
|
1211
1278
|
transformOptions.platform,
|
|
1279
|
+
resolverOptions,
|
|
1212
1280
|
);
|
|
1213
1281
|
const rootDir =
|
|
1214
1282
|
relativeTo === 'server'
|
|
@@ -1229,14 +1297,16 @@ class Server {
|
|
|
1229
1297
|
return this._config.watchFolders;
|
|
1230
1298
|
}
|
|
1231
1299
|
|
|
1232
|
-
static DEFAULT_GRAPH_OPTIONS: {
|
|
1233
|
-
|
|
1300
|
+
static DEFAULT_GRAPH_OPTIONS: $ReadOnly<{
|
|
1301
|
+
customResolverOptions: CustomResolverOptions,
|
|
1302
|
+
customTransformOptions: CustomTransformOptions,
|
|
1234
1303
|
dev: boolean,
|
|
1235
1304
|
hot: boolean,
|
|
1236
1305
|
minify: boolean,
|
|
1237
1306
|
runtimeBytecodeVersion: ?number,
|
|
1238
1307
|
unstable_transformProfile: 'default',
|
|
1239
|
-
} = {
|
|
1308
|
+
}> = {
|
|
1309
|
+
customResolverOptions: Object.create(null),
|
|
1240
1310
|
customTransformOptions: Object.create(null),
|
|
1241
1311
|
dev: true,
|
|
1242
1312
|
hot: false,
|
package/src/index.flow.js
CHANGED
|
@@ -340,14 +340,22 @@ exports.buildGraph = async function (
|
|
|
340
340
|
const bundler = new IncrementalBundler(mergedConfig);
|
|
341
341
|
|
|
342
342
|
try {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
343
|
+
const { customResolverOptions, ...defaultTransformInputOptions } =
|
|
344
|
+
MetroServer.DEFAULT_GRAPH_OPTIONS;
|
|
345
|
+
return await bundler.buildGraphForEntries(
|
|
346
|
+
entries,
|
|
347
|
+
{
|
|
348
|
+
...defaultTransformInputOptions,
|
|
349
|
+
customTransformOptions,
|
|
350
|
+
dev,
|
|
351
|
+
minify,
|
|
352
|
+
platform,
|
|
353
|
+
type,
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
customResolverOptions,
|
|
357
|
+
}
|
|
358
|
+
);
|
|
351
359
|
} finally {
|
|
352
360
|
bundler.end();
|
|
353
361
|
}
|
package/src/index.flow.js.flow
CHANGED
|
@@ -424,14 +424,20 @@ exports.buildGraph = async function (
|
|
|
424
424
|
const bundler = new IncrementalBundler(mergedConfig);
|
|
425
425
|
|
|
426
426
|
try {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
427
|
+
const {customResolverOptions, ...defaultTransformInputOptions} =
|
|
428
|
+
MetroServer.DEFAULT_GRAPH_OPTIONS;
|
|
429
|
+
return await bundler.buildGraphForEntries(
|
|
430
|
+
entries,
|
|
431
|
+
{
|
|
432
|
+
...defaultTransformInputOptions,
|
|
433
|
+
customTransformOptions,
|
|
434
|
+
dev,
|
|
435
|
+
minify,
|
|
436
|
+
platform,
|
|
437
|
+
type,
|
|
438
|
+
},
|
|
439
|
+
{customResolverOptions},
|
|
440
|
+
);
|
|
435
441
|
} finally {
|
|
436
442
|
bundler.end();
|
|
437
443
|
}
|
|
@@ -9,14 +9,13 @@
|
|
|
9
9
|
*/
|
|
10
10
|
"use strict";
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
// The magic number is used as a header for bytecode.
|
|
13
13
|
// It represents a Metro tunnel in binary.
|
|
14
14
|
//
|
|
15
15
|
// 11111111
|
|
16
16
|
// 11100111
|
|
17
17
|
// 11000011
|
|
18
18
|
// 11000011
|
|
19
|
-
|
|
20
19
|
const MAGIC_NUMBER = 0xffe7c3c3;
|
|
21
20
|
|
|
22
21
|
function getFileHeader(moduleCount) {
|
|
@@ -27,6 +26,8 @@ function getFileHeader(moduleCount) {
|
|
|
27
26
|
}
|
|
28
27
|
|
|
29
28
|
function addModuleHeader(buffer) {
|
|
29
|
+
const { getFileLength } = require("metro-hermes-compiler");
|
|
30
|
+
|
|
30
31
|
const fileLength = getFileLength(buffer, 0);
|
|
31
32
|
const header = Buffer.alloc(4);
|
|
32
33
|
header.writeUInt32LE(fileLength, 0);
|
|
@@ -15,8 +15,6 @@ import type {
|
|
|
15
15
|
BytecodeBundle,
|
|
16
16
|
} from 'metro-runtime/src/modules/types.flow';
|
|
17
17
|
|
|
18
|
-
const {getFileLength} = require('metro-hermes-compiler');
|
|
19
|
-
|
|
20
18
|
// The magic number is used as a header for bytecode.
|
|
21
19
|
// It represents a Metro tunnel in binary.
|
|
22
20
|
//
|
|
@@ -34,6 +32,8 @@ function getFileHeader(moduleCount: number): Buffer {
|
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
function addModuleHeader(buffer: Buffer): [Buffer, Buffer] {
|
|
35
|
+
const {getFileLength} = require('metro-hermes-compiler');
|
|
36
|
+
|
|
37
37
|
const fileLength = getFileLength(buffer, 0);
|
|
38
38
|
const header = Buffer.alloc(4);
|
|
39
39
|
header.writeUInt32LE(fileLength, 0);
|
package/src/lib/getGraphId.js
CHANGED
|
@@ -14,15 +14,28 @@ const canonicalize = require("metro-core/src/canonicalize");
|
|
|
14
14
|
function getGraphId(
|
|
15
15
|
entryFile,
|
|
16
16
|
options,
|
|
17
|
-
{
|
|
17
|
+
{
|
|
18
|
+
shallow,
|
|
19
|
+
experimentalImportBundleSupport,
|
|
20
|
+
unstable_allowRequireContext,
|
|
21
|
+
resolverOptions,
|
|
22
|
+
}
|
|
18
23
|
) {
|
|
24
|
+
var _resolverOptions$cust, _options$customTransf;
|
|
25
|
+
|
|
19
26
|
return JSON.stringify(
|
|
20
27
|
{
|
|
21
28
|
entryFile,
|
|
22
29
|
options: {
|
|
30
|
+
customResolverOptions:
|
|
31
|
+
(_resolverOptions$cust = resolverOptions.customResolverOptions) !==
|
|
32
|
+
null && _resolverOptions$cust !== void 0
|
|
33
|
+
? _resolverOptions$cust
|
|
34
|
+
: {},
|
|
23
35
|
customTransformOptions:
|
|
24
|
-
options.customTransformOptions
|
|
25
|
-
|
|
36
|
+
(_options$customTransf = options.customTransformOptions) !== null &&
|
|
37
|
+
_options$customTransf !== void 0
|
|
38
|
+
? _options$customTransf
|
|
26
39
|
: null,
|
|
27
40
|
dev: options.dev,
|
|
28
41
|
experimentalImportSupport: options.experimentalImportSupport || false,
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
import type {TransformInputOptions} from '../DeltaBundler/types.flow';
|
|
14
|
+
import type {ResolverInputOptions} from '../shared/types.flow';
|
|
14
15
|
|
|
15
16
|
const canonicalize = require('metro-core/src/canonicalize');
|
|
16
17
|
|
|
@@ -23,21 +24,20 @@ function getGraphId(
|
|
|
23
24
|
shallow,
|
|
24
25
|
experimentalImportBundleSupport,
|
|
25
26
|
unstable_allowRequireContext,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
resolverOptions,
|
|
28
|
+
}: $ReadOnly<{
|
|
29
|
+
shallow: boolean,
|
|
30
|
+
experimentalImportBundleSupport: boolean,
|
|
31
|
+
unstable_allowRequireContext: boolean,
|
|
32
|
+
resolverOptions: ResolverInputOptions,
|
|
33
|
+
}>,
|
|
32
34
|
): GraphId {
|
|
33
35
|
return JSON.stringify(
|
|
34
36
|
{
|
|
35
37
|
entryFile,
|
|
36
38
|
options: {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
? options.customTransformOptions
|
|
40
|
-
: null,
|
|
39
|
+
customResolverOptions: resolverOptions.customResolverOptions ?? {},
|
|
40
|
+
customTransformOptions: options.customTransformOptions ?? null,
|
|
41
41
|
dev: options.dev,
|
|
42
42
|
experimentalImportSupport: options.experimentalImportSupport || false,
|
|
43
43
|
hot: options.hot,
|
|
@@ -23,9 +23,13 @@ const transformHelpers = require("./transformHelpers");
|
|
|
23
23
|
|
|
24
24
|
const defaults = require("metro-config/src/defaults/defaults");
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
async function getPrependedScripts(
|
|
27
|
+
config,
|
|
28
|
+
options,
|
|
29
|
+
resolverOptions,
|
|
30
|
+
bundler,
|
|
31
|
+
deltaBundler
|
|
32
|
+
) {
|
|
29
33
|
// Get all the polyfills from the relevant option params (the
|
|
30
34
|
// `getPolyfills()` method and the `polyfillModuleNames` variable).
|
|
31
35
|
const polyfillModuleNames = config.serializer
|
|
@@ -39,14 +43,16 @@ async function getPrependedScripts(config, options, bundler, deltaBundler) {
|
|
|
39
43
|
{
|
|
40
44
|
resolve: await transformHelpers.getResolveDependencyFn(
|
|
41
45
|
bundler,
|
|
42
|
-
options.platform
|
|
46
|
+
options.platform,
|
|
47
|
+
resolverOptions
|
|
43
48
|
),
|
|
44
49
|
transform: await transformHelpers.getTransformFn(
|
|
45
50
|
[defaults.moduleSystem, ...polyfillModuleNames],
|
|
46
51
|
bundler,
|
|
47
52
|
deltaBundler,
|
|
48
53
|
config,
|
|
49
|
-
transformOptions
|
|
54
|
+
transformOptions,
|
|
55
|
+
resolverOptions
|
|
50
56
|
),
|
|
51
57
|
unstable_allowRequireContext:
|
|
52
58
|
config.transformer.unstable_allowRequireContext,
|
|
@@ -68,6 +74,8 @@ async function getPrependedScripts(config, options, bundler, deltaBundler) {
|
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
function _getPrelude({ dev, globalPrefix, requireCycleIgnorePatterns }) {
|
|
77
|
+
const { compile } = require("metro-hermes-compiler");
|
|
78
|
+
|
|
71
79
|
const code = getPreludeCode({
|
|
72
80
|
isDev: dev,
|
|
73
81
|
globalPrefix,
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import type Bundler from '../Bundler';
|
|
14
14
|
import type DeltaBundler, {Module} from '../DeltaBundler';
|
|
15
15
|
import type {TransformInputOptions} from '../DeltaBundler/types.flow';
|
|
16
|
+
import type {ResolverInputOptions} from '../shared/types.flow';
|
|
16
17
|
import type {ConfigT} from 'metro-config/src/configTypes.flow';
|
|
17
18
|
|
|
18
19
|
import CountingSet from './CountingSet';
|
|
@@ -21,7 +22,6 @@ const countLines = require('./countLines');
|
|
|
21
22
|
const getPreludeCode = require('./getPreludeCode');
|
|
22
23
|
const transformHelpers = require('./transformHelpers');
|
|
23
24
|
const defaults = require('metro-config/src/defaults/defaults');
|
|
24
|
-
const {compile} = require('metro-hermes-compiler');
|
|
25
25
|
|
|
26
26
|
async function getPrependedScripts(
|
|
27
27
|
config: ConfigT,
|
|
@@ -29,6 +29,7 @@ async function getPrependedScripts(
|
|
|
29
29
|
TransformInputOptions,
|
|
30
30
|
{type: $PropertyType<TransformInputOptions, 'type'>, ...},
|
|
31
31
|
>,
|
|
32
|
+
resolverOptions: ResolverInputOptions,
|
|
32
33
|
bundler: Bundler,
|
|
33
34
|
deltaBundler: DeltaBundler<>,
|
|
34
35
|
): Promise<$ReadOnlyArray<Module<>>> {
|
|
@@ -51,6 +52,7 @@ async function getPrependedScripts(
|
|
|
51
52
|
resolve: await transformHelpers.getResolveDependencyFn(
|
|
52
53
|
bundler,
|
|
53
54
|
options.platform,
|
|
55
|
+
resolverOptions,
|
|
54
56
|
),
|
|
55
57
|
transform: await transformHelpers.getTransformFn(
|
|
56
58
|
[defaults.moduleSystem, ...polyfillModuleNames],
|
|
@@ -58,6 +60,7 @@ async function getPrependedScripts(
|
|
|
58
60
|
deltaBundler,
|
|
59
61
|
config,
|
|
60
62
|
transformOptions,
|
|
63
|
+
resolverOptions,
|
|
61
64
|
),
|
|
62
65
|
unstable_allowRequireContext:
|
|
63
66
|
config.transformer.unstable_allowRequireContext,
|
|
@@ -89,6 +92,8 @@ function _getPrelude({
|
|
|
89
92
|
requireCycleIgnorePatterns: $ReadOnlyArray<RegExp>,
|
|
90
93
|
...
|
|
91
94
|
}): Module<> {
|
|
95
|
+
const {compile} = require('metro-hermes-compiler');
|
|
96
|
+
|
|
92
97
|
const code = getPreludeCode({
|
|
93
98
|
isDev: dev,
|
|
94
99
|
globalPrefix,
|