metro 0.70.2 → 0.71.1

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 (79) hide show
  1. package/package.json +22 -21
  2. package/src/Assets.js.flow +4 -4
  3. package/src/Bundler/util.js +1 -1
  4. package/src/Bundler/util.js.flow +2 -2
  5. package/src/Bundler.js +17 -10
  6. package/src/Bundler.js.flow +19 -14
  7. package/src/DeltaBundler/DeltaCalculator.js +13 -17
  8. package/src/DeltaBundler/DeltaCalculator.js.flow +15 -20
  9. package/src/DeltaBundler/Serializers/getAllFiles.js.flow +2 -2
  10. package/src/DeltaBundler/Serializers/getAssets.js.flow +2 -2
  11. package/src/DeltaBundler/Serializers/getExplodedSourceMap.js.flow +4 -4
  12. package/src/DeltaBundler/Serializers/getRamBundleInfo.js.flow +6 -6
  13. package/src/DeltaBundler/Serializers/helpers/getSourceMapInfo.js.flow +4 -4
  14. package/src/DeltaBundler/Serializers/helpers/processBytecodeModules.js.flow +2 -2
  15. package/src/DeltaBundler/Serializers/helpers/processModules.js.flow +2 -2
  16. package/src/DeltaBundler/Serializers/hmrJSBundle.js.flow +2 -2
  17. package/src/DeltaBundler/Serializers/sourceMapGenerator.js.flow +6 -6
  18. package/src/DeltaBundler/Serializers/sourceMapObject.js.flow +4 -4
  19. package/src/DeltaBundler/Serializers/sourceMapString.js.flow +2 -2
  20. package/src/DeltaBundler/Worker.flow.js +78 -0
  21. package/src/DeltaBundler/Worker.flow.js.flow +121 -0
  22. package/src/DeltaBundler/Worker.js +8 -66
  23. package/src/DeltaBundler/Worker.js.flow +8 -107
  24. package/src/DeltaBundler/WorkerFarm.js.flow +4 -4
  25. package/src/DeltaBundler/__fixtures__/hasteImpl.js +4 -0
  26. package/src/DeltaBundler/getTransformCacheKey.js.flow +2 -2
  27. package/src/DeltaBundler/graphOperations.js +634 -0
  28. package/src/DeltaBundler/graphOperations.js.flow +749 -0
  29. package/src/DeltaBundler/types.flow.js.flow +36 -30
  30. package/src/DeltaBundler.js +14 -6
  31. package/src/DeltaBundler.js.flow +14 -10
  32. package/src/HmrServer.js.flow +6 -6
  33. package/src/IncrementalBundler.js +1 -1
  34. package/src/IncrementalBundler.js.flow +8 -8
  35. package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
  36. package/src/ModuleGraph/node-haste/ModuleCache.js.flow +1 -1
  37. package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +2 -2
  38. package/src/ModuleGraph/node-haste/node-haste.js +4 -4
  39. package/src/ModuleGraph/node-haste/node-haste.js.flow +13 -7
  40. package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +2 -2
  41. package/src/ModuleGraph/output/plain-bundle.js.flow +2 -2
  42. package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +8 -8
  43. package/src/ModuleGraph/output/util.js.flow +2 -2
  44. package/src/ModuleGraph/types.flow.js.flow +37 -37
  45. package/src/ModuleGraph/worker/collectDependencies.js.flow +2 -2
  46. package/src/Server/symbolicate.js.flow +1 -1
  47. package/src/Server.js.flow +18 -18
  48. package/src/cli.js +5 -0
  49. package/src/cli.js.flow +5 -0
  50. package/src/commands/build.js +4 -3
  51. package/src/commands/build.js.flow +5 -3
  52. package/src/commands/serve.js +3 -3
  53. package/src/commands/serve.js.flow +5 -3
  54. package/src/index.flow.js +392 -0
  55. package/src/index.flow.js.flow +480 -0
  56. package/src/index.js +8 -366
  57. package/src/index.js.flow +8 -456
  58. package/src/lib/bundleToBytecode.js.flow +2 -2
  59. package/src/lib/bundleToString.js.flow +2 -2
  60. package/src/lib/getPreludeCode.js.flow +2 -2
  61. package/src/lib/transformHelpers.js.flow +2 -2
  62. package/src/node-haste/DependencyGraph/ModuleResolution.js +17 -4
  63. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +20 -12
  64. package/src/node-haste/DependencyGraph/createHasteMap.js +79 -19
  65. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +15 -14
  66. package/src/node-haste/DependencyGraph.js +31 -27
  67. package/src/node-haste/DependencyGraph.js.flow +43 -37
  68. package/src/node-haste/ModuleCache.js.flow +1 -1
  69. package/src/node-haste/lib/AssetPaths.js.flow +2 -2
  70. package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -2
  71. package/src/shared/output/RamBundle/as-indexed-file.js.flow +1 -1
  72. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +2 -2
  73. package/src/shared/types.flow.js.flow +14 -14
  74. package/src/DeltaBundler/computeDelta.js +0 -42
  75. package/src/DeltaBundler/computeDelta.js.flow +0 -47
  76. package/src/DeltaBundler/traverseDependencies.js +0 -470
  77. package/src/DeltaBundler/traverseDependencies.js.flow +0 -565
  78. package/src/node-haste/DependencyGraph/types.js +0 -10
  79. package/src/node-haste/DependencyGraph/types.js.flow +0 -88
