@@ -109,49 +109,55 @@ const getIsIgnoredPredicate = (files, cwd) => {
109109 } ;
110110} ;
111111
112- const normalizeOptions = ( options = { } ) => ( {
113- cwd : toPath ( options . cwd ) ?? process . cwd ( ) ,
114- suppressErrors : Boolean ( options . suppressErrors ) ,
115- deep : typeof options . deep === 'number' ? options . deep : Number . POSITIVE_INFINITY ,
116- ignore : [ ...options . ignore ?? [ ] , ...defaultIgnoredDirectories ] ,
117- } ) ;
112+ const normalizeOptions = ( options = { } ) => {
113+ const ignoreOption = options . ignore
114+ ? ( Array . isArray ( options . ignore ) ? options . ignore : [ options . ignore ] )
115+ : [ ] ;
116+
117+ const cwd = toPath ( options . cwd ) ?? process . cwd ( ) ;
118+
119+ // Only pass through specific fast-glob options that make sense for finding ignore files
120+ return {
121+ cwd,
122+ suppressErrors : options . suppressErrors ?? false ,
123+ deep : typeof options . deep === 'number' ? options . deep : Number . POSITIVE_INFINITY ,
124+ ignore : [ ...ignoreOption , ...defaultIgnoredDirectories ] ,
125+ followSymbolicLinks : options . followSymbolicLinks ?? true ,
126+ concurrency : options . concurrency ,
127+ throwErrorOnBrokenSymbolicLink : options . throwErrorOnBrokenSymbolicLink ?? false ,
128+ } ;
129+ } ;
118130
119131export const isIgnoredByIgnoreFiles = async ( patterns , options ) => {
120- const { cwd , suppressErrors , deep , ignore } = normalizeOptions ( options ) ;
132+ const normalizedOptions = normalizeOptions ( options ) ;
121133
122134 const paths = await fastGlob ( patterns , {
123- cwd,
124- suppressErrors,
125- deep,
126- ignore,
127- ...ignoreFilesGlobOptions ,
135+ ...normalizedOptions ,
136+ ...ignoreFilesGlobOptions , // Must be last to ensure absolute and dot are always set
128137 } ) ;
129138
130139 const files = await Promise . all ( paths . map ( async filePath => ( {
131140 filePath,
132141 content : await fsPromises . readFile ( filePath , 'utf8' ) ,
133142 } ) ) ) ;
134143
135- return getIsIgnoredPredicate ( files , cwd ) ;
144+ return getIsIgnoredPredicate ( files , normalizedOptions . cwd ) ;
136145} ;
137146
138147export const isIgnoredByIgnoreFilesSync = ( patterns , options ) => {
139- const { cwd , suppressErrors , deep , ignore } = normalizeOptions ( options ) ;
148+ const normalizedOptions = normalizeOptions ( options ) ;
140149
141150 const paths = fastGlob . sync ( patterns , {
142- cwd,
143- suppressErrors,
144- deep,
145- ignore,
146- ...ignoreFilesGlobOptions ,
151+ ...normalizedOptions ,
152+ ...ignoreFilesGlobOptions , // Must be last to ensure absolute and dot are always set
147153 } ) ;
148154
149155 const files = paths . map ( filePath => ( {
150156 filePath,
151157 content : fs . readFileSync ( filePath , 'utf8' ) ,
152158 } ) ) ;
153159
154- return getIsIgnoredPredicate ( files , cwd ) ;
160+ return getIsIgnoredPredicate ( files , normalizedOptions . cwd ) ;
155161} ;
156162
157163const getPatternsFromIgnoreFiles = ( files , cwd ) => files . flatMap ( file => parseIgnoreFile ( file , cwd ) ) ;
@@ -163,14 +169,11 @@ This avoids reading the same files twice (once for patterns, once for filtering)
163169@returns {Promise<{patterns: string[], predicate: Function}> }
164170*/
165171export const getIgnorePatternsAndPredicate = async ( patterns , options ) => {
166- const { cwd , suppressErrors , deep , ignore } = normalizeOptions ( options ) ;
172+ const normalizedOptions = normalizeOptions ( options ) ;
167173
168174 const paths = await fastGlob ( patterns , {
169- cwd,
170- suppressErrors,
171- deep,
172- ignore,
173- ...ignoreFilesGlobOptions ,
175+ ...normalizedOptions ,
176+ ...ignoreFilesGlobOptions , // Must be last to ensure absolute and dot are always set
174177 } ) ;
175178
176179 const files = await Promise . all ( paths . map ( async filePath => ( {
@@ -179,8 +182,8 @@ export const getIgnorePatternsAndPredicate = async (patterns, options) => {
179182 } ) ) ) ;
180183
181184 return {
182- patterns : getPatternsFromIgnoreFiles ( files , cwd ) ,
183- predicate : getIsIgnoredPredicate ( files , cwd ) ,
185+ patterns : getPatternsFromIgnoreFiles ( files , normalizedOptions . cwd ) ,
186+ predicate : getIsIgnoredPredicate ( files , normalizedOptions . cwd ) ,
184187 } ;
185188} ;
186189
@@ -190,14 +193,11 @@ Read ignore files and return both patterns and predicate (sync version).
190193@returns {{patterns: string[], predicate: Function} }
191194*/
192195export const getIgnorePatternsAndPredicateSync = ( patterns , options ) => {
193- const { cwd , suppressErrors , deep , ignore } = normalizeOptions ( options ) ;
196+ const normalizedOptions = normalizeOptions ( options ) ;
194197
195198 const paths = fastGlob . sync ( patterns , {
196- cwd,
197- suppressErrors,
198- deep,
199- ignore,
200- ...ignoreFilesGlobOptions ,
199+ ...normalizedOptions ,
200+ ...ignoreFilesGlobOptions , // Must be last to ensure absolute and dot are always set
201201 } ) ;
202202
203203 const files = paths . map ( filePath => ( {
@@ -206,8 +206,8 @@ export const getIgnorePatternsAndPredicateSync = (patterns, options) => {
206206 } ) ) ;
207207
208208 return {
209- patterns : getPatternsFromIgnoreFiles ( files , cwd ) ,
210- predicate : getIsIgnoredPredicate ( files , cwd ) ,
209+ patterns : getPatternsFromIgnoreFiles ( files , normalizedOptions . cwd ) ,
210+ predicate : getIsIgnoredPredicate ( files , normalizedOptions . cwd ) ,
211211 } ;
212212} ;
213213
0 commit comments