metro 0.76.2 → 0.76.4

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.
Files changed (44) hide show
  1. package/package.json +22 -22
  2. package/src/Bundler/util.js +27 -3
  3. package/src/Bundler/util.js.flow +29 -3
  4. package/src/DeltaBundler/Graph.js +40 -26
  5. package/src/DeltaBundler/Graph.js.flow +42 -23
  6. package/src/DeltaBundler/Serializers/baseJSBundle.js +1 -0
  7. package/src/DeltaBundler/Serializers/baseJSBundle.js.flow +1 -0
  8. package/src/DeltaBundler/Serializers/getRamBundleInfo.js +1 -0
  9. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +3 -1
  10. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js +1 -0
  11. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +3 -0
  12. package/src/DeltaBundler/Serializers/sourceMapGenerator.js +1 -0
  13. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +10 -12
  14. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +3 -8
  15. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -4
  16. package/src/DeltaBundler/types.d.ts +2 -1
  17. package/src/DeltaBundler/types.flow.js.flow +2 -1
  18. package/src/HmrServer.js +3 -3
  19. package/src/HmrServer.js.flow +5 -3
  20. package/src/IncrementalBundler.js +7 -6
  21. package/src/IncrementalBundler.js.flow +8 -6
  22. package/src/Server.js +34 -8
  23. package/src/Server.js.flow +48 -14
  24. package/src/index.flow.js +6 -0
  25. package/src/index.flow.js.flow +6 -0
  26. package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js +16 -0
  27. package/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js.flow +20 -0
  28. package/src/integration_tests/execBundle.js +3 -0
  29. package/src/integration_tests/execBundle.js.flow +4 -1
  30. package/src/integration_tests/metro.config.js +5 -0
  31. package/src/lib/getAppendScripts.js +1 -0
  32. package/src/lib/getAppendScripts.js.flow +12 -10
  33. package/src/lib/getGraphId.js +2 -7
  34. package/src/lib/getGraphId.js.flow +3 -3
  35. package/src/lib/getPrependedScripts.js +1 -2
  36. package/src/lib/getPrependedScripts.js.flow +1 -2
  37. package/src/lib/parseOptionsFromUrl.js +1 -0
  38. package/src/lib/parseOptionsFromUrl.js.flow +1 -0
  39. package/src/lib/splitBundleOptions.js +1 -0
  40. package/src/lib/splitBundleOptions.js.flow +1 -0
  41. package/src/lib/transformHelpers.js +1 -2
  42. package/src/lib/transformHelpers.js.flow +1 -2
  43. package/src/shared/types.d.ts +2 -0
  44. package/src/shared/types.flow.js.flow +2 -0
package/src/HmrServer.js CHANGED
@@ -79,8 +79,7 @@ class HmrServer {
79
79
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
80
80
  resolverOptions,
81
81
  shallow: graphOptions.shallow,
82
- experimentalImportBundleSupport:
83
- this._config.server.experimentalImportBundleSupport,
82
+ lazy: graphOptions.lazy,
84
83
  unstable_allowRequireContext:
85
84
  this._config.transformer.unstable_allowRequireContext,
86
85
  });
@@ -120,6 +119,7 @@ class HmrServer {
120
119
  clients: new Set([client]),
121
120
  clientUrl,
122
121
  revisionId: id,
122
+ graphOptions,
123
123
  unlisten: () => unlisten(),
124
124
  };
125
125
  this._clientGroups.set(id, clientGroup);
