metro 0.76.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.76.2",
3
+ "version": "0.76.3",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
@@ -34,22 +34,22 @@
34
34
  "invariant": "^2.2.4",
35
35
  "jest-worker": "^27.2.0",
36
36
  "lodash.throttle": "^4.1.1",
37
- "metro-babel-transformer": "0.76.2",
38
- "metro-cache": "0.76.2",
39
- "metro-cache-key": "0.76.2",
40
- "metro-config": "0.76.2",
41
- "metro-core": "0.76.2",
42
- "metro-file-map": "0.76.2",
43
- "metro-inspector-proxy": "0.76.2",
44
- "metro-minify-terser": "0.76.2",
45
- "metro-minify-uglify": "0.76.2",
46
- "metro-react-native-babel-preset": "0.76.2",
47
- "metro-resolver": "0.76.2",
48
- "metro-runtime": "0.76.2",
49
- "metro-source-map": "0.76.2",
50
- "metro-symbolicate": "0.76.2",
51
- "metro-transform-plugins": "0.76.2",
52
- "metro-transform-worker": "0.76.2",
37
+ "metro-babel-transformer": "0.76.3",
38
+ "metro-cache": "0.76.3",
39
+ "metro-cache-key": "0.76.3",
40
+ "metro-config": "0.76.3",
41
+ "metro-core": "0.76.3",
42
+ "metro-file-map": "0.76.3",
43
+ "metro-inspector-proxy": "0.76.3",
44
+ "metro-minify-terser": "0.76.3",
45
+ "metro-minify-uglify": "0.76.3",
46
+ "metro-react-native-babel-preset": "0.76.3",
47
+ "metro-resolver": "0.76.3",
48
+ "metro-runtime": "0.76.3",
49
+ "metro-source-map": "0.76.3",
50
+ "metro-symbolicate": "0.76.3",
51
+ "metro-transform-plugins": "0.76.3",
52
+ "metro-transform-worker": "0.76.3",
53
53
  "mime-types": "^2.1.27",
54
54
  "node-fetch": "^2.2.0",
55
55
  "nullthrows": "^1.1.1",
@@ -67,10 +67,10 @@
67
67
  "dedent": "^0.7.0",
68
68
  "jest-snapshot": "^26.5.2",
69
69
  "jest-snapshot-serializer-raw": "^1.2.0",
70
- "metro-babel-register": "0.76.2",
71
- "metro-memory-fs": "0.76.2",
72
- "metro-react-native-babel-preset": "0.76.2",
73
- "metro-react-native-babel-transformer": "0.76.2",
70
+ "metro-babel-register": "0.76.3",
71
+ "metro-memory-fs": "0.76.3",
72
+ "metro-react-native-babel-preset": "0.76.3",
73
+ "metro-react-native-babel-transformer": "0.76.3",
74
74
  "mock-req": "^0.2.0",
75
75
  "mock-res": "^0.6.0",
76
76
  "stack-trace": "^0.0.10"
@@ -86,17 +86,11 @@ const nullthrows = require("nullthrows");
86
86
 
87
87
  // TODO: Convert to a Flow enum
88
88
 
