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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metro",
3
- "version": "0.76.2",
3
+ "version": "0.76.4",
4
4
  "description": "🚇 The JavaScript bundler for React Native.",
5
5
  "main": "src/index.js",
6
6
  "bin": "src/cli.js",
@@ -30,26 +30,26 @@
30
30
  "error-stack-parser": "^2.0.6",
31
31
  "graceful-fs": "^4.2.4",
32
32
  "hermes-parser": "0.8.0",
33
- "image-size": "^0.6.0",
33
+ "image-size": "^1.0.2",
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.4",
38
+ "metro-cache": "0.76.4",
39
+ "metro-cache-key": "0.76.4",
40
+ "metro-config": "0.76.4",
41
+ "metro-core": "0.76.4",
42
+ "metro-file-map": "0.76.4",
43
+ "metro-inspector-proxy": "0.76.4",
44
+ "metro-minify-terser": "0.76.4",
45
+ "metro-minify-uglify": "0.76.4",
46
+ "metro-react-native-babel-preset": "0.76.4",
47
+ "metro-resolver": "0.76.4",
48
+ "metro-runtime": "0.76.4",
49
+ "metro-source-map": "0.76.4",
50
+ "metro-symbolicate": "0.76.4",
51
+ "metro-transform-plugins": "0.76.4",
52
+ "metro-transform-worker": "0.76.4",
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.4",
71
+ "metro-memory-fs": "0.76.4",
72
+ "metro-react-native-babel-preset": "0.76.4",
73
+ "metro-react-native-babel-transformer": "0.76.4",
74
74
  "mock-req": "^0.2.0",
75
75
  "mock-res": "^0.6.0",
76
76
  "stack-trace": "^0.0.10"
@@ -15,6 +15,7 @@ const babylon = require("@babel/parser");
15
15
  const template = require("@babel/template").default;
16
16
  const babelTypes = require("@babel/types");
17
17
  const nullthrows = require("nullthrows");
18
+ const getImageSize = require("image-size");
18
19
 
19
20
  // Structure of the object: dir.name.scale = asset
20
21
 