@@ -10,16 +10,17 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {PrivateState} from './graphOperations';
13
14
  import type {JsTransformOptions} from 'metro-transform-worker';
14
15
 
15
- export type MixedOutput = {|
16
+ export type MixedOutput = {
16
17
  +data: mixed,
17
18
  +type: string,
18
- |};
19
+ };
19
20
 
20
21
  export type AsyncDependencyType = 'async' | 'prefetch';
21
22
 
22
- export type TransformResultDependency = {|
23
+ export type TransformResultDependency = {
23
24
  /**
24
25
  * The literal name provided to a require or import call. For example 'foo' in
25
26
  * case of `require('foo')`.
@@ -30,7 +31,7 @@ export type TransformResultDependency = {|
30
31
  * Extra data returned by the dependency extractor. Whatever is added here is
31
32
  * blindly piped by Metro to the serializers.
32
33
  */
33
- +data: {|
34
+ +data: {
34
35
  /**
35
36
  * If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
36
37
  */
@@ -38,30 +39,30 @@ export type TransformResultDependency = {|
38
39
  /**
39
40
  * The condition for splitting on this dependency edge.
40
41
  */
41
- +splitCondition?: {|
42
+ +splitCondition?: {
42
43
  +mobileConfigName: string,
43
- |},
44
+ },
44
45
  /**
45
46
  * The dependency is enclosed in a try/catch block.
46
47
  */
47
48
  +isOptional?: boolean,
48
49
 
49
50
  +locs: $ReadOnlyArray<BabelSourceLocation>,
50
- |},
51
- |};
51
+ },
52
+ };
52
53
 
53
- export type Dependency = {|
54
+ export type Dependency = {
54
55
  +absolutePath: string,
55
56
  +data: TransformResultDependency,
56
- |};
57
+ };
57
58
 
58
- export type Module<T = MixedOutput> = {|
59
+ export type Module<T = MixedOutput> = {
59
60
  +dependencies: Map<string, Dependency>,
60
61
  +inverseDependencies: Set<string>,
61
62
  +output: $ReadOnlyArray<T>,
62
63
  +path: string,
63
64
  +getSource: () => Buffer,
64
- |};
65
+ };
65
66
 
66
67
  export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
67
68
 
@@ -74,51 +75,56 @@ export type TransformInputOptions = $Diff<
74
75
  },
75
76
  >;
76
77
 
77
- export type Graph<T = MixedOutput> = {|
78
- dependencies: Dependencies<T>,
79
- importBundleNames: Set<string>,
80
- +entryPoints: $ReadOnlyArray<string>,
78
+ export type GraphInputOptions = $ReadOnly<{
79
+ entryPoints: $ReadOnlySet<string>,
81
80
  // Unused in core but useful for custom serializers / experimentalSerializerHook
82
- +transformOptions: TransformInputOptions,
83
- |};
81
+ transformOptions: TransformInputOptions,
82
+ }>;
83
+
84
+ export type Graph<T = MixedOutput> = {
85
+ ...$ReadOnly<GraphInputOptions>,
86
+ dependencies: Dependencies<T>,
87
+ +importBundleNames: Set<string>,
88
+ +privateState: PrivateState,
89
+ };
84
90
 
