Skip to content

Commit

Permalink
feat(cli): check cwd for config file before traversing (#7395)
Browse files Browse the repository at this point in the history
  • Loading branch information
chachako authored Jul 11, 2023
1 parent 764968a commit 907425d
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tooling/cli/src/helpers/app_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,21 @@ fn lookup<F: Fn(&PathBuf) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {
fn get_tauri_dir() -> PathBuf {
let cwd = current_dir().expect("failed to read cwd");

if cwd.join("src-tauri/tauri.conf.json").exists()
|| cwd.join("src-tauri/tauri.conf.json5").exists()
if cwd.join(ConfigFormat::Json.into_file_name()).exists()
|| cwd.join(ConfigFormat::Json5.into_file_name()).exists()
|| cwd.join(ConfigFormat::Toml.into_file_name()).exists()
{
return cwd.join("src-tauri/");
return cwd;
}

let src_tauri = cwd.join("src-tauri");
if src_tauri.join(ConfigFormat::Json.into_file_name()).exists()
|| src_tauri
.join(ConfigFormat::Json5.into_file_name())
.exists()
|| src_tauri.join(ConfigFormat::Toml.into_file_name()).exists()
{
return src_tauri;
}

lookup(&cwd, |path| folder_has_configuration_file(path) || is_configuration_file(path))
Expand All @@ -80,7 +91,13 @@ fn get_tauri_dir() -> PathBuf {
}

fn get_app_dir() -> Option<PathBuf> {
lookup(&current_dir().expect("failed to read cwd"), |path| {
let cwd = current_dir().expect("failed to read cwd");

if cwd.join("package.json").exists() {
return Some(cwd);
}

lookup(&cwd, |path| {
if let Some(file_name) = path.file_name() {
file_name == OsStr::new("package.json")
} else {
Expand Down

0 comments on commit 907425d

Please sign in to comment.