@@ -6,18 +6,19 @@ use std::{
66 cmp:: Ordering ,
77 env:: current_dir,
88 ffi:: OsStr ,
9- fs:: FileType ,
109 path:: { Path , PathBuf } ,
1110} ;
1211
1312use ignore:: WalkBuilder ;
1413use once_cell:: sync:: Lazy ;
1514
16- use tauri_utils:: config:: parse:: ConfigFormat ;
15+ use tauri_utils:: config:: parse:: {
16+ folder_has_configuration_file, is_configuration_file, ConfigFormat ,
17+ } ;
1718
1819const TAURI_GITIGNORE : & [ u8 ] = include_bytes ! ( "../../tauri.gitignore" ) ;
1920
20- fn lookup < F : Fn ( & PathBuf , FileType ) -> bool > ( dir : & Path , checker : F ) -> Option < PathBuf > {
21+ fn lookup < F : Fn ( & PathBuf ) -> bool > ( dir : & Path , checker : F ) -> Option < PathBuf > {
2122 let mut default_gitignore = std:: env:: temp_dir ( ) ;
2223 default_gitignore. push ( ".gitignore" ) ;
2324 if !default_gitignore. exists ( ) {
@@ -51,7 +52,7 @@ fn lookup<F: Fn(&PathBuf, FileType) -> bool>(dir: &Path, checker: F) -> Option<P
5152
5253 for entry in builder. build ( ) . flatten ( ) {
5354 let path = dir. join ( entry. path ( ) ) ;
54- if checker ( & path, entry . file_type ( ) . unwrap ( ) ) {
55+ if checker ( & path) {
5556 return Some ( path) ;
5657 }
5758 }
@@ -67,13 +68,7 @@ fn get_tauri_dir() -> PathBuf {
6768 return cwd. join ( "src-tauri/" ) ;
6869 }
6970
70- lookup ( & cwd, |path, file_type| if file_type. is_dir ( ) {
71- path. join ( ConfigFormat :: Json . into_file_name ( ) ) . exists ( ) || path. join ( ConfigFormat :: Json5 . into_file_name ( ) ) . exists ( ) || path. join ( ConfigFormat :: Toml . into_file_name ( ) ) . exists ( )
72- } else if let Some ( file_name) = path. file_name ( ) {
73- file_name == OsStr :: new ( ConfigFormat :: Json . into_file_name ( ) ) || file_name == OsStr :: new ( ConfigFormat :: Json5 . into_file_name ( ) ) || file_name == OsStr :: new ( ConfigFormat :: Toml . into_file_name ( ) )
74- } else {
75- false
76- } )
71+ lookup ( & cwd, |path| folder_has_configuration_file ( path) || is_configuration_file ( path) )
7772 . map ( |p| if p. is_dir ( ) { p } else { p. parent ( ) . unwrap ( ) . to_path_buf ( ) } )
7873 . unwrap_or_else ( ||
7974 panic ! ( "Couldn't recognize the current folder as a Tauri project. It must contain a `{}`, `{}` or `{}` file in any subfolder." ,
@@ -85,7 +80,7 @@ fn get_tauri_dir() -> PathBuf {
8580}
8681
8782fn get_app_dir ( ) -> Option < PathBuf > {
88- lookup ( & current_dir ( ) . expect ( "failed to read cwd" ) , |path, _ | {
83+ lookup ( & current_dir ( ) . expect ( "failed to read cwd" ) , |path| {
8984 if let Some ( file_name) = path. file_name ( ) {
9085 file_name == OsStr :: new ( "package.json" )
9186 } else {
0 commit comments