@@ -62,9 +62,6 @@ pub struct GlobEntry {
6262
6363#[ derive( Debug , Clone , Default ) ]
6464pub struct Scanner {
65- /// Auto content configuration
66- detect_sources : Option < DetectSources > ,
67-
6865 /// Glob sources
6966 sources : Option < Vec < GlobEntry > > ,
7067
@@ -86,9 +83,8 @@ pub struct Scanner {
8683}
8784
8885impl Scanner {
89- pub fn new ( detect_sources : Option < DetectSources > , sources : Option < Vec < GlobEntry > > ) -> Self {
86+ pub fn new ( sources : Option < Vec < GlobEntry > > ) -> Self {
9087 Self {
91- detect_sources,
9288 sources,
9389 ..Default :: default ( )
9490 }
@@ -206,51 +202,11 @@ impl Scanner {
206202 return ;
207203 }
208204
209- self . detect_sources ( ) ;
210205 self . scan_sources ( ) ;
211206
212207 self . ready = true ;
213208 }
214209
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-
254210 #[ tracing:: instrument( skip_all) ]
255211 fn scan_sources ( & mut self ) {
256212 let Some ( sources) = & self . sources else {
@@ -261,7 +217,38 @@ impl Scanner {
261217 return ;
262218 }
263219
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) {
265252 Ok ( matches) => matches
266253 . filter_map ( |x| dunce:: canonicalize ( & x) . ok ( ) )
267254 . collect ( ) ,
@@ -272,7 +259,7 @@ impl Scanner {
272259 } ;
273260
274261 self . files . extend ( resolved_files) ;
275- self . globs . extend ( sources . clone ( ) ) ;
262+ self . globs . extend ( glob_sources ) ;
276263
277264 // Re-optimize the globs to reduce the number of patterns we have to scan.
278265 self . globs = get_fast_patterns ( & self . globs )
0 commit comments