metro-file-map 0.83.3 → 0.84.0

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 +4 -3
  2. package/src/Watcher.js +59 -52
  3. package/src/Watcher.js.flow +39 -39
  4. package/src/cache/DiskCacheManager.js.flow +3 -3
  5. package/src/constants.js +9 -8
  6. package/src/constants.js.flow +6 -18
  7. package/src/crawlers/node/index.js +27 -25
  8. package/src/crawlers/node/index.js.flow +6 -8
  9. package/src/crawlers/watchman/index.js +26 -22
  10. package/src/crawlers/watchman/index.js.flow +3 -4
  11. package/src/crawlers/watchman/planQuery.d.ts +24 -0
  12. package/src/crawlers/watchman/planQuery.js.flow +4 -4
  13. package/src/flow-types.js.flow +125 -87
  14. package/src/index.js +267 -235
  15. package/src/index.js.flow +269 -275
  16. package/src/lib/FileProcessor.js +76 -54
  17. package/src/lib/FileProcessor.js.flow +93 -72
  18. package/src/lib/RootPathUtils.js +25 -21
  19. package/src/lib/RootPathUtils.js.flow +4 -4
  20. package/src/lib/TreeFS.js +72 -77
  21. package/src/lib/TreeFS.js.flow +104 -124
  22. package/src/lib/checkWatchmanCapabilities.js.flow +4 -4
  23. package/src/lib/dependencyExtractor.d.ts +14 -0
  24. package/src/lib/normalizePathSeparatorsToPosix.js +25 -21
  25. package/src/lib/normalizePathSeparatorsToPosix.js.flow +3 -3
  26. package/src/lib/normalizePathSeparatorsToSystem.js +25 -21
  27. package/src/lib/normalizePathSeparatorsToSystem.js.flow +3 -3
  28. package/src/lib/rootRelativeCacheKeys.js +0 -20
  29. package/src/lib/rootRelativeCacheKeys.js.flow +1 -23
  30. package/src/plugins/DependencyPlugin.js +75 -0
  31. package/src/plugins/DependencyPlugin.js.flow +144 -0
  32. package/src/plugins/HastePlugin.js +83 -38
  33. package/src/plugins/HastePlugin.js.flow +105 -51
  34. package/src/plugins/MockPlugin.js +7 -4
  35. package/src/plugins/MockPlugin.js.flow +24 -15
  36. package/src/plugins/dependencies/dependencyExtractor.d.ts +14 -0
  37. package/src/{lib → plugins/dependencies}/dependencyExtractor.js.flow +3 -6
  38. package/src/plugins/dependencies/worker.d.ts +24 -0
  39. package/src/plugins/dependencies/worker.js +24 -0
  40. package/src/plugins/dependencies/worker.js.flow +53 -0
  41. package/src/plugins/haste/HasteConflictsError.js.flow +2 -2
  42. package/src/plugins/haste/computeConflicts.js +2 -1
  43. package/src/plugins/haste/computeConflicts.js.flow +11 -12
  44. package/src/plugins/haste/getPlatformExtension.js.flow +2 -2
  45. package/src/plugins/haste/worker.d.ts +24 -0
  46. package/src/plugins/haste/worker.js +35 -0
  47. package/src/plugins/haste/worker.js.flow +64 -0
  48. package/src/plugins/mocks/getMockName.js +27 -23
  49. package/src/plugins/mocks/getMockName.js.flow +2 -4
  50. package/src/watchers/AbstractWatcher.js +27 -22
  51. package/src/watchers/AbstractWatcher.js.flow +6 -5
  52. package/src/watchers/FallbackWatcher.js +88 -84
  53. package/src/watchers/FallbackWatcher.js.flow +65 -65
  54. package/src/watchers/NativeWatcher.js +25 -21
  55. package/src/watchers/NativeWatcher.js.flow +3 -3
  56. package/src/watchers/RecrawlWarning.js.flow +1 -1
  57. package/src/watchers/WatchmanWatcher.js +61 -53
  58. package/src/watchers/WatchmanWatcher.js.flow +39 -38
  59. package/src/watchers/common.js.flow +5 -5
  60. package/src/worker.d.ts +36 -0
  61. package/src/worker.js +16 -58
  62. package/src/worker.js.flow +19 -69
  63. package/src/workerExclusionList.d.ts +12 -0
  64. package/src/workerExclusionList.js.flow +1 -1
  65. package/src/Watcher.d.ts +0 -24
  66. package/src/cache/DiskCacheManager.d.ts +0 -38
  67. package/src/flow-types.d.ts +0 -353
  68. package/src/index.d.ts +0 -97
  69. package/src/lib/DuplicateHasteCandidatesError.d.ts +0 -24
  70. /package/src/{lib → plugins/dependencies}/dependencyExtractor.js +0 -0
