Browse Source

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

Lucas Fernandes Nogueira 3 năm trước cách đây
mục cha
commit
d8acbe1149

+ 6 - 0
.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.

+ 2 - 1
tooling/cli/Cargo.toml

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

+ 3 - 1
tooling/cli/schema.json

@@ -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"
             }
           },

+ 17 - 2
tooling/cli/src/helpers/app_paths.rs

@@ -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);

+ 3 - 0
tooling/cli/tauri.gitignore

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