@@ -6,6 +6,7 @@ use std::{
66 cmp:: Ordering ,
77 env:: current_dir,
88 ffi:: OsStr ,
9+ fs:: FileType ,
910 path:: { Path , PathBuf } ,
1011} ;
1112
@@ -14,7 +15,7 @@ use once_cell::sync::Lazy;
1415
1516const TAURI_GITIGNORE : & [ u8 ] = include_bytes ! ( "../../tauri.gitignore" ) ;
1617
17- fn lookup < F : Fn ( & PathBuf ) -> bool > ( dir : & Path , checker : F ) -> Option < PathBuf > {
18+ fn lookup < F : Fn ( & PathBuf , FileType ) -> bool > ( dir : & Path , checker : F ) -> Option < PathBuf > {
1819 let mut default_gitignore = std:: env:: temp_dir ( ) ;
1920 default_gitignore. push ( ".gitignore" ) ;
2021 if !default_gitignore. exists ( ) {
@@ -47,25 +48,27 @@ fn lookup<F: Fn(&PathBuf) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {
4748
4849 for entry in builder. build ( ) . flatten ( ) {
4950 let path = dir. join ( entry. path ( ) ) ;
50- if checker ( & path) {
51+ if checker ( & path, entry . file_type ( ) . unwrap ( ) ) {
5152 return Some ( path) ;
5253 }
5354 }
5455 None
5556}
5657
5758fn get_tauri_dir ( ) -> PathBuf {
58- lookup ( & current_dir ( ) . expect ( "failed to read cwd" ) , |path| if let Some ( file_name) = path. file_name ( ) {
59+ lookup ( & current_dir ( ) . expect ( "failed to read cwd" ) , |path, file_type| if file_type. is_dir ( ) {
60+ path. join ( "tauri.conf.json" ) . exists ( ) || path. join ( "tauri.conf.json5" ) . exists ( )
61+ } else if let Some ( file_name) = path. file_name ( ) {
5962 file_name == OsStr :: new ( "tauri.conf.json" ) || file_name == OsStr :: new ( "tauri.conf.json5" )
6063 } else {
6164 false
6265 } )
63- . map ( |p| p . parent ( ) . unwrap ( ) . to_path_buf ( ) )
66+ . map ( |p| if p . is_dir ( ) { p } else { p . parent ( ) . unwrap ( ) . to_path_buf ( ) } )
6467 . expect ( "Couldn't recognize the current folder as a Tauri project. It must contain a `tauri.conf.json` or `tauri.conf.json5` file in any subfolder." )
6568}
6669
6770fn get_app_dir ( ) -> Option < PathBuf > {
68- lookup ( & current_dir ( ) . expect ( "failed to read cwd" ) , |path| {
71+ lookup ( & current_dir ( ) . expect ( "failed to read cwd" ) , |path, _ | {
6972 if let Some ( file_name) = path. file_name ( ) {
7073 file_name == OsStr :: new ( "package.json" )
7174 } else {
0 commit comments