package/src/lib/TreeFS.js CHANGED
@@ -19,11 +19,12 @@ function isRegularFile(node) {
19
19
  }
20
20
  class TreeFS {
21
21
  #cachedNormalSymlinkTargets = new WeakMap();
22
- #rootDir;
23
- #rootNode = new Map();
24
22
  #pathUtils;
25
23
  #processFile;
26
- constructor({ rootDir, files, processFile }) {
24
+ #rootDir;
25
+ #rootNode = new Map();
26
+ constructor(opts) {
27
+ const { rootDir, files, processFile } = opts;
27
28
  this.#rootDir = rootDir;
28
29
  this.#pathUtils = new _RootPathUtils.RootPathUtils(rootDir);
29
30
  this.#processFile = processFile;
@@ -32,42 +33,27 @@ class TreeFS {
32
33
  }
33
34
  }
34
35
  getSerializableSnapshot() {
35
- return this._cloneTree(this.#rootNode);
36
+ return this.#cloneTree(this.#rootNode);
36
37
  }
37
- static fromDeserializedSnapshot({ rootDir, fileSystemData, processFile }) {
38
+ static fromDeserializedSnapshot(args) {
39
+ const { rootDir, fileSystemData, processFile } = args;
38
40
  const tfs = new TreeFS({
39
- rootDir,
40
41
  processFile,
42
+ rootDir,
41
43
  });
42
44
  tfs.#rootNode = fileSystemData;
43
45
  return tfs;
44
46
  }
45
- getModuleName(mixedPath) {
46
- const fileMetadata = this._getFileData(mixedPath);
47
- return (fileMetadata && fileMetadata[_constants.default.ID]) ?? null;
48
- }
49
47
  getSize(mixedPath) {
50
- const fileMetadata = this._getFileData(mixedPath);
48
+ const fileMetadata = this.#getFileData(mixedPath);
51
49
  return (fileMetadata && fileMetadata[_constants.default.SIZE]) ?? null;
52
50
  }
53
- getDependencies(mixedPath) {
54
- const fileMetadata = this._getFileData(mixedPath);
55
- if (fileMetadata) {
56
- return fileMetadata[_constants.default.DEPENDENCIES]
57
- ? fileMetadata[_constants.default.DEPENDENCIES].split(
58
- _constants.default.DEPENDENCY_DELIM,
59
- )
60
- : [];
61
- } else {
62
- return null;
63
- }
64
- }
65
51
  getDifference(files) {
66
52
  const changedFiles = new Map(files);
67
53
  const removedFiles = new Set();
68
54
  for (const { canonicalPath, metadata } of this.metadataIterator({
69
- includeSymlinks: true,
70
55
  includeNodeModules: true,
56
+ includeSymlinks: true,
71
57
  })) {
72
58
  const newMetadata = files.get(canonicalPath);
73
59
  if (newMetadata) {
@@ -102,12 +88,12 @@ class TreeFS {
102
88
  };
103
89
  }
104
90
  getSha1(mixedPath) {
105
- const fileMetadata = this._getFileData(mixedPath);
91
+ const fileMetadata = this.#getFileData(mixedPath);
106
92
  return (fileMetadata && fileMetadata[_constants.default.SHA1]) ?? null;
107
93
  }
108
94
  async getOrComputeSha1(mixedPath) {
109
- const normalPath = this._normalizePath(mixedPath);
110
- const result = this._lookupByNormalPath(normalPath, {
95
+ const normalPath = this.#normalizePath(mixedPath);
96
+ const result = this.#lookupByNormalPath(normalPath, {
111
97
  followLeaf: true,
112
98
  });
113
99
  if (!result.exists || isDirectory(result.node)) {
@@ -120,33 +106,32 @@ class TreeFS {
120
106
  sha1: existing,
121
107
  };
122
108
  }
123
- const absolutePath = this.#pathUtils.normalToAbsolute(canonicalPath);
124
- const maybeContent = await this.#processFile(absolutePath, fileMetadata, {
109
+ const maybeContent = await this.#processFile(canonicalPath, fileMetadata, {
125
110
  computeSha1: true,
126
111
  });
127
112
  const sha1 = fileMetadata[_constants.default.SHA1];
128
113
  (0, _invariant.default)(
129
114
  sha1 != null && sha1.length > 0,
130
115
  "File processing didn't populate a SHA-1 hash for %s",
131
- absolutePath,
116
+ canonicalPath,
132
117
  );
133
118
  return maybeContent
134
119
  ? {
135
- sha1,
136
120
  content: maybeContent,
121
+ sha1,
137
122
  }
138
123
  : {
139
124
  sha1,
140
125
  };
141
126
  }
142
127
  exists(mixedPath) {
143
- const result = this._getFileData(mixedPath);
128
+ const result = this.#getFileData(mixedPath);
144
129
  return result != null;
145
130
  }
146
131
  lookup(mixedPath) {
147
- const normalPath = this._normalizePath(mixedPath);
132
+ const normalPath = this.#normalizePath(mixedPath);
148
133
  const links = new Set();
149
- const result = this._lookupByNormalPath(normalPath, {
134
+ const result = this.#lookupByNormalPath(normalPath, {
150
135
  collectLinkPaths: links,
151
136
  followLeaf: true,
152
137
  });
@@ -159,9 +144,17 @@ class TreeFS {
159
144
  };
160
145
  }
161
146
  const { canonicalPath, node } = result;
162
- const type = isDirectory(node) ? "d" : isRegularFile(node) ? "f" : "l";
147
+ const realPath = this.#pathUtils.normalToAbsolute(canonicalPath);
148
+ if (isDirectory(node)) {
149
+ return {
150
+ exists: true,
151
+ links,
152
+ realPath,
153
+ type: "d",
154
+ };
155
+ }
163
156
  (0, _invariant.default)(
164
- type !== "l",
157
+ isRegularFile(node),
165
158
  "lookup follows symlinks, so should never return one (%s -> %s)",
166
159
  mixedPath,
167
160
  canonicalPath,
@@ -169,21 +162,22 @@ class TreeFS {
169
162
  return {
170
163
  exists: true,
171
164
  links,
172
- realPath: this.#pathUtils.normalToAbsolute(canonicalPath),
173
- type,
165
+ realPath,
166
+ type: "f",
167
+ metadata: node,
174
168
  };
175
169
  }
176
170
  getAllFiles() {
177
171
  return Array.from(
178
172
  this.metadataIterator({
179
- includeSymlinks: false,
180
173
  includeNodeModules: true,
174
+ includeSymlinks: false,
181
175
  }),
182
176
  ({ canonicalPath }) => this.#pathUtils.normalToAbsolute(canonicalPath),
183
177
  );
184
178
  }
185
179
  linkStats(mixedPath) {
186
- const fileMetadata = this._getFileData(mixedPath, {
180
+ const fileMetadata = this.#getFileData(mixedPath, {
187
181
  followLeaf: false,
188
182
  });
189
183
  if (fileMetadata == null) {
@@ -196,16 +190,17 @@ class TreeFS {
196
190
  size: fileMetadata[_constants.default.SIZE],
197
191
  };
198
192
  }
199
- *matchFiles({
200
- filter = null,
201
- filterCompareAbsolute = false,
202
- filterComparePosix = false,
203
- follow = false,
204
- recursive = true,
205
- rootDir = null,
206
- }) {
207
- const normalRoot = rootDir == null ? "" : this._normalizePath(rootDir);
208
- const contextRootResult = this._lookupByNormalPath(normalRoot);
193
+ *matchFiles(opts) {
194
+ const {
195
+ filter = null,
196
+ filterCompareAbsolute = false,
197
+ filterComparePosix = false,
198
+ follow = false,
199
+ recursive = true,
200
+ rootDir = null,
201
+ } = opts;
202
+ const normalRoot = rootDir == null ? "" : this.#normalizePath(rootDir);
203
+ const contextRootResult = this.#lookupByNormalPath(normalRoot);
209
204
  if (!contextRootResult.exists) {
210
205
  return;
211
206
  }
@@ -227,7 +222,7 @@ class TreeFS {
227
222
  filterComparePosix && _path.default.sep !== "/"
228
223
  ? contextRootAbsolutePath.replaceAll(_path.default.sep, "/")
229
224
  : contextRootAbsolutePath;
230
- for (const relativePathForComparison of this._pathIterator(
225
+ for (const relativePathForComparison of this.#pathIterator(
231
226
  contextRoot,
232
227
  contextRootParent,
233
228
  ancestorOfRootIdx,
@@ -259,8 +254,8 @@ class TreeFS {
259
254
  }
260
255
  }
261
256
  addOrModify(mixedPath, metadata) {
262
- const normalPath = this._normalizePath(mixedPath);
263
- const parentDirNode = this._lookupByNormalPath(
257
+ const normalPath = this.#normalizePath(mixedPath);
258
+ const parentDirNode = this.#lookupByNormalPath(
264
259
  _path.default.dirname(normalPath),
265
260
  {
266
261
  makeDirectories: true,
@@ -271,7 +266,7 @@ class TreeFS {
271
266
  `TreeFS: Failed to make parent directory entry for ${mixedPath}`,
272
267
  );
273
268
  }
274
- const canonicalPath = this._normalizePath(
269
+ const canonicalPath = this.#normalizePath(
275
270
  parentDirNode.canonicalPath +
276
271
  _path.default.sep +
277
272
  _path.default.basename(normalPath),
@@ -287,7 +282,7 @@ class TreeFS {
287
282
  const basename =
288
283
  lastSepIdx === -1 ? normalPath : normalPath.slice(lastSepIdx + 1);
289
284
  if (directoryNode == null || dirname !== lastDir) {
290
- const lookup = this._lookupByNormalPath(dirname, {
285
+ const lookup = this.#lookupByNormalPath(dirname, {
291
286
  followLeaf: false,
292
287
  makeDirectories: true,
293
288
  });
@@ -310,8 +305,8 @@ class TreeFS {
310
305
  }
311
306
  }
312
307
  remove(mixedPath) {
313
- const normalPath = this._normalizePath(mixedPath);
314
- const result = this._lookupByNormalPath(normalPath, {
308
+ const normalPath = this.#normalizePath(mixedPath);
309
+ const result = this.#lookupByNormalPath(normalPath, {
315
310
  followLeaf: false,
316
311
  });
317
312
  if (!result.exists) {
@@ -331,7 +326,7 @@ class TreeFS {
331
326
  }
332
327
  return isDirectory(node) ? null : node;
333
328
  }
334
- _lookupByNormalPath(
329
+ #lookupByNormalPath(
335
330
  requestedNormalPath,
336
331
  opts = {
337
332
  followLeaf: true,
@@ -419,7 +414,7 @@ class TreeFS {
419
414
  missingSegmentName: segmentName,
420
415
  };
421
416
  }
422
- const normalSymlinkTarget = this._resolveSymlinkTargetToNormalPath(
417
+ const normalSymlinkTarget = this.#resolveSymlinkTargetToNormalPath(
423
418
  segmentNode,
424
419
  currentPath,
425
420
  );
@@ -501,9 +496,9 @@ class TreeFS {
501
496
  }
502
497
  hierarchicalLookup(mixedStartPath, subpath, opts) {
503
498
  const ancestorsOfInput = [];
504
- const normalPath = this._normalizePath(mixedStartPath);
499
+ const normalPath = this.#normalizePath(mixedStartPath);
505
500
  const invalidatedBy = opts.invalidatedBy;
506
- const closestLookup = this._lookupByNormalPath(normalPath, {
501
+ const closestLookup = this.#lookupByNormalPath(normalPath, {
507
502
  collectAncestors: ancestorsOfInput,
508
503
  collectLinkPaths: invalidatedBy,
509
504
  });
@@ -644,7 +639,7 @@ class TreeFS {
644
639
  invalidatedBy,
645
640
  start,
646
641
  ) {
647
- const lookupResult = this._lookupByNormalPath(
642
+ const lookupResult = this.#lookupByNormalPath(
648
643
  this.#pathUtils.joinNormalToRelative(normalCandidatePath, subpath)
649
644
  .normalPath,
650
645
  {
@@ -668,9 +663,9 @@ class TreeFS {
668
663
  return null;
669
664
  }
670
665
  *metadataIterator(opts) {
671
- yield* this._metadataIterator(this.#rootNode, opts);
666
+ yield* this.#metadataIterator(this.#rootNode, opts);
672
667
  }
673
- *_metadataIterator(rootNode, opts, prefix = "") {
668
+ *#metadataIterator(rootNode, opts, prefix = "") {
674
669
  for (const [name, node] of rootNode) {
675
670
  if (
676
671
  !opts.includeNodeModules &&
@@ -682,17 +677,17 @@ class TreeFS {
682
677
  const prefixedName =
683
678
  prefix === "" ? name : prefix + _path.default.sep + name;
684
679
  if (isDirectory(node)) {
685
- yield* this._metadataIterator(node, opts, prefixedName);
680
+ yield* this.#metadataIterator(node, opts, prefixedName);
686
681
  } else if (isRegularFile(node) || opts.includeSymlinks) {
687
682
  yield {
683
+ baseName: name,
688
684
  canonicalPath: prefixedName,
689
685
  metadata: node,
690
- baseName: name,
691
686
  };
692
687
  }
693
688
  }
694
689
  }
695
- _normalizePath(relativeOrAbsolutePath) {
690
+ #normalizePath(relativeOrAbsolutePath) {
696
691
  return _path.default.isAbsolute(relativeOrAbsolutePath)
697
692
  ? this.#pathUtils.absoluteToNormal(relativeOrAbsolutePath)
698
693
  : this.#pathUtils.relativeToNormal(relativeOrAbsolutePath);
@@ -706,7 +701,7 @@ class TreeFS {
706
701
  }
707
702
  yield* node.entries();
708
703
  }
709
- *_pathIterator(
704
+ *#pathIterator(
710
705
  iterationRootNode,
711
706
  iterationRootParentNode,
712
707
  ancestorOfRootIdx,
@@ -737,7 +732,7 @@ class TreeFS {
737
732
  opts.canonicalPathOfRoot,
738
733
  nodePathWithSystemSeparators,
739
734
  );
740
- const resolved = this._lookupByNormalPath(normalPathOfSymlink, {
735
+ const resolved = this.#lookupByNormalPath(normalPathOfSymlink, {
741
736
  followLeaf: true,
742
737
  });
743
738
  if (!resolved.exists) {
@@ -751,7 +746,7 @@ class TreeFS {
751
746
  opts.follow &&
752
747
  !followedLinks.has(node)
753
748
  ) {
754
- yield* this._pathIterator(
749
+ yield* this.#pathIterator(
755
750
  target,
756
751
  resolved.parentNode,
757
752
  resolved.ancestorOfRootIdx,
@@ -762,7 +757,7 @@ class TreeFS {
762
757
  }
763
758
  }
764
759
  } else if (opts.recursive) {
765
- yield* this._pathIterator(
760
+ yield* this.#pathIterator(
766
761
  node,
767
762
  iterationRootParentNode,
768
763
  ancestorOfRootIdx != null && ancestorOfRootIdx > 0
@@ -775,7 +770,7 @@ class TreeFS {
775
770
  }
776
771
  }
777
772
  }
778
- _resolveSymlinkTargetToNormalPath(symlinkNode, canonicalPathOfSymlink) {
773
+ #resolveSymlinkTargetToNormalPath(symlinkNode, canonicalPathOfSymlink) {
779
774
  const cachedResult = this.#cachedNormalSymlinkTargets.get(symlinkNode);
780
775
  if (cachedResult != null) {
781
776
  return cachedResult;
@@ -805,14 +800,14 @@ class TreeFS {
805
800
  this.#cachedNormalSymlinkTargets.set(symlinkNode, result);
806
801
  return result;
807
802
  }
808
- _getFileData(
803
+ #getFileData(
809
804
  filePath,
810
805
  opts = {
811
806
  followLeaf: true,
812
807
  },
813
808
  ) {
814
- const normalPath = this._normalizePath(filePath);
815
- const result = this._lookupByNormalPath(normalPath, {
809
+ const normalPath = this.#normalizePath(filePath);
810
+ const result = this.#lookupByNormalPath(normalPath, {
816
811
  followLeaf: opts.followLeaf,
817
812
  });
818
813
  if (!result.exists || isDirectory(result.node)) {
@@ -820,11 +815,11 @@ class TreeFS {
820
815
  }
821
816
  return result.node;
822
817
  }
823
- _cloneTree(root) {
818
+ #cloneTree(root) {
824
819
  const clone = new Map();
825
820
  for (const [name, node] of root) {
826
821
  if (isDirectory(node)) {
827
- clone.set(name, this._cloneTree(node));
822
+ clone.set(name, this.#cloneTree(node));
828
823
  } else {
829
824
  clone.set(name, [...node]);
830
825
  }