85
- export type TransformResult<T = MixedOutput> = $ReadOnly<{|
91
+ export type TransformResult<T = MixedOutput> = $ReadOnly<{
86
92
  dependencies: $ReadOnlyArray<TransformResultDependency>,
87
93
  output: $ReadOnlyArray<T>,
88
- |}>;
94
+ }>;
89
95
 
90
- export type TransformResultWithSource<T = MixedOutput> = $ReadOnly<{|
96
+ export type TransformResultWithSource<T = MixedOutput> = $ReadOnly<{
91
97
  ...TransformResult<T>,
92
98
  getSource: () => Buffer,
93
- |}>;
99
+ }>;
94
100
 
95
101
  export type TransformFn<T = MixedOutput> = string => Promise<
96
102
  TransformResultWithSource<T>,
97
103
  >;
98
- export type AllowOptionalDependenciesWithOptions = {|
104
+ export type AllowOptionalDependenciesWithOptions = {
99
105
  +exclude: Array<string>,
100
- |};
106
+ };
101
107
  export type AllowOptionalDependencies =
102
108
  | boolean
103
109
  | AllowOptionalDependenciesWithOptions;
104
110
 
105
- export type Options<T = MixedOutput> = {|
111
+ export type Options<T = MixedOutput> = {
106
112
  +resolve: (from: string, to: string) => string,
107
113
  +transform: TransformFn<T>,
108
114
  +transformOptions: TransformInputOptions,
109
115
  +onProgress: ?(numProcessed: number, total: number) => mixed,
110
116
  +experimentalImportBundleSupport: boolean,
111
117
  +shallow: boolean,
112
- |};
118
+ };
113
119
 
114
- export type DeltaResult<T = MixedOutput> = {|
120
+ export type DeltaResult<T = MixedOutput> = {
115
121
  +added: Map<string, Module<T>>,
116
122
  +modified: Map<string, Module<T>>,
117
123
  +deleted: Set<string>,
118
124
  +reset: boolean,
119
- |};
125
+ };
120
126
 
