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.
- package/package.json +4 -3
- package/src/Watcher.js +59 -52
- package/src/Watcher.js.flow +39 -39
- package/src/cache/DiskCacheManager.js.flow +3 -3
- package/src/constants.js +9 -8
- package/src/constants.js.flow +6 -18
- package/src/crawlers/node/index.js +27 -25
- package/src/crawlers/node/index.js.flow +6 -8
- package/src/crawlers/watchman/index.js +26 -22
- package/src/crawlers/watchman/index.js.flow +3 -4
- package/src/crawlers/watchman/planQuery.d.ts +24 -0
- package/src/crawlers/watchman/planQuery.js.flow +4 -4
- package/src/flow-types.js.flow +125 -87
- package/src/index.js +267 -235
- package/src/index.js.flow +269 -275
- package/src/lib/FileProcessor.js +76 -54
- package/src/lib/FileProcessor.js.flow +93 -72
- package/src/lib/RootPathUtils.js +25 -21
- package/src/lib/RootPathUtils.js.flow +4 -4
- package/src/lib/TreeFS.js +72 -77
- package/src/lib/TreeFS.js.flow +104 -124
- package/src/lib/checkWatchmanCapabilities.js.flow +4 -4
- package/src/lib/dependencyExtractor.d.ts +14 -0
- package/src/lib/normalizePathSeparatorsToPosix.js +25 -21
- package/src/lib/normalizePathSeparatorsToPosix.js.flow +3 -3
- package/src/lib/normalizePathSeparatorsToSystem.js +25 -21
- package/src/lib/normalizePathSeparatorsToSystem.js.flow +3 -3
- package/src/lib/rootRelativeCacheKeys.js +0 -20
- package/src/lib/rootRelativeCacheKeys.js.flow +1 -23
- package/src/plugins/DependencyPlugin.js +75 -0
- package/src/plugins/DependencyPlugin.js.flow +144 -0
- package/src/plugins/HastePlugin.js +83 -38
- package/src/plugins/HastePlugin.js.flow +105 -51
- package/src/plugins/MockPlugin.js +7 -4
- package/src/plugins/MockPlugin.js.flow +24 -15
- package/src/plugins/dependencies/dependencyExtractor.d.ts +14 -0
- package/src/{lib → plugins/dependencies}/dependencyExtractor.js.flow +3 -6
- package/src/plugins/dependencies/worker.d.ts +24 -0
- package/src/plugins/dependencies/worker.js +24 -0
- package/src/plugins/dependencies/worker.js.flow +53 -0
- package/src/plugins/haste/HasteConflictsError.js.flow +2 -2
- package/src/plugins/haste/computeConflicts.js +2 -1
- package/src/plugins/haste/computeConflicts.js.flow +11 -12
- package/src/plugins/haste/getPlatformExtension.js.flow +2 -2
- package/src/plugins/haste/worker.d.ts +24 -0
- package/src/plugins/haste/worker.js +35 -0
- package/src/plugins/haste/worker.js.flow +64 -0
- package/src/plugins/mocks/getMockName.js +27 -23
- package/src/plugins/mocks/getMockName.js.flow +2 -4
- package/src/watchers/AbstractWatcher.js +27 -22
- package/src/watchers/AbstractWatcher.js.flow +6 -5
- package/src/watchers/FallbackWatcher.js +88 -84
- package/src/watchers/FallbackWatcher.js.flow +65 -65
- package/src/watchers/NativeWatcher.js +25 -21
- package/src/watchers/NativeWatcher.js.flow +3 -3
- package/src/watchers/RecrawlWarning.js.flow +1 -1
- package/src/watchers/WatchmanWatcher.js +61 -53
- package/src/watchers/WatchmanWatcher.js.flow +39 -38
- package/src/watchers/common.js.flow +5 -5
- package/src/worker.d.ts +36 -0
- package/src/worker.js +16 -58
- package/src/worker.js.flow +19 -69
- package/src/workerExclusionList.d.ts +12 -0
- package/src/workerExclusionList.js.flow +1 -1
- package/src/Watcher.d.ts +0 -24
- package/src/cache/DiskCacheManager.d.ts +0 -38
- package/src/flow-types.d.ts +0 -353
- package/src/index.d.ts +0 -97
- package/src/lib/DuplicateHasteCandidatesError.d.ts +0 -24
- /package/src/{lib → plugins/dependencies}/dependencyExtractor.js +0 -0
package/src/lib/TreeFS.js.flow
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @format
|
|
8
7
|
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type {
|
|
@@ -42,6 +42,37 @@ type NormalizedSymlinkTarget = {
|
|
|
42
42
|
startOfBasenameIdx: number,
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
type DeserializedSnapshotInput = {
|
|
46
|
+
rootDir: string,
|
|
47
|
+
fileSystemData: DirectoryNode,
|
|
48
|
+
processFile: ProcessFileFunction,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type TreeFSOptions = {
|
|
52
|
+
rootDir: Path,
|
|
53
|
+
files?: FileData,
|
|
54
|
+
processFile: ProcessFileFunction,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type MatchFilesOptions = Readonly<{
|
|
58
|
+
/* Filter relative paths against a pattern. */
|
|
59
|
+
filter?: ?RegExp,
|
|
60
|
+
/* `filter` is applied against absolute paths, vs rootDir-relative. (default: false) */
|
|
61
|
+
filterCompareAbsolute?: boolean,
|
|
62
|
+
/* `filter` is applied against posix-delimited paths, even on Windows. (default: false) */
|
|
63
|
+
filterComparePosix?: boolean,
|
|
64
|
+
/* Follow symlinks when enumerating paths. (default: false) */
|
|
65
|
+
follow?: boolean,
|
|
66
|
+
/* Should search for files recursively. (default: true) */
|
|
67
|
+
recursive?: boolean,
|
|
68
|
+
/* Match files under a given root, or null for all files */
|
|
69
|
+
rootDir?: ?Path,
|
|
70
|
+
}>;
|
|
71
|
+
|
|
72
|
+
type MetadataIteratorOptions = Readonly<{
|
|
73
|
+
includeSymlinks: boolean,
|
|
74
|
+
includeNodeModules: boolean,
|
|
75
|
+
}>;
|
|
45
76
|
/**
|
|
46
77
|
* OVERVIEW:
|
|
47
78
|
*
|
|
@@ -94,20 +125,13 @@ type NormalizedSymlinkTarget = {
|
|
|
94
125
|
export default class TreeFS implements MutableFileSystem {
|
|
95
126
|
+#cachedNormalSymlinkTargets: WeakMap<FileNode, NormalizedSymlinkTarget> =
|
|
96
127
|
new WeakMap();
|
|
128
|
+
+#pathUtils: RootPathUtils;
|
|
129
|
+
+#processFile: ProcessFileFunction;
|
|
97
130
|
+#rootDir: Path;
|
|
98
131
|
#rootNode: DirectoryNode = new Map();
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
constructor({
|
|
103
|
-
rootDir,
|
|
104
|
-
files,
|
|
105
|
-
processFile,
|
|
106
|
-
}: {
|
|
107
|
-
rootDir: Path,
|
|
108
|
-
files?: FileData,
|
|
109
|
-
processFile: ProcessFileFunction,
|
|
110
|
-
}) {
|
|
132
|
+
|
|
133
|
+
constructor(opts: TreeFSOptions) {
|
|
134
|
+
const {rootDir, files, processFile} = opts;
|
|
111
135
|
this.#rootDir = rootDir;
|
|
112
136
|
this.#pathUtils = new RootPathUtils(rootDir);
|
|
113
137
|
this.#processFile = processFile;
|
|
@@ -117,45 +141,21 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
117
141
|
}
|
|
118
142
|
|
|
119
143
|
getSerializableSnapshot(): CacheData['fileSystemData'] {
|
|
120
|
-
return this
|
|
144
|
+
return this.#cloneTree(this.#rootNode);
|
|
121
145
|
}
|
|
122
146
|
|
|
123
|
-
static fromDeserializedSnapshot({
|
|
124
|
-
rootDir,
|
|
125
|
-
|
|
126
|
-
processFile,
|
|
127
|
-
}: {
|
|
128
|
-
rootDir: string,
|
|
129
|
-
fileSystemData: DirectoryNode,
|
|
130
|
-
processFile: ProcessFileFunction,
|
|
131
|
-
}): TreeFS {
|
|
132
|
-
const tfs = new TreeFS({rootDir, processFile});
|
|
147
|
+
static fromDeserializedSnapshot(args: DeserializedSnapshotInput): TreeFS {
|
|
148
|
+
const {rootDir, fileSystemData, processFile} = args;
|
|
149
|
+
const tfs = new TreeFS({processFile, rootDir});
|
|
133
150
|
tfs.#rootNode = fileSystemData;
|
|
134
151
|
return tfs;
|
|
135
152
|
}
|
|
136
153
|
|
|
137
|
-
getModuleName(mixedPath: Path): ?string {
|
|
138
|
-
const fileMetadata = this._getFileData(mixedPath);
|
|
139
|
-
return (fileMetadata && fileMetadata[H.ID]) ?? null;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
154
|
getSize(mixedPath: Path): ?number {
|
|
143
|
-
const fileMetadata = this
|
|
155
|
+
const fileMetadata = this.#getFileData(mixedPath);
|
|
144
156
|
return (fileMetadata && fileMetadata[H.SIZE]) ?? null;
|
|
145
157
|
}
|
|
146
158
|
|
|
147
|
-
getDependencies(mixedPath: Path): ?Array<string> {
|
|
148
|
-
const fileMetadata = this._getFileData(mixedPath);
|
|
149
|
-
|
|
150
|
-
if (fileMetadata) {
|
|
151
|
-
return fileMetadata[H.DEPENDENCIES]
|
|
152
|
-
? fileMetadata[H.DEPENDENCIES].split(H.DEPENDENCY_DELIM)
|
|
153
|
-
: [];
|
|
154
|
-
} else {
|
|
155
|
-
return null;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
159
|
getDifference(files: FileData): {
|
|
160
160
|
changedFiles: FileData,
|
|
161
161
|
removedFiles: Set<string>,
|
|
@@ -163,8 +163,8 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
163
163
|
const changedFiles: FileData = new Map(files);
|
|
164
164
|
const removedFiles: Set<string> = new Set();
|
|
165
165
|
for (const {canonicalPath, metadata} of this.metadataIterator({
|
|
166
|
-
includeSymlinks: true,
|
|
167
166
|
includeNodeModules: true,
|
|
167
|
+
includeSymlinks: true,
|
|
168
168
|
})) {
|
|
169
169
|
const newMetadata = files.get(canonicalPath);
|
|
170
170
|
if (newMetadata) {
|
|
@@ -201,15 +201,15 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
getSha1(mixedPath: Path): ?string {
|
|
204
|
-
const fileMetadata = this
|
|
204
|
+
const fileMetadata = this.#getFileData(mixedPath);
|
|
205
205
|
return (fileMetadata && fileMetadata[H.SHA1]) ?? null;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
async getOrComputeSha1(
|
|
209
209
|
mixedPath: Path,
|
|
210
210
|
): Promise<?{sha1: string, content?: Buffer}> {
|
|
211
|
-
const normalPath = this
|
|
212
|
-
const result = this
|
|
211
|
+
const normalPath = this.#normalizePath(mixedPath);
|
|
212
|
+
const result = this.#lookupByNormalPath(normalPath, {
|
|
213
213
|
followLeaf: true,
|
|
214
214
|
});
|
|
215
215
|
if (!result.exists || isDirectory(result.node)) {
|
|
@@ -222,39 +222,38 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
222
222
|
if (existing != null && existing.length > 0) {
|
|
223
223
|
return {sha1: existing};
|
|
224
224
|
}
|
|
225
|
-
const absolutePath = this.#pathUtils.normalToAbsolute(canonicalPath);
|
|
226
225
|
|
|
227
226
|
// Mutate the metadata we first retrieved. This may be orphaned or about
|
|
228
227
|
// to be overwritten if the file changes while we are processing it -
|
|
229
228
|
// by only mutating the original metadata, we don't risk caching a stale
|
|
230
229
|
// SHA-1 after a change event.
|
|
231
|
-
const maybeContent = await this.#processFile(
|
|
230
|
+
const maybeContent = await this.#processFile(canonicalPath, fileMetadata, {
|
|
232
231
|
computeSha1: true,
|
|
233
232
|
});
|
|
234
233
|
const sha1 = fileMetadata[H.SHA1];
|
|
235
234
|
invariant(
|
|
236
235
|
sha1 != null && sha1.length > 0,
|
|
237
236
|
"File processing didn't populate a SHA-1 hash for %s",
|
|
238
|
-
|
|
237
|
+
canonicalPath,
|
|
239
238
|
);
|
|
240
239
|
|
|
241
240
|
return maybeContent
|
|
242
241
|
? {
|
|
243
|
-
sha1,
|
|
244
242
|
content: maybeContent,
|
|
243
|
+
sha1,
|
|
245
244
|
}
|
|
246
245
|
: {sha1};
|
|
247
246
|
}
|
|
248
247
|
|
|
249
248
|
exists(mixedPath: Path): boolean {
|
|
250
|
-
const result = this
|
|
249
|
+
const result = this.#getFileData(mixedPath);
|
|
251
250
|
return result != null;
|
|
252
251
|
}
|
|
253
252
|
|
|
254
253
|
lookup(mixedPath: Path): LookupResult {
|
|
255
|
-
const normalPath = this
|
|
254
|
+
const normalPath = this.#normalizePath(mixedPath);
|
|
256
255
|
const links = new Set<string>();
|
|
257
|
-
const result = this
|
|
256
|
+
const result = this.#lookupByNormalPath(normalPath, {
|
|
258
257
|
collectLinkPaths: links,
|
|
259
258
|
followLeaf: true,
|
|
260
259
|
});
|
|
@@ -267,33 +266,31 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
267
266
|
};
|
|
268
267
|
}
|
|
269
268
|
const {canonicalPath, node} = result;
|
|
270
|
-
const
|
|
269
|
+
const realPath = this.#pathUtils.normalToAbsolute(canonicalPath);
|
|
270
|
+
if (isDirectory(node)) {
|
|
271
|
+
return {exists: true, links, realPath, type: 'd'};
|
|
272
|
+
}
|
|
271
273
|
invariant(
|
|
272
|
-
|
|
274
|
+
isRegularFile(node),
|
|
273
275
|
'lookup follows symlinks, so should never return one (%s -> %s)',
|
|
274
276
|
mixedPath,
|
|
275
277
|
canonicalPath,
|
|
276
278
|
);
|
|
277
|
-
return {
|
|
278
|
-
exists: true,
|
|
279
|
-
links,
|
|
280
|
-
realPath: this.#pathUtils.normalToAbsolute(canonicalPath),
|
|
281
|
-
type,
|
|
282
|
-
};
|
|
279
|
+
return {exists: true, links, realPath, type: 'f', metadata: node};
|
|
283
280
|
}
|
|
284
281
|
|
|
285
282
|
getAllFiles(): Array<Path> {
|
|
286
283
|
return Array.from(
|
|
287
284
|
this.metadataIterator({
|
|
288
|
-
includeSymlinks: false,
|
|
289
285
|
includeNodeModules: true,
|
|
286
|
+
includeSymlinks: false,
|
|
290
287
|
}),
|
|
291
288
|
({canonicalPath}) => this.#pathUtils.normalToAbsolute(canonicalPath),
|
|
292
289
|
);
|
|
293
290
|
}
|
|
294
291
|
|
|
295
292
|
linkStats(mixedPath: Path): ?FileStats {
|
|
296
|
-
const fileMetadata = this
|
|
293
|
+
const fileMetadata = this.#getFileData(mixedPath, {followLeaf: false});
|
|
297
294
|
if (fileMetadata == null) {
|
|
298
295
|
return null;
|
|
299
296
|
}
|
|
@@ -310,29 +307,17 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
310
307
|
* The query matches against normalized paths which start with `./`,
|
|
311
308
|
* for example: `a/b.js` -> `./a/b.js`
|
|
312
309
|
*/
|
|
313
|
-
*matchFiles({
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
filterCompareAbsolute?: boolean,
|
|
325
|
-
/* `filter` is applied against posix-delimited paths, even on Windows. (default: false) */
|
|
326
|
-
filterComparePosix?: boolean,
|
|
327
|
-
/* Follow symlinks when enumerating paths. (default: false) */
|
|
328
|
-
follow?: boolean,
|
|
329
|
-
/* Should search for files recursively. (default: true) */
|
|
330
|
-
recursive?: boolean,
|
|
331
|
-
/* Match files under a given root, or null for all files */
|
|
332
|
-
rootDir?: ?Path,
|
|
333
|
-
}>): Iterable<Path> {
|
|
334
|
-
const normalRoot = rootDir == null ? '' : this._normalizePath(rootDir);
|
|
335
|
-
const contextRootResult = this._lookupByNormalPath(normalRoot);
|
|
310
|
+
*matchFiles(opts: MatchFilesOptions): Iterable<Path> {
|
|
311
|
+
const {
|
|
312
|
+
filter = null,
|
|
313
|
+
filterCompareAbsolute = false,
|
|
314
|
+
filterComparePosix = false,
|
|
315
|
+
follow = false,
|
|
316
|
+
recursive = true,
|
|
317
|
+
rootDir = null,
|
|
318
|
+
} = opts;
|
|
319
|
+
const normalRoot = rootDir == null ? '' : this.#normalizePath(rootDir);
|
|
320
|
+
const contextRootResult = this.#lookupByNormalPath(normalRoot);
|
|
336
321
|
if (!contextRootResult.exists) {
|
|
337
322
|
return;
|
|
338
323
|
}
|
|
@@ -357,7 +342,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
357
342
|
? contextRootAbsolutePath.replaceAll(path.sep, '/')
|
|
358
343
|
: contextRootAbsolutePath;
|
|
359
344
|
|
|
360
|
-
for (const relativePathForComparison of this
|
|
345
|
+
for (const relativePathForComparison of this.#pathIterator(
|
|
361
346
|
contextRoot,
|
|
362
347
|
contextRootParent,
|
|
363
348
|
ancestorOfRootIdx,
|
|
@@ -394,10 +379,10 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
394
379
|
}
|
|
395
380
|
|
|
396
381
|
addOrModify(mixedPath: Path, metadata: FileMetadata): void {
|
|
397
|
-
const normalPath = this
|
|
382
|
+
const normalPath = this.#normalizePath(mixedPath);
|
|
398
383
|
// Walk the tree to find the *real* path of the parent node, creating
|
|
399
384
|
// directories as we need.
|
|
400
|
-
const parentDirNode = this
|
|
385
|
+
const parentDirNode = this.#lookupByNormalPath(path.dirname(normalPath), {
|
|
401
386
|
makeDirectories: true,
|
|
402
387
|
});
|
|
403
388
|
if (!parentDirNode.exists) {
|
|
@@ -406,7 +391,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
406
391
|
);
|
|
407
392
|
}
|
|
408
393
|
// Normalize the resulting path to account for the parent node being root.
|
|
409
|
-
const canonicalPath = this
|
|
394
|
+
const canonicalPath = this.#normalizePath(
|
|
410
395
|
parentDirNode.canonicalPath + path.sep + path.basename(normalPath),
|
|
411
396
|
);
|
|
412
397
|
this.bulkAddOrModify(new Map([[canonicalPath, metadata]]));
|
|
@@ -427,7 +412,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
427
412
|
lastSepIdx === -1 ? normalPath : normalPath.slice(lastSepIdx + 1);
|
|
428
413
|
|
|
429
414
|
if (directoryNode == null || dirname !== lastDir) {
|
|
430
|
-
const lookup = this
|
|
415
|
+
const lookup = this.#lookupByNormalPath(dirname, {
|
|
431
416
|
followLeaf: false,
|
|
432
417
|
makeDirectories: true,
|
|
433
418
|
});
|
|
@@ -453,8 +438,8 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
453
438
|
}
|
|
454
439
|
|
|
455
440
|
remove(mixedPath: Path): ?FileMetadata {
|
|
456
|
-
const normalPath = this
|
|
457
|
-
const result = this
|
|
441
|
+
const normalPath = this.#normalizePath(mixedPath);
|
|
442
|
+
const result = this.#lookupByNormalPath(normalPath, {followLeaf: false});
|
|
458
443
|
if (!result.exists) {
|
|
459
444
|
return null;
|
|
460
445
|
}
|
|
@@ -494,7 +479,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
494
479
|
* Note that this code is extremely hot during resolution, being the most
|
|
495
480
|
* expensive part of a file existence check. Benchmark any modifications!
|
|
496
481
|
*/
|
|
497
|
-
|
|
482
|
+
#lookupByNormalPath(
|
|
498
483
|
requestedNormalPath: string,
|
|
499
484
|
opts: {
|
|
500
485
|
collectAncestors?: Array<{
|
|
@@ -654,7 +639,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
654
639
|
}
|
|
655
640
|
|
|
656
641
|
// Symlink in a directory path
|
|
657
|
-
const normalSymlinkTarget = this
|
|
642
|
+
const normalSymlinkTarget = this.#resolveSymlinkTargetToNormalPath(
|
|
658
643
|
segmentNode,
|
|
659
644
|
currentPath,
|
|
660
645
|
);
|
|
@@ -801,9 +786,9 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
801
786
|
normalPath: string,
|
|
802
787
|
segmentName: string,
|
|
803
788
|
}> = [];
|
|
804
|
-
const normalPath = this
|
|
789
|
+
const normalPath = this.#normalizePath(mixedStartPath);
|
|
805
790
|
const invalidatedBy = opts.invalidatedBy;
|
|
806
|
-
const closestLookup = this
|
|
791
|
+
const closestLookup = this.#lookupByNormalPath(normalPath, {
|
|
807
792
|
collectAncestors: ancestorsOfInput,
|
|
808
793
|
collectLinkPaths: invalidatedBy,
|
|
809
794
|
});
|
|
@@ -976,7 +961,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
976
961
|
pathIdx: number,
|
|
977
962
|
},
|
|
978
963
|
): ?string {
|
|
979
|
-
const lookupResult = this
|
|
964
|
+
const lookupResult = this.#lookupByNormalPath(
|
|
980
965
|
this.#pathUtils.joinNormalToRelative(normalCandidatePath, subpath)
|
|
981
966
|
.normalPath,
|
|
982
967
|
{
|
|
@@ -1001,22 +986,17 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1001
986
|
return null;
|
|
1002
987
|
}
|
|
1003
988
|
|
|
1004
|
-
*metadataIterator(
|
|
1005
|
-
opts: $ReadOnly<{
|
|
1006
|
-
includeSymlinks: boolean,
|
|
1007
|
-
includeNodeModules: boolean,
|
|
1008
|
-
}>,
|
|
1009
|
-
): Iterable<{
|
|
989
|
+
*metadataIterator(opts: MetadataIteratorOptions): Iterator<{
|
|
1010
990
|
baseName: string,
|
|
1011
991
|
canonicalPath: string,
|
|
1012
992
|
metadata: FileMetadata,
|
|
1013
993
|
}> {
|
|
1014
|
-
yield* this
|
|
994
|
+
yield* this.#metadataIterator(this.#rootNode, opts);
|
|
1015
995
|
}
|
|
1016
996
|
|
|
1017
|
-
|
|
997
|
+
*#metadataIterator(
|
|
1018
998
|
rootNode: DirectoryNode,
|
|
1019
|
-
opts:
|
|
999
|
+
opts: Readonly<{includeSymlinks: boolean, includeNodeModules: boolean}>,
|
|
1020
1000
|
prefix: string = '',
|
|
1021
1001
|
): Iterable<{
|
|
1022
1002
|
baseName: string,
|
|
@@ -1033,14 +1013,14 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1033
1013
|
}
|
|
1034
1014
|
const prefixedName = prefix === '' ? name : prefix + path.sep + name;
|
|
1035
1015
|
if (isDirectory(node)) {
|
|
1036
|
-
yield* this
|
|
1016
|
+
yield* this.#metadataIterator(node, opts, prefixedName);
|
|
1037
1017
|
} else if (isRegularFile(node) || opts.includeSymlinks) {
|
|
1038
|
-
yield {canonicalPath: prefixedName, metadata: node
|
|
1018
|
+
yield {baseName: name, canonicalPath: prefixedName, metadata: node};
|
|
1039
1019
|
}
|
|
1040
1020
|
}
|
|
1041
1021
|
}
|
|
1042
1022
|
|
|
1043
|
-
|
|
1023
|
+
#normalizePath(relativeOrAbsolutePath: Path): string {
|
|
1044
1024
|
return path.isAbsolute(relativeOrAbsolutePath)
|
|
1045
1025
|
? this.#pathUtils.absoluteToNormal(relativeOrAbsolutePath)
|
|
1046
1026
|
: this.#pathUtils.relativeToNormal(relativeOrAbsolutePath);
|
|
@@ -1052,10 +1032,10 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1052
1032
|
ancestorOfRootIdx: ?number,
|
|
1053
1033
|
): Iterator<[string, MixedNode]> {
|
|
1054
1034
|
if (ancestorOfRootIdx != null && ancestorOfRootIdx > 0 && parent) {
|
|
1055
|
-
yield
|
|
1035
|
+
yield [
|
|
1056
1036
|
this.#pathUtils.getBasenameOfNthAncestor(ancestorOfRootIdx - 1),
|
|
1057
1037
|
parent,
|
|
1058
|
-
]
|
|
1038
|
+
] as [string, MixedNode];
|
|
1059
1039
|
}
|
|
1060
1040
|
yield* node.entries();
|
|
1061
1041
|
}
|
|
@@ -1064,11 +1044,11 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1064
1044
|
* Enumerate paths under a given node, including symlinks and through
|
|
1065
1045
|
* symlinks (if `follow` is enabled).
|
|
1066
1046
|
*/
|
|
1067
|
-
|
|
1047
|
+
*#pathIterator(
|
|
1068
1048
|
iterationRootNode: DirectoryNode,
|
|
1069
1049
|
iterationRootParentNode: ?DirectoryNode,
|
|
1070
1050
|
ancestorOfRootIdx: ?number,
|
|
1071
|
-
opts:
|
|
1051
|
+
opts: Readonly<{
|
|
1072
1052
|
alwaysYieldPosix: boolean,
|
|
1073
1053
|
canonicalPathOfRoot: string,
|
|
1074
1054
|
follow: boolean,
|
|
@@ -1076,7 +1056,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1076
1056
|
subtreeOnly: boolean,
|
|
1077
1057
|
}>,
|
|
1078
1058
|
pathPrefix: string = '',
|
|
1079
|
-
followedLinks:
|
|
1059
|
+
followedLinks: ReadonlySet<FileMetadata> = new Set(),
|
|
1080
1060
|
): Iterable<Path> {
|
|
1081
1061
|
const pathSep = opts.alwaysYieldPosix ? '/' : path.sep;
|
|
1082
1062
|
const prefixWithSep = pathPrefix === '' ? pathPrefix : pathPrefix + pathSep;
|
|
@@ -1114,7 +1094,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1114
1094
|
// are at /foo/bar/baz where baz -> '..' - that should resolve to
|
|
1115
1095
|
// /foo, not /foo/bar). We *can* use _lookupByNormalPath to walk to
|
|
1116
1096
|
// the canonical symlink, and then to its target.
|
|
1117
|
-
const resolved = this
|
|
1097
|
+
const resolved = this.#lookupByNormalPath(normalPathOfSymlink, {
|
|
1118
1098
|
followLeaf: true,
|
|
1119
1099
|
});
|
|
1120
1100
|
if (!resolved.exists) {
|
|
@@ -1132,7 +1112,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1132
1112
|
) {
|
|
1133
1113
|
// Symlink points to a directory - iterate over its contents using
|
|
1134
1114
|
// the path where we found the symlink as a prefix.
|
|
1135
|
-
yield* this
|
|
1115
|
+
yield* this.#pathIterator(
|
|
1136
1116
|
target,
|
|
1137
1117
|
resolved.parentNode,
|
|
1138
1118
|
resolved.ancestorOfRootIdx,
|
|
@@ -1143,7 +1123,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1143
1123
|
}
|
|
1144
1124
|
}
|
|
1145
1125
|
} else if (opts.recursive) {
|
|
1146
|
-
yield* this
|
|
1126
|
+
yield* this.#pathIterator(
|
|
1147
1127
|
node,
|
|
1148
1128
|
iterationRootParentNode,
|
|
1149
1129
|
ancestorOfRootIdx != null && ancestorOfRootIdx > 0
|
|
@@ -1157,7 +1137,7 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1157
1137
|
}
|
|
1158
1138
|
}
|
|
1159
1139
|
|
|
1160
|
-
|
|
1140
|
+
#resolveSymlinkTargetToNormalPath(
|
|
1161
1141
|
symlinkNode: FileMetadata,
|
|
1162
1142
|
canonicalPathOfSymlink: Path,
|
|
1163
1143
|
): NormalizedSymlinkTarget {
|
|
@@ -1191,12 +1171,12 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1191
1171
|
return result;
|
|
1192
1172
|
}
|
|
1193
1173
|
|
|
1194
|
-
|
|
1174
|
+
#getFileData(
|
|
1195
1175
|
filePath: Path,
|
|
1196
1176
|
opts: {followLeaf: boolean} = {followLeaf: true},
|
|
1197
1177
|
): ?FileMetadata {
|
|
1198
|
-
const normalPath = this
|
|
1199
|
-
const result = this
|
|
1178
|
+
const normalPath = this.#normalizePath(filePath);
|
|
1179
|
+
const result = this.#lookupByNormalPath(normalPath, {
|
|
1200
1180
|
followLeaf: opts.followLeaf,
|
|
1201
1181
|
});
|
|
1202
1182
|
if (!result.exists || isDirectory(result.node)) {
|
|
@@ -1205,11 +1185,11 @@ export default class TreeFS implements MutableFileSystem {
|
|
|
1205
1185
|
return result.node;
|
|
1206
1186
|
}
|
|
1207
1187
|
|
|
1208
|
-
|
|
1188
|
+
#cloneTree(root: DirectoryNode): DirectoryNode {
|
|
1209
1189
|
const clone: DirectoryNode = new Map();
|
|
1210
1190
|
for (const [name, node] of root) {
|
|
1211
1191
|
if (isDirectory(node)) {
|
|
1212
|
-
clone.set(name, this
|
|
1192
|
+
clone.set(name, this.#cloneTree(node));
|
|
1213
1193
|
} else {
|
|
1214
1194
|
clone.set(name, [...node]);
|
|
1215
1195
|
}
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @format
|
|
8
7
|
* @flow strict
|
|
8
|
+
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import {execFile} from 'child_process';
|
|
12
12
|
import {promisify} from 'util';
|
|
13
13
|
|
|
14
14
|
export default async function checkWatchmanCapabilities(
|
|
15
|
-
requiredCapabilities:
|
|
15
|
+
requiredCapabilities: ReadonlyArray<string>,
|
|
16
16
|
): Promise<{version: string}> {
|
|
17
17
|
const execFilePromise: (
|
|
18
18
|
cmd: string,
|
|
19
|
-
args:
|
|
19
|
+
args: ReadonlyArray<string>,
|
|
20
20
|
) => Promise<{stdout: string}> = promisify(execFile);
|
|
21
21
|
|
|
22
22
|
let rawResponse;
|
|
@@ -37,7 +37,7 @@ export default async function checkWatchmanCapabilities(
|
|
|
37
37
|
|
|
38
38
|
let parsedResponse;
|
|
39
39
|
try {
|
|
40
|
-
parsedResponse =
|
|
40
|
+
parsedResponse = JSON.parse(rawResponse) as unknown;
|
|
41
41
|
} catch {
|
|
42
42
|
throw new Error(
|
|
43
43
|
'Failed to parse response from `watchman list-capabilities`',
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
* @format
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
declare const dependencyExtractor: {
|
|
11
|
+
extract: (code: string) => Set<string>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export = dependencyExtractor;
|
|
@@ -5,28 +5,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var path = _interopRequireWildcard(require("path"));
|
|
8
|
-
function
|
|
9
|
-
if ("function"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
var n = { __proto__: null },
|
|
23
|
-
a = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
24
|
-
for (var u in e)
|
|
25
|
-
if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
|
|
26
|
-
var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
|
|
27
|
-
i && (i.get || i.set) ? Object.defineProperty(n, u, i) : (n[u] = e[u]);
|
|
8
|
+
function _interopRequireWildcard(e, t) {
|
|
9
|
+
if ("function" == typeof WeakMap)
|
|
10
|
+
var r = new WeakMap(),
|
|
11
|
+
n = new WeakMap();
|
|
12
|
+
return (_interopRequireWildcard = function (e, t) {
|
|
13
|
+
if (!t && e && e.__esModule) return e;
|
|
14
|
+
var o,
|
|
15
|
+
i,
|
|
16
|
+
f = { __proto__: null, default: e };
|
|
17
|
+
if (null === e || ("object" != typeof e && "function" != typeof e))
|
|
18
|
+
return f;
|
|
19
|
+
if ((o = t ? n : r)) {
|
|
20
|
+
if (o.has(e)) return o.get(e);
|
|
21
|
+
o.set(e, f);
|
|
28
22
|
}
|
|
29
|
-
|
|
23
|
+
for (const t in e)
|
|
24
|
+
"default" !== t &&
|
|
25
|
+
{}.hasOwnProperty.call(e, t) &&
|
|
26
|
+
((i =
|
|
27
|
+
(o = Object.defineProperty) &&
|
|
28
|
+
Object.getOwnPropertyDescriptor(e, t)) &&
|
|
29
|
+
(i.get || i.set)
|
|
30
|
+
? o(f, t, i)
|
|
31
|
+
: (f[t] = e[t]));
|
|
32
|
+
return f;
|
|
33
|
+
})(e, t);
|
|
30
34
|
}
|
|
31
35
|
let normalizePathSeparatorsToPosix;
|
|
32
36
|
if (path.sep === "/") {
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @format
|
|
8
7
|
* @flow strict
|
|
8
|
+
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import * as path from 'path';
|
|
12
12
|
|
|
13
|
-
let normalizePathSeparatorsToPosix
|
|
13
|
+
let normalizePathSeparatorsToPosix;
|
|
14
14
|
if (path.sep === '/') {
|
|
15
15
|
normalizePathSeparatorsToPosix = (filePath: string): string => filePath;
|
|
16
16
|
} else {
|
|
@@ -18,4 +18,4 @@ if (path.sep === '/') {
|
|
|
18
18
|
filePath.replace(/\\/g, '/');
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export default normalizePathSeparatorsToPosix;
|
|
21
|
+
export default normalizePathSeparatorsToPosix as (filePath: string) => string;
|