@@ -105,11 +106,33 @@ function generateRemoteAssetCodeFileAst(
105
106
  // If it's not one of these, we won't treat it as an image.
106
107
  function isAssetTypeAnImage(type) {
107
108
  return (
108
- ["png", "jpg", "jpeg", "bmp", "gif", "webp", "psd", "svg", "tiff"].indexOf(
109
- type
110
- ) !== -1
109
+ [
110
+ "png",
111
+ "jpg",
112
+ "jpeg",
113
+ "bmp",
114
+ "gif",
115
+ "webp",
116
+ "psd",
117
+ "svg",
118
+ "tiff",
119
+ "ktx",
120
+ ].indexOf(type) !== -1
111
121
  );
112
122
  }
123
+ function getAssetSize(type, content, filePath) {
124
+ if (!isAssetTypeAnImage(type)) {
125
+ return null;
126
+ }
127
+ if (content.length === 0) {
128
+ throw new Error(`Image asset \`${filePath}\` cannot be an empty file.`);
129
+ }
130
+ const { width, height } = getImageSize(content);
131
+ return {
132
+ width,
133
+ height,
134
+ };
135
+ }
113
136
  function filterObject(object, blockList) {
114
137
  const copied = {
115
138
  ...object,
@@ -191,5 +214,6 @@ module.exports = {
191
214
  createRamBundleGroups,
192
215
  generateAssetCodeFileAst,
193
216
  generateRemoteAssetCodeFileAst,
217
+ getAssetSize,
194
218
  isAssetTypeAnImage,
195
219
  };
@@ -19,6 +19,7 @@ const babylon = require('@babel/parser');
19
19
  const template = require('@babel/template').default;
20
20
  const babelTypes = require('@babel/types');
21
21
  const nullthrows = require('nullthrows');
22
+ const getImageSize = require('image-size');
22
23
 
23
24
  // Structure of the object: dir.name.scale = asset
24
25
  export type RemoteFileMap = {
@@ -146,12 +147,36 @@ function generateRemoteAssetCodeFileAst(
146
147
  // If it's not one of these, we won't treat it as an image.
147
148
  function isAssetTypeAnImage(type: string): boolean {
148
149
  return (
149
- ['png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'].indexOf(
150
- type,
151
- ) !== -1
150
+ [
151
+ 'png',
152
+ 'jpg',
153
+ 'jpeg',
154
+ 'bmp',
155
+ 'gif',
156
+ 'webp',
157
+ 'psd',
158
+ 'svg',
159
+ 'tiff',
160
+ 'ktx',
161
+ ].indexOf(type) !== -1
152
162
  );
153
163
  }
154
164
 
165
+ function getAssetSize(
166
+ type: string,
167
+ content: Buffer,
168
+ filePath: string,
169
+ ): ?{+width: number, +height: number} {
170
+ if (!isAssetTypeAnImage(type)) {
171
+ return null;
172
+ }
173
+ if (content.length === 0) {
174
+ throw new Error(`Image asset \`${filePath}\` cannot be an empty file.`);
175
+ }
176
+ const {width, height} = getImageSize(content);
177
+ return {width, height};
178
+ }
179
+
155
180
  function filterObject(
156
181
  object: AssetDataWithoutFiles,
157
182
  blockList: Set<string>,
@@ -247,5 +272,6 @@ module.exports = {
247
272
  createRamBundleGroups,
248
273
  generateAssetCodeFileAst,
249
274
  generateRemoteAssetCodeFileAst,
275
+ getAssetSize,
250
276
  isAssetTypeAnImage,
251
277
  };
@@ -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),
@@ -140,10 +134,19 @@ class Graph {
140
134
  earlyInverseDependencies: new Map(),
141
135
  };
142
136
  const internalOptions = getInternalOptions(options);
143
- for (const path of paths) {
144
- // Start traversing from modules that are already part of the dependency graph.
137
+
138
+ // Record the paths that are part of the dependency graph before we start
139
+ // traversing - we'll use this to ensure we don't report modules modified
140
+ // that only exist as part of the graph mid-traversal.
141
+ const existingPaths = paths.filter((path) => this.dependencies.has(path));
142
+ for (const path of existingPaths) {
143
+ // Traverse over modules that are part of the dependency graph.
144
+ //
145
+ // Note: A given path may not be part of the graph *at this time*, in
146
+ // particular it may have been removed since we started traversing, but
147
+ // in that case the path will be visited if and when we add it back to
148
+ // the graph in a subsequent iteration.
145
149
  if (this.dependencies.get(path)) {
146
- delta.modified.add(path);
147
150
  await this._traverseDependenciesForSingleFile(
148
151
  path,
149
152
  delta,
@@ -157,10 +160,23 @@ class Graph {
157
160
  added.set(path, nullthrows(this.dependencies.get(path)));
158
161
  }
159
162
  const modified = new Map();
160
- for (const path of delta.modified) {
161
- // Only report a module as modified if we're not already reporting it as added or deleted.
162
- if (!delta.added.has(path) && !delta.deleted.has(path)) {
163
- modified.set(path, nullthrows(this.dependencies.get(path)));
163
+
164
+ // A path in delta.modified has been processed during this traversal,
165
+ // but may not actually differ, may be new, or may have been deleted after
166
+ // processing. The actually-modified modules are the intersection of
167
+ // delta.modified with the pre-existing paths, minus modules deleted.
168
+ for (const path of existingPaths) {
169
+ invariant(
170
+ !delta.added.has(path),
171
+ "delta.added has %s, but this path was already in the graph.",
172
+ path
173
+ );
174
+ if (delta.modified.has(path)) {
175
+ // Only report a module as modified if we're not already reporting it
176
+ // as added or deleted.
177
+ if (!delta.deleted.has(path)) {
178
+ modified.set(path, nullthrows(this.dependencies.get(path)));
179
+ }
164
180
  }
165
181
  }
166
182
  return {
@@ -209,6 +225,11 @@ class Graph {
209
225
  }
210
226
  async _processModule(path, delta, options) {
211
227
  const resolvedContext = this.#resolvedContexts.get(path);
228
+
229
+ // Mark any module processed as potentially modified. Once we've finished
230
+ // traversing we'll filter this set down.
231
+ delta.modified.add(path);
232
+
212
233
  // Transform the file via the given option.
213
234
  // TODO: Unbind the transform method from options
214
235
  const result = await options.transform(path, resolvedContext);
@@ -286,10 +307,7 @@ class Graph {
286
307
  // Don't add a node for the module if the graph is shallow (single-module).
287
308
  } else if (dependency.data.data.asyncType === "weak") {
288
309
  // Exclude weak dependencies from the bundle.
289
- } else if (
290
- options.experimentalImportBundleSupport &&
291
- dependency.data.data.asyncType != null
292
- ) {
310
+ } else if (options.lazy && dependency.data.data.asyncType != null) {
293
311
  // Don't add a node for the module if we are traversing async dependencies
294
312
  // lazily (and this is an async dependency). Instead, record it in
295
313
  // importBundleNodes.
@@ -338,10 +356,7 @@ class Graph {
338
356
  // Weak dependencies are excluded from the bundle.
339
357
  return;
340
358
  }
341
- if (
342
- options.experimentalImportBundleSupport &&
343
- dependency.data.data.asyncType != null
344
- ) {
359
+ if (options.lazy && dependency.data.data.asyncType != null) {
345
360
  this._decrementImportBundleReference(dependency, parentModule);
346
361
  }
347
362
  const module = this.dependencies.get(absolutePath);
@@ -515,7 +530,7 @@ class Graph {
515
530
  );
516
531
  invariant(
517
532
  importBundleNode.inverseDependencies.has(parentModule.path),
518
- "experimentalImportBundleSupport: import bundle inverse references"
533
+ "lazy: import bundle inverse references"
519
534
  );
520
535
  importBundleNode.inverseDependencies.delete(parentModule.path);
521
536
  if (importBundleNode.inverseDependencies.size === 0) {
@@ -667,8 +682,7 @@ function dependenciesEqual(a, b, options) {
667
682
  return (
668
683
  a === b ||
669
684
  (a.absolutePath === b.absolutePath &&
670
- (!options.experimentalImportBundleSupport ||
671
- a.data.data.asyncType === b.data.data.asyncType) &&
685
+ (!options.lazy || a.data.data.asyncType === b.data.data.asyncType) &&
672
686
  contextParamsEqual(a.data.data.contextParams, b.data.data.contextParams))
673
687
  );
674
688
  }
@@ -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),
@@ -174,11 +174,19 @@ export class Graph<T = MixedOutput> {
174
174
 
175
175
  const internalOptions = getInternalOptions(options);
176
176
 
177
- for (const path of paths) {
178
- // Start traversing from modules that are already part of the dependency graph.
177
+ // Record the paths that are part of the dependency graph before we start
178
+ // traversing - we'll use this to ensure we don't report modules modified
179
+ // that only exist as part of the graph mid-traversal.
180
+ const existingPaths = paths.filter(path => this.dependencies.has(path));
181
+
182
+ for (const path of existingPaths) {
183
+ // Traverse over modules that are part of the dependency graph.
184
+ //
185
+ // Note: A given path may not be part of the graph *at this time*, in
186
+ // particular it may have been removed since we started traversing, but
187
+ // in that case the path will be visited if and when we add it back to
188
+ // the graph in a subsequent iteration.
179
189
  if (this.dependencies.get(path)) {
180
- delta.modified.add(path);
181
-
182
190
  await this._traverseDependenciesForSingleFile(
183
191
  path,
184
192
  delta,
@@ -195,10 +203,23 @@ export class Graph<T = MixedOutput> {
195
203
  }
196
204
 
197
205
  const modified = new Map<string, Module<T>>();
198
- for (const path of delta.modified) {
199
- // Only report a module as modified if we're not already reporting it as added or deleted.
200
- if (!delta.added.has(path) && !delta.deleted.has(path)) {
201
- modified.set(path, nullthrows(this.dependencies.get(path)));
206
+
207
+ // A path in delta.modified has been processed during this traversal,
208
+ // but may not actually differ, may be new, or may have been deleted after
209
+ // processing. The actually-modified modules are the intersection of
210
+ // delta.modified with the pre-existing paths, minus modules deleted.
211
+ for (const path of existingPaths) {
212
+ invariant(
213
+ !delta.added.has(path),
214
+ 'delta.added has %s, but this path was already in the graph.',
215
+ path,
216
+ );
217
+ if (delta.modified.has(path)) {
218
+ // Only report a module as modified if we're not already reporting it
219
+ // as added or deleted.
220
+ if (!delta.deleted.has(path)) {
221
+ modified.set(path, nullthrows(this.dependencies.get(path)));
222
+ }
202
223
  }
203
224
  }
204
225
 
@@ -268,6 +289,11 @@ export class Graph<T = MixedOutput> {
268
289
  options: InternalOptions<T>,
269
290
  ): Promise<Module<T>> {
270
291
  const resolvedContext = this.#resolvedContexts.get(path);
292
+
293
+ // Mark any module processed as potentially modified. Once we've finished
294
+ // traversing we'll filter this set down.
295
+ delta.modified.add(path);
296
+
271
297
  // Transform the file via the given option.
272
298
  // TODO: Unbind the transform method from options
273
299
  const result = await options.transform(path, resolvedContext);
@@ -357,10 +383,7 @@ export class Graph<T = MixedOutput> {
357
383
  // Don't add a node for the module if the graph is shallow (single-module).
358
384
  } else if (dependency.data.data.asyncType === 'weak') {
359
385
  // Exclude weak dependencies from the bundle.
360
- } else if (
361
- options.experimentalImportBundleSupport &&
362
- dependency.data.data.asyncType != null
363
- ) {
386
+ } else if (options.lazy && dependency.data.data.asyncType != null) {
364
387
  // Don't add a node for the module if we are traversing async dependencies
365
388
  // lazily (and this is an async dependency). Instead, record it in
366
389
  // importBundleNodes.
@@ -421,10 +444,7 @@ export class Graph<T = MixedOutput> {
421
444
  return;
422
445
  }
423
446
 
424
- if (
425
- options.experimentalImportBundleSupport &&
426
- dependency.data.data.asyncType != null
427
- ) {
447
+ if (options.lazy && dependency.data.data.asyncType != null) {
428
448
  this._decrementImportBundleReference(dependency, parentModule);
429
449
  }
430
450
 
@@ -629,7 +649,7 @@ export class Graph<T = MixedOutput> {
629
649
  );
630
650
  invariant(
631
651
  importBundleNode.inverseDependencies.has(parentModule.path),
632
- 'experimentalImportBundleSupport: import bundle inverse references',
652
+ 'lazy: import bundle inverse references',
633
653
  );
634
654
  importBundleNode.inverseDependencies.delete(parentModule.path);
635
655
  if (importBundleNode.inverseDependencies.size === 0) {
@@ -784,13 +804,12 @@ export class Graph<T = MixedOutput> {
784
804
  function dependenciesEqual(
785
805
  a: Dependency,
786
806
  b: Dependency,
787
- options: $ReadOnly<{experimentalImportBundleSupport: boolean, ...}>,
807
+ options: $ReadOnly<{lazy: boolean, ...}>,
788
808
  ): boolean {
789
809
  return (
790
810
  a === b ||
791
811
  (a.absolutePath === b.absolutePath &&
792
- (!options.experimentalImportBundleSupport ||
793
- a.data.data.asyncType === b.data.data.asyncType) &&
812
+ (!options.lazy || a.data.data.asyncType === b.data.data.asyncType) &&
794
813
  contextParamsEqual(a.data.data.contextParams, b.data.data.contextParams))
795
814
  );
796
815
  }
@@ -45,6 +45,7 @@ function baseJSBundle(entryPoint, preModules, graph, options) {
45
45
  inlineSourceMap: options.inlineSourceMap,
46
46
  runBeforeMainModule: options.runBeforeMainModule,
47
47
  runModule: options.runModule,
48
+ shouldAddToIgnoreList: options.shouldAddToIgnoreList,
48
49
  sourceMapUrl: options.sourceMapUrl,
49
50
  sourceUrl: options.sourceUrl,
50
51
  }),
@@ -64,6 +64,7 @@ function baseJSBundle(
64
64
  inlineSourceMap: options.inlineSourceMap,
65
65
  runBeforeMainModule: options.runBeforeMainModule,
66
66
  runModule: options.runModule,
67
+ shouldAddToIgnoreList: options.shouldAddToIgnoreList,
67
68
  sourceMapUrl: options.sourceMapUrl,
68
69
  sourceUrl: options.sourceUrl,
69
70
  }),
@@ -31,6 +31,7 @@ async function getRamBundleInfo(entryPoint, pre, graph, options) {
31
31
  map: sourceMapObject([module], {
32
32
  excludeSource: options.excludeSource,
33
33
  processModuleFilter: options.processModuleFilter,
34
+ shouldAddToIgnoreList: options.shouldAddToIgnoreList,
34
35
  }),
35
36
  name: path.basename(module.path),
36
37
  sourcePath: module.path,
@@ -16,6 +16,7 @@ import type {
16
16
  RamModuleTransport,
17
17
  } from '../../shared/types.flow';
18
18
  import type {Module, ReadOnlyGraph, SerializerOptions} from '../types.flow';
19
+ import type {SourceMapGeneratorOptions} from './sourceMapGenerator';
19
20
  import type {GetTransformOptions} from 'metro-config/src/configTypes.flow.js';
20
21
 
21
22
  const {createRamBundleGroups} = require('../../Bundler/util');
@@ -28,7 +29,7 @@ const path = require('path');
28
29
 
29
30
  type Options = $ReadOnly<{
30
31
  ...SerializerOptions,
31
- excludeSource: boolean,
32
+ ...SourceMapGeneratorOptions,
32
33
  getTransformOptions: ?GetTransformOptions,
33
34
  platform: ?string,
34
35
  }>;
@@ -63,6 +64,7 @@ async function getRamBundleInfo(
63
64
  map: sourceMapObject([module], {
64
65
  excludeSource: options.excludeSource,
65
66
  processModuleFilter: options.processModuleFilter,
67
+ shouldAddToIgnoreList: options.shouldAddToIgnoreList,
66
68
  }),
67
69
  name: path.basename(module.path),
68
70
  sourcePath: module.path,
@@ -15,6 +15,7 @@ const { getJsOutput } = require("./js");
15
15
  function getSourceMapInfo(module, options) {
16
16
  return {
17
17
  ...getJsOutput(module).data,
18
+ isIgnored: options.shouldAddToIgnoreList(module),
18
19
  path: module.path,
19
20
  source: options.excludeSource ? "" : getModuleSource(module),
20
21
  };
@@ -23,6 +23,7 @@ function getSourceMapInfo(
23
23
  module: Module<>,
24
24
  options: {
25
25
  +excludeSource: boolean,
26
+ +shouldAddToIgnoreList: (Module<>) => boolean,
26
27
  },
27
28
  ): {
28
29
  +map: Array<MetroSourceMapSegmentTuple>,
@@ -31,9 +32,11 @@ function getSourceMapInfo(
31
32
  +path: string,
32
33
  +source: string,
33
34
  +lineCount: number,
35
+ +isIgnored: boolean,
34
36
  } {
35
37
  return {
36
38
  ...getJsOutput(module).data,
39
+ isIgnored: options.shouldAddToIgnoreList(module),
37
40
  path: module.path,
38
41
  source: options.excludeSource ? '' : getModuleSource(module),
39
42
  };
@@ -29,6 +29,7 @@ function getSourceMapInfosImpl(isBlocking, onDone, modules, options) {
29
29
  const mod = modulesToProcess.shift();
30
30
  const info = getSourceMapInfo(mod, {
31
31
  excludeSource: options.excludeSource,
32
+ shouldAddToIgnoreList: options.shouldAddToIgnoreList,
32
33
  });
33
34
  sourceMapInfos.push(info);
34
35
  return false;
@@ -13,6 +13,12 @@
13
13
 
14
14
  import type {Module} from '../types.flow';
15
15
 
16
+ export type SourceMapGeneratorOptions = $ReadOnly<{
17
+ excludeSource: boolean,
18
+ processModuleFilter: (module: Module<>) => boolean,
19
+ shouldAddToIgnoreList: (module: Module<>) => boolean,
20
+ }>;
21
+
16
22
  const getSourceMapInfo = require('./helpers/getSourceMapInfo');
17
23
  const {isJsModule} = require('./helpers/js');
18
24
  const {
@@ -26,10 +32,7 @@ function getSourceMapInfosImpl(
26
32
  isBlocking: boolean,
27
33
  onDone: ($ReadOnlyArray<ReturnType<typeof getSourceMapInfo>>) => void,
28
34
  modules: $ReadOnlyArray<Module<>>,
29
- options: {
30
- +excludeSource: boolean,
31
- +processModuleFilter: (module: Module<>) => boolean,
32
- },
35
+ options: SourceMapGeneratorOptions,
33
36
  ): void {
34
37
  const sourceMapInfos = [];
35
38
  const modulesToProcess = modules
@@ -44,6 +47,7 @@ function getSourceMapInfosImpl(
44
47
  const mod = modulesToProcess.shift();
45
48
  const info = getSourceMapInfo(mod, {
46
49
  excludeSource: options.excludeSource,
50
+ shouldAddToIgnoreList: options.shouldAddToIgnoreList,
47
51
  });
48
52
  sourceMapInfos.push(info);
49
53
  return false;
@@ -77,10 +81,7 @@ function getSourceMapInfosImpl(
77
81
 
78
82
  function sourceMapGenerator(
79
83
  modules: $ReadOnlyArray<Module<>>,
80
- options: {
81
- +excludeSource: boolean,
82
- +processModuleFilter: (module: Module<>) => boolean,
83
- },
84
+ options: SourceMapGeneratorOptions,
84
85
  ): ReturnType<typeof fromRawMappings> {
85
86
  let sourceMapInfos;
86
87
  getSourceMapInfosImpl(
@@ -101,10 +102,7 @@ function sourceMapGenerator(
101
102
 
102
103
  async function sourceMapGeneratorNonBlocking(
103
104
  modules: $ReadOnlyArray<Module<>>,
104
- options: {
105
- +excludeSource: boolean,
106
- +processModuleFilter: (module: Module<>) => boolean,
107
- },
105
+ options: SourceMapGeneratorOptions,
108
106
  ): ReturnType<typeof fromRawMappingsNonBlocking> {
109
107
  const sourceMapInfos = await new Promise<
110
108
  $ReadOnlyArray<ReturnType<typeof getSourceMapInfo>>,
@@ -12,6 +12,7 @@
12
12
  'use strict';
13
13
 
14
14
  import type {Module} from '../types.flow';
15
+ import type {SourceMapGeneratorOptions} from './sourceMapGenerator';
15
16
  import type {MixedSourceMap} from 'metro-source-map';
16
17
 
17
18
  const {
@@ -21,10 +22,7 @@ const {
21
22
 
22
23
  function sourceMapObject(
23
24
  modules: $ReadOnlyArray<Module<>>,
24
- options: {
25
- +excludeSource: boolean,
26
- +processModuleFilter: (module: Module<>) => boolean,
27
- },
25
+ options: SourceMapGeneratorOptions,
28
26
  ): MixedSourceMap {
29
27
  const generator = sourceMapGenerator(modules, options);
30
28
  return generator.toMap(undefined, {
@@ -34,10 +32,7 @@ function sourceMapObject(
34
32
 
35
33
  async function sourceMapObjectNonBlocking(
36
34
  modules: $ReadOnlyArray<Module<>>,
37
- options: {
38
- +excludeSource: boolean,
39
- +processModuleFilter: (module: Module<>) => boolean,
40
- },
35
+ options: SourceMapGeneratorOptions,
41
36
  ): Promise<MixedSourceMap> {
42
37
  const generator = await sourceMapGeneratorNonBlocking(modules, options);
43
38
  return generator.toMap(undefined, {
@@ -12,15 +12,13 @@
12
12
  'use strict';
13
13
 
14
14
  import type {Module} from '../types.flow';
15
+ import type {SourceMapGeneratorOptions} from './sourceMapGenerator';
15
16
 
16
17
  const {sourceMapGenerator} = require('./sourceMapGenerator');
17
18
 
18
19
  function sourceMapString(
19
20
  modules: $ReadOnlyArray<Module<>>,
20
- options: {
21
- +excludeSource: boolean,
22
- +processModuleFilter: (module: Module<>) => boolean,
23
- },
21
+ options: SourceMapGeneratorOptions,
24
22
  ): string {
25
23
  return sourceMapGenerator(modules, options).toString(undefined, {
26
24
  excludeSource: options.excludeSource,
@@ -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
  }
@@ -164,6 +164,7 @@ export interface SerializerOptions<T = MixedOutput> {
164
164
  readonly runBeforeMainModule: ReadonlyArray<string>;
165
165
  readonly runModule: boolean;
166
166
  readonly serverRoot: string;
167
+ readonly shouldAddToIgnoreList: (module: Module<T>) => boolean;
167
168
  readonly sourceMapUrl?: string;
168
169
  readonly sourceUrl?: string;
169
170
  }
@@ -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,
@@ -156,6 +156,7 @@ export type SerializerOptions = $ReadOnly<{
156
156
  runBeforeMainModule: $ReadOnlyArray<string>,
157
157
  runModule: boolean,
158
158
  serverRoot: string,
159
+ shouldAddToIgnoreList: (Module<>) => boolean,
159
160
  sourceMapUrl: ?string,
160
161
  sourceUrl: ?string,
161
162
  }>;