metro-file-map 0.83.4 → 0.83.6

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 (70) hide show
  1. package/package.json +3 -2
  2. package/src/Watcher.d.ts +74 -0
  3. package/src/Watcher.js +68 -48
  4. package/src/Watcher.js.flow +84 -51
  5. package/src/cache/DiskCacheManager.d.ts +49 -0
  6. package/src/cache/DiskCacheManager.js +1 -5
  7. package/src/constants.d.ts +22 -0
  8. package/src/crawlers/node/hasNativeFindSupport.d.ts +19 -0
  9. package/src/crawlers/node/index.d.ts +21 -0
  10. package/src/crawlers/node/index.js +6 -10
  11. package/src/crawlers/node/index.js.flow +8 -6
  12. package/src/crawlers/watchman/index.d.ts +23 -0
  13. package/src/crawlers/watchman/index.js +2 -9
  14. package/src/crawlers/watchman/index.js.flow +2 -6
  15. package/src/flow-types.d.ts +460 -0
  16. package/src/flow-types.js.flow +89 -29
  17. package/src/index.d.ts +182 -0
  18. package/src/index.js +148 -132
  19. package/src/index.js.flow +200 -155
  20. package/src/lib/FileProcessor.d.ts +60 -0
  21. package/src/lib/FileProcessor.js +1 -5
  22. package/src/lib/FileSystemChangeAggregator.d.ts +40 -0
  23. package/src/lib/FileSystemChangeAggregator.js +89 -0
  24. package/src/lib/FileSystemChangeAggregator.js.flow +143 -0
  25. package/src/lib/RootPathUtils.d.ts +30 -0
  26. package/src/lib/RootPathUtils.js +2 -9
  27. package/src/lib/TreeFS.d.ts +174 -0
  28. package/src/lib/TreeFS.js +68 -21
  29. package/src/lib/TreeFS.js.flow +89 -16
  30. package/src/lib/checkWatchmanCapabilities.d.ts +20 -0
  31. package/src/lib/normalizePathSeparatorsToPosix.d.ts +20 -0
  32. package/src/lib/normalizePathSeparatorsToPosix.js +1 -4
  33. package/src/lib/normalizePathSeparatorsToSystem.d.ts +20 -0
  34. package/src/lib/normalizePathSeparatorsToSystem.js +1 -4
  35. package/src/lib/rootRelativeCacheKeys.d.ts +24 -0
  36. package/src/lib/rootRelativeCacheKeys.js +1 -5
  37. package/src/lib/sorting.d.ts +23 -0
  38. package/src/plugins/DependencyPlugin.d.ts +52 -0
  39. package/src/plugins/DependencyPlugin.js +1 -3
  40. package/src/plugins/DependencyPlugin.js.flow +1 -16
  41. package/src/plugins/HastePlugin.d.ts +69 -0
  42. package/src/plugins/HastePlugin.js +12 -16
  43. package/src/plugins/HastePlugin.js.flow +12 -12
  44. package/src/plugins/MockPlugin.d.ts +48 -0
  45. package/src/plugins/MockPlugin.js +18 -25
  46. package/src/plugins/MockPlugin.js.flow +18 -22
  47. package/src/plugins/dependencies/dependencyExtractor.d.ts +1 -1
  48. package/src/plugins/haste/DuplicateHasteCandidatesError.d.ts +31 -0
  49. package/src/plugins/haste/DuplicateHasteCandidatesError.js +1 -5
  50. package/src/plugins/haste/HasteConflictsError.d.ts +23 -0
  51. package/src/plugins/haste/HasteConflictsError.js +1 -5
  52. package/src/plugins/haste/computeConflicts.d.ts +34 -0
  53. package/src/plugins/haste/computeConflicts.js +1 -5
  54. package/src/plugins/haste/getPlatformExtension.d.ts +21 -0
  55. package/src/plugins/mocks/getMockName.d.ts +20 -0
  56. package/src/plugins/mocks/getMockName.js +1 -4
  57. package/src/watchers/AbstractWatcher.d.ts +41 -0
  58. package/src/watchers/AbstractWatcher.js +2 -9
  59. package/src/watchers/FallbackWatcher.d.ts +28 -0
  60. package/src/watchers/FallbackWatcher.js +21 -12
  61. package/src/watchers/FallbackWatcher.js.flow +28 -5
  62. package/src/watchers/NativeWatcher.d.ts +55 -0
  63. package/src/watchers/NativeWatcher.js +28 -9
  64. package/src/watchers/NativeWatcher.js.flow +33 -6
  65. package/src/watchers/RecrawlWarning.d.ts +32 -0
  66. package/src/watchers/WatchmanWatcher.d.ts +34 -0
  67. package/src/watchers/WatchmanWatcher.js +2 -9
  68. package/src/watchers/common.d.ts +70 -0
  69. package/src/watchers/common.js +7 -6
  70. package/src/watchers/common.js.flow +1 -0
