metro 0.70.3 → 0.71.2

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 (94) hide show
  1. package/package.json +23 -22
  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 +15 -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 +641 -0
  28. package/src/DeltaBundler/graphOperations.js.flow +752 -0
  29. package/src/DeltaBundler/types.flow.js +6 -0
  30. package/src/DeltaBundler/types.flow.js.flow +43 -31
  31. package/src/DeltaBundler.js +12 -6
  32. package/src/DeltaBundler.js.flow +14 -10
  33. package/src/HmrServer.js +0 -2
  34. package/src/HmrServer.js.flow +7 -8
  35. package/src/IncrementalBundler.js +1 -1
  36. package/src/IncrementalBundler.js.flow +8 -8
  37. package/src/ModuleGraph/node-haste/ModuleCache.js +1 -1
  38. package/src/ModuleGraph/node-haste/ModuleCache.js.flow +1 -1
  39. package/src/ModuleGraph/node-haste/node-haste.flow.js +0 -1
  40. package/src/ModuleGraph/node-haste/node-haste.flow.js.flow +3 -4
  41. package/src/ModuleGraph/node-haste/node-haste.js +4 -4
  42. package/src/ModuleGraph/node-haste/node-haste.js.flow +13 -7
  43. package/src/ModuleGraph/output/indexed-ram-bundle.js.flow +2 -2
  44. package/src/ModuleGraph/output/plain-bundle.js.flow +2 -2
  45. package/src/ModuleGraph/output/reverse-dependency-map-references.js.flow +8 -8
  46. package/src/ModuleGraph/output/util.js.flow +2 -2
  47. package/src/ModuleGraph/types.flow.js.flow +37 -37
  48. package/src/ModuleGraph/worker/collectDependencies.js +215 -8
  49. package/src/ModuleGraph/worker/collectDependencies.js.flow +230 -13
  50. package/src/Server/symbolicate.js.flow +1 -1
  51. package/src/Server.js.flow +18 -18
  52. package/src/cli.js +5 -0
  53. package/src/cli.js.flow +5 -0
  54. package/src/commands/build.js +4 -3
  55. package/src/commands/build.js.flow +5 -3
  56. package/src/commands/serve.js +3 -3
  57. package/src/commands/serve.js.flow +5 -3
  58. package/src/index.flow.js +392 -0
  59. package/src/index.flow.js.flow +480 -0
  60. package/src/index.js +8 -366
  61. package/src/index.js.flow +8 -456
  62. package/src/lib/CountingSet.js +116 -0
  63. package/src/lib/CountingSet.js.flow +126 -0
  64. package/src/lib/JsonReporter.js +0 -2
  65. package/src/lib/JsonReporter.js.flow +1 -1
  66. package/src/lib/bundleToBytecode.js.flow +2 -2
  67. package/src/lib/bundleToString.js.flow +2 -2
  68. package/src/lib/getAppendScripts.js +10 -4
  69. package/src/lib/getAppendScripts.js.flow +6 -4
  70. package/src/lib/getPreludeCode.js +19 -1
  71. package/src/lib/getPreludeCode.js.flow +17 -2
  72. package/src/lib/getPrependedScripts.js +10 -2
  73. package/src/lib/getPrependedScripts.js.flow +11 -2
  74. package/src/lib/reporting.js +0 -2
  75. package/src/lib/reporting.js.flow +2 -1
  76. package/src/lib/transformHelpers.js.flow +2 -2
  77. package/src/node-haste/DependencyGraph/ModuleResolution.js +17 -4
  78. package/src/node-haste/DependencyGraph/ModuleResolution.js.flow +20 -12
  79. package/src/node-haste/DependencyGraph/createHasteMap.js +80 -19
  80. package/src/node-haste/DependencyGraph/createHasteMap.js.flow +16 -14
  81. package/src/node-haste/DependencyGraph.js +31 -29
  82. package/src/node-haste/DependencyGraph.js.flow +44 -38
  83. package/src/node-haste/ModuleCache.js.flow +1 -1
  84. package/src/node-haste/lib/AssetPaths.js.flow +2 -2
  85. package/src/node-haste/lib/parsePlatformFilePath.js.flow +2 -2
  86. package/src/shared/output/RamBundle/as-indexed-file.js.flow +1 -1
  87. package/src/shared/output/RamBundle/buildSourcemapWithMetadata.js.flow +2 -2
  88. package/src/shared/types.flow.js.flow +14 -14
  89. package/src/DeltaBundler/computeDelta.js +0 -42
  90. package/src/DeltaBundler/computeDelta.js.flow +0 -47
  91. package/src/DeltaBundler/traverseDependencies.js +0 -470
  92. package/src/DeltaBundler/traverseDependencies.js.flow +0 -565
  93. package/src/node-haste/DependencyGraph/types.js +0 -10
  94. package/src/node-haste/DependencyGraph/types.js.flow +0 -88
