fix(cli.rs): app path resolution on projects without git, closes #3409 (#3410)

This commit is contained in:
Lucas Fernandes Nogueira 2022-02-11 19:41:50 -03:00 committed by GitHub
parent d29c5d551f
commit d8acbe1149
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 4 deletions

View File

@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---
Fixes Tauri path resolution on projects without Git or a `.gitignore` file.

View File

@ -18,7 +18,8 @@ include = [
"MergeModules/",
"*.json",
"*.rs",
"vswhere.exe"
"vswhere.exe",
"tauri.gitignore"
]
[[bin]]

View File

@ -1310,10 +1310,12 @@
{
"description": "A variable that is set while calling the command from the webview API.",
"type": "object",
"required": [
"validator"
],
"properties": {
"validator": {
"description": "[regex] validator to require passed values to conform to an expected input.\n\nThis will require the argument value passed to this variable to match the `validator` regex before it will be executed.\n\n[regex]: https://docs.rs/regex/latest/regex/#syntax",
"default": "",
"type": "string"
}
},

View File

@ -8,11 +8,26 @@ use std::{
path::{Path, PathBuf},
};
use ignore::Walk;
use ignore::WalkBuilder;
use once_cell::sync::Lazy;
const TAURI_GITIGNORE: &[u8] = include_bytes!("../../tauri.gitignore");
fn lookup<F: Fn(&PathBuf) -> bool>(dir: &Path, checker: F) -> Option<PathBuf> {
for entry in Walk::new(dir).flatten() {
let mut default_gitignore = std::env::temp_dir();
default_gitignore.push(".gitignore");
if !default_gitignore.exists() {
if let Ok(mut file) = std::fs::File::create(default_gitignore.clone()) {
use std::io::Write;
let _ = file.write_all(TAURI_GITIGNORE);
}
}
let mut builder = WalkBuilder::new(dir);
let _ = builder.add_ignore(default_gitignore);
builder.require_git(false).ignore(false).max_depth(Some(2));
for entry in builder.build().flatten() {
let path = dir.join(entry.path());
if checker(&path) {
return Some(path);

View File

@ -0,0 +1,3 @@
node_modules/
target/
WixTools