@@ -13,6 +13,7 @@ import type {
13
13
  FileData,
14
14
  FileMetadata,
15
15
  FileStats,
16
+ FileSystemListener,
16
17
  LookupResult,
17
18
  MutableFileSystem,
18
19
  Path,
@@ -156,16 +157,45 @@ export default class TreeFS implements MutableFileSystem {
156
157
  return (fileMetadata && fileMetadata[H.SIZE]) ?? null;
157
158
  }
158
159
 
159
- getDifference(files: FileData): {
160
+ getDifference(
161
+ files: FileData,
162
+ options?: Readonly<{
163
+ // Only consider files under this normal subdirectory when computing
164
+ // removedFiles. If not provided, all files in the file system are
165
+ // considered.
166
+ subpath?: string,
167
+ }>,
168
+ ): {
160
169
  changedFiles: FileData,
161
170
  removedFiles: Set<string>,
162
171
  } {
163
172
  const changedFiles: FileData = new Map(files);
164
173
  const removedFiles: Set<string> = new Set();
165
- for (const {canonicalPath, metadata} of this.metadataIterator({
166
- includeNodeModules: true,
167
- includeSymlinks: true,
168
- })) {
174
+ const subpath = options?.subpath;
175
+
176
+ // If a subpath is specified, start iteration from that node
177
+ let rootNode: DirectoryNode = this.#rootNode;
178
+ let prefix: string = '';
179
+ if (subpath != null && subpath !== '') {
180
+ const lookupResult = this.#lookupByNormalPath(subpath, {
181
+ followLeaf: true,
182
+ });
183
+ if (!lookupResult.exists || !isDirectory(lookupResult.node)) {
184
+ // Directory doesn't exist, nothing to compare - all files are new
185
+ return {changedFiles, removedFiles};
186
+ }
187
+ rootNode = lookupResult.node;
188
+ prefix = lookupResult.canonicalPath;
189
+ }
190
+
191
+ for (const {canonicalPath, metadata} of this.#metadataIterator(
192
+ rootNode,
193
+ {
194
+ includeNodeModules: true,
195
+ includeSymlinks: true,
196
+ },
197
+ prefix,
198
+ )) {
169
199
  const newMetadata = files.get(canonicalPath);
170
200
  if (newMetadata) {
171
201
  if (isRegularFile(newMetadata) !== isRegularFile(metadata)) {
@@ -378,11 +408,16 @@ export default class TreeFS implements MutableFileSystem {
378
408
  }
379
409
  }
380
410
 
381
- addOrModify(mixedPath: Path, metadata: FileMetadata): void {
411
+ addOrModify(
412
+ mixedPath: Path,
413
+ metadata: FileMetadata,
414
+ changeListener?: FileSystemListener,
415
+ ): void {
382
416
  const normalPath = this.#normalizePath(mixedPath);
383
417
  // Walk the tree to find the *real* path of the parent node, creating
384
418
  // directories as we need.
385
419
  const parentDirNode = this.#lookupByNormalPath(path.dirname(normalPath), {
420
+ changeListener,
386
421
  makeDirectories: true,
387
422
  });
388
423
  if (!parentDirNode.exists) {
@@ -394,10 +429,13 @@ export default class TreeFS implements MutableFileSystem {
394
429
  const canonicalPath = this.#normalizePath(
395
430
  parentDirNode.canonicalPath + path.sep + path.basename(normalPath),
396
431
  );
397
- this.bulkAddOrModify(new Map([[canonicalPath, metadata]]));
432
+ this.bulkAddOrModify(new Map([[canonicalPath, metadata]]), changeListener);
398
433
  }
399
434
 
400
- bulkAddOrModify(addedOrModifiedFiles: FileData): void {
435
+ bulkAddOrModify(
436
+ addedOrModifiedFiles: FileData,
437
+ changeListener?: FileSystemListener,
438
+ ): void {
401
439
  // Optimisation: Bulk FileData are typically clustered by directory, so we
402
440
  // optimise for that case by remembering the last directory we looked up.
403
441
  // Experiments with large result sets show this to be significantly (~30%)
@@ -413,6 +451,7 @@ export default class TreeFS implements MutableFileSystem {
413
451
 
414
452
  if (directoryNode == null || dirname !== lastDir) {
415
453
  const lookup = this.#lookupByNormalPath(dirname, {
454
+ changeListener,
416
455
  followLeaf: false,
417
456
  makeDirectories: true,
418
457
  });
@@ -433,24 +472,48 @@ export default class TreeFS implements MutableFileSystem {
433
472
  lastDir = dirname;
434
473
  directoryNode = lookup.node;
435
474
  }
475
+ if (changeListener != null) {
476
+ const existingNode = directoryNode.get(basename);
477
+ if (existingNode != null) {
478
+ invariant(
479
+ !isDirectory(existingNode),
480
+ 'Detected addition or modification of file %s, but it is tracked as a non-empty directory',
481
+ normalPath,
482
+ );
483
+ // File already exists - this is a modification
484
+ changeListener.fileModified(normalPath, existingNode, metadata);
485
+ } else {
486
+ // New file
487
+ changeListener.fileAdded(normalPath, metadata);
488
+ }
489
+ }
436
490
  directoryNode.set(basename, metadata);
437
491
  }
438
492
  }
439
493
 
440
- remove(mixedPath: Path): ?FileMetadata {
494
+ remove(mixedPath: Path, changeListener?: FileSystemListener): void {
441
495
  const normalPath = this.#normalizePath(mixedPath);
442
496
  const result = this.#lookupByNormalPath(normalPath, {followLeaf: false});
443
497
  if (!result.exists) {
444
- return null;
498
+ return;
445
499
  }
446
500
  const {parentNode, canonicalPath, node} = result;
447
501
 
448
502
  if (isDirectory(node) && node.size > 0) {
449
- throw new Error(
450
- `TreeFS: remove called on a non-empty directory: ${mixedPath}`,
451
- );
503
+ for (const basename of node.keys()) {
504
+ this.remove(canonicalPath + path.sep + basename, changeListener);
505
+ }
506
+ // Removing the last file will delete this directory
507
+ return;
452
508
  }
453
509
  if (parentNode != null) {
510
+ if (changeListener != null) {
511
+ if (isDirectory(node)) {
512
+ changeListener.directoryRemoved(canonicalPath);
513
+ } else {
514
+ changeListener.fileRemoved(canonicalPath, node);
515
+ }
516
+ }
454
517
  parentNode.delete(path.basename(canonicalPath));
455
518
  if (parentNode.size === 0 && parentNode !== this.#rootNode) {
456
519
  // NB: This isn't the most efficient algorithm - in the case of
@@ -458,10 +521,9 @@ export default class TreeFS implements MutableFileSystem {
458
521
  // that's not expected to be a case common enough to justify
459
522
  // implementation complexity, or slowing down more common uses of
460
523
  // _lookupByNormalPath.
461
- this.remove(path.dirname(canonicalPath));
524
+ this.remove(path.dirname(canonicalPath), changeListener);
462
525
  }
463
526
  }
464
- return isDirectory(node) ? null : node;
465
527
  }
466
528
 
467
529
  /**
@@ -492,6 +554,10 @@ export default class TreeFS implements MutableFileSystem {
492
554
  // be added. Omit for performance if not needed.
493
555
  collectLinkPaths?: ?Set<string>,
494
556
 
557
+ // Low-level callbacks called on mutations of TreeFS data.
558
+ // Omit for performance if not needed.
559
+ changeListener?: FileSystemListener,
560
+
495
561
  // Like lstat vs stat, whether to follow a symlink at the basename of
496
562
  // the given path, or return the details of the symlink itself.
497
563
  followLeaf?: boolean,
@@ -541,7 +607,8 @@ export default class TreeFS implements MutableFileSystem {
541
607
  // null.
542
608
  let ancestorOfRootIdx: ?number = opts.start?.ancestorOfRootIdx ?? 0;
543
609
 
544
- const collectAncestors = opts.collectAncestors;
610
+ const {collectAncestors, changeListener} = opts;
611
+
545
612
  // Used only when collecting ancestors, to avoid double-counting nodes and
546
613
  // paths when traversing a symlink takes us back to rootNode and out again.
547
614
  // This tracks the first character of the first segment not already
@@ -583,6 +650,12 @@ export default class TreeFS implements MutableFileSystem {
583
650
  }
584
651
  segmentNode = new Map();
585
652
  if (opts.makeDirectories === true) {
653
+ if (changeListener != null) {
654
+ const canonicalPath = isLastSegment
655
+ ? targetNormalPath
656
+ : targetNormalPath.slice(0, fromIdx - 1);
657
+ changeListener.directoryAdded(canonicalPath);
658
+ }
586
659
  parentNode.set(segmentName, segmentNode);
587
660
  }
588
661
  }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @noformat
8
+ * @generated SignedSource<<f72d8f0c4d8f513383584a02f36795ef>>
9
+ *
10
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
+ * Original file: packages/metro-file-map/src/lib/checkWatchmanCapabilities.js
12
+ * To regenerate, run:
13
+ * js1 build metro-ts-defs (internal) OR
14
+ * yarn run build-ts-defs (OSS)
15
+ */
16
+
17
+ declare function checkWatchmanCapabilities(
18
+ requiredCapabilities: ReadonlyArray<string>,
19
+ ): Promise<{version: string}>;
20
+ export default checkWatchmanCapabilities;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @noformat
8
+ * @generated SignedSource<<30b5e6d2308dde108c136f95a59e3740>>
9
+ *
10
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
+ * Original file: packages/metro-file-map/src/lib/normalizePathSeparatorsToPosix.js
12
+ * To regenerate, run:
13
+ * js1 build metro-ts-defs (internal) OR
14
+ * yarn run build-ts-defs (OSS)
15
+ */
16
+
17
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: (filePath: string) => string;
18
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
19
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
20
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -13,10 +13,7 @@ function _interopRequireWildcard(e, t) {
13
13
  if (!t && e && e.__esModule) return e;
14
14
  var o,
15
15
  i,
16
- f = {
17
- __proto__: null,
18
- default: e,
19
- };
16
+ f = { __proto__: null, default: e };
20
17
  if (null === e || ("object" != typeof e && "function" != typeof e))
21
18
  return f;
22
19
  if ((o = t ? n : r)) {
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @noformat
8
+ * @generated SignedSource<<719a82b7670f09ecb97e007293fddfc6>>
9
+ *
10
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
+ * Original file: packages/metro-file-map/src/lib/normalizePathSeparatorsToSystem.js
12
+ * To regenerate, run:
13
+ * js1 build metro-ts-defs (internal) OR
14
+ * yarn run build-ts-defs (OSS)
15
+ */
16
+
17
+ declare const $$EXPORT_DEFAULT_DECLARATION$$: (filePath: string) => string;
18
+ declare type $$EXPORT_DEFAULT_DECLARATION$$ =
19
+ typeof $$EXPORT_DEFAULT_DECLARATION$$;
20
+ export default $$EXPORT_DEFAULT_DECLARATION$$;
@@ -13,10 +13,7 @@ function _interopRequireWildcard(e, t) {
13
13
  if (!t && e && e.__esModule) return e;
14
14
  var o,
15
15
  i,
16
- f = {
17
- __proto__: null,
18
- default: e,
19
- };
16
+ f = { __proto__: null, default: e };
20
17
  if (null === e || ("object" != typeof e && "function" != typeof e))
21
18
  return f;
22
19
  if ((o = t ? n : r)) {
@@ -0,0 +1,24 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<f82cf1eeac38c409c5bf891686c2e828>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/lib/rootRelativeCacheKeys.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {BuildParameters} from '../flow-types';
19
+
20
+ declare function rootRelativeCacheKeys(buildParameters: BuildParameters): {
21
+ rootDirHash: string;
22
+ relativeConfigHash: string;
23
+ };
24
+ export default rootRelativeCacheKeys;
@@ -10,11 +10,7 @@ var _normalizePathSeparatorsToPosix = _interopRequireDefault(
10
10
  var _RootPathUtils = require("./RootPathUtils");
11
11
  var _crypto = require("crypto");
12
12
  function _interopRequireDefault(e) {
13
- return e && e.__esModule
14
- ? e
15
- : {
16
- default: e,
17
- };
13
+ return e && e.__esModule ? e : { default: e };
18
14
  }
19
15
  function rootRelativeCacheKeys(buildParameters) {
20
16
  const { rootDir, plugins, ...otherParameters } = buildParameters;
@@ -0,0 +1,23 @@
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
+ * @noformat
8
+ * @generated SignedSource<<8805bc71542c6b43e940f8c5761ff187>>
9
+ *
10
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
11
+ * Original file: packages/metro-file-map/src/lib/sorting.js
12
+ * To regenerate, run:
13
+ * js1 build metro-ts-defs (internal) OR
14
+ * yarn run build-ts-defs (OSS)
15
+ */
16
+
17
+ export declare function compareStrings(
18
+ a: null | string,
19
+ b: null | string,
20
+ ): number;
21
+ export declare function chainComparators<T>(
22
+ ...comparators: Array<(a: T, b: T) => number>
23
+ ): (a: T, b: T) => number;
@@ -0,0 +1,52 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<e07a9c061b0224fc44191d956461bd6f>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/plugins/DependencyPlugin.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {
19
+ FileMapPlugin,
20
+ FileMapPluginInitOptions,
21
+ FileMapPluginWorker,
22
+ Path,
23
+ } from '../flow-types';
24
+
25
+ export type DependencyPluginOptions = Readonly<{
26
+ /** Path to custom dependency extractor module */
27
+ dependencyExtractor: null | undefined | string;
28
+ /** Whether to compute dependencies (performance optimization) */
29
+ computeDependencies: boolean;
30
+ rootDir: Path;
31
+ }>;
32
+ declare class DependencyPlugin
33
+ implements FileMapPlugin<null, ReadonlyArray<string> | null>
34
+ {
35
+ readonly name: 'dependencies';
36
+ constructor(options: DependencyPluginOptions);
37
+ initialize(
38
+ initOptions: FileMapPluginInitOptions<null, ReadonlyArray<string> | null>,
39
+ ): Promise<void>;
40
+ getSerializableSnapshot(): null;
41
+ onChanged(): void;
42
+ assertValid(): void;
43
+ getCacheKey(): string;
44
+ getWorker(): FileMapPluginWorker;
45
+ /**
46
+ * Get the list of dependencies for a given file.
47
+ * @param mixedPath Absolute or project-relative path to the file
48
+ * @returns Array of dependency module names, or null if the file doesn't exist
49
+ */
50
+ getDependencies(mixedPath: Path): null | undefined | ReadonlyArray<string>;
51
+ }
52
+ export default DependencyPlugin;
@@ -28,9 +28,7 @@ class DependencyPlugin {
28
28
  getSerializableSnapshot() {
29
29
  return null;
30
30
  }
31
- async bulkUpdate(delta) {}
32
- onNewOrModifiedFile(relativeFilePath, pluginData) {}
33
- onRemovedFile(relativeFilePath, pluginData) {}
31
+ onChanged() {}
34
32
  assertValid() {}
35
33
  getCacheKey() {
36
34
  if (this.#dependencyExtractor != null) {
@@ -10,7 +10,6 @@
10
10
  */
11
11
 
12
12
  import type {
13
- FileMapDelta,
14
13
  FileMapPlugin,
15
14
  FileMapPluginInitOptions,
16
15
  FileMapPluginWorker,
@@ -64,25 +63,11 @@ export default class DependencyPlugin
64
63
  return null;
65
64
  }
66
65
 
67
- async bulkUpdate(delta: FileMapDelta<?ReadonlyArray<string>>): Promise<void> {
66
+ onChanged(): void {
68
67
  // No-op: Worker already populated plugin data
69
68
  // Plugin data is write-only from worker
70
69
  }
71
70
 
72
- onNewOrModifiedFile(
73
- relativeFilePath: string,
74
- pluginData: ?ReadonlyArray<string>,
75
- ): void {
76
- // No-op: Dependencies already in plugin data
77
- }
78
-
79
- onRemovedFile(
80
- relativeFilePath: string,
81
- pluginData: ?ReadonlyArray<string>,
82
- ): void {
83
- // No-op
84
- }
85
-
86
71
  assertValid(): void {
87
72
  // No validation needed
88
73
  }
@@ -0,0 +1,69 @@
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
+ * @noformat
8
+ * @oncall react_native
9
+ * @generated SignedSource<<3d1462ab2325a09553e02b69b5de84eb>>
10
+ *
11
+ * This file was translated from Flow by scripts/generateTypeScriptDefinitions.js
12
+ * Original file: packages/metro-file-map/src/plugins/HastePlugin.js
13
+ * To regenerate, run:
14
+ * js1 build metro-ts-defs (internal) OR
15
+ * yarn run build-ts-defs (OSS)
16
+ */
17
+
18
+ import type {
19
+ Console,
20
+ FileMapPlugin,
21
+ FileMapPluginInitOptions,
22
+ FileMapPluginWorker,
23
+ HasteConflict,
24
+ HasteMap,
25
+ HasteMapItemMetadata,
26
+ HTypeValue,
27
+ Path,
28
+ PerfLogger,
29
+ ReadonlyFileSystemChanges,
30
+ } from '../flow-types';
31
+
32
+ export type HasteMapOptions = Readonly<{
33
+ console?: null | undefined | Console;
34
+ enableHastePackages: boolean;
35
+ hasteImplModulePath: null | undefined | string;
36
+ perfLogger?: null | undefined | PerfLogger;
37
+ platforms: ReadonlySet<string>;
38
+ rootDir: Path;
39
+ failValidationOnConflicts: boolean;
40
+ }>;
41
+ declare class HastePlugin
42
+ implements HasteMap, FileMapPlugin<null, string | null>
43
+ {
44
+ readonly name: 'haste';
45
+ constructor(options: HasteMapOptions);
46
+ initialize(
47
+ $$PARAM_0$$: FileMapPluginInitOptions<null, string | null>,
48
+ ): Promise<void>;
49
+ getSerializableSnapshot(): null;
50
+ getModule(
51
+ name: string,
52
+ platform?: null | undefined | string,
53
+ supportsNativePlatform?: null | undefined | boolean,
54
+ type?: null | undefined | HTypeValue,
55
+ ): null | undefined | Path;
56
+ getModuleNameByPath(mixedPath: Path): null | undefined | string;
57
+ getPackage(
58
+ name: string,
59
+ platform: null | undefined | string,
60
+ _supportsNativePlatform?: null | undefined | boolean,
61
+ ): null | undefined | Path;
62
+ onChanged(delta: ReadonlyFileSystemChanges<null | undefined | string>): void;
63
+ setModule(id: string, module: HasteMapItemMetadata): void;
64
+ assertValid(): void;
65
+ computeConflicts(): Array<HasteConflict>;
66
+ getCacheKey(): string;
67
+ getWorker(): FileMapPluginWorker;
68
+ }
69
+ export default HastePlugin;
@@ -14,11 +14,7 @@ var _getPlatformExtension = _interopRequireDefault(
14
14
  var _HasteConflictsError = require("./haste/HasteConflictsError");
15
15
  var _path = _interopRequireDefault(require("path"));
16
16
  function _interopRequireDefault(e) {
17
- return e && e.__esModule
18
- ? e
19
- : {
20
- default: e,
21
- };
17
+ return e && e.__esModule ? e : { default: e };
22
18
  }
23
19
  const EMPTY_OBJ = {};
24
20
  const EMPTY_MAP = new Map();
@@ -167,22 +163,22 @@ class HastePlugin {
167
163
  duplicates,
168
164
  );
169
165
  }
170
- async bulkUpdate(delta) {
171
- for (const [normalPath, maybeHasteId] of delta.removed) {
172
- this.onRemovedFile(normalPath, maybeHasteId);
166
+ onChanged(delta) {
167
+ for (const [canonicalPath, maybeHasteId] of delta.removedFiles) {
168
+ this.#onRemovedFile(canonicalPath, maybeHasteId);
173
169
  }
174
- for (const [normalPath, maybeHasteId] of delta.addedOrModified) {
175
- this.onNewOrModifiedFile(normalPath, maybeHasteId);
170
+ for (const [canonicalPath, maybeHasteId] of delta.addedFiles) {
171
+ this.#onNewFile(canonicalPath, maybeHasteId);
176
172
  }
177
173
  }
178
- onNewOrModifiedFile(relativeFilePath, id) {
174
+ #onNewFile(canonicalPath, id) {
179
175
  if (id == null) {
180
176
  return;
181
177
  }
182
178
  const module = [
183
- relativeFilePath,
179
+ canonicalPath,
184
180
  this.#enableHastePackages &&
185
- _path.default.basename(relativeFilePath) === "package.json"
181
+ _path.default.basename(canonicalPath) === "package.json"
186
182
  ? _constants.default.PACKAGE
187
183
  : _constants.default.MODULE,
188
184
  ];
@@ -252,12 +248,12 @@ class HastePlugin {
252
248
  }
253
249
  hasteMapItem[platform] = module;
254
250
  }
255
- onRemovedFile(relativeFilePath, moduleName) {
251
+ #onRemovedFile(canonicalPath, moduleName) {
256
252
  if (moduleName == null) {
257
253
  return;
258
254
  }
259
255
  const platform =
260
- (0, _getPlatformExtension.default)(relativeFilePath, this.#platforms) ||
256
+ (0, _getPlatformExtension.default)(canonicalPath, this.#platforms) ||
261
257
  _constants.default.GENERIC_PLATFORM;
262
258
  const hasteMapItem = this.#map.get(moduleName);
263
259
  if (hasteMapItem != null) {
@@ -268,7 +264,7 @@ class HastePlugin {
268
264
  this.#map.set(moduleName, hasteMapItem);
269
265
  }
270
266
  }
271
- this.#recoverDuplicates(moduleName, relativeFilePath);
267
+ this.#recoverDuplicates(moduleName, canonicalPath);
272
268
  }
273
269
  assertValid() {
274
270
  if (!this.#failValidationOnConflicts) {
@@ -13,7 +13,6 @@ import type {
13
13
  Console,
14
14
  DuplicatesIndex,
15
15
  DuplicatesSet,
16
- FileMapDelta,
17
16
  FileMapPlugin,
18
17
  FileMapPluginInitOptions,
19
18
  FileMapPluginWorker,
@@ -24,6 +23,7 @@ import type {
24
23
  HTypeValue,
25
24
  Path,
26
25
  PerfLogger,
26
+ ReadonlyFileSystemChanges,
27
27
  } from '../flow-types';
28
28
 
29
29
  import H from '../constants';
@@ -237,26 +237,26 @@ export default class HastePlugin
237
237
  );
238
238
  }
239
239
 
240
- async bulkUpdate(delta: FileMapDelta<?string>): Promise<void> {
240
+ onChanged(delta: ReadonlyFileSystemChanges<?string>): void {
241
241
  // Process removals first so that moves aren't treated as duplicates.
242
- for (const [normalPath, maybeHasteId] of delta.removed) {
243
- this.onRemovedFile(normalPath, maybeHasteId);
242
+ for (const [canonicalPath, maybeHasteId] of delta.removedFiles) {
243
+ this.#onRemovedFile(canonicalPath, maybeHasteId);
244
244
  }
245
- for (const [normalPath, maybeHasteId] of delta.addedOrModified) {
246
- this.onNewOrModifiedFile(normalPath, maybeHasteId);
245
+ for (const [canonicalPath, maybeHasteId] of delta.addedFiles) {
246
+ this.#onNewFile(canonicalPath, maybeHasteId);
247
247
  }
248
248
  }
249
249
 
250
- onNewOrModifiedFile(relativeFilePath: string, id: ?string) {
250
+ #onNewFile(canonicalPath: string, id: ?string) {
251
251
  if (id == null) {
252
252
  // Not a Haste module or package
253
253
  return;
254
254
  }
255
255
 
256
256
  const module: HasteMapItemMetadata = [
257
- relativeFilePath,
257
+ canonicalPath,
258
258
  this.#enableHastePackages &&
259
- path.basename(relativeFilePath) === 'package.json'
259
+ path.basename(canonicalPath) === 'package.json'
260
260
  ? H.PACKAGE
261
261
  : H.MODULE,
262
262
  ];
@@ -324,14 +324,14 @@ export default class HastePlugin
324
324
  hasteMapItem[platform] = module;
325
325
  }
326
326
 
327
- onRemovedFile(relativeFilePath: string, moduleName: ?string) {
327
+ #onRemovedFile(canonicalPath: string, moduleName: ?string) {
328
328
  if (moduleName == null) {
329
329
  // Not a Haste module or package
330
330
  return;
331
331
  }
332
332
 
333
333
  const platform =
334
- getPlatformExtension(relativeFilePath, this.#platforms) ||
334
+ getPlatformExtension(canonicalPath, this.#platforms) ||
335
335
  H.GENERIC_PLATFORM;
336
336
 
337
337
  const hasteMapItem = this.#map.get(moduleName);
@@ -344,7 +344,7 @@ export default class HastePlugin
344
344
  }
345
345
  }
346
346
 
347
- this.#recoverDuplicates(moduleName, relativeFilePath);
347
+ this.#recoverDuplicates(moduleName, canonicalPath);
348
348
  }
349
349
 
350
350
  assertValid(): void {