@@ -8,3 +8,9 @@
8
8
  * @format
9
9
  */
10
10
  "use strict";
11
+
12
+ var _CountingSet = _interopRequireDefault(require("../lib/CountingSet"));
13
+
14
+ function _interopRequireDefault(obj) {
15
+ return obj && obj.__esModule ? obj : { default: obj };
16
+ }
@@ -10,16 +10,20 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
14
+ import type {PrivateState} from './graphOperations';
13
15
  import type {JsTransformOptions} from 'metro-transform-worker';
14
16
 
15
- export type MixedOutput = {|
17
+ import CountingSet from '../lib/CountingSet';
18
+
19
+ export type MixedOutput = {
16
20
  +data: mixed,
17
21
  +type: string,
18
- |};
22
+ };
19
23
 
20
24
  export type AsyncDependencyType = 'async' | 'prefetch';
21
25
 
22
- export type TransformResultDependency = {|
26
+ export type TransformResultDependency = {
23
27
  /**
24
28
  * The literal name provided to a require or import call. For example 'foo' in
25
29
  * case of `require('foo')`.
@@ -30,7 +34,7 @@ export type TransformResultDependency = {|
30
34
  * Extra data returned by the dependency extractor. Whatever is added here is
31
35
  * blindly piped by Metro to the serializers.
32
36
  */
33
- +data: {|
37
+ +data: {
34
38
  /**
35
39
  * If not null, this dependency is due to a dynamic `import()` or `__prefetchImport()` call.
36
40
  */
@@ -38,30 +42,33 @@ export type TransformResultDependency = {|
38
42
  /**
39
43
  * The condition for splitting on this dependency edge.
40
44
  */
41
- +splitCondition?: {|
45
+ +splitCondition?: {
42
46
  +mobileConfigName: string,
43
- |},
47
+ },
44
48
  /**
45
49
  * The dependency is enclosed in a try/catch block.
46
50
  */
47
51
  +isOptional?: boolean,
48
52
 
49
53
  +locs: $ReadOnlyArray<BabelSourceLocation>,
50
- |},
51
- |};
52
54
 
53
- export type Dependency = {|
55
+ /** Context for requiring a collection of modules. */
56
+ +contextParams?: RequireContextParams,
57
+ },
58
+ };
59
+
60
+ export type Dependency = {
54
61
  +absolutePath: string,
55
62
  +data: TransformResultDependency,
56
- |};
63
+ };
57
64
 
58
- export type Module<T = MixedOutput> = {|
65
+ export type Module<T = MixedOutput> = {
59
66
  +dependencies: Map<string, Dependency>,
60
- +inverseDependencies: Set<string>,
67
+ +inverseDependencies: CountingSet<string>,
61
68
  +output: $ReadOnlyArray<T>,
62
69
  +path: string,
63
70
  +getSource: () => Buffer,
64
- |};
71
+ };
65
72
 
66
73
  export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;
67
74
 
@@ -74,51 +81,56 @@ export type TransformInputOptions = $Diff<
74
81
  },
75
82
  >;
76
83
 
77
- export type Graph<T = MixedOutput> = {|
78
- dependencies: Dependencies<T>,
79
- importBundleNames: Set<string>,
80
- +entryPoints: $ReadOnlyArray<string>,
84
+ export type GraphInputOptions = $ReadOnly<{
85
+ entryPoints: $ReadOnlySet<string>,
81
86
  // Unused in core but useful for custom serializers / experimentalSerializerHook
82
- +transformOptions: TransformInputOptions,
83
- |};
87
+ transformOptions: TransformInputOptions,
88
+ }>;
89
+
90
+ export type Graph<T = MixedOutput> = {
91
+ ...$ReadOnly<GraphInputOptions>,
92
+ dependencies: Dependencies<T>,
93
+ +importBundleNames: Set<string>,
94
+ +privateState: PrivateState,
95
+ };
84
96
 
