@@ -62,9 +62,6 @@ pub struct GlobEntry {
62
62
63
63
#[ derive( Debug , Clone , Default ) ]
64
64
pub struct Scanner {
65
- /// Auto content configuration
66
- detect_sources : Option < DetectSources > ,
67
-
68
65
/// Glob sources
69
66
sources : Option < Vec < GlobEntry > > ,
70
67
@@ -86,9 +83,8 @@ pub struct Scanner {
86
83
}
87
84
88
85
impl Scanner {
89
- pub fn new ( detect_sources : Option < DetectSources > , sources : Option < Vec < GlobEntry > > ) -> Self {
86
+ pub fn new ( sources : Option < Vec < GlobEntry > > ) -> Self {
90
87
Self {
91
- detect_sources,
92
88
sources,
93
89
..Default :: default ( )
94
90
}
@@ -206,51 +202,11 @@ impl Scanner {
206
202
return ;
207
203
}
208
204
209
- self . detect_sources ( ) ;
210
205
self . scan_sources ( ) ;
211
206
212
207
self . ready = true ;
213
208
}
214
209
215
- #[ tracing:: instrument( skip_all) ]
216
- fn detect_sources ( & mut self ) {
217
- if let Some ( detect_sources) = & self . detect_sources {
218
- let ( files, globs) = detect_sources. detect ( ) ;
219
- self . files . extend ( files) ;
220
- self . globs . extend ( globs) ;
221
- }
222
-
223
- // Find all `@source` globs that point to a directory. If so, promote the source to auto
224
- // source detection instead.
225
- if let Some ( sources) = & mut self . sources {
226
- for source in sources {
227
- // If a glob ends with `**/*`, then we just want to register the base path as a new
228
- // base.
229
- if source. pattern . ends_with ( "**/*" ) {
230
- source. pattern = source. pattern . trim_end_matches ( "**/*" ) . to_owned ( ) ;
231
- }
232
-
233
- let path = PathBuf :: from ( & source. base ) . join ( & source. pattern ) ;
234
- let Some ( folder_name) = path. file_name ( ) else {
235
- continue ;
236
- } ;
237
-
238
- // Contains a file extension, e.g.: `foo.html`, therefore we don't want to
239
- // detect sources here.
240
- if folder_name. to_str ( ) . unwrap ( ) . contains ( "." ) {
241
- continue ;
242
- }
243
-
244
- // Promote to auto source detection
245
- let detect_sources = DetectSources :: new ( path. clone ( ) ) ;
246
-
247
- let ( files, globs) = detect_sources. detect ( ) ;
248
- self . files . extend ( files) ;
249
- self . globs . extend ( globs) ;
250
- }
251
- }
252
- }
253
-
254
210
#[ tracing:: instrument( skip_all) ]
255
211
fn scan_sources ( & mut self ) {
256
212
let Some ( sources) = & self . sources else {
@@ -261,7 +217,38 @@ impl Scanner {
261
217
return ;
262
218
}
263
219
264
- let resolved_files: Vec < _ > = match fast_glob ( sources) {
220
+ // Partition sources into sources that should be promoted to auto source detection and
221
+ // sources that should be resolved as globs.
222
+ let ( auto_sources, glob_sources) : ( Vec < _ > , Vec < _ > ) = sources. iter ( ) . partition ( |source| {
223
+ // If a glob ends with `/**/*`, then we just want to register the base path as a new
224
+ // base. Essentially converting it to use auto source detection.
225
+ if source. pattern . ends_with ( "**/*" ) {
226
+ return true ;
227
+ }
228
+
229
+ // Directories should be promoted to auto source detection
230
+ if PathBuf :: from ( & source. base ) . join ( & source. pattern ) . is_dir ( ) {
231
+ return true ;
232
+ }
233
+
234
+ false
235
+ } ) ;
236
+
237
+ // Turn `Vec<&GlobEntry>` in `Vec<GlobEntry>`
238
+ let glob_sources: Vec < _ > = glob_sources. into_iter ( ) . cloned ( ) . collect ( ) ;
239
+
240
+ for path in auto_sources
241
+ . iter ( )
242
+ . map ( |source| PathBuf :: from ( & source. base ) . join ( source. pattern . trim_end_matches ( "**/*" ) ) )
243
+ {
244
+ let detect_sources = DetectSources :: new ( path) ;
245
+
246
+ let ( files, globs) = detect_sources. detect ( ) ;
247
+ self . files . extend ( files) ;
248
+ self . globs . extend ( globs) ;
249
+ }
250
+
251
+ let resolved_files: Vec < _ > = match fast_glob ( & glob_sources) {
265
252
Ok ( matches) => matches
266
253
. filter_map ( |x| dunce:: canonicalize ( & x) . ok ( ) )
267
254
. collect ( ) ,
@@ -272,7 +259,7 @@ impl Scanner {
272
259
} ;
273
260
274
261
self . files . extend ( resolved_files) ;
275
- self . globs . extend ( sources . clone ( ) ) ;
262
+ self . globs . extend ( glob_sources ) ;
276
263
277
264
// Re-optimize the globs to reduce the number of patterns we have to scan.
278
265
self . globs = get_fast_patterns ( & self . globs )
0 commit comments