44 * This source code is licensed under the MIT license found in the
55 * LICENSE file in the root directory of this source tree.
66 *
7- * @format
87 * @flow strict-local
8+ * @format
99 */
1010
1111import type {
@@ -42,6 +42,37 @@ type NormalizedSymlinkTarget = {
4242 startOfBasenameIdx : number ,
4343} ;
4444
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+ } > ;
4576/**
4677 * OVERVIEW:
4778 *
@@ -99,15 +130,8 @@ export default class TreeFS implements MutableFileSystem {
99130 + #rootDir: Path ;
100131 #rootNode: DirectoryNode = new Map ( ) ;
101132
102- constructor ( {
103- rootDir,
104- files,
105- processFile,
106- } : {
107- rootDir : Path ,
108- files ?: FileData ,
109- processFile : ProcessFileFunction ,
110- } ) {
133+ constructor ( opts : TreeFSOptions ) {
134+ const { rootDir, files, processFile} = opts ;
111135 this . #rootDir = rootDir ;
112136 this . #pathUtils = new RootPathUtils ( rootDir ) ;
113137 this . #processFile = processFile ;
@@ -120,15 +144,8 @@ export default class TreeFS implements MutableFileSystem {
120144 return this . #cloneTree( this . #rootNode) ;
121145 }
122146
123- static fromDeserializedSnapshot ( {
124- rootDir,
125- fileSystemData,
126- processFile,
127- } : {
128- rootDir : string ,
129- fileSystemData : DirectoryNode ,
130- processFile : ProcessFileFunction ,
131- } ) : TreeFS {
147+ static fromDeserializedSnapshot ( args : DeserializedSnapshotInput ) : TreeFS {
148+ const { rootDir, fileSystemData, processFile} = args ;
132149 const tfs = new TreeFS ( { processFile, rootDir} ) ;
133150 tfs . #rootNode = fileSystemData ;
134151 return tfs ;
@@ -302,27 +319,15 @@ export default class TreeFS implements MutableFileSystem {
302319 * The query matches against normalized paths which start with `./`,
303320 * for example: `a/b.js` -> `./a/b.js`
304321 */
305- * matchFiles ( {
306- filter = null ,
307- filterCompareAbsolute = false ,
308- filterComparePosix = false ,
309- follow = false ,
310- recursive = true ,
311- rootDir = null ,
312- } : Readonly < {
313- /* Filter relative paths against a pattern. */
314- filter ?: ?RegExp ,
315- /* `filter` is applied against absolute paths, vs rootDir-relative. (default: false) */
316- filterCompareAbsolute ?: boolean ,
317- /* `filter` is applied against posix-delimited paths, even on Windows. (default: false) */
318- filterComparePosix ?: boolean ,
319- /* Follow symlinks when enumerating paths. (default: false) */
320- follow ?: boolean ,
321- /* Should search for files recursively. (default: true) */
322- recursive ?: boolean ,
323- /* Match files under a given root, or null for all files */
324- rootDir ?: ?Path ,
325- } > ) : Iterable < Path > {
322+ * matchFiles ( opts : MatchFilesOptions ) : Iterable < Path > {
323+ const {
324+ filter = null ,
325+ filterCompareAbsolute = false ,
326+ filterComparePosix = false ,
327+ follow = false ,
328+ recursive = true ,
329+ rootDir = null ,
330+ } = opts ;
326331 const normalRoot = rootDir == null ? '' : this . #normalizePath( rootDir ) ;
327332 const contextRootResult = this . #lookupByNormalPath( normalRoot ) ;
328333 if ( ! contextRootResult . exists ) {
@@ -993,12 +998,7 @@ export default class TreeFS implements MutableFileSystem {
993998 return null ;
994999 }
9951000
996- * metadataIterator (
997- opts : Readonly < {
998- includeSymlinks : boolean ,
999- includeNodeModules : boolean ,
1000- } > ,
1001- ) : Iterator < {
1001+ * metadataIterator ( opts : MetadataIteratorOptions ) : Iterator < {
10021002 baseName : string ,
10031003 canonicalPath : string ,
10041004 metadata : FileMetadata ,
0 commit comments