@@ -28,7 +28,7 @@ async function isBinaryFile(filePath: string, chunkSize: number = 8192): Promise
28
28
return isBinary ;
29
29
}
30
30
31
- async function processFile ( filePath : string , config : ProcessingConfig ) : Promise < void > {
31
+ async function processFile ( filePath : string ) : Promise < void > {
32
32
try {
33
33
if ( await isBinaryFile ( filePath ) ) {
34
34
console . error ( `Warning: Skipping binary file ${ filePath } ` ) ;
@@ -81,7 +81,12 @@ async function processPath(
81
81
pathToProcess : string ,
82
82
config : ProcessingConfig
83
83
) : Promise < void > {
84
- if ( fs . statSync ( pathToProcess ) . isDirectory ( ) ) {
84
+ if ( fs . statSync ( pathToProcess ) . isFile ( ) ) {
85
+ // Process a single file
86
+ if ( ! shouldIgnore ( pathToProcess , config ) ) {
87
+ await processFile ( pathToProcess ) ;
88
+ }
89
+ } else if ( fs . statSync ( pathToProcess ) . isDirectory ( ) ) {
85
90
let newConfig : ProcessingConfig = config ; // intentional reference copy
86
91
if ( config . gitignoreRules . length === 0 ) {
87
92
// only check for another .gitingore for this hierarchy part if not already found one
@@ -94,18 +99,18 @@ async function processPath(
94
99
}
95
100
96
101
const files = fs . readdirSync ( pathToProcess , { withFileTypes : true } )
97
- . filter ( ( dirent : any ) => config . includeHidden || ! dirent . name . startsWith ( '.' ) )
98
- . filter ( ( dirent : any ) => dirent . isFile ( ) )
99
- . map ( ( dirent : any ) => path . join ( pathToProcess , dirent . name ) ) ;
102
+ . filter ( ( directoryEntry : fs . Dirent ) => config . includeHidden || ! directoryEntry . name . startsWith ( '.' ) )
103
+ . filter ( ( directoryEntry : fs . Dirent ) => directoryEntry . isFile ( ) )
104
+ . map ( ( directoryEntry : fs . Dirent ) => path . join ( pathToProcess , directoryEntry . name ) ) ;
100
105
101
106
const directories = fs . readdirSync ( pathToProcess , { withFileTypes : true } )
102
- . filter ( ( dirent : any ) => config . includeHidden || ! dirent . name . startsWith ( '.' ) )
103
- . filter ( ( dirent : any ) => dirent . isDirectory ( ) )
104
- . map ( ( dirent : any ) => path . join ( pathToProcess , dirent . name ) ) ;
107
+ . filter ( ( directoryEntry : fs . Dirent ) => config . includeHidden || ! directoryEntry . name . startsWith ( '.' ) )
108
+ . filter ( ( directoryEntry : fs . Dirent ) => directoryEntry . isDirectory ( ) )
109
+ . map ( ( directoryEntry : fs . Dirent ) => path . join ( pathToProcess , directoryEntry . name ) ) ;
105
110
106
111
for ( const file of files ) {
107
112
if ( ! shouldIgnore ( file , newConfig ) ) {
108
- await processFile ( file , newConfig ) ;
113
+ await processFile ( file ) ;
109
114
}
110
115
}
111
116
@@ -115,10 +120,8 @@ async function processPath(
115
120
}
116
121
}
117
122
} else {
118
- // Process a single file
119
- if ( ! shouldIgnore ( pathToProcess , config ) ) {
120
- await processFile ( pathToProcess , config ) ;
121
- }
123
+ // Skip everything else, e.g. FIFOs, sockets, symlinks
124
+ console . error ( `Skipping ${ pathToProcess } : unsupported file type` ) ;
122
125
}
123
126
}
124
127
@@ -130,7 +133,7 @@ program
130
133
. argument ( '<paths...>' , 'One or more paths to files or directories to process' )
131
134
. option ( '--include-hidden' , 'Include files and folders starting with .' , false )
132
135
. option ( '--ignore-gitignore' , 'Ignore .gitignore files and include all files' , false )
133
- . option ( '-i, --ignore <pattern>' , 'Specify one or more patterns to ignore' , ( value : any , previous : any ) => [ ...previous , value ] , [ ] )
136
+ . option ( '-i, --ignore <pattern>' , 'Specify one or more patterns to ignore' , ( value : string , previous : any [ ] ) => [ ...previous , value ] , [ ] )
134
137
. action ( ( paths , options ) => {
135
138
const config : ProcessingConfig = {
136
139
includeHidden : options . includeHidden ,
0 commit comments