85
- export type TransformResult<T = MixedOutput> = $ReadOnly<{|
97
+ export type TransformResult<T = MixedOutput> = $ReadOnly<{
86
98
  dependencies: $ReadOnlyArray<TransformResultDependency>,
87
99
  output: $ReadOnlyArray<T>,
88
- |}>;
100
+ }>;
89
101
 
90
- export type TransformResultWithSource<T = MixedOutput> = $ReadOnly<{|
102
+ export type TransformResultWithSource<T = MixedOutput> = $ReadOnly<{
91
103
  ...TransformResult<T>,
92
104
  getSource: () => Buffer,
93
- |}>;
105
+ }>;
94
106
 
95
107
  export type TransformFn<T = MixedOutput> = string => Promise<
96
108
  TransformResultWithSource<T>,
97
109
  >;
98
- export type AllowOptionalDependenciesWithOptions = {|
110
+ export type AllowOptionalDependenciesWithOptions = {
99
111
  +exclude: Array<string>,
100
- |};
112
+ };
101
113
  export type AllowOptionalDependencies =
102
114
  | boolean
103
115
  | AllowOptionalDependenciesWithOptions;
104
116
 
105
- export type Options<T = MixedOutput> = {|
117
+ export type Options<T = MixedOutput> = {
106
118
  +resolve: (from: string, to: string) => string,
107
119
  +transform: TransformFn<T>,
108
120
  +transformOptions: TransformInputOptions,
109
121
  +onProgress: ?(numProcessed: number, total: number) => mixed,
110
122
  +experimentalImportBundleSupport: boolean,
111
123
  +shallow: boolean,
112
- |};
124
+ };
113
125
 
114
- export type DeltaResult<T = MixedOutput> = {|
126
+ export type DeltaResult<T = MixedOutput> = {
115
127
  +added: Map<string, Module<T>>,
116
128
  +modified: Map<string, Module<T>>,
117
129
  +deleted: Set<string>,
118
130
  +reset: boolean,
119
- |};
131
+ };
120
132
 
121
- export type SerializerOptions = {|
133
+ export type SerializerOptions = {
122
134
  +asyncRequireModulePath: string,
123
135
  +createModuleId: string => number,
124
136
  +dev: boolean,
@@ -132,4 +144,4 @@ export type SerializerOptions = {|
132
144
  +serverRoot: string,
133
145
  +sourceMapUrl: ?string,
134
146
  +sourceUrl: ?string,
135
- |};
147
+ };
@@ -20,8 +20,8 @@ const DeltaCalculator = require("./DeltaBundler/DeltaCalculator");
20
20
  class DeltaBundler {
21
21
  _deltaCalculators = new Map();
22
22
 
23
- constructor(bundler) {
24
- this._bundler = bundler;
23
+ constructor(changeEventSource) {
24
+ this._changeEventSource = changeEventSource;
25
25
  }
26
26
 
27
27
  end() {
@@ -31,8 +31,11 @@ class DeltaBundler {
31
31
  }
32
32
 
33
33
  async getDependencies(entryPoints, options) {
34
- const depGraph = await this._bundler.getDependencyGraph();
35
- const deltaCalculator = new DeltaCalculator(entryPoints, depGraph, options);
34
+ const deltaCalculator = new DeltaCalculator(
35
+ new Set(entryPoints),
36
+ this._changeEventSource,
37
+ options
38
+ );
36
39
  await deltaCalculator.getDelta({
37
40
  reset: true,
38
41
  shallow: options.shallow,
@@ -45,8 +48,11 @@ class DeltaBundler {
45
48
  // To get just the dependencies, use getDependencies which will not leak graphs.
46
49
 
47
50
  async buildGraph(entryPoints, options) {
48
- const depGraph = await this._bundler.getDependencyGraph();
49
- const deltaCalculator = new DeltaCalculator(entryPoints, depGraph, options);
51
+ const deltaCalculator = new DeltaCalculator(
52
+ new Set(entryPoints),
53
+ this._changeEventSource,
54
+ options
55
+ );
50
56
  await deltaCalculator.getDelta({
51
57
  reset: true,
52
58
  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,
@@ -19,6 +18,7 @@ import type {
19
18
  MixedOutput,
20
19
  Options,
21
20
  } from './DeltaBundler/types.flow';
21
+ import type EventEmitter from 'events';
22
22
 
23
23
  const DeltaCalculator = require('./DeltaBundler/DeltaCalculator');
24
24
 
@@ -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();
package/src/HmrServer.js CHANGED
@@ -11,8 +11,6 @@
11
11
 
12
12
  const hmrJSBundle = require("./DeltaBundler/Serializers/hmrJSBundle");
13
13
 
14
- const IncrementalBundler = require("./IncrementalBundler");
15
-
16
14
  const GraphNotFoundError = require("./IncrementalBundler/GraphNotFoundError");
17
15
 
18
16
  const RevisionNotFoundError = require("./IncrementalBundler/RevisionNotFoundError");
@@ -10,7 +10,7 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- import type {RevisionId} from './IncrementalBundler';
13
+ import type IncrementalBundler, {RevisionId} from './IncrementalBundler';
14
14
  import type {ConfigT} from 'metro-config/src/configTypes.flow';
15
15
  import type {
16
16
  HmrClientMessage,
@@ -20,7 +20,6 @@ import type {
20
20
  } from 'metro-runtime/src/modules/types.flow';
21
21
 
22
22
  const hmrJSBundle = require('./DeltaBundler/Serializers/hmrJSBundle');
23
- const IncrementalBundler = require('./IncrementalBundler');
24
23
  const GraphNotFoundError = require('./IncrementalBundler/GraphNotFoundError');
25
24
  const RevisionNotFoundError = require('./IncrementalBundler/RevisionNotFoundError');
26
25
  const debounceAsyncQueue = require('./lib/debounceAsyncQueue');
@@ -39,18 +38,18 @@ const url = require('url');
39
38
  type $ReturnType<F> = $Call<<A, R>((...A) => R) => R, F>;
40
39
  export type EntryPointURL = $ReturnType<typeof url.parse>;
41
40
 
42
- type Client = {|
41
+ type Client = {
43
42
  optedIntoHMR: boolean,
44
43
  revisionIds: Array<RevisionId>,
45
44
  +sendFn: string => void,
46
- |};
45
+ };
47
46
 
48
- type ClientGroup = {|
47
+ type ClientGroup = {
49
48
  +clients: Set<Client>,
50
49
  clientUrl: EntryPointURL,
51
50
  revisionId: RevisionId,
52
51
  +unlisten: () => void,
53
- |};
52
+ };
54
53
 
55
54
  function send(sendFns: Array<(string) => void>, message: HmrMessage): void {
56
55
  const strMessage = JSON.stringify(message);
@@ -252,7 +251,7 @@ class HmrServer<TClient: Client> {
252
251
 
253
252
  async _handleFileChange(
254
253
  group: ClientGroup,
255
- options: {|isInitialUpdate: boolean|},
254
+ options: {isInitialUpdate: boolean},
256
255
  ): Promise<void> {
257
256
  const optedIntoHMR = [...group.clients].some(
258
257
  (client: Client) => client.optedIntoHMR,
@@ -292,7 +291,7 @@ class HmrServer<TClient: Client> {
292
291
 
293
292
  async _prepareMessage(
294
293
  group: ClientGroup,
295
- options: {|isInitialUpdate: boolean|},
294
+ options: {isInitialUpdate: boolean},
296
295
  ): Promise<HmrUpdateMessage | HmrErrorMessage> {
297
296
  try {
298
297
  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
@@ -8,4 +8,3 @@
8
8
  * @format
9
9
  */
10
10
  "use strict";
11
- "use strict";
@@ -10,8 +10,6 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- 'use strict';
14
-
15
13
  type ModuleID = string;
16
14
  export type Path = string;
17
15
  type Platform = string;
@@ -55,14 +53,15 @@ export type FastFS = {
55
53
  ...
56
54
  };
57
55
 
58
- type HasteMapOptions = {|
56
+ type HasteMapOptions = {
59
57
  extensions: Extensions,
60
58
  files: Array<string>,
61
59
  moduleCache: ModuleCache,
62
60
  platforms: Platforms,
63
61
  preferNativePlatform: true,
64
- |};
62
+ };
65
63
 
64
+ // eslint-disable-next-line no-unused-vars
66
65
  declare class HasteMap {
67
66
  // node-haste/DependencyGraph/HasteMap.js
68
67
  build(): Promise<Object>;
@@ -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