89
- function getInternalOptions({
90
- transform,
91
- resolve,
92
- onProgress,
93
- experimentalImportBundleSupport,
94
- shallow,
95
- }) {
89
+ function getInternalOptions({ transform, resolve, onProgress, lazy, shallow }) {
96
90
  let numProcessed = 0;
97
91
  let total = 0;
98
92
  return {
99
- experimentalImportBundleSupport,
93
+ lazy,
100
94
  transform,
101
95
  resolve,
102
96
  onDependencyAdd: () => onProgress && onProgress(numProcessed, ++total),
@@ -286,10 +280,7 @@ class Graph {
286
280
  // Don't add a node for the module if the graph is shallow (single-module).
287
281
  } else if (dependency.data.data.asyncType === "weak") {
288
282
  // Exclude weak dependencies from the bundle.
289
- } else if (
290
- options.experimentalImportBundleSupport &&
291
- dependency.data.data.asyncType != null
292
- ) {
283
+ } else if (options.lazy && dependency.data.data.asyncType != null) {
293
284
  // Don't add a node for the module if we are traversing async dependencies
294
285
  // lazily (and this is an async dependency). Instead, record it in
295
286
  // importBundleNodes.
@@ -338,10 +329,7 @@ class Graph {
338
329
  // Weak dependencies are excluded from the bundle.
339
330
  return;
340
331
  }
341
- if (
342
- options.experimentalImportBundleSupport &&
343
- dependency.data.data.asyncType != null
344
- ) {
332
+ if (options.lazy && dependency.data.data.asyncType != null) {
345
333
  this._decrementImportBundleReference(dependency, parentModule);
346
334
  }
347
335
  const module = this.dependencies.get(absolutePath);
@@ -515,7 +503,7 @@ class Graph {
515
503
  );
516
504
  invariant(
517
505
  importBundleNode.inverseDependencies.has(parentModule.path),
518
- "experimentalImportBundleSupport: import bundle inverse references"
506
+ "lazy: import bundle inverse references"
519
507
  );
520
508
  importBundleNode.inverseDependencies.delete(parentModule.path);
521
509
  if (importBundleNode.inverseDependencies.size === 0) {
@@ -667,8 +655,7 @@ function dependenciesEqual(a, b, options) {
667
655
  return (
668
656
  a === b ||
669
657
  (a.absolutePath === b.absolutePath &&
670
- (!options.experimentalImportBundleSupport ||
671
- a.data.data.asyncType === b.data.data.asyncType) &&
658
+ (!options.lazy || a.data.data.asyncType === b.data.data.asyncType) &&
672
659
  contextParamsEqual(a.data.data.contextParams, b.data.data.contextParams))
673
660
  );
674
661
  }
@@ -94,7 +94,7 @@ type Delta = $ReadOnly<{
94
94
  }>;
95
95
 
96
96
  type InternalOptions<T> = $ReadOnly<{
97
- experimentalImportBundleSupport: boolean,
97
+ lazy: boolean,
98
98
  onDependencyAdd: () => mixed,
99
99
  onDependencyAdded: () => mixed,
100
100
  resolve: Options<T>['resolve'],
@@ -106,14 +106,14 @@ function getInternalOptions<T>({
106
106
  transform,
107
107
  resolve,
108
108
  onProgress,
109
- experimentalImportBundleSupport,
109
+ lazy,
110
110
  shallow,
111
111
  }: Options<T>): InternalOptions<T> {
112
112
  let numProcessed = 0;
113
113
  let total = 0;
114
114
 
115
115
  return {
116
- experimentalImportBundleSupport,
116
+ lazy,
117
117
  transform,
118
118
  resolve,
119
119
  onDependencyAdd: () => onProgress && onProgress(numProcessed, ++total),
@@ -357,10 +357,7 @@ export class Graph<T = MixedOutput> {
357
357
  // Don't add a node for the module if the graph is shallow (single-module).
358
358
  } else if (dependency.data.data.asyncType === 'weak') {
359
359
  // Exclude weak dependencies from the bundle.
360
- } else if (
361
- options.experimentalImportBundleSupport &&
362
- dependency.data.data.asyncType != null
363
- ) {
360
+ } else if (options.lazy && dependency.data.data.asyncType != null) {
364
361
  // Don't add a node for the module if we are traversing async dependencies
365
362
  // lazily (and this is an async dependency). Instead, record it in
366
363
  // importBundleNodes.
@@ -421,10 +418,7 @@ export class Graph<T = MixedOutput> {
421
418
  return;
422
419
  }
423
420
 
424
- if (
425
- options.experimentalImportBundleSupport &&
426
- dependency.data.data.asyncType != null
427
- ) {
421
+ if (options.lazy && dependency.data.data.asyncType != null) {
428
422
  this._decrementImportBundleReference(dependency, parentModule);
429
423
  }
430
424
 
@@ -629,7 +623,7 @@ export class Graph<T = MixedOutput> {
629
623
  );
630
624
  invariant(
631
625
  importBundleNode.inverseDependencies.has(parentModule.path),
632
- 'experimentalImportBundleSupport: import bundle inverse references',
626
+ 'lazy: import bundle inverse references',
633
627
  );
634
628
  importBundleNode.inverseDependencies.delete(parentModule.path);
635
629
  if (importBundleNode.inverseDependencies.size === 0) {
@@ -784,13 +778,12 @@ export class Graph<T = MixedOutput> {
784
778
  function dependenciesEqual(
785
779
  a: Dependency,
786
780
  b: Dependency,
787
- options: $ReadOnly<{experimentalImportBundleSupport: boolean, ...}>,
781
+ options: $ReadOnly<{lazy: boolean, ...}>,
788
782
  ): boolean {
789
783
  return (
790
784
  a === b ||
791
785
  (a.absolutePath === b.absolutePath &&
792
- (!options.experimentalImportBundleSupport ||
793
- a.data.data.asyncType === b.data.data.asyncType) &&
786
+ (!options.lazy || a.data.data.asyncType === b.data.data.asyncType) &&
794
787
  contextParamsEqual(a.data.data.contextParams, b.data.data.contextParams))
795
788
  );
796
789
  }
@@ -139,7 +139,7 @@ export interface Options<T = MixedOutput> {
139
139
  readonly onProgress:
140
140
  | ((numProcessed: number, total: number) => unknown)
141
141
  | null;
142
- readonly experimentalImportBundleSupport: boolean;
142
+ readonly lazy: boolean;
143
143
  readonly unstable_allowRequireContext: boolean;
144
144
  readonly shallow: boolean;
145
145
  }
@@ -130,7 +130,7 @@ export type Options<T = MixedOutput> = {
130
130
  +transform: TransformFn<T>,
131
131
  +transformOptions: TransformInputOptions,
132
132
  +onProgress: ?(numProcessed: number, total: number) => mixed,
133
- +experimentalImportBundleSupport: boolean,
133
+ +lazy: boolean,
134
134
  +unstable_allowRequireContext: boolean,
135
135
  +unstable_enablePackageExports: boolean,
136
136
  +shallow: boolean,
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:
@@ -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: this._config.server.experimentalImportBundleSupport,
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, {
@@ -964,12 +969,11 @@ class Server {
964
969
  transformOptions,
965
970
  });
966
971
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
967
- experimentalImportBundleSupport:
968
- this._config.server.experimentalImportBundleSupport,
969
972
  unstable_allowRequireContext:
970
973
  this._config.transformer.unstable_allowRequireContext,
971
974
  resolverOptions,
972
975
  shallow: graphOptions.shallow,
976
+ lazy: graphOptions.lazy,
973
977
  });
974
978
  let revision;
975
979
  const revPromise = this._bundler.getRevisionByGraphId(graphId);
@@ -981,6 +985,7 @@ class Server {
981
985
  {
982
986
  onProgress,
983
987
  shallow: graphOptions.shallow,
988
+ lazy: graphOptions.lazy,
984
989
  }
985
990
  ));
986
991
  } else {
@@ -1033,6 +1038,7 @@ class Server {
1033
1038
  ...Server.DEFAULT_GRAPH_OPTIONS,
1034
1039
  excludeSource: false,
1035
1040
  inlineSourceMap: false,
1041
+ lazy: false,
1036
1042
  modulesOnly: false,
1037
1043
  onProgress: null,
1038
1044
  runModule: true,
@@ -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:
@@ -282,7 +283,11 @@ class Server {
282
283
  entryFile,
283
284
  transformOptions,
284
285
  resolverOptions,
285
- {onProgress, shallow: graphOptions.shallow},
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: this._config.server.experimentalImportBundleSupport,
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
- {onProgress, shallow: graphOptions.shallow},
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, {
@@ -1177,12 +1185,11 @@ class Server {
1177
1185
  });
1178
1186
 
1179
1187
  const graphId = getGraphId(resolvedEntryFilePath, transformOptions, {
1180
- experimentalImportBundleSupport:
1181
- this._config.server.experimentalImportBundleSupport,
1182
1188
  unstable_allowRequireContext:
1183
1189
  this._config.transformer.unstable_allowRequireContext,
1184
1190
  resolverOptions,
1185
1191
  shallow: graphOptions.shallow,
1192
+ lazy: graphOptions.lazy,
1186
1193
  });
1187
1194
  let revision;
1188
1195
  const revPromise = this._bundler.getRevisionByGraphId(graphId);
@@ -1191,7 +1198,11 @@ class Server {
1191
1198
  resolvedEntryFilePath,
1192
1199
  transformOptions,
1193
1200
  resolverOptions,
1194
- {onProgress, shallow: graphOptions.shallow},
1201
+ {
1202
+ onProgress,
1203
+ shallow: graphOptions.shallow,
1204
+ lazy: graphOptions.lazy,
1205
+ },
1195
1206
  ));
1196
1207
  } else {
1197
1208
  ({revision} = await this._bundler.updateGraph(await revPromise, false));
@@ -1266,6 +1277,7 @@ class Server {
1266
1277
  ...typeof Server.DEFAULT_GRAPH_OPTIONS,
1267
1278
  excludeSource: false,
1268
1279
  inlineSourceMap: false,
1280
+ lazy: false,
1269
1281
  modulesOnly: false,
1270
1282
  onProgress: null,
1271
1283
  runModule: true,
@@ -1276,6 +1288,7 @@ class Server {
1276
1288
  ...Server.DEFAULT_GRAPH_OPTIONS,
1277
1289
  excludeSource: false,
1278
1290
  inlineSourceMap: false,
1291
+ lazy: false,
1279
1292
  modulesOnly: false,
1280
1293
  onProgress: null,
1281
1294
  runModule: true,
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
  };
@@ -13,6 +13,9 @@
13
13
 
14
14
  const vm = require('vm');
15
15
 
16
- module.exports = function execBundle(code: string, context: {...} = {}): mixed {
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
  };
@@ -45,4 +45,9 @@ module.exports = {
45
45
  ramGroups: [],
46
46
  }),
47
47
  },
48
+ serializer: {
49
+ getPolyfills: () => [
50
+ require.resolve("./basic_bundle/loadBundleAsyncForTest"),
51
+ ],
52
+ },
48
53
  };
@@ -15,12 +15,7 @@ const canonicalize = require("metro-core/src/canonicalize");
15
15
  function getGraphId(
16
16
  entryFile,
17
17
  options,
18
- {
19
- shallow,
20
- experimentalImportBundleSupport,
21
- unstable_allowRequireContext,
22
- resolverOptions,
23
- }
18
+ { shallow, lazy, unstable_allowRequireContext, resolverOptions }
24
19
  ) {
25
20
  return JSON.stringify(
26
21
  {
@@ -35,7 +30,7 @@ function getGraphId(
35
30
  unstable_disableES6Transforms: options.unstable_disableES6Transforms,
36
31
  platform: options.platform != null ? options.platform : null,
37
32
  type: options.type,
38
- experimentalImportBundleSupport,
33
+ lazy,
39
34
  unstable_allowRequireContext,
40
35
  shallow,
41
36
  unstable_transformProfile:
@@ -23,12 +23,12 @@ function getGraphId(
23
23
  options: TransformInputOptions,
24
24
  {
25
25
  shallow,
26
- experimentalImportBundleSupport,
26
+ lazy,
27
27
  unstable_allowRequireContext,
28
28
  resolverOptions,
29
29
  }: $ReadOnly<{
30
30
  shallow: boolean,
31
- experimentalImportBundleSupport: boolean,
31
+ lazy: boolean,
32
32
  unstable_allowRequireContext: boolean,
33
33
  resolverOptions: ResolverInputOptions,
34
34
  }>,
@@ -46,7 +46,7 @@ function getGraphId(
46
46
  unstable_disableES6Transforms: options.unstable_disableES6Transforms,
47
47
  platform: options.platform != null ? options.platform : null,
48
48
  type: options.type,
49
- experimentalImportBundleSupport,
49
+ lazy,
50
50
  unstable_allowRequireContext,
51
51
  shallow,
52
52
  unstable_transformProfile:
@@ -57,8 +57,7 @@ async function getPrependedScripts(
57
57
  config.transformer.unstable_allowRequireContext,
58
58
  transformOptions,
59
59
  onProgress: null,
60
- experimentalImportBundleSupport:
61
- config.server.experimentalImportBundleSupport,
60
+ lazy: false,
62
61
  unstable_enablePackageExports:
63
62
  config.resolver.unstable_enablePackageExports,
64
63
  shallow: false,
@@ -67,8 +67,7 @@ async function getPrependedScripts(
67
67
  config.transformer.unstable_allowRequireContext,
68
68
  transformOptions,
69
69
  onProgress: null,
70
- experimentalImportBundleSupport:
71
- config.server.experimentalImportBundleSupport,
70
+ lazy: false,
72
71
  unstable_enablePackageExports:
73
72
  config.resolver.unstable_enablePackageExports,
74
73
  shallow: false,
@@ -45,6 +45,7 @@ module.exports = function parseOptionsFromUrl(requestUrl, platforms) {
45
45
  excludeSource: getBoolean(query, "excludeSource", false),
46
46
  hot: true,
47
47
  inlineSourceMap: getBoolean(query, "inlineSourceMap", false),
48
+ lazy: getBoolean(query, "lazy", false),
48
49
  minify: getBoolean(query, "minify", false),
49
50
  modulesOnly: getBoolean(query, "modulesOnly", false),
50
51
  onProgress: null,
@@ -60,6 +60,7 @@ module.exports = function parseOptionsFromUrl(
60
60
  excludeSource: getBoolean(query, 'excludeSource', false),
61
61
  hot: true,
62
62
  inlineSourceMap: getBoolean(query, 'inlineSourceMap', false),
63
+ lazy: getBoolean(query, 'lazy', false),
63
64
  minify: getBoolean(query, 'minify', false),
64
65
  modulesOnly: getBoolean(query, 'modulesOnly', false),
65
66
  onProgress: null,
@@ -39,6 +39,7 @@ function splitBundleOptions(options) {
39
39
  },
40
40
  graphOptions: {
41
41
  shallow: options.shallow,
42
+ lazy: options.lazy,
42
43
  },
43
44
  onProgress: options.onProgress,
44
45
  };
@@ -41,6 +41,7 @@ function splitBundleOptions(options: BundleOptions): SplitBundleOptions {
41
41
  },
42
42
  graphOptions: {
43
43
  shallow: options.shallow,
44
+ lazy: options.lazy,
44
45
  },
45
46
  onProgress: options.onProgress,
46
47
  };
@@ -67,8 +67,7 @@ async function calcTransformerOptions(
67
67
  ),
68
68
  transformOptions: options,
69
69
  onProgress: null,
70
- experimentalImportBundleSupport:
71
- config.server.experimentalImportBundleSupport,
70
+ lazy: false,
72
71
  unstable_allowRequireContext:
73
72
  config.transformer.unstable_allowRequireContext,
74
73
  unstable_enablePackageExports:
@@ -85,8 +85,7 @@ async function calcTransformerOptions(
85
85
  ),
86
86
  transformOptions: options,
87
87
  onProgress: null,
88
- experimentalImportBundleSupport:
89
- config.server.experimentalImportBundleSupport,
88
+ lazy: false,
90
89
  unstable_allowRequireContext:
91
90
  config.transformer.unstable_allowRequireContext,
92
91
  unstable_enablePackageExports:
@@ -46,6 +46,7 @@ export interface BundleOptions {
46
46
  readonly excludeSource: boolean;
47
47
  readonly hot: boolean;
48
48
  readonly inlineSourceMap: boolean;
49
+ readonly lazy: boolean;
49
50
  minify: boolean;
50
51
  readonly modulesOnly: boolean;
51
52
  onProgress?: (doneCont: number, totalCount: number) => unknown;
@@ -73,6 +74,7 @@ export interface SerializerOptions {
73
74
  }
74
75
 
75
76
  export interface GraphOptions {
77
+ readonly lazy: boolean;
76
78
  readonly shallow: boolean;
77
79
  }
78
80
 
@@ -50,6 +50,7 @@ export type BundleOptions = {
50
50
  +excludeSource: boolean,
51
51
  +hot: boolean,
52
52
  +inlineSourceMap: boolean,
53
+ +lazy: boolean,
53
54
  minify: boolean,
54
55
  +modulesOnly: boolean,
55
56
  onProgress: ?(doneCont: number, totalCount: number) => mixed,
@@ -76,6 +77,7 @@ export type SerializerOptions = {
76
77
  };
77
78
 
78
79
  export type GraphOptions = {
80
+ +lazy: boolean,
79
81
  +shallow: boolean,
80
82
  };
81
83