121
- export type SerializerOptions = {|
127
+ export type SerializerOptions = {
122
128
  +asyncRequireModulePath: string,
123
129
  +createModuleId: string => number,
124
130
  +dev: boolean,
@@ -132,4 +138,4 @@ export type SerializerOptions = {|
132
138
  +serverRoot: string,
133
139
  +sourceMapUrl: ?string,
134
140
  +sourceUrl: ?string,
135
- |};
141
+ };
@@ -11,6 +11,8 @@
11
11
 
12
12
  const DeltaCalculator = require("./DeltaBundler/DeltaCalculator");
13
13
 
14
+ const { EventEmitter } = require("events");
15
+
14
16
  /**
15
17
  * `DeltaBundler` uses the `DeltaTransformer` to build bundle deltas. This
16
18
  * module handles all the transformer instances so it can support multiple
@@ -20,8 +22,8 @@ const DeltaCalculator = require("./DeltaBundler/DeltaCalculator");
20
22
  class DeltaBundler {
21
23
  _deltaCalculators = new Map();
22
24
 
23
- constructor(bundler) {
24
- this._bundler = bundler;
25
+ constructor(changeEventSource) {
26
+ this._changeEventSource = changeEventSource;
25
27
  }
26
28
 
27
29
  end() {
@@ -31,8 +33,11 @@ class DeltaBundler {
31
33
  }
32
34
 
33
35
  async getDependencies(entryPoints, options) {
34
- const depGraph = await this._bundler.getDependencyGraph();
35
- const deltaCalculator = new DeltaCalculator(entryPoints, depGraph, options);
36
+ const deltaCalculator = new DeltaCalculator(
37
+ new Set(entryPoints),
38
+ this._changeEventSource,
39
+ options
40
+ );
36
41
  await deltaCalculator.getDelta({
37
42
  reset: true,
38
43
  shallow: options.shallow,
@@ -45,8 +50,11 @@ class DeltaBundler {
45
50
  // To get just the dependencies, use getDependencies which will not leak graphs.
46
51
 
47
52
  async buildGraph(entryPoints, options) {
48
- const depGraph = await this._bundler.getDependencyGraph();
49
- const deltaCalculator = new DeltaCalculator(entryPoints, depGraph, options);
53
+ const deltaCalculator = new DeltaCalculator(
54
+ new Set(entryPoints),
55
+ this._changeEventSource,
56
+ options
57
+ );
50
58
  await deltaCalculator.getDelta({
51
59
  reset: true,
52
60
  shallow: options.shallow,
@@ -10,7 +10,6 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- import type Bundler from './Bundler';
14
13
  import type {
15
14
  DeltaResult,
16
15
  Dependencies,
@@ -21,6 +20,7 @@ import type {
21
20
  } from './DeltaBundler/types.flow';
22
21
 
23
22
  const DeltaCalculator = require('./DeltaBundler/DeltaCalculator');
23
+ const {EventEmitter} = require('events');
24
24
 
25
25
  export type {
26
26
  DeltaResult,
@@ -41,11 +41,11 @@ export type {
41
41
  * `clientId` param (which maps a client to a specific delta transformer).
42
42
  */
43
43
  class DeltaBundler<T = MixedOutput> {
44
- _bundler: Bundler;
44
+ _changeEventSource: EventEmitter;
45
45
  _deltaCalculators: Map<Graph<T>, DeltaCalculator<T>> = new Map();
46
46
 
47
- constructor(bundler: Bundler) {
48
- this._bundler = bundler;
47
+ constructor(changeEventSource: EventEmitter) {
48
+ this._changeEventSource = changeEventSource;
49
49
  }
50
50
 
51
51
  end(): void {
@@ -59,9 +59,11 @@ class DeltaBundler<T = MixedOutput> {
59
59
  entryPoints: $ReadOnlyArray<string>,
60
60
  options: Options<T>,
61
61
  ): Promise<Dependencies<T>> {
62
- const depGraph = await this._bundler.getDependencyGraph();
63
-
64
- const deltaCalculator = new DeltaCalculator(entryPoints, depGraph, options);
62
+ const deltaCalculator = new DeltaCalculator(
63
+ new Set(entryPoints),
64
+ this._changeEventSource,
65
+ options,
66
+ );
65
67
 
66
68
  await deltaCalculator.getDelta({reset: true, shallow: options.shallow});
67
69
  const graph = deltaCalculator.getGraph();
@@ -77,9 +79,11 @@ class DeltaBundler<T = MixedOutput> {
77
79
  entryPoints: $ReadOnlyArray<string>,
78
80
  options: Options<T>,
79
81
  ): Promise<Graph<T>> {
80
- const depGraph = await this._bundler.getDependencyGraph();
81
-
82
- const deltaCalculator = new DeltaCalculator(entryPoints, depGraph, options);
82
+ const deltaCalculator = new DeltaCalculator(
83
+ new Set(entryPoints),
84
+ this._changeEventSource,
85
+ options,
86
+ );
83
87
 
84
88
  await deltaCalculator.getDelta({reset: true, shallow: options.shallow});
85
89
  const graph = deltaCalculator.getGraph();
@@ -39,18 +39,18 @@ const url = require('url');
39
39
  type $ReturnType<F> = $Call<<A, R>((...A) => R) => R, F>;
40
40
  export type EntryPointURL = $ReturnType<typeof url.parse>;
41
41
 
42
- type Client = {|
42
+ type Client = {
43
43
  optedIntoHMR: boolean,
44
44
  revisionIds: Array<RevisionId>,
45
45
  +sendFn: string => void,
46
- |};
46
+ };
47
47
 
48
- type ClientGroup = {|
48
+ type ClientGroup = {
49
49
  +clients: Set<Client>,
50
50
  clientUrl: EntryPointURL,
51
51
  revisionId: RevisionId,
52
52
  +unlisten: () => void,
53
- |};
53
+ };
54
54
 
55
55
  function send(sendFns: Array<(string) => void>, message: HmrMessage): void {
56
56
  const strMessage = JSON.stringify(message);
@@ -252,7 +252,7 @@ class HmrServer<TClient: Client> {
252
252
 
253
253
  async _handleFileChange(
254
254
  group: ClientGroup,
255
- options: {|isInitialUpdate: boolean|},
255
+ options: {isInitialUpdate: boolean},
256
256
  ): Promise<void> {
257
257
  const optedIntoHMR = [...group.clients].some(
258
258
  (client: Client) => client.optedIntoHMR,
@@ -292,7 +292,7 @@ class HmrServer<TClient: Client> {
292
292
 
293
293
  async _prepareMessage(
294
294
  group: ClientGroup,
295
- options: {|isInitialUpdate: boolean|},
295
+ options: {isInitialUpdate: boolean},
296
296
  ): Promise<HmrUpdateMessage | HmrErrorMessage> {
297
297
  try {
298
298
  const revPromise = this._bundler.getRevision(group.revisionId);
@@ -43,7 +43,7 @@ class IncrementalBundler {
43
43
  constructor(config, options) {
44
44
  this._config = config;
45
45
  this._bundler = new Bundler(config, options);
46
- this._deltaBundler = new DeltaBundler(this._bundler);
46
+ this._deltaBundler = new DeltaBundler(this._bundler.getWatcher());
47
47
  }
48
48
 
49
49
  end() {
@@ -33,24 +33,24 @@ export opaque type RevisionId: string = string;
33
33
 
34
34
  export type OutputGraph = Graph<>;
35
35
 
36
- type OtherOptions = {|
36
+ type OtherOptions = {
37
37
  +onProgress: $PropertyType<DeltaBundlerOptions<>, 'onProgress'>,
38
38
  +shallow: boolean,
39
- |};
39
+ };
40
40
 
41
- export type GraphRevision = {|
41
+ export type GraphRevision = {
42
42
  // Identifies the last computed revision.
43
43
  +id: RevisionId,
44
44
  +date: Date,
45
45
  +graphId: GraphId,
46
46
  +graph: OutputGraph,
47
47
  +prepend: $ReadOnlyArray<Module<>>,
48
- |};
48
+ };
49
49
 
50
- export type IncrementalBundlerOptions = $ReadOnly<{|
50
+ export type IncrementalBundlerOptions = $ReadOnly<{
51
51
  hasReducedPerformance?: boolean,
52
52
  watch?: boolean,
53
- |}>;
53
+ }>;
54
54
 
55
55
  function createRevisionId(): RevisionId {
56
56
  return crypto.randomBytes(8).toString('hex');
@@ -73,7 +73,7 @@ class IncrementalBundler {
73
73
  constructor(config: ConfigT, options?: IncrementalBundlerOptions) {
74
74
  this._config = config;
75
75
  this._bundler = new Bundler(config, options);
76
- this._deltaBundler = new DeltaBundler(this._bundler);
76
+ this._deltaBundler = new DeltaBundler(this._bundler.getWatcher());
77
77
  }
78
78
 
79
79
  end(): void {
@@ -178,7 +178,7 @@ class IncrementalBundler {
178
178
  onProgress: null,
179
179
  shallow: false,
180
180
  },
181
- ): Promise<{|+graph: OutputGraph, +prepend: $ReadOnlyArray<Module<>>|}> {
181
+ ): Promise<{+graph: OutputGraph, +prepend: $ReadOnlyArray<Module<>>}> {
182
182
  const graph = await this.buildGraphForEntries(
183
183
  [entryFile],
184
184
  transformOptions,
@@ -24,7 +24,7 @@ module.exports = class ModuleCache {
24
24
  getModule(path) {
25
25
  // This is hacky as hell... `ModuleGraph` handles relative paths but which
26
26
  // start with a slash (so we can have `/js/foo.js` or even `/../foo.js`).
27
- // This does not play well with `jest-haste-map`, which tries to convert
27
+ // This does not play well with `metro-file-map`, which tries to convert
28
28
  // paths to absolute (https://fburl.com/vbwmjsxa) causing an additional
29
29
  // slashed to be prepended in the file path.
30
30
  // TODO: Refactor the way metro-buck handles paths to make them either
@@ -36,7 +36,7 @@ module.exports = class ModuleCache {
36
36
  getModule(path: string): Module {
37
37
  // This is hacky as hell... `ModuleGraph` handles relative paths but which
38
38
  // start with a slash (so we can have `/js/foo.js` or even `/../foo.js`).
39
- // This does not play well with `jest-haste-map`, which tries to convert
39
+ // This does not play well with `metro-file-map`, which tries to convert
40
40
  // paths to absolute (https://fburl.com/vbwmjsxa) causing an additional
41
41
  // slashed to be prepended in the file path.
42
42
  // TODO: Refactor the way metro-buck handles paths to make them either
@@ -55,13 +55,13 @@ export type FastFS = {
55
55
  ...
56
56
  };
57
57
 
58
- type HasteMapOptions = {|
58
+ type HasteMapOptions = {
59
59
  extensions: Extensions,
60
60
  files: Array<string>,
61
61
  moduleCache: ModuleCache,
62
62
  platforms: Platforms,
63
63
  preferNativePlatform: true,
64
- |};
64
+ };
65
65
 
66
66
  declare class HasteMap {
67
67
  // node-haste/DependencyGraph/HasteMap.js
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- var _jestHasteMap = require("jest-haste-map");
3
+ var _metroFileMap = require("metro-file-map");
4
4
 
5
5
  /**
6
6
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -45,7 +45,7 @@ const NULL_MODULE = {
45
45
  };
46
46
  const NODE_MODULES = path.sep + "node_modules" + path.sep;
47
47
 
48
- const isNodeModules = (file) => file.includes(NODE_MODULES); // This function maps the ModuleGraph data structure to jest-haste-map's ModuleMap
48
+ const isNodeModules = (file) => file.includes(NODE_MODULES); // This function maps the ModuleGraph data structure to metro-file-map's ModuleMap
49
49
 
50
50
  const createModuleMap = ({ files, moduleCache, sourceExts, platforms }) => {
51
51
  const platformSet = new Set(
@@ -78,7 +78,7 @@ const createModuleMap = ({ files, moduleCache, sourceExts, platforms }) => {
78
78
  const mapModule = map.get(id) || Object.create(null);
79
79
  const platform =
80
80
  parsePlatformFilePath(filePath, platformSet).platform || GENERIC_PLATFORM;
81
- const existingModule = mapModule[platform]; // 0 = Module, 1 = Package in jest-haste-map
81
+ const existingModule = mapModule[platform]; // 0 = Module, 1 = Package in metro-file-map
82
82
 
83
83
  mapModule[platform] = [filePath, module.type === "Package" ? 1 : 0];
84
84
 
@@ -141,7 +141,7 @@ exports.createResolveFn = function (options) {
141
141
  mainFields: options.mainFields,
142
142
  // $FlowFixMe -- error revealed by types-first codemod
143
143
  moduleCache,
144
- moduleMap: new _jestHasteMap.ModuleMap({
144
+ moduleMap: new _metroFileMap.ModuleMap({
145
145
  duplicates: new Map(),
146
146
  map: createModuleMap({
147
147
  files,
@@ -11,9 +11,10 @@
11
11
  import type {Moduleish} from '../../node-haste/DependencyGraph/ModuleResolution';
12
12
  import type {ResolveFn, TransformedCodeFile} from '../types.flow';
13
13
  import type {Extensions, Path} from './node-haste.flow';
14
+ import type {ModuleMapData, ModuleMapItem} from 'metro-file-map';
14
15
  import type {CustomResolver} from 'metro-resolver';
15
16
 
16
- import {ModuleMap} from 'jest-haste-map';
17
+ import {ModuleMap} from 'metro-file-map';
17
18
 
18
19
  const {
19
20
  ModuleResolver,
@@ -25,7 +26,7 @@ const ModuleCache = require('./ModuleCache');
25
26
  const defaults = require('metro-config/src/defaults/defaults');
26
27
  const path = require('path');
27
28
 
28
- type ResolveOptions = {|
29
+ type ResolveOptions = {
29
30
  assetExts: Extensions,
30
31
  assetResolutions: $ReadOnlyArray<string>,
31
32
  +disableHierarchicalLookup: boolean,
@@ -38,7 +39,7 @@ type ResolveOptions = {|
38
39
  resolveRequest?: ?CustomResolver,
39
40
  +sourceExts: Extensions,
40
41
  transformedFiles: {[path: Path]: TransformedCodeFile, ...},
41
- |};
42
+ };
42
43
 
43
44
  const NATIVE_PLATFORM = 'native';
44
45
  const GENERIC_PLATFORM = 'g';
@@ -57,8 +58,13 @@ const NULL_MODULE: Moduleish = {
57
58
  const NODE_MODULES = path.sep + 'node_modules' + path.sep;
58
59
  const isNodeModules = file => file.includes(NODE_MODULES);
59
60
 
60
- // This function maps the ModuleGraph data structure to jest-haste-map's ModuleMap
61
- const createModuleMap = ({files, moduleCache, sourceExts, platforms}) => {
61
+ // This function maps the ModuleGraph data structure to metro-file-map's ModuleMap
62
+ const createModuleMap = ({
63
+ files,
64
+ moduleCache,
65
+ sourceExts,
66
+ platforms,
67
+ }): ModuleMapData => {
62
68
  const platformSet = new Set(
63
69
  (platforms ?? defaults.platforms).concat([NATIVE_PLATFORM]),
64
70
  );
@@ -83,13 +89,13 @@ const createModuleMap = ({files, moduleCache, sourceExts, platforms}) => {
83
89
  return;
84
90
  }
85
91
 
86
- const mapModule = map.get(id) || Object.create(null);
92
+ const mapModule: ModuleMapItem = map.get(id) || Object.create(null);
87
93
 
88
94
  const platform =
89
95
  parsePlatformFilePath(filePath, platformSet).platform || GENERIC_PLATFORM;
90
96
 
91
97
  const existingModule = mapModule[platform];
92
- // 0 = Module, 1 = Package in jest-haste-map
98
+ // 0 = Module, 1 = Package in metro-file-map
93
99
  mapModule[platform] = [filePath, module.type === 'Package' ? 1 : 0];
94
100
 
95
101
  if (existingModule && existingModule[0] !== filePath) {
@@ -45,11 +45,11 @@ function asIndexedRamBundle({
45
45
  requireCalls: Iterable<Module>,
46
46
  segmentID: number,
47
47
  sourceMapPath?: ?string,
48
- }>): {|
48
+ }>): {
49
49
  code: string | Buffer,
50
50
  extraFiles?: Iterable<[string, string | Buffer]>,
51
51
  map: IndexMap,
52
- |} {
52
+ } {
53
53
  const idForPath = (x: {path: string, ...}) => idsForPath(x).moduleId;
54
54
  const [startup, deferred] = partition(modules, preloadedModules);
55
55
  const startupModules = [...startup, ...requireCalls];
@@ -27,11 +27,11 @@ function asPlainBundle({
27
27
  requireCalls,
28
28
  sourceMapPath,
29
29
  enableIDInlining,
30
- }: OutputFnArg): {|
30
+ }: OutputFnArg): {
31
31
  code: string | Buffer,
32
32
  extraFiles?: Iterable<[string, string | Buffer]>,
33
33
  map: MixedSourceMap,
34
- |} {
34
+ } {
35
35
  const builder = new BundleBuilder(filename);
36
36
  const modIdForPath = (x: {path: string, ...}) => idsForPath(x).moduleId;
37
37
 
@@ -17,18 +17,18 @@ import typeof * as Types from '@babel/types';
17
17
  import invariant from 'invariant';
18
18
  import nullthrows from 'nullthrows';
19
19
 
20
- type State = {|
21
- opts: {|
20
+ type State = {
21
+ opts: {
22
22
  +dependencyIds: $ReadOnlyArray<number>,
23
23
  +globalPrefix: string,
24
- |},
25
- |};
24
+ },
25
+ };
26
26
 
27
- function reverseDependencyMapReferences({types: t}: {types: Types, ...}): {|
28
- visitor: {|
27
+ function reverseDependencyMapReferences({types: t}: {types: Types, ...}): {
28
+ visitor: {
29
29
  CallExpression: (path: NodePath<CallExpression>, state: State) => void,
30
- |},
31
- |} {
30
+ },
31
+ } {
32
32
  return {
33
33
  visitor: {
34
34
  CallExpression(path: NodePath<CallExpression>, state: State) {
@@ -238,10 +238,10 @@ function getModuleCodeAndMap(
238
238
  dependencyMapReservedName: ?string,
239
239
  globalPrefix: string,
240
240
  }>,
241
- ): {|
241
+ ): {
242
242
  moduleCode: string,
243
243
  moduleMap: ?BasicSourceMap,
244
- |} {
244
+ } {
245
245
  const {file} = module;
246
246
  let moduleCode, moduleMap;
247
247