@@ -30,28 +30,77 @@ export async function findGitRoot(path: string): Promise<string | undefined> {
30
30
}
31
31
}
32
32
33
+ export async function isDirectory ( path : string ) : Promise < boolean > {
34
+ try {
35
+ return ( await stat ( path ) ) . isDirectory ( ) ;
36
+ } catch {
37
+ return false ;
38
+ }
39
+ }
40
+
41
+ async function resolveFilesOrDirectories (
42
+ input : string [ ] ,
43
+ cwd : string ,
44
+ ) : Promise < { filesSet : Set < string > ; directoriesSet : Set < string > } > {
45
+ const files = new Set < string > ( ) ;
46
+ const directories = new Set < string > ( ) ;
47
+
48
+ const checks = input . map ( async ( item ) => {
49
+ const fullPath = resolve ( cwd , item ) ;
50
+ try {
51
+ const statResult = await stat ( fullPath ) ;
52
+ if ( statResult . isDirectory ( ) ) {
53
+ directories . add ( fullPath ) ;
54
+ } else {
55
+ files . add ( fullPath ) ;
56
+ }
57
+ } catch {
58
+ files . add ( fullPath ) ;
59
+ }
60
+ } ) ;
61
+
62
+ await Promise . all ( checks ) ;
63
+
64
+ return { filesSet : files , directoriesSet : directories } ;
65
+ }
66
+
33
67
export async function findSourceFiles (
34
- path : string ,
68
+ cwd : string ,
69
+ paths : string [ ] ,
35
70
extensions : string [ ] ,
36
- skipFiles : string [ ] ,
71
+ skipFiles : ReadonlySet < string > | null ,
37
72
gitRoot : string | undefined ,
38
73
) : Promise < Array < string > > {
39
- path = resolve ( path ) ;
40
-
41
- let files = await glob (
42
- extensions . map ( ( ext ) => `**/*${ ext } ` ) ,
43
- {
44
- dot : true ,
45
- cwd : path ,
46
- nodir : true ,
47
- absolute : true ,
48
- ignore : [ '**/node_modules/**' , '**/.git/**' ] ,
49
- } ,
50
- ) ;
51
-
52
- if ( skipFiles . length > 0 ) {
53
- const skipFilesSet = new Set ( skipFiles ) ;
54
- files = files . filter ( ( file ) => ! skipFilesSet . has ( file ) ) ;
74
+ const { filesSet, directoriesSet } = await resolveFilesOrDirectories ( paths , cwd ) ;
75
+
76
+ for ( let path of directoriesSet ) {
77
+ path = resolve ( path ) ;
78
+ for ( const file of await glob (
79
+ extensions . map ( ( ext ) => `**/*${ ext } ` ) ,
80
+ {
81
+ dot : true ,
82
+ cwd : path ,
83
+ nodir : true ,
84
+ absolute : true ,
85
+ ignore : [
86
+ '**/node_modules/**' ,
87
+ '**/.git/**' ,
88
+ '**/.hg/**' ,
89
+ '**/.svn/**' ,
90
+
91
+ // ignore .d.ts files as we cannot properly parse and process them
92
+ '**/*.d.ts' ,
93
+ ] ,
94
+ } ,
95
+ ) ) {
96
+ filesSet . add ( file ) ;
97
+ }
98
+ }
99
+
100
+ let files = Array . from ( filesSet ) ;
101
+
102
+ if ( skipFiles && skipFiles . size > 0 ) {
103
+ files = files . filter ( ( file ) => ! skipFiles . has ( file ) ) ;
55
104
}
56
105
57
106
interface DirGitignore {
0 commit comments