@@ -279,7 +279,7 @@ class HmrServer {
279
279
  const hmrUpdate = hmrJSBundle(delta, revision.graph, {
280
280
  clientUrl: group.clientUrl,
281
281
  createModuleId: this._createModuleId,
282
- includeAsyncPaths: this._config.server.experimentalImportBundleSupport,
282
+ includeAsyncPaths: group.graphOptions.lazy,
283
283
  projectRoot: this._config.projectRoot,
284
284
  serverRoot:
285
285
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
@@ -11,6 +11,7 @@
11
11
  'use strict';
12
12
 
13
13
  import type IncrementalBundler, {RevisionId} from './IncrementalBundler';
14
+ import type {GraphOptions} from './shared/types.flow';
14
15
  import type {ConfigT, RootPerfLogger} from 'metro-config';
15
16
  import type {
16
17
  HmrClientMessage,
@@ -48,6 +49,7 @@ type ClientGroup = {
48
49
  clientUrl: EntryPointURL,
49
50
  revisionId: RevisionId,
50
51
  +unlisten: () => void,
52
+ +graphOptions: GraphOptions,
51
53
  };
52
54
 
53
55
  function send(sendFns: Array<(string) => void>, message: HmrMessage): void {
@@ -123,8 +125,7 @@ class HmrServer<TClient: Client> {
123
125
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
124
126
  resolverOptions,
125
127
  shallow: graphOptions.shallow,
126
- experimentalImportBundleSupport:
127
- this._config.server.experimentalImportBundleSupport,
128
+ lazy: graphOptions.lazy,
128
129
  unstable_allowRequireContext:
129
130
  this._config.transformer.unstable_allowRequireContext,
130
131
  });
@@ -167,6 +168,7 @@ class HmrServer<TClient: Client> {
167
168
  clients: new Set([client]),
168
169
  clientUrl,
169
170
  revisionId: id,
171
+ graphOptions,
170
172
  unlisten: (): void => unlisten(),
171
173
  };
172
174
 
@@ -356,7 +358,7 @@ class HmrServer<TClient: Client> {
356
358
  const hmrUpdate = hmrJSBundle(delta, revision.graph, {
357
359
  clientUrl: group.clientUrl,
358
360
  createModuleId: this._createModuleId,
359
- includeAsyncPaths: this._config.server.experimentalImportBundleSupport,
361
+ includeAsyncPaths: group.graphOptions.lazy,
360
362
  projectRoot: this._config.projectRoot,
361
363
  serverRoot:
362
364
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
@@ -59,6 +59,7 @@ class IncrementalBundler {
59
59
  otherOptions = {
60
60
  onProgress: null,
61
61
  shallow: false,
62
+ lazy: false,
62
63
  }
63
64
  ) {
64
65
  const absoluteEntryFiles = await this._getAbsoluteEntryFiles(entryFiles);
@@ -78,8 +79,7 @@ class IncrementalBundler {
78
79
  ),
79
80
  transformOptions,
80
81
  onProgress: otherOptions.onProgress,
81
- experimentalImportBundleSupport:
82
- this._config.server.experimentalImportBundleSupport,
82
+ lazy: otherOptions.lazy,
83
83
  unstable_allowRequireContext:
84
84
  this._config.transformer.unstable_allowRequireContext,
85
85
  unstable_enablePackageExports:
@@ -101,6 +101,7 @@ class IncrementalBundler {
101
101
  otherOptions = {
102
102
  onProgress: null,
103
103
  shallow: false,
104
+ lazy: false,
104
105
  }
105
106
  ) {
106
107
  const absoluteEntryFiles = await this._getAbsoluteEntryFiles(entryFiles);
@@ -122,8 +123,7 @@ class IncrementalBundler {
122
123
  ),
123
124
  transformOptions,
124
125
  onProgress: otherOptions.onProgress,
125
- experimentalImportBundleSupport:
126
- this._config.server.experimentalImportBundleSupport,
126
+ lazy: otherOptions.lazy,
127
127
  unstable_allowRequireContext:
128
128
  this._config.transformer.unstable_allowRequireContext,
129
129
  unstable_enablePackageExports:
@@ -140,6 +140,7 @@ class IncrementalBundler {
140
140
  otherOptions = {
141
141
  onProgress: null,
142
142
  shallow: false,
143
+ lazy: false,
143
144
  }
144
145
  ) {
145
146
  const graph = await this.buildGraphForEntries(
@@ -171,13 +172,13 @@ class IncrementalBundler {
171
172
  otherOptions = {
172
173
  onProgress: null,
173
174
  shallow: false,
175
+ lazy: false,
174
176
  }
175
177
  ) {
176
178
  const graphId = getGraphId(entryFile, transformOptions, {
177
179
  resolverOptions,
178
180
  shallow: otherOptions.shallow,
179
- experimentalImportBundleSupport:
180
- this._config.server.experimentalImportBundleSupport,
181
+ lazy: otherOptions.lazy,
181
182
  unstable_allowRequireContext:
182
183
  this._config.transformer.unstable_allowRequireContext,
183
184
  });
@@ -38,6 +38,7 @@ export type OutputGraph = Graph<>;
38
38
  type OtherOptions = $ReadOnly<{
39
39
  onProgress: $PropertyType<DeltaBundlerOptions<>, 'onProgress'>,
40
40
  shallow: boolean,
41
+ lazy: boolean,
41
42
  }>;
42
43
 
43
44
  export type GraphRevision = {
@@ -107,6 +108,7 @@ class IncrementalBundler {
107
108
  otherOptions?: OtherOptions = {
108
109
  onProgress: null,
109
110
  shallow: false,
111
+ lazy: false,
110
112
  },
111
113
  ): Promise<OutputGraph> {
112
114
  const absoluteEntryFiles = await this._getAbsoluteEntryFiles(entryFiles);
@@ -127,8 +129,7 @@ class IncrementalBundler {
127
129
  ),
128
130
  transformOptions,
129
131
  onProgress: otherOptions.onProgress,
130
- experimentalImportBundleSupport:
131
- this._config.server.experimentalImportBundleSupport,
132
+ lazy: otherOptions.lazy,
132
133
  unstable_allowRequireContext:
133
134
  this._config.transformer.unstable_allowRequireContext,
134
135
  unstable_enablePackageExports:
@@ -153,6 +154,7 @@ class IncrementalBundler {
153
154
  otherOptions?: OtherOptions = {
154
155
  onProgress: null,
155
156
  shallow: false,
157
+ lazy: false,
156
158
  },
157
159
  ): Promise<ReadOnlyDependencies<>> {
158
160
  const absoluteEntryFiles = await this._getAbsoluteEntryFiles(entryFiles);
@@ -175,8 +177,7 @@ class IncrementalBundler {
175
177
  ),
176
178
  transformOptions,
177
179
  onProgress: otherOptions.onProgress,
178
- experimentalImportBundleSupport:
179
- this._config.server.experimentalImportBundleSupport,
180
+ lazy: otherOptions.lazy,
180
181
  unstable_allowRequireContext:
181
182
  this._config.transformer.unstable_allowRequireContext,
182
183
  unstable_enablePackageExports:
@@ -195,6 +196,7 @@ class IncrementalBundler {
195
196
  otherOptions?: OtherOptions = {
196
197
  onProgress: null,
197
198
  shallow: false,
199
+ lazy: false,
198
200
  },
199
201
  ): Promise<{+graph: OutputGraph, +prepend: $ReadOnlyArray<Module<>>}> {
200
202
  const graph = await this.buildGraphForEntries(
@@ -229,6 +231,7 @@ class IncrementalBundler {
229
231
  otherOptions?: OtherOptions = {
230
232
  onProgress: null,
231
233
  shallow: false,
234
+ lazy: false,
232
235
  },
233
236
  ): Promise<{
234
237
  delta: DeltaResult<>,
@@ -238,8 +241,7 @@ class IncrementalBundler {
238
241
  const graphId = getGraphId(entryFile, transformOptions, {
239
242
  resolverOptions,
240
243
  shallow: otherOptions.shallow,
241
- experimentalImportBundleSupport:
242
- this._config.server.experimentalImportBundleSupport,
244
+ lazy: otherOptions.lazy,
243
245
  unstable_allowRequireContext:
244
246
  this._config.transformer.unstable_allowRequireContext,
245
247
  });
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: this._config.server.experimentalImportBundleSupport,
126
+ includeAsyncPaths: graphOptions.lazy,
126
127
  projectRoot: this._config.projectRoot,
127
128
  modulesOnly: serializerOptions.modulesOnly,
128
129
  runBeforeMainModule:
@@ -135,6 +136,8 @@ class Server {
135
136
  inlineSourceMap: serializerOptions.inlineSourceMap,
136
137
  serverRoot:
137
138
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
139
+ shouldAddToIgnoreList: (module) =>
140
+ this._shouldAddModuleToIgnoreList(module),
138
141
  };
139
142
  let bundleCode = null;
140
143
  let bundleMap = null;
@@ -162,6 +165,7 @@ class Server {
162
165
  {
163
166
  excludeSource: serializerOptions.excludeSource,
164
167
  processModuleFilter: this._config.serializer.processModuleFilter,
168
+ shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList,
165
169
  }
166
170
  );
167
171
  }
@@ -186,6 +190,7 @@ class Server {
186
190
  {
187
191
  onProgress,
188
192
  shallow: graphOptions.shallow,
193
+ lazy: graphOptions.lazy,
189
194
  }
190
195
  );
191
196
  const entryPoint = this._getEntryPointAbsolutePath(entryFile);
@@ -204,7 +209,7 @@ class Server {
204
209
  excludeSource: serializerOptions.excludeSource,
205
210
  getRunModuleStatement: this._config.serializer.getRunModuleStatement,
206
211
  getTransformOptions: this._config.transformer.getTransformOptions,
207
- includeAsyncPaths: this._config.server.experimentalImportBundleSupport,
212
+ includeAsyncPaths: graphOptions.lazy,
208
213
  platform: transformOptions.platform,
209
214
  projectRoot: this._config.projectRoot,
210
215
  modulesOnly: serializerOptions.modulesOnly,
@@ -218,6 +223,8 @@ class Server {
218
223
  inlineSourceMap: serializerOptions.inlineSourceMap,
219
224
  serverRoot:
220
225
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
226
+ shouldAddToIgnoreList: (module) =>
227
+ this._shouldAddModuleToIgnoreList(module),
221
228
  });
222
229
  }
223
230
  async getAssets(options) {
@@ -230,6 +237,7 @@ class Server {
230
237
  {
231
238
  onProgress,
232
239
  shallow: false,
240
+ lazy: false,
233
241
  }
234
242
  );
235
243
  return await getAssets(dependencies, {
@@ -261,6 +269,7 @@ class Server {
261
269
  {
262
270
  onProgress,
263
271
  shallow: false,
272
+ lazy: false,
264
273
  }
265
274
  );
266
275
  const platform =
@@ -436,12 +445,11 @@ class Server {
436
445
  transformOptions,
437
446
  });
438
447
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
439
- experimentalImportBundleSupport:
440
- this._config.server.experimentalImportBundleSupport,
441
448
  unstable_allowRequireContext:
442
449
  this._config.transformer.unstable_allowRequireContext,
443
450
  resolverOptions,
444
451
  shallow: graphOptions.shallow,
452
+ lazy: graphOptions.lazy,
445
453
  });
446
454
 
447
455
  // For resources that support deletion, handle the DELETE method.
@@ -640,6 +648,7 @@ class Server {
640
648
  {
641
649
  onProgress,
642
650
  shallow: graphOptions.shallow,
651
+ lazy: graphOptions.lazy,
643
652
  }
644
653
  ));
645
654
  bundlePerfLogger.point("resolvingAndTransformingDependencies_end");
@@ -665,8 +674,7 @@ class Server {
665
674
  processModuleFilter: this._config.serializer.processModuleFilter,
666
675
  createModuleId: this._createModuleId,
667
676
  getRunModuleStatement: this._config.serializer.getRunModuleStatement,
668
- includeAsyncPaths:
669
- this._config.server.experimentalImportBundleSupport,
677
+ includeAsyncPaths: graphOptions.lazy,
670
678
  dev: transformOptions.dev,
671
679
  projectRoot: this._config.projectRoot,
672
680
  modulesOnly: serializerOptions.modulesOnly,
@@ -680,6 +688,8 @@ class Server {
680
688
  inlineSourceMap: serializerOptions.inlineSourceMap,
681
689
  serverRoot:
682
690
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
691
+ shouldAddToIgnoreList: (module) =>
692
+ this._shouldAddModuleToIgnoreList(module),
683
693
  }
684
694
  );
685
695
  bundlePerfLogger.point("serializingBundle_end");
@@ -773,6 +783,7 @@ class Server {
773
783
  {
774
784
  onProgress,
775
785
  shallow: graphOptions.shallow,
786
+ lazy: graphOptions.lazy,
776
787
  }
777
788
  ));
778
789
  } else {
@@ -788,6 +799,8 @@ class Server {
788
799
  return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
789
800
  excludeSource: serializerOptions.excludeSource,
790
801
  processModuleFilter: this._config.serializer.processModuleFilter,
802
+ shouldAddToIgnoreList: (module) =>
803
+ this._shouldAddModuleToIgnoreList(module),
791
804
  });
792
805
  },
793
806
  finish({ mres, result }) {
@@ -822,6 +835,7 @@ class Server {
822
835
  {
823
836
  onProgress,
824
837
  shallow: false,
838
+ lazy: false,
825
839
  }
826
840
  );
827
841
  return await getAssets(dependencies, {
@@ -964,12 +978,11 @@ class Server {
964
978
  transformOptions,
965
979
  });
966
980
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
967
- experimentalImportBundleSupport:
968
- this._config.server.experimentalImportBundleSupport,
969
981
  unstable_allowRequireContext:
970
982
  this._config.transformer.unstable_allowRequireContext,
971
983
  resolverOptions,
972
984
  shallow: graphOptions.shallow,
985
+ lazy: graphOptions.lazy,
973
986
  });
974
987
  let revision;
975
988
  const revPromise = this._bundler.getRevisionByGraphId(graphId);
@@ -981,6 +994,7 @@ class Server {
981
994
  {
982
995
  onProgress,
983
996
  shallow: graphOptions.shallow,
997
+ lazy: graphOptions.lazy,
984
998
  }
985
999
  ));
986
1000
  } else {
@@ -1033,6 +1047,7 @@ class Server {
1033
1047
  ...Server.DEFAULT_GRAPH_OPTIONS,
1034
1048
  excludeSource: false,
1035
1049
  inlineSourceMap: false,
1050
+ lazy: false,
1036
1051
  modulesOnly: false,
1037
1052
  onProgress: null,
1038
1053
  runModule: true,
@@ -1051,6 +1066,17 @@ class Server {
1051
1066
  async ready() {
1052
1067
  await this._bundler.ready();
1053
1068
  }
1069
+ _shouldAddModuleToIgnoreList(module) {
1070
+ // TODO: Add flag to Module signifying whether it represents generated code
1071
+ // and clean up these heuristics.
1072
+ return (
1073
+ // Prelude code, see getPrependedScripts.js
1074
+ module.path === "__prelude__" ||
1075
+ // Generated require.context() module, see contextModule.js
1076
+ module.path.includes("?ctx=") ||
1077
+ this._config.serializer.isThirdPartyModule(module)
1078
+ );
1079
+ }
1054
1080
  }
1055
1081
  function* zip(xs, ys) {
1056
1082
  //$FlowIssue #9324959
@@ -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: this._config.server.experimentalImportBundleSupport,
223
+ includeAsyncPaths: graphOptions.lazy,
223
224
  projectRoot: this._config.projectRoot,
224
225
  modulesOnly: serializerOptions.modulesOnly,
225
226
  runBeforeMainModule:
@@ -232,6 +233,8 @@ class Server {
232
233
  inlineSourceMap: serializerOptions.inlineSourceMap,
233
234
  serverRoot:
234
235
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
236
+ shouldAddToIgnoreList: (module: Module<>) =>
237
+ this._shouldAddModuleToIgnoreList(module),
235
238
  };
236
239
  let bundleCode = null;
237
240
  let bundleMap = null;
@@ -259,6 +262,7 @@ class Server {
259
262
  {
260
263
  excludeSource: serializerOptions.excludeSource,
261
264
  processModuleFilter: this._config.serializer.processModuleFilter,
265
+ shouldAddToIgnoreList: bundleOptions.shouldAddToIgnoreList,
262
266
  },
263
267
  );
264
268
  }
@@ -282,7 +286,11 @@ class Server {
282
286
  entryFile,
283
287
  transformOptions,
284
288
  resolverOptions,
285
- {onProgress, shallow: graphOptions.shallow},
289
+ {
290
+ onProgress,
291
+ shallow: graphOptions.shallow,
292
+ lazy: graphOptions.lazy,
293
+ },
286
294
  );
287
295
 
288
296
  const entryPoint = this._getEntryPointAbsolutePath(entryFile);
@@ -302,7 +310,7 @@ class Server {
302
310
  excludeSource: serializerOptions.excludeSource,
303
311
  getRunModuleStatement: this._config.serializer.getRunModuleStatement,
304
312
  getTransformOptions: this._config.transformer.getTransformOptions,
305
- includeAsyncPaths: this._config.server.experimentalImportBundleSupport,
313
+ includeAsyncPaths: graphOptions.lazy,
306
314
  platform: transformOptions.platform,
307
315
  projectRoot: this._config.projectRoot,
308
316
  modulesOnly: serializerOptions.modulesOnly,
@@ -316,6 +324,8 @@ class Server {
316
324
  inlineSourceMap: serializerOptions.inlineSourceMap,
317
325
  serverRoot:
318
326
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
327
+ shouldAddToIgnoreList: (module: Module<>) =>
328
+ this._shouldAddModuleToIgnoreList(module),
319
329
  });
320
330
  }
321
331
 
@@ -327,7 +337,7 @@ class Server {
327
337
  [entryFile],
328
338
  transformOptions,
329
339
  resolverOptions,
330
- {onProgress, shallow: false},
340
+ {onProgress, shallow: false, lazy: false},
331
341
  );
332
342
 
333
343
  return await getAssets(dependencies, {
@@ -364,7 +374,7 @@ class Server {
364
374
  entryFile,
365
375
  transformOptions,
366
376
  resolverOptions,
367
- {onProgress, shallow: false},
377
+ {onProgress, shallow: false, lazy: false},
368
378
  );
369
379
 
370
380
  const platform =
@@ -596,12 +606,11 @@ class Server {
596
606
  transformOptions,
597
607
  });
598
608
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
599
- experimentalImportBundleSupport:
600
- this._config.server.experimentalImportBundleSupport,
601
609
  unstable_allowRequireContext:
602
610
  this._config.transformer.unstable_allowRequireContext,
603
611
  resolverOptions,
604
612
  shallow: graphOptions.shallow,
613
+ lazy: graphOptions.lazy,
605
614
  });
606
615
 
607
616
  // For resources that support deletion, handle the DELETE method.
@@ -830,6 +839,7 @@ class Server {
830
839
  {
831
840
  onProgress,
832
841
  shallow: graphOptions.shallow,
842
+ lazy: graphOptions.lazy,
833
843
  },
834
844
  ));
835
845
  bundlePerfLogger.point('resolvingAndTransformingDependencies_end');
@@ -856,8 +866,7 @@ class Server {
856
866
  processModuleFilter: this._config.serializer.processModuleFilter,
857
867
  createModuleId: this._createModuleId,
858
868
  getRunModuleStatement: this._config.serializer.getRunModuleStatement,
859
- includeAsyncPaths:
860
- this._config.server.experimentalImportBundleSupport,
869
+ includeAsyncPaths: graphOptions.lazy,
861
870
  dev: transformOptions.dev,
862
871
  projectRoot: this._config.projectRoot,
863
872
  modulesOnly: serializerOptions.modulesOnly,
@@ -871,6 +880,8 @@ class Server {
871
880
  inlineSourceMap: serializerOptions.inlineSourceMap,
872
881
  serverRoot:
873
882
  this._config.server.unstable_serverRoot ?? this._config.projectRoot,
883
+ shouldAddToIgnoreList: (module: Module<>) =>
884
+ this._shouldAddModuleToIgnoreList(module),
874
885
  },
875
886
  );
876
887
  bundlePerfLogger.point('serializingBundle_end');
@@ -974,7 +985,11 @@ class Server {
974
985
  entryFile,
975
986
  transformOptions,
976
987
  resolverOptions,
977
- {onProgress, shallow: graphOptions.shallow},
988
+ {
989
+ onProgress,
990
+ shallow: graphOptions.shallow,
991
+ lazy: graphOptions.lazy,
992
+ },
978
993
  ));
979
994
  } else {
980
995
  ({revision} = await this._bundler.updateGraph(await revPromise, false));
@@ -988,6 +1003,8 @@ class Server {
988
1003
  return sourceMapString([...prepend, ...this._getSortedModules(graph)], {
989
1004
  excludeSource: serializerOptions.excludeSource,
990
1005
  processModuleFilter: this._config.serializer.processModuleFilter,
1006
+ shouldAddToIgnoreList: (module: Module<>) =>
1007
+ this._shouldAddModuleToIgnoreList(module),
991
1008
  });
992
1009
  },
993
1010
  finish({mres, result}) {
@@ -1028,7 +1045,7 @@ class Server {
1028
1045
  [entryFile],
1029
1046
  transformOptions,
1030
1047
  resolverOptions,
1031
- {onProgress, shallow: false},
1048
+ {onProgress, shallow: false, lazy: false},
1032
1049
  );
1033
1050
 
1034
1051
  return await getAssets(dependencies, {
@@ -1177,12 +1194,11 @@ class Server {
1177
1194
  });
1178
1195
 
1179
1196
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
1180
- experimentalImportBundleSupport:
1181
- this._config.server.experimentalImportBundleSupport,
1182
1197
  unstable_allowRequireContext:
1183
1198
  this._config.transformer.unstable_allowRequireContext,
1184
1199
  resolverOptions,
1185
1200
  shallow: graphOptions.shallow,
1201
+ lazy: graphOptions.lazy,
1186
1202
  });
1187
1203
  let revision;
1188
1204
  const revPromise = this._bundler.getRevisionByGraphId(graphId);
@@ -1191,7 +1207,11 @@ class Server {
1191
1207
  resolvedEntryFilePath,
1192
1208
  transformOptions,
1193
1209
  resolverOptions,
1194
- {onProgress, shallow: graphOptions.shallow},
1210
+ {
1211
+ onProgress,
1212
+ shallow: graphOptions.shallow,
1213
+ lazy: graphOptions.lazy,
1214
+ },
1195
1215
  ));
1196
1216
  } else {
1197
1217
  ({revision} = await this._bundler.updateGraph(await revPromise, false));
@@ -1266,6 +1286,7 @@ class Server {
1266
1286
  ...typeof Server.DEFAULT_GRAPH_OPTIONS,
1267
1287
  excludeSource: false,
1268
1288
  inlineSourceMap: false,
1289
+ lazy: false,
1269
1290
  modulesOnly: false,
1270
1291
  onProgress: null,
1271
1292
  runModule: true,
@@ -1276,6 +1297,7 @@ class Server {
1276
1297
  ...Server.DEFAULT_GRAPH_OPTIONS,
1277
1298
  excludeSource: false,
1278
1299
  inlineSourceMap: false,
1300
+ lazy: false,
1279
1301
  modulesOnly: false,
1280
1302
  onProgress: null,
1281
1303
  runModule: true,
@@ -1296,6 +1318,18 @@ class Server {
1296
1318
  async ready(): Promise<void> {
1297
1319
  await this._bundler.ready();
1298
1320
  }
1321
+
1322
+ _shouldAddModuleToIgnoreList(module: Module<>): boolean {
1323
+ // TODO: Add flag to Module signifying whether it represents generated code
1324
+ // and clean up these heuristics.
1325
+ return (
1326
+ // Prelude code, see getPrependedScripts.js
1327
+ module.path === '__prelude__' ||
1328
+ // Generated require.context() module, see contextModule.js
1329
+ module.path.includes('?ctx=') ||
1330
+ this._config.serializer.isThirdPartyModule(module)
1331
+ );
1332
+ }
1299
1333
  }
1300
1334
 
1301
1335
  function* zip<X, Y>(xs: Iterable<X>, ys: Iterable<Y>): Iterable<[X, Y]> {
package/src/index.flow.js CHANGED
@@ -36,6 +36,8 @@ const { parse } = require("url");
36
36
  exports.Terminal = Terminal;
37
37
  async function getConfig(config) {
38
38
  const defaultConfig = await getDefaultConfig(config.projectRoot);
39
+ // $FlowFixMe[incompatible-variance]
40
+ // $FlowFixMe[incompatible-call]
39
41
  return mergeConfig(defaultConfig, config);
40
42
  }
41
43
  async function runMetro(config, options) {
@@ -78,6 +80,8 @@ exports.loadConfig = loadConfig;
78
80
  exports.mergeConfig = mergeConfig;
79
81
  exports.resolveConfig = resolveConfig;
80
82
  const createConnectMiddleware = async function (config, options) {
83
+ // $FlowFixMe[incompatible-variance]
84
+ // $FlowFixMe[incompatible-call]
81
85
  const metroServer = await runMetro(config, options);
82
86
  let enhancedMiddleware = metroServer.processRequest;
83
87
 
@@ -254,6 +258,8 @@ exports.runBuild = async (
254
258
  sourceMapUrl,
255
259
  }
256
260
  ) => {
261
+ // $FlowFixMe[incompatible-variance]
262
+ // $FlowFixMe[incompatible-call]
257
263
  const metroServer = await runMetro(config, {
258
264
  watch: false,
259
265
  });
@@ -143,6 +143,8 @@ export type {MetroConfig};
143
143
 
144
144
  async function getConfig(config: InputConfigT): Promise<ConfigT> {
145
145
  const defaultConfig = await getDefaultConfig(config.projectRoot);
146
+ // $FlowFixMe[incompatible-variance]
147
+ // $FlowFixMe[incompatible-call]
146
148
  return mergeConfig(defaultConfig, config);
147
149
  }
148
150
 
@@ -198,6 +200,8 @@ const createConnectMiddleware = async function (
198
200
  config: ConfigT,
199
201
  options?: RunMetroOptions,
200
202
  ): Promise<MetroMiddleWare> {
203
+ // $FlowFixMe[incompatible-variance]
204
+ // $FlowFixMe[incompatible-call]
201
205
  const metroServer = await runMetro(config, options);
202
206
 
203
207
  let enhancedMiddleware: Middleware = metroServer.processRequest;
@@ -392,6 +396,8 @@ exports.runBuild = async (
392
396
  map: string,
393
397
  ...
394
398
  }> => {
399
+ // $FlowFixMe[incompatible-variance]
400
+ // $FlowFixMe[incompatible-call]
395
401
  const metroServer = await runMetro(config, {
396
402
  watch: false,
397
403
  });
@@ -0,0 +1,16 @@
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
+ *
8
+ * @format
9
+ */
10
+
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,5 +13,8 @@
13
13
 
14
14
  const vm = require("vm");
15
15
  module.exports = function execBundle(code, context = {}) {
16
+ if (vm.isContext(context)) {
17
+ return vm.runInContext(code, context);
18
+ }
16
19
  return vm.runInNewContext(code, context);
17
20
  };