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
@@ -1,565 +0,0 @@
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
- import type {
14
- Dependency,
15
- Graph,
16
- Module,
17
- Options,
18
- TransformResultDependency,
19
- } from './types.flow';
20
-
21
- const nullthrows = require('nullthrows');
22
-
23
- type Result<T> = {
24
- added: Map<string, Module<T>>,
25
- modified: Map<string, Module<T>>,
26
- deleted: Set<string>,
27
- ...
28
- };
29
-
30
- /**
31
- * Internal data structure that the traversal logic uses to know which of the
32
- * files have been modified. This allows to return the added modules before the
33
- * modified ones (which is useful for things like Hot Module Reloading).
34
- **/
35
- type Delta = $ReadOnly<{|
36
- added: Set<string>,
37
- modified: Set<string>,
38
- deleted: Set<string>,
39
- inverseDependencies: Map<string, Set<string>>,
40
- |}>;
41
-
42
- type InternalOptions<T> = $ReadOnly<{|
43
- experimentalImportBundleSupport: boolean,
44
- onDependencyAdd: () => mixed,
45
- onDependencyAdded: () => mixed,
46
- resolve: $PropertyType<Options<T>, 'resolve'>,
47
- transform: $PropertyType<Options<T>, 'transform'>,
48
- shallow: boolean,
49
- |}>;
50
-
51
- function getInternalOptions<T>({
52
- transform,
53
- resolve,
54
- onProgress,
55
- experimentalImportBundleSupport,
56
- shallow,
57
- }: Options<T>): InternalOptions<T> {
58
- let numProcessed = 0;
59
- let total = 0;
60
-
61
- return {
62
- experimentalImportBundleSupport,
63
- transform,
64
- resolve,
65
- onDependencyAdd: () => onProgress && onProgress(numProcessed, ++total),
66
- onDependencyAdded: () => onProgress && onProgress(++numProcessed, total),
67
- shallow,
68
- };
69
- }
70
-
71
- /**
72
- * Dependency Traversal logic for the Delta Bundler. This method calculates
73
- * the modules that should be included in the bundle by traversing the
74
- * dependency graph.
75
- * Instead of traversing the whole graph each time, it just calculates the
76
- * difference between runs by only traversing the added/removed dependencies.
77
- * To do so, it uses the passed passed graph dependencies and it mutates it.
78
- * The paths parameter contains the absolute paths of the root files that the
79
- * method should traverse. Normally, these paths should be the modified files
80
- * since the last traversal.
81
- */
82
- async function traverseDependencies<T>(
83
- paths: $ReadOnlyArray<string>,
84
- graph: Graph<T>,
85
- options: Options<T>,
86
- ): Promise<Result<T>> {
87
- const delta = {
88
- added: new Set(),
89
- modified: new Set(),
90
- deleted: new Set(),
91
- inverseDependencies: new Map(),
92
- };
93
-
94
- const internalOptions = getInternalOptions(options);
95
-
96
- for (const path of paths) {
97
- // Only process the path if it's part of the dependency graph. It's possible
98
- // that this method receives a path that is no longer part of it (e.g if a
99
- // module gets removed from the dependency graph and just afterwards it gets
100
- // modified), and we have to ignore these cases.
101
- if (graph.dependencies.get(path)) {
102
- delta.modified.add(path);
103
-
104
- await traverseDependenciesForSingleFile(
105
- path,
106
- graph,
107
- delta,
108
- internalOptions,
109
- );
110
- }
111
- }
112
-
113
- const added = new Map();
114
- const modified = new Map();
115
- const deleted = new Set();
116
-
117
- for (const path of delta.deleted) {
118
- // If a dependency has been marked both as added and deleted, it means that
119
- // this is a renamed file (or that dependency has been removed from one path
120
- // but added back in a different path). In this case the addition and
121
- // deletion "get cancelled".
122
- if (!delta.added.has(path)) {
123
- deleted.add(path);
124
- }
125
-
126
- delta.modified.delete(path);
127
- delta.added.delete(path);
128
- }
129
-
130
- for (const path of delta.added) {
131
- added.set(path, nullthrows(graph.dependencies.get(path)));
132
- }
133
-
134
- for (const path of delta.modified) {
135
- // Similarly to the above, a file can be marked as both added and modified
136
- // when its path and dependencies have changed. In this case, we only
137
- // consider the addition.
138
- if (!delta.added.has(path)) {
139
- modified.set(path, nullthrows(graph.dependencies.get(path)));
140
- }
141
- }
142
-
143
- return {
144
- added,
145
- modified,
146
- deleted,
147
- };
148
- }
149
-
150
- async function initialTraverseDependencies<T>(
151
- graph: Graph<T>,
152
- options: Options<T>,
153
- ): Promise<Result<T>> {
154
- const delta = {
155
- added: new Set(),
156
- modified: new Set(),
157
- deleted: new Set(),
158
- inverseDependencies: new Map(),
159
- };
160
-
161
- const internalOptions = getInternalOptions(options);
162
-
163
- await Promise.all(
164
- graph.entryPoints.map((path: string) =>
165
- traverseDependenciesForSingleFile(path, graph, delta, internalOptions),
166
- ),
167
- );
168
-
169
- reorderGraph(graph, {
170
- shallow: options.shallow,
171
- });
172
-
173
- return {
174
- added: graph.dependencies,
175
- modified: new Map(),
176
- deleted: new Set(),
177
- };
178
- }
179
-
180
- async function traverseDependenciesForSingleFile<T>(
181
- path: string,
182
- graph: Graph<T>,
183
- delta: Delta,
184
- options: InternalOptions<T>,
185
- ): Promise<void> {
186
- options.onDependencyAdd();
187
-
188
- await processModule(path, graph, delta, options);
189
-
190
- options.onDependencyAdded();
191
- }
192
-
193
- async function processModule<T>(
194
- path: string,
195
- graph: Graph<T>,
196
- delta: Delta,
197
- options: InternalOptions<T>,
198
- ): Promise<Module<T>> {
199
- // Transform the file via the given option.
200
- const result = await options.transform(path);
201
-
202
- // Get the absolute path of all sub-dependencies (some of them could have been
203
- // moved but maintain the same relative path).
204
- const currentDependencies = resolveDependencies(
205
- path,
206
- result.dependencies,
207
- options,
208
- );
209
-
210
- const previousModule = graph.dependencies.get(path) || {
211
- inverseDependencies: delta.inverseDependencies.get(path) || new Set(),
212
- path,
213
- };
214
- const previousDependencies = previousModule.dependencies || new Map();
215
-
216
- // Update the module information.
217
- const module = {
218
- ...previousModule,
219
- dependencies: new Map(),
220
- getSource: result.getSource,
221
- output: result.output,
222
- };
223
- graph.dependencies.set(module.path, module);
224
-
225
- for (const [relativePath, dependency] of currentDependencies) {
226
- module.dependencies.set(relativePath, dependency);
227
- }
228
-
229
- Array.from(previousDependencies.entries())
230
- .filter(
231
- ([relativePath, dependency]) =>
232
- !currentDependencies.has(relativePath) ||
233
- nullthrows(currentDependencies.get(relativePath)).absolutePath !==
234
- dependency.absolutePath,
235
- )
236
- .forEach(([relativePath, dependency]) =>
237
- removeDependency(
238
- module,
239
- dependency.absolutePath,
240
- graph,
241
- delta,
242
- new Set(),
243
- ),
244
- );
245
-
246
- // Check all the module dependencies and start traversing the tree from each
247
- // added and removed dependency, to get all the modules that have to be added
248
- // and removed from the dependency graph.
249
- const promises = [];
250
-
251
- for (const [relativePath, dependency] of currentDependencies) {
252
- if (!options.shallow) {
253
- if (
254
- options.experimentalImportBundleSupport &&
255
- dependency.data.data.asyncType != null
256
- ) {
257
- graph.importBundleNames.add(dependency.absolutePath);
258
- } else if (
259
- !previousDependencies.has(relativePath) ||
260
- nullthrows(previousDependencies.get(relativePath)).absolutePath !==
261
- dependency.absolutePath
262
- ) {
263
- promises.push(
264
- addDependency(module, dependency.absolutePath, graph, delta, options),
265
- );
266
- }
267
- }
268
- }
269
-
270
- try {
271
- await Promise.all(promises);
272
- } catch (err) {
273
- // If there is an error, restore the previous dependency list.
274
- // This ensures we don't skip over them during the next traversal attempt.
275
- // $FlowFixMe[cannot-write]
276
- module.dependencies = previousDependencies;
277
- throw err;
278
- }
279
- return module;
280
- }
281
-
282
- async function addDependency<T>(
283
- parentModule: Module<T>,
284
- path: string,
285
- graph: Graph<T>,
286
- delta: Delta,
287
- options: InternalOptions<T>,
288
- ): Promise<void> {
289
- // The new dependency was already in the graph, we don't need to do anything.
290
- const existingModule = graph.dependencies.get(path);
291
-
292
- if (existingModule) {
293
- existingModule.inverseDependencies.add(parentModule.path);
294
-
295
- return;
296
- }
297
-
298
- // This module is being transformed at the moment in parallel, so we should
299
- // only mark its parent as an inverse dependency.
300
- const inverse = delta.inverseDependencies.get(path);
301
- if (inverse) {
302
- inverse.add(parentModule.path);
303
-
304
- return;
305
- }
306
-
307
- delta.added.add(path);
308
- delta.inverseDependencies.set(path, new Set([parentModule.path]));
309
-
310
- options.onDependencyAdd();
311
-
312
- const module = await processModule(path, graph, delta, options);
313
-
314
- graph.dependencies.set(module.path, module);
315
- module.inverseDependencies.add(parentModule.path);
316
-
317
- options.onDependencyAdded();
318
- }
319
-
320
- /**
321
- * Recursively look up `inverseDependencies` until it is empty,
322
- * returning a set of paths for the last module that does not have
323
- * `inverseDependencies`.
324
- */
325
- function getAllTopLevelInverseDependencies<T>(
326
- inverseDependencies: Set<string>,
327
- graph: Graph<T>,
328
- currModule: string,
329
- visited: Set<string>,
330
- ): Set<string> {
331
- if (visited.has(currModule)) {
332
- return new Set();
333
- }
334
- visited.add(currModule);
335
- if (!inverseDependencies.size) {
336
- return new Set([currModule]);
337
- }
338
-
339
- return Array.from(inverseDependencies)
340
- .filter(inverseDep => graph.dependencies.has(inverseDep))
341
- .reduce((acc, inverseDep) => {
342
- const mod = graph.dependencies.get(inverseDep);
343
- if (!mod) {
344
- return acc;
345
- }
346
- getAllTopLevelInverseDependencies(
347
- mod.inverseDependencies,
348
- graph,
349
- inverseDep,
350
- visited,
351
- ).forEach(x => {
352
- acc.add(x);
353
- });
354
- return acc;
355
- }, new Set());
356
- }
357
-
358
- /**
359
- * Given `inverseDependencies`, tracing back inverse dependencies to
360
- * see if it only leads back to `parentModule`.
361
- */
362
- function canSafelyRemoveFromParentModule<T>(
363
- inverseDependencies: Set<string>,
364
- parentModule: string,
365
- graph: Graph<T>,
366
- canBeRemovedSafely: Set<string>,
367
- delta: Delta,
368
- ): boolean {
369
- const visited = new Set();
370
- const topInverseDependencies = getAllTopLevelInverseDependencies(
371
- inverseDependencies,
372
- graph,
373
- '', // current module name
374
- visited,
375
- );
376
-
377
- if (!topInverseDependencies.size) {
378
- /**
379
- * This happens when parentModule and inverseDependencies have a circular dependency.
380
- * This will eventually become an empty set due to the `visited` Set being the
381
- * base case for the recursive call.
382
- */
383
- return true;
384
- }
385
-
386
- const undeletedInverseDependencies = Array.from(
387
- topInverseDependencies,
388
- ).filter(x => !delta.deleted.has(x));
389
-
390
- /**
391
- * We can only mark the `visited` Set of modules to be safely removable if
392
- * 1. We do not have top a level module to compare with parentModule.
393
- * This can happen when trying to see if we can safely remove from
394
- * a module that was deleted. This is why we filtered them out with `delta.deleted`
395
- * 2. We have one top module and it is parentModule
396
- */
397
- const canSafelyRemove =
398
- !undeletedInverseDependencies.length ||
399
- (undeletedInverseDependencies.length === 1 &&
400
- undeletedInverseDependencies[0] === parentModule);
401
-
402
- if (canSafelyRemove) {
403
- visited.forEach(mod => {
404
- canBeRemovedSafely.add(mod);
405
- });
406
- }
407
- return canSafelyRemove;
408
- }
409
-
410
- function removeDependency<T>(
411
- parentModule: Module<T>,
412
- absolutePath: string,
413
- graph: Graph<T>,
414
- delta: Delta,
415
- // We use `canBeRemovedSafely` set to keep track of visited
416
- // module(s) that we're sure can be removed. This will skip expensive
417
- // inverse dependency traversals.
418
- canBeRemovedSafely: Set<string> = new Set(),
419
- ): void {
420
- const module = graph.dependencies.get(absolutePath);
421
-
422
- if (!module) {
423
- return;
424
- }
425
-
426
- module.inverseDependencies.delete(parentModule.path);
427
-
428
- // Even if there are modules still using parentModule, we want to ensure
429
- // there is no circular dependency. Thus, we check if it can be safely removed
430
- // by tracing back the inverseDependencies.
431
- if (!canBeRemovedSafely.has(module.path)) {
432
- if (
433
- module.inverseDependencies.size &&
434
- !canSafelyRemoveFromParentModule(
435
- module.inverseDependencies,
436
- module.path,
437
- graph,
438
- canBeRemovedSafely,
439
- delta,
440
- )
441
- ) {
442
- return;
443
- }
444
- }
445
-
446
- delta.deleted.add(module.path);
447
-
448
- // Now we need to iterate through the module dependencies in order to
449
- // clean up everything (we cannot read the module because it may have
450
- // been deleted).
451
- Array.from(module.dependencies.values())
452
- .filter(
453
- dependency =>
454
- !delta.deleted.has(dependency.absolutePath) &&
455
- dependency.absolutePath !== parentModule.path,
456
- )
457
- .forEach(dependency =>
458
- removeDependency(
459
- module,
460
- dependency.absolutePath,
461
- graph,
462
- delta,
463
- canBeRemovedSafely,
464
- ),
465
- );
466
- // This module is not used anywhere else!! we can clear it from the bundle
467
- graph.dependencies.delete(module.path);
468
- }
469
-
470
- function resolveDependencies<T>(
471
- parentPath: string,
472
- dependencies: $ReadOnlyArray<TransformResultDependency>,
473
- options: InternalOptions<T>,
474
- ): Map<string, Dependency> {
475
- const resolve = (parentPath: string, result: TransformResultDependency) => {
476
- const relativePath = result.name;
477
- try {
478
- return [
479
- relativePath,
480
- {
481
- absolutePath: options.resolve(parentPath, relativePath),
482
- data: result,
483
- },
484
- ];
485
- } catch (error) {
486
- // Ignore unavailable optional dependencies. They are guarded
487
- // with a try-catch block and will be handled during runtime.
488
- if (result.data.isOptional !== true) {
489
- throw error;
490
- }
491
- }
492
- return undefined;
493
- };
494
-
495
- const resolved = dependencies.reduce(
496
- (list: Array<[string, Dependency]>, result: TransformResultDependency) => {
497
- const resolvedPath = resolve(parentPath, result);
498
- if (resolvedPath) {
499
- list.push(resolvedPath);
500
- }
501
- return list;
502
- },
503
- [],
504
- );
505
- return new Map(resolved);
506
- }
507
-
508
- /**
509
- * Re-traverse the dependency graph in DFS order to reorder the modules and
510
- * guarantee the same order between runs. This method mutates the passed graph.
511
- */
512
- function reorderGraph<T>(
513
- graph: Graph<T>,
514
- options: {shallow: boolean, ...},
515
- ): void {
516
- const orderedDependencies = new Map();
517
-
518
- graph.entryPoints.forEach((entryPoint: string) => {
519
- const mainModule = graph.dependencies.get(entryPoint);
520
-
521
- if (!mainModule) {
522
- throw new ReferenceError('Module not registered in graph: ' + entryPoint);
523
- }
524
-
525
- reorderDependencies(graph, mainModule, orderedDependencies, options);
526
- });
527
-
528
- graph.dependencies = orderedDependencies;
529
- }
530
-
531
- function reorderDependencies<T>(
532
- graph: Graph<T>,
533
- module: Module<T>,
534
- orderedDependencies: Map<string, Module<T>>,
535
- options: {shallow: boolean, ...},
536
- ): void {
537
- if (module.path) {
538
- if (orderedDependencies.has(module.path)) {
539
- return;
540
- }
541
-
542
- orderedDependencies.set(module.path, module);
543
- }
544
-
545
- module.dependencies.forEach((dependency: Dependency) => {
546
- const path = dependency.absolutePath;
547
- const childModule = graph.dependencies.get(path);
548
-
549
- if (!childModule) {
550
- if (dependency.data.data.asyncType != null || options.shallow) {
551
- return;
552
- } else {
553
- throw new ReferenceError('Module not registered in graph: ' + path);
554
- }
555
- }
556
-
557
- reorderDependencies(graph, childModule, orderedDependencies, options);
558
- });
559
- }
560
-
561
- module.exports = {
562
- initialTraverseDependencies,
563
- traverseDependencies,
564
- reorderGraph,
565
- };
@@ -1,10 +0,0 @@
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
- "use strict";
@@ -1,88 +0,0 @@
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
8
- * @format
9
- */
10
-
11
- 'use strict';
12
-
13
- import type EventEmitter from 'events';
14
-
15
- // TODO(cpojer): Create a jest-types repo.
16
- export type HasteFS = {
17
- exists(filePath: string): boolean,
18
- getAllFiles(): Array<string>,
19
- getDependencies(filePath: string): Array<string>,
20
- getFileIterator(): Iterator<string>,
21
- getModuleName(filePath: string): ?string,
22
- getSha1(string): ?string,
23
- matchFiles(pattern: RegExp | string): Array<string>,
24
- ...
25
- };
26
-
27
- export type HasteConfig = $ReadOnly<{
28
- cacheDirectory?: ?string,
29
- computeDependencies?: ?boolean,
30
- computeSha1?: ?boolean,
31
- dependencyExtractor?: ?string | null,
32
- enableSymlinks?: ?boolean,
33
- extensions: $ReadOnlyArray<string>,
34
- forceNodeFilesystemAPI?: ?boolean,
35
- hasteImplModulePath?: ?string,
36
- hasteMapModulePath?: ?string,
37
- ignorePattern?: ?RegExp | ((str: string) => boolean),
38
- maxWorkers: number,
39
- mocksPattern?: ?string,
40
- name: string,
41
- platforms: $ReadOnlyArray<string>,
42
- resetCache?: ?boolean,
43
- retainAllFiles: boolean,
44
- rootDir: string,
45
- roots: $ReadOnlyArray<string>,
46
- skipPackageJson?: ?boolean,
47
- throwOnModuleCollision?: ?boolean,
48
- useWatchman?: ?boolean,
49
- watch?: ?boolean,
50
- ...
51
- }>;
52
-
53
- type ModuleMapItem = {[platform: string]: ModuleMetaData};
54
- type ModuleMetaData = [string, number];
55
- type MockData = Map<string, string>;
56
- type ModuleMapData = Map<string, ModuleMapItem>;
57
- type DuplicatesSet = Map<string, number>;
58
- type DuplicatesIndex = Map<string, Map<string, DuplicatesSet>>;
59
-
60
- type RawModuleMap = {
61
- rootDir: string,
62
- duplicates: DuplicatesIndex,
63
- map: ModuleMapData,
64
- mocks: MockData,
65
- };
66
-
67
- // `jest-haste-map`'s interface for ModuleMap.
68
- export type ModuleMap = {
69
- getModule(
70
- name: string,
71
- platform: string | null,
72
- supportsNativePlatform: ?boolean,
73
- ): ?string,
74
- getPackage(
75
- name: string,
76
- platform: string | null,
77
- supportsNativePlatform: ?boolean,
78
- ): ?string,
79
- getRawModuleMap(): RawModuleMap,
80
- ...
81
- };
82
-
83
- // Interface as used by node-haste / internal tools, satisfied by JestHasteMap
84
- export interface HasteMap extends EventEmitter {
85
- build: () => Promise<{hasteFS: HasteFS, moduleMap: ModuleMap}>;
86
- end: () => void;
87
- getCacheFilePath: () => string;
88
- }