metro 0.76.1 → 0.76.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 +21 -23
- package/src/DeltaBundler/Graph.js +6 -19
- package/src/DeltaBundler/Graph.js.flow +8 -15
- package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -0
- package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -0
- package/src/DeltaBundler/Serializers/helpers/js.js +22 -6
- package/src/DeltaBundler/Serializers/helpers/js.js.flow +24 -6
- package/src/DeltaBundler/Serializers/helpers/processModules.js +2 -0
- package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +3 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.js +1 -0
- package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +1 -0
- package/src/DeltaBundler/types.d.ts +5 -3
- package/src/DeltaBundler/types.flow.js.flow +1 -1
- package/src/HmrServer.js +3 -3
- package/src/HmrServer.js.flow +5 -3
- package/src/IncrementalBundler.js +7 -6
- package/src/IncrementalBundler.js.flow +8 -6
- package/src/Server/symbolicate.js +33 -5
- package/src/Server/symbolicate.js.flow +40 -9
- package/src/Server.js +19 -11
- package/src/Server.js.flow +31 -16
- package/src/index.d.ts +16 -6
- package/src/index.flow.js +15 -2
- package/src/index.flow.js.flow +29 -4
- package/{types/lib/getGraphId.d.ts → src/integration_tests/basic_bundle/loadBundleAsyncForTest.js} +7 -2
- package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js.flow +20 -0
- package/src/integration_tests/execBundle.js +3 -0
- package/src/integration_tests/execBundle.js.flow +4 -1
- package/src/integration_tests/metro.config.js +5 -0
- package/src/lib/getGraphId.js +2 -7
- package/src/lib/getGraphId.js.flow +3 -3
- package/src/lib/getPrependedScripts.js +1 -2
- package/src/lib/getPrependedScripts.js.flow +1 -2
- package/src/lib/parseOptionsFromUrl.js +1 -0
- package/src/lib/parseOptionsFromUrl.js.flow +1 -0
- package/src/lib/splitBundleOptions.js +1 -0
- package/src/lib/splitBundleOptions.js.flow +1 -0
- package/src/lib/transformHelpers.js +1 -2
- package/src/lib/transformHelpers.js.flow +1 -2
- package/src/node-haste/DependencyGraph.js +6 -1
- package/src/node-haste/DependencyGraph.js.flow +7 -1
- package/src/shared/types.d.ts +2 -0
- package/src/shared/types.flow.js.flow +2 -1
- package/types/Asset.d.ts +0 -25
- package/types/Bundler.d.ts +0 -39
- package/types/DeltaBundler/Graph.d.ts +0 -40
- package/types/DeltaBundler/Serializers/getRamBundleInfo.d.ts +0 -18
- package/types/DeltaBundler/Worker.d.ts +0 -47
- package/types/DeltaBundler/types.d.ts +0 -167
- package/types/DeltaBundler.d.ts +0 -58
- package/types/IncrementalBundler.d.ts +0 -97
- package/types/ModuleGraph/worker/collectDependencies.d.ts +0 -27
- package/types/Server/MultipartResponse.d.ts +0 -31
- package/types/Server.d.ts +0 -113
- package/types/index.d.ts +0 -151
- package/types/lib/CountingSet.d.ts +0 -48
- package/types/lib/TerminalReporter.d.ts +0 -27
- package/types/lib/contextModule.d.ts +0 -22
- package/types/lib/reporting.d.ts +0 -140
- package/types/node-haste/DependencyGraph.d.ts +0 -59
- package/types/shared/output/bundle.d.ts +0 -31
- package/types/shared/types.d.ts +0 -138
|
@@ -30,9 +30,13 @@ export type StackFrameInput = {
|
|
|
30
30
|
+methodName: ?string,
|
|
31
31
|
...
|
|
32
32
|
};
|
|
33
|
-
export type
|
|
33
|
+
export type IntermediateStackFrame = {
|
|
34
34
|
...StackFrameInput,
|
|
35
|
-
|
|
35
|
+
collapse?: boolean,
|
|
36
|
+
...
|
|
37
|
+
};
|
|
38
|
+
export type StackFrameOutput = $ReadOnly<{
|
|
39
|
+
...IntermediateStackFrame,
|
|
36
40
|
...
|
|
37
41
|
}>;
|
|
38
42
|
type ExplodedSourceMapModule = $ElementType<ExplodedSourceMap, number>;
|
|
@@ -63,6 +67,7 @@ async function symbolicate(
|
|
|
63
67
|
stack: $ReadOnlyArray<StackFrameInput>,
|
|
64
68
|
maps: Iterable<[string, ExplodedSourceMap]>,
|
|
65
69
|
config: ConfigT,
|
|
70
|
+
extraData: mixed,
|
|
66
71
|
): Promise<$ReadOnlyArray<StackFrameOutput>> {
|
|
67
72
|
const mapsByUrl = new Map<?string, ExplodedSourceMap>();
|
|
68
73
|
for (const [url, map] of maps) {
|
|
@@ -157,10 +162,10 @@ async function symbolicate(
|
|
|
157
162
|
return null;
|
|
158
163
|
}
|
|
159
164
|
|
|
160
|
-
function symbolicateFrame(frame: StackFrameInput):
|
|
165
|
+
function symbolicateFrame(frame: StackFrameInput): IntermediateStackFrame {
|
|
161
166
|
const module = findModule(frame);
|
|
162
167
|
if (!module) {
|
|
163
|
-
return frame;
|
|
168
|
+
return {...frame};
|
|
164
169
|
}
|
|
165
170
|
if (!Array.isArray(module.map)) {
|
|
166
171
|
throw new Error(
|
|
@@ -169,7 +174,7 @@ async function symbolicate(
|
|
|
169
174
|
}
|
|
170
175
|
const originalPos = findOriginalPos(frame, module);
|
|
171
176
|
if (!originalPos) {
|
|
172
|
-
return frame;
|
|
177
|
+
return {...frame};
|
|
173
178
|
}
|
|
174
179
|
const methodName =
|
|
175
180
|
findFunctionName(originalPos, module) ?? frame.methodName;
|
|
@@ -182,15 +187,41 @@ async function symbolicate(
|
|
|
182
187
|
};
|
|
183
188
|
}
|
|
184
189
|
|
|
190
|
+
/**
|
|
191
|
+
* `customizeFrame` allows for custom modifications of the symbolicated frame in a stack.
|
|
192
|
+
* It can be used to collapse stack frames that are not relevant to users, pointing them
|
|
193
|
+
* to more relevant product code instead.
|
|
194
|
+
*
|
|
195
|
+
* An example usecase is a library throwing an error while sanitizing inputs from product code.
|
|
196
|
+
* In some cases, it's more useful to point the developer looking at the error towards the product code directly.
|
|
197
|
+
*/
|
|
185
198
|
async function customizeFrame(
|
|
186
|
-
frame:
|
|
187
|
-
): Promise<
|
|
199
|
+
frame: IntermediateStackFrame,
|
|
200
|
+
): Promise<IntermediateStackFrame> {
|
|
188
201
|
const customizations =
|
|
189
202
|
(await config.symbolicator.customizeFrame(frame)) || {};
|
|
190
|
-
return {...frame,
|
|
203
|
+
return {...frame, ...customizations};
|
|
191
204
|
}
|
|
192
205
|
|
|
193
|
-
|
|
206
|
+
/**
|
|
207
|
+
* `customizeStack` allows for custom modifications of a symbolicated stack.
|
|
208
|
+
* Where `customizeFrame` operates on individual frames, this hook can process the entire stack in context.
|
|
209
|
+
*
|
|
210
|
+
* Note: `customizeStack` has access to an `extraData` object which can be used to attach metadata
|
|
211
|
+
* to the error coming in, to be used by the customizeStack hook.
|
|
212
|
+
*/
|
|
213
|
+
async function customizeStack(
|
|
214
|
+
symbolicatedStack: Array<IntermediateStackFrame>,
|
|
215
|
+
): Promise<Array<IntermediateStackFrame>> {
|
|
216
|
+
return await config.symbolicator.customizeStack(
|
|
217
|
+
symbolicatedStack,
|
|
218
|
+
extraData,
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return Promise.all(stack.map(symbolicateFrame).map(customizeFrame)).then(
|
|
223
|
+
customizeStack,
|
|
224
|
+
);
|
|
194
225
|
}
|
|
195
226
|
|
|
196
227
|
module.exports = symbolicate;
|
package/src/Server.js
CHANGED
|
@@ -106,6 +106,7 @@ class Server {
|
|
|
106
106
|
{
|
|
107
107
|
onProgress,
|
|
108
108
|
shallow: graphOptions.shallow,
|
|
109
|
+
lazy: graphOptions.lazy,
|
|
109
110
|
}
|
|
110
111
|
);
|
|
111
112
|
const entryPoint = this._getEntryPointAbsolutePath(entryFile);
|
|
@@ -122,7 +123,7 @@ class Server {
|
|
|
122
123
|
createModuleId: this._createModuleId,
|
|
123
124
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
124
125
|
dev: transformOptions.dev,
|
|
125
|
-
includeAsyncPaths:
|
|
126
|
+
includeAsyncPaths: graphOptions.lazy,
|
|
126
127
|
projectRoot: this._config.projectRoot,
|
|
127
128
|
modulesOnly: serializerOptions.modulesOnly,
|
|
128
129
|
runBeforeMainModule:
|
|
@@ -186,6 +187,7 @@ class Server {
|
|
|
186
187
|
{
|
|
187
188
|
onProgress,
|
|
188
189
|
shallow: graphOptions.shallow,
|
|
190
|
+
lazy: graphOptions.lazy,
|
|
189
191
|
}
|
|
190
192
|
);
|
|
191
193
|
const entryPoint = this._getEntryPointAbsolutePath(entryFile);
|
|
@@ -204,7 +206,7 @@ class Server {
|
|
|
204
206
|
excludeSource: serializerOptions.excludeSource,
|
|
205
207
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
206
208
|
getTransformOptions: this._config.transformer.getTransformOptions,
|
|
207
|
-
includeAsyncPaths:
|
|
209
|
+
includeAsyncPaths: graphOptions.lazy,
|
|
208
210
|
platform: transformOptions.platform,
|
|
209
211
|
projectRoot: this._config.projectRoot,
|
|
210
212
|
modulesOnly: serializerOptions.modulesOnly,
|
|
@@ -230,6 +232,7 @@ class Server {
|
|
|
230
232
|
{
|
|
231
233
|
onProgress,
|
|
232
234
|
shallow: false,
|
|
235
|
+
lazy: false,
|
|
233
236
|
}
|
|
234
237
|
);
|
|
235
238
|
return await getAssets(dependencies, {
|
|
@@ -261,6 +264,7 @@ class Server {
|
|
|
261
264
|
{
|
|
262
265
|
onProgress,
|
|
263
266
|
shallow: false,
|
|
267
|
+
lazy: false,
|
|
264
268
|
}
|
|
265
269
|
);
|
|
266
270
|
const platform =
|
|
@@ -436,12 +440,11 @@ class Server {
|
|
|
436
440
|
transformOptions,
|
|
437
441
|
});
|
|
438
442
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
439
|
-
experimentalImportBundleSupport:
|
|
440
|
-
this._config.server.experimentalImportBundleSupport,
|
|
441
443
|
unstable_allowRequireContext:
|
|
442
444
|
this._config.transformer.unstable_allowRequireContext,
|
|
443
445
|
resolverOptions,
|
|
444
446
|
shallow: graphOptions.shallow,
|
|
447
|
+
lazy: graphOptions.lazy,
|
|
445
448
|
});
|
|
446
449
|
|
|
447
450
|
// For resources that support deletion, handle the DELETE method.
|
|
@@ -640,6 +643,7 @@ class Server {
|
|
|
640
643
|
{
|
|
641
644
|
onProgress,
|
|
642
645
|
shallow: graphOptions.shallow,
|
|
646
|
+
lazy: graphOptions.lazy,
|
|
643
647
|
}
|
|
644
648
|
));
|
|
645
649
|
bundlePerfLogger.point("resolvingAndTransformingDependencies_end");
|
|
@@ -665,8 +669,7 @@ class Server {
|
|
|
665
669
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
666
670
|
createModuleId: this._createModuleId,
|
|
667
671
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
668
|
-
includeAsyncPaths:
|
|
669
|
-
this._config.server.experimentalImportBundleSupport,
|
|
672
|
+
includeAsyncPaths: graphOptions.lazy,
|
|
670
673
|
dev: transformOptions.dev,
|
|
671
674
|
projectRoot: this._config.projectRoot,
|
|
672
675
|
modulesOnly: serializerOptions.modulesOnly,
|
|
@@ -773,6 +776,7 @@ class Server {
|
|
|
773
776
|
{
|
|
774
777
|
onProgress,
|
|
775
778
|
shallow: graphOptions.shallow,
|
|
779
|
+
lazy: graphOptions.lazy,
|
|
776
780
|
}
|
|
777
781
|
));
|
|
778
782
|
} else {
|
|
@@ -822,6 +826,7 @@ class Server {
|
|
|
822
826
|
{
|
|
823
827
|
onProgress,
|
|
824
828
|
shallow: false,
|
|
829
|
+
lazy: false,
|
|
825
830
|
}
|
|
826
831
|
);
|
|
827
832
|
return await getAssets(dependencies, {
|
|
@@ -884,7 +889,8 @@ class Server {
|
|
|
884
889
|
debug("Start symbolication");
|
|
885
890
|
/* $FlowFixMe: where is `rawBody` defined? Is it added by the `connect` framework? */
|
|
886
891
|
const body = await req.rawBody;
|
|
887
|
-
const
|
|
892
|
+
const parsedBody = JSON.parse(body);
|
|
893
|
+
const stack = parsedBody.stack.map((frame) => {
|
|
888
894
|
if (frame.file && frame.file.includes("://")) {
|
|
889
895
|
return {
|
|
890
896
|
...frame,
|
|
@@ -913,10 +919,11 @@ class Server {
|
|
|
913
919
|
Array.from(urls.values()).map(this._explodedSourceMapForURL, this)
|
|
914
920
|
);
|
|
915
921
|
debug("Performing fast symbolication");
|
|
916
|
-
const symbolicatedStack = await
|
|
922
|
+
const symbolicatedStack = await symbolicate(
|
|
917
923
|
stack,
|
|
918
924
|
zip(urls.values(), sourceMaps),
|
|
919
|
-
this._config
|
|
925
|
+
this._config,
|
|
926
|
+
parsedBody.extraData ?? {}
|
|
920
927
|
);
|
|
921
928
|
debug("Symbolication done");
|
|
922
929
|
res.end(
|
|
@@ -962,12 +969,11 @@ class Server {
|
|
|
962
969
|
transformOptions,
|
|
963
970
|
});
|
|
964
971
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
965
|
-
experimentalImportBundleSupport:
|
|
966
|
-
this._config.server.experimentalImportBundleSupport,
|
|
967
972
|
unstable_allowRequireContext:
|
|
968
973
|
this._config.transformer.unstable_allowRequireContext,
|
|
969
974
|
resolverOptions,
|
|
970
975
|
shallow: graphOptions.shallow,
|
|
976
|
+
lazy: graphOptions.lazy,
|
|
971
977
|
});
|
|
972
978
|
let revision;
|
|
973
979
|
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
@@ -979,6 +985,7 @@ class Server {
|
|
|
979
985
|
{
|
|
980
986
|
onProgress,
|
|
981
987
|
shallow: graphOptions.shallow,
|
|
988
|
+
lazy: graphOptions.lazy,
|
|
982
989
|
}
|
|
983
990
|
));
|
|
984
991
|
} else {
|
|
@@ -1031,6 +1038,7 @@ class Server {
|
|
|
1031
1038
|
...Server.DEFAULT_GRAPH_OPTIONS,
|
|
1032
1039
|
excludeSource: false,
|
|
1033
1040
|
inlineSourceMap: false,
|
|
1041
|
+
lazy: false,
|
|
1034
1042
|
modulesOnly: false,
|
|
1035
1043
|
onProgress: null,
|
|
1036
1044
|
runModule: true,
|
package/src/Server.js.flow
CHANGED
|
@@ -201,6 +201,7 @@ class Server {
|
|
|
201
201
|
{
|
|
202
202
|
onProgress,
|
|
203
203
|
shallow: graphOptions.shallow,
|
|
204
|
+
lazy: graphOptions.lazy,
|
|
204
205
|
},
|
|
205
206
|
);
|
|
206
207
|
|
|
@@ -219,7 +220,7 @@ class Server {
|
|
|
219
220
|
createModuleId: this._createModuleId,
|
|
220
221
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
221
222
|
dev: transformOptions.dev,
|
|
222
|
-
includeAsyncPaths:
|
|
223
|
+
includeAsyncPaths: graphOptions.lazy,
|
|
223
224
|
projectRoot: this._config.projectRoot,
|
|
224
225
|
modulesOnly: serializerOptions.modulesOnly,
|
|
225
226
|
runBeforeMainModule:
|
|
@@ -282,7 +283,11 @@ class Server {
|
|
|
282
283
|
entryFile,
|
|
283
284
|
transformOptions,
|
|
284
285
|
resolverOptions,
|
|
285
|
-
{
|
|
286
|
+
{
|
|
287
|
+
onProgress,
|
|
288
|
+
shallow: graphOptions.shallow,
|
|
289
|
+
lazy: graphOptions.lazy,
|
|
290
|
+
},
|
|
286
291
|
);
|
|
287
292
|
|
|
288
293
|
const entryPoint = this._getEntryPointAbsolutePath(entryFile);
|
|
@@ -302,7 +307,7 @@ class Server {
|
|
|
302
307
|
excludeSource: serializerOptions.excludeSource,
|
|
303
308
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
304
309
|
getTransformOptions: this._config.transformer.getTransformOptions,
|
|
305
|
-
includeAsyncPaths:
|
|
310
|
+
includeAsyncPaths: graphOptions.lazy,
|
|
306
311
|
platform: transformOptions.platform,
|
|
307
312
|
projectRoot: this._config.projectRoot,
|
|
308
313
|
modulesOnly: serializerOptions.modulesOnly,
|
|
@@ -327,7 +332,7 @@ class Server {
|
|
|
327
332
|
[entryFile],
|
|
328
333
|
transformOptions,
|
|
329
334
|
resolverOptions,
|
|
330
|
-
{onProgress, shallow: false},
|
|
335
|
+
{onProgress, shallow: false, lazy: false},
|
|
331
336
|
);
|
|
332
337
|
|
|
333
338
|
return await getAssets(dependencies, {
|
|
@@ -364,7 +369,7 @@ class Server {
|
|
|
364
369
|
entryFile,
|
|
365
370
|
transformOptions,
|
|
366
371
|
resolverOptions,
|
|
367
|
-
{onProgress, shallow: false},
|
|
372
|
+
{onProgress, shallow: false, lazy: false},
|
|
368
373
|
);
|
|
369
374
|
|
|
370
375
|
const platform =
|
|
@@ -596,12 +601,11 @@ class Server {
|
|
|
596
601
|
transformOptions,
|
|
597
602
|
});
|
|
598
603
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
599
|
-
experimentalImportBundleSupport:
|
|
600
|
-
this._config.server.experimentalImportBundleSupport,
|
|
601
604
|
unstable_allowRequireContext:
|
|
602
605
|
this._config.transformer.unstable_allowRequireContext,
|
|
603
606
|
resolverOptions,
|
|
604
607
|
shallow: graphOptions.shallow,
|
|
608
|
+
lazy: graphOptions.lazy,
|
|
605
609
|
});
|
|
606
610
|
|
|
607
611
|
// For resources that support deletion, handle the DELETE method.
|
|
@@ -830,6 +834,7 @@ class Server {
|
|
|
830
834
|
{
|
|
831
835
|
onProgress,
|
|
832
836
|
shallow: graphOptions.shallow,
|
|
837
|
+
lazy: graphOptions.lazy,
|
|
833
838
|
},
|
|
834
839
|
));
|
|
835
840
|
bundlePerfLogger.point('resolvingAndTransformingDependencies_end');
|
|
@@ -856,8 +861,7 @@ class Server {
|
|
|
856
861
|
processModuleFilter: this._config.serializer.processModuleFilter,
|
|
857
862
|
createModuleId: this._createModuleId,
|
|
858
863
|
getRunModuleStatement: this._config.serializer.getRunModuleStatement,
|
|
859
|
-
includeAsyncPaths:
|
|
860
|
-
this._config.server.experimentalImportBundleSupport,
|
|
864
|
+
includeAsyncPaths: graphOptions.lazy,
|
|
861
865
|
dev: transformOptions.dev,
|
|
862
866
|
projectRoot: this._config.projectRoot,
|
|
863
867
|
modulesOnly: serializerOptions.modulesOnly,
|
|
@@ -974,7 +978,11 @@ class Server {
|
|
|
974
978
|
entryFile,
|
|
975
979
|
transformOptions,
|
|
976
980
|
resolverOptions,
|
|
977
|
-
{
|
|
981
|
+
{
|
|
982
|
+
onProgress,
|
|
983
|
+
shallow: graphOptions.shallow,
|
|
984
|
+
lazy: graphOptions.lazy,
|
|
985
|
+
},
|
|
978
986
|
));
|
|
979
987
|
} else {
|
|
980
988
|
({revision} = await this._bundler.updateGraph(await revPromise, false));
|
|
@@ -1028,7 +1036,7 @@ class Server {
|
|
|
1028
1036
|
[entryFile],
|
|
1029
1037
|
transformOptions,
|
|
1030
1038
|
resolverOptions,
|
|
1031
|
-
{onProgress, shallow: false},
|
|
1039
|
+
{onProgress, shallow: false, lazy: false},
|
|
1032
1040
|
);
|
|
1033
1041
|
|
|
1034
1042
|
return await getAssets(dependencies, {
|
|
@@ -1094,7 +1102,8 @@ class Server {
|
|
|
1094
1102
|
debug('Start symbolication');
|
|
1095
1103
|
/* $FlowFixMe: where is `rawBody` defined? Is it added by the `connect` framework? */
|
|
1096
1104
|
const body = await req.rawBody;
|
|
1097
|
-
const
|
|
1105
|
+
const parsedBody = JSON.parse(body);
|
|
1106
|
+
const stack = parsedBody.stack.map(frame => {
|
|
1098
1107
|
if (frame.file && frame.file.includes('://')) {
|
|
1099
1108
|
return {
|
|
1100
1109
|
...frame,
|
|
@@ -1126,10 +1135,11 @@ class Server {
|
|
|
1126
1135
|
);
|
|
1127
1136
|
|
|
1128
1137
|
debug('Performing fast symbolication');
|
|
1129
|
-
const symbolicatedStack = await
|
|
1138
|
+
const symbolicatedStack = await symbolicate(
|
|
1130
1139
|
stack,
|
|
1131
1140
|
zip(urls.values(), sourceMaps),
|
|
1132
1141
|
this._config,
|
|
1142
|
+
parsedBody.extraData ?? {},
|
|
1133
1143
|
);
|
|
1134
1144
|
|
|
1135
1145
|
debug('Symbolication done');
|
|
@@ -1175,12 +1185,11 @@ class Server {
|
|
|
1175
1185
|
});
|
|
1176
1186
|
|
|
1177
1187
|
const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
|
|
1178
|
-
experimentalImportBundleSupport:
|
|
1179
|
-
this._config.server.experimentalImportBundleSupport,
|
|
1180
1188
|
unstable_allowRequireContext:
|
|
1181
1189
|
this._config.transformer.unstable_allowRequireContext,
|
|
1182
1190
|
resolverOptions,
|
|
1183
1191
|
shallow: graphOptions.shallow,
|
|
1192
|
+
lazy: graphOptions.lazy,
|
|
1184
1193
|
});
|
|
1185
1194
|
let revision;
|
|
1186
1195
|
const revPromise = this._bundler.getRevisionByGraphId(graphId);
|
|
@@ -1189,7 +1198,11 @@ class Server {
|
|
|
1189
1198
|
resolvedEntryFilePath,
|
|
1190
1199
|
transformOptions,
|
|
1191
1200
|
resolverOptions,
|
|
1192
|
-
{
|
|
1201
|
+
{
|
|
1202
|
+
onProgress,
|
|
1203
|
+
shallow: graphOptions.shallow,
|
|
1204
|
+
lazy: graphOptions.lazy,
|
|
1205
|
+
},
|
|
1193
1206
|
));
|
|
1194
1207
|
} else {
|
|
1195
1208
|
({revision} = await this._bundler.updateGraph(await revPromise, false));
|
|
@@ -1264,6 +1277,7 @@ class Server {
|
|
|
1264
1277
|
...typeof Server.DEFAULT_GRAPH_OPTIONS,
|
|
1265
1278
|
excludeSource: false,
|
|
1266
1279
|
inlineSourceMap: false,
|
|
1280
|
+
lazy: false,
|
|
1267
1281
|
modulesOnly: false,
|
|
1268
1282
|
onProgress: null,
|
|
1269
1283
|
runModule: true,
|
|
@@ -1274,6 +1288,7 @@ class Server {
|
|
|
1274
1288
|
...Server.DEFAULT_GRAPH_OPTIONS,
|
|
1275
1289
|
excludeSource: false,
|
|
1276
1290
|
inlineSourceMap: false,
|
|
1291
|
+
lazy: false,
|
|
1277
1292
|
modulesOnly: false,
|
|
1278
1293
|
onProgress: null,
|
|
1279
1294
|
runModule: true,
|
package/src/index.d.ts
CHANGED
|
@@ -14,22 +14,25 @@ export * from './ModuleGraph/worker/collectDependencies';
|
|
|
14
14
|
export * from './Server';
|
|
15
15
|
export * from './lib/reporting';
|
|
16
16
|
|
|
17
|
-
import type {
|
|
17
|
+
import type {EventEmitter} from 'events';
|
|
18
|
+
import type {IncomingMessage, Server as HttpServer} from 'http';
|
|
18
19
|
import type {Server as HttpsServer} from 'https';
|
|
19
20
|
import type {
|
|
20
21
|
ConfigT,
|
|
21
22
|
InputConfigT,
|
|
22
|
-
loadConfig,
|
|
23
23
|
MetroConfig,
|
|
24
24
|
Middleware,
|
|
25
25
|
} from 'metro-config';
|
|
26
26
|
import type {CustomTransformOptions} from 'metro-babel-transformer';
|
|
27
27
|
import type {ReadOnlyGraph} from './DeltaBundler/types';
|
|
28
|
-
import type {
|
|
28
|
+
import type {Duplex} from 'stream';
|
|
29
29
|
import Yargs = require('yargs');
|
|
30
30
|
import type {default as MetroServer, ServerOptions} from './Server';
|
|
31
31
|
import type {OutputOptions, RequestOptions} from './shared/types';
|
|
32
32
|
|
|
33
|
+
export {loadConfig, mergeConfig, resolveConfig} from 'metro-config';
|
|
34
|
+
export {Terminal} from 'metro-core';
|
|
35
|
+
|
|
33
36
|
export {HttpServer, HttpsServer};
|
|
34
37
|
|
|
35
38
|
interface MetroMiddleWare {
|
|
@@ -43,6 +46,15 @@ export interface RunMetroOptions extends ServerOptions {
|
|
|
43
46
|
waitForBundler?: boolean;
|
|
44
47
|
}
|
|
45
48
|
|
|
49
|
+
interface WebsocketServer extends EventEmitter {
|
|
50
|
+
handleUpgrade<T = WebsocketServer>(
|
|
51
|
+
request: IncomingMessage,
|
|
52
|
+
socket: Duplex,
|
|
53
|
+
upgradeHead: Buffer,
|
|
54
|
+
callback: (client: T, request: IncomingMessage) => void,
|
|
55
|
+
): void;
|
|
56
|
+
}
|
|
57
|
+
|
|
46
58
|
export interface RunServerOptions {
|
|
47
59
|
hasReducedPerformance?: boolean;
|
|
48
60
|
host?: string;
|
|
@@ -63,7 +75,7 @@ export interface RunServerOptions {
|
|
|
63
75
|
waitForBundler?: boolean;
|
|
64
76
|
watch?: boolean;
|
|
65
77
|
websocketEndpoints?: {
|
|
66
|
-
[path: string]:
|
|
78
|
+
[path: string]: WebsocketServer;
|
|
67
79
|
};
|
|
68
80
|
}
|
|
69
81
|
|
|
@@ -114,8 +126,6 @@ export function runMetro(
|
|
|
114
126
|
options?: RunMetroOptions,
|
|
115
127
|
): Promise<MetroServer>;
|
|
116
128
|
|
|
117
|
-
export {loadConfig};
|
|
118
|
-
|
|
119
129
|
export function createConnectMiddleWare(
|
|
120
130
|
config: ConfigT,
|
|
121
131
|
options?: RunMetroOptions,
|
package/src/index.flow.js
CHANGED
|
@@ -23,13 +23,21 @@ const chalk = require("chalk");
|
|
|
23
23
|
const fs = require("fs");
|
|
24
24
|
const http = require("http");
|
|
25
25
|
const https = require("https");
|
|
26
|
-
const {
|
|
26
|
+
const {
|
|
27
|
+
getDefaultConfig,
|
|
28
|
+
loadConfig,
|
|
29
|
+
mergeConfig,
|
|
30
|
+
resolveConfig,
|
|
31
|
+
} = require("metro-config");
|
|
32
|
+
const { Terminal } = require("metro-core");
|
|
27
33
|
const { InspectorProxy } = require("metro-inspector-proxy");
|
|
28
34
|
const net = require("net");
|
|
29
35
|
const { parse } = require("url");
|
|
30
|
-
|
|
36
|
+
exports.Terminal = Terminal;
|
|
31
37
|
async function getConfig(config) {
|
|
32
38
|
const defaultConfig = await getDefaultConfig(config.projectRoot);
|
|
39
|
+
// $FlowFixMe[incompatible-variance]
|
|
40
|
+
// $FlowFixMe[incompatible-call]
|
|
33
41
|
return mergeConfig(defaultConfig, config);
|
|
34
42
|
}
|
|
35
43
|
async function runMetro(config, options) {
|
|
@@ -70,7 +78,10 @@ async function runMetro(config, options) {
|
|
|
70
78
|
exports.runMetro = runMetro;
|
|
71
79
|
exports.loadConfig = loadConfig;
|
|
72
80
|
exports.mergeConfig = mergeConfig;
|
|
81
|
+
exports.resolveConfig = resolveConfig;
|
|
73
82
|
const createConnectMiddleware = async function (config, options) {
|
|
83
|
+
// $FlowFixMe[incompatible-variance]
|
|
84
|
+
// $FlowFixMe[incompatible-call]
|
|
74
85
|
const metroServer = await runMetro(config, options);
|
|
75
86
|
let enhancedMiddleware = metroServer.processRequest;
|
|
76
87
|
|
|
@@ -247,6 +258,8 @@ exports.runBuild = async (
|
|
|
247
258
|
sourceMapUrl,
|
|
248
259
|
}
|
|
249
260
|
) => {
|
|
261
|
+
// $FlowFixMe[incompatible-variance]
|
|
262
|
+
// $FlowFixMe[incompatible-call]
|
|
250
263
|
const metroServer = await runMetro(config, {
|
|
251
264
|
watch: false,
|
|
252
265
|
});
|
package/src/index.flow.js.flow
CHANGED
|
@@ -15,7 +15,8 @@ import type {CustomResolverOptions} from 'metro-resolver';
|
|
|
15
15
|
import type {ReadOnlyGraph} from './DeltaBundler';
|
|
16
16
|
import type {ServerOptions} from './Server';
|
|
17
17
|
import type {OutputOptions, RequestOptions} from './shared/types.flow.js';
|
|
18
|
-
import type
|
|
18
|
+
import type EventEmitter from 'events';
|
|
19
|
+
import type {IncomingMessage, Server as HttpServer} from 'http';
|
|
19
20
|
import type {Server as HttpsServer} from 'https';
|
|
20
21
|
import type {
|
|
21
22
|
ConfigT,
|
|
@@ -24,6 +25,7 @@ import type {
|
|
|
24
25
|
Middleware,
|
|
25
26
|
} from 'metro-config/src/configTypes.flow';
|
|
26
27
|
import type {CustomTransformOptions} from 'metro-transform-worker';
|
|
28
|
+
import type {Duplex} from 'stream';
|
|
27
29
|
import typeof Yargs from 'yargs';
|
|
28
30
|
|
|
29
31
|
const makeBuildCommand = require('./commands/build');
|
|
@@ -38,11 +40,16 @@ const chalk = require('chalk');
|
|
|
38
40
|
const fs = require('fs');
|
|
39
41
|
const http = require('http');
|
|
40
42
|
const https = require('https');
|
|
41
|
-
const {
|
|
43
|
+
const {
|
|
44
|
+
getDefaultConfig,
|
|
45
|
+
loadConfig,
|
|
46
|
+
mergeConfig,
|
|
47
|
+
resolveConfig,
|
|
48
|
+
} = require('metro-config');
|
|
49
|
+
const {Terminal} = require('metro-core');
|
|
42
50
|
const {InspectorProxy} = require('metro-inspector-proxy');
|
|
43
51
|
const net = require('net');
|
|
44
52
|
const {parse} = require('url');
|
|
45
|
-
const ws = require('ws');
|
|
46
53
|
|
|
47
54
|
type MetroMiddleWare = {
|
|
48
55
|
attachHmrServer: (httpServer: HttpServer | HttpsServer) => void,
|
|
@@ -56,6 +63,15 @@ export type RunMetroOptions = {
|
|
|
56
63
|
waitForBundler?: boolean,
|
|
57
64
|
};
|
|
58
65
|
|
|
66
|
+
interface WebsocketServer extends EventEmitter {
|
|
67
|
+
handleUpgrade<T = WebsocketServer>(
|
|
68
|
+
request: IncomingMessage,
|
|
69
|
+
socket: Duplex,
|
|
70
|
+
upgradeHead: Buffer,
|
|
71
|
+
callback: (client: T, request: IncomingMessage) => void,
|
|
72
|
+
): void;
|
|
73
|
+
}
|
|
74
|
+
|
|
59
75
|
export type RunServerOptions = $ReadOnly<{
|
|
60
76
|
hasReducedPerformance?: boolean,
|
|
61
77
|
host?: string,
|
|
@@ -69,7 +85,7 @@ export type RunServerOptions = $ReadOnly<{
|
|
|
69
85
|
waitForBundler?: boolean,
|
|
70
86
|
watch?: boolean,
|
|
71
87
|
websocketEndpoints?: $ReadOnly<{
|
|
72
|
-
[path: string]:
|
|
88
|
+
[path: string]: WebsocketServer,
|
|
73
89
|
}>,
|
|
74
90
|
}>;
|
|
75
91
|
|
|
@@ -121,10 +137,14 @@ export type RunBuildOptions = {
|
|
|
121
137
|
type BuildCommandOptions = {} | null;
|
|
122
138
|
type ServeCommandOptions = {} | null;
|
|
123
139
|
|
|
140
|
+
exports.Terminal = Terminal;
|
|
141
|
+
|
|
124
142
|
export type {MetroConfig};
|
|
125
143
|
|
|
126
144
|
async function getConfig(config: InputConfigT): Promise<ConfigT> {
|
|
127
145
|
const defaultConfig = await getDefaultConfig(config.projectRoot);
|
|
146
|
+
// $FlowFixMe[incompatible-variance]
|
|
147
|
+
// $FlowFixMe[incompatible-call]
|
|
128
148
|
return mergeConfig(defaultConfig, config);
|
|
129
149
|
}
|
|
130
150
|
|
|
@@ -174,11 +194,14 @@ async function runMetro(
|
|
|
174
194
|
exports.runMetro = runMetro;
|
|
175
195
|
exports.loadConfig = loadConfig;
|
|
176
196
|
exports.mergeConfig = mergeConfig;
|
|
197
|
+
exports.resolveConfig = resolveConfig;
|
|
177
198
|
|
|
178
199
|
const createConnectMiddleware = async function (
|
|
179
200
|
config: ConfigT,
|
|
180
201
|
options?: RunMetroOptions,
|
|
181
202
|
): Promise<MetroMiddleWare> {
|
|
203
|
+
// $FlowFixMe[incompatible-variance]
|
|
204
|
+
// $FlowFixMe[incompatible-call]
|
|
182
205
|
const metroServer = await runMetro(config, options);
|
|
183
206
|
|
|
184
207
|
let enhancedMiddleware: Middleware = metroServer.processRequest;
|
|
@@ -373,6 +396,8 @@ exports.runBuild = async (
|
|
|
373
396
|
map: string,
|
|
374
397
|
...
|
|
375
398
|
}> => {
|
|
399
|
+
// $FlowFixMe[incompatible-variance]
|
|
400
|
+
// $FlowFixMe[incompatible-call]
|
|
376
401
|
const metroServer = await runMetro(config, {
|
|
377
402
|
watch: false,
|
|
378
403
|
});
|
package/{types/lib/getGraphId.d.ts → src/integration_tests/basic_bundle/loadBundleAsyncForTest.js}
RENAMED
|
@@ -4,8 +4,13 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
+
*
|
|
7
8
|
* @format
|
|
8
|
-
* @oncall react_native
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
"use strict";
|
|
12
|
+
|
|
13
|
+
const key = `${global.__METRO_GLOBAL_PREFIX__ ?? ""}__loadBundleAsync`;
|
|
14
|
+
global[key] = async function loadBundleAsyncForTest(path) {
|
|
15
|
+
await __DOWNLOAD_AND_EXEC_FOR_TESTS__(path);
|
|
16
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
declare var __METRO_GLOBAL_PREFIX__: string;
|
|
14
|
+
declare var __DOWNLOAD_AND_EXEC_FOR_TESTS__: (path: string) => Promise<mixed>;
|
|
15
|
+
|
|
16
|
+
const key = `${global.__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`;
|
|
17
|
+
|
|
18
|
+
global[key] = async function loadBundleAsyncForTest(path: string) {
|
|
19
|
+
await __DOWNLOAD_AND_EXEC_FOR_TESTS__(path);
|
|
20
|
+
};
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
const vm = require('vm');
|
|
15
15
|
|
|
16
|
-
module.exports = function execBundle(code: string, context:
|
|
16
|
+
module.exports = function execBundle(code: string, context: any = {}): mixed {
|
|
17
|
+
if (vm.isContext(context)) {
|
|
18
|
+
return vm.runInContext(code, context);
|
|
19
|
+
}
|
|
17
20
|
return vm.runInNewContext(code, context);
|
|
18
21
|
};
|