Skip to content

Commit cc7c2d7

Browse files
authored
feat(cli): allow conf path to be gitignored, closes #3636 (#3683)
1 parent 263b45e commit cc7c2d7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.changes/allow-conf-gitignore.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
Allows the `tauri.conf.json` file to be git ignored on the path lookup function.

tooling/cli/src/helpers/app_paths.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1516
const 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

5758
fn 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

6770
fn 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

Comments
 (0)