Skip to content

Commit

Permalink
fix(cli.rs): app path resolution on projects without git, closes #3409 (
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Feb 11, 2022
1 parent d29c5d5 commit d8acbe1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-path-resolution-node_modules.md
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"cli.js": patch
---

Fixes Tauri path resolution on projects without Git or a `.gitignore` file.
3 changes: 2 additions & 1 deletion tooling/cli/Cargo.toml
Expand Up @@ -18,7 +18,8 @@ include = [
"MergeModules/",
"*.json",
"*.rs",
"vswhere.exe"
"vswhere.exe",
"tauri.gitignore"
]

[[bin]]
Expand Down
4 changes: 3 additions & 1 deletion tooling/cli/schema.json
Expand Up @@ -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"
}
},
Expand Down
19 changes: 17 additions & 2 deletions tooling/cli/src/helpers/app_paths.rs
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions tooling/cli/tauri.gitignore
@@ -0,0 +1,3 @@
node_modules/
target/
WixTools

0 comments on commit d8acbe1

Please sign in to comment.