Pārlūkot izejas kodu

fix(cli/android): fallback to `${program}.cmd` (#6576)

* fix(cli/android): fallback to `${program}.cmd`

* cleanup [skip ci]

* revert variable to tauri-binary [skip ci]

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Amr Bashir 2 gadi atpakaļ
vecāks
revīzija
39df2c982e

+ 5 - 0
.changes/pnpm-android.md

@@ -0,0 +1,5 @@
+---
+'cli.rs': 'patch'
+---
+
+Fix `tauri anroid build/dev` crashing when used with standalone `pnpm` executable on Windows.

+ 0 - 16
tooling/cli/src/mobile/init.rs

@@ -121,10 +121,8 @@ pub fn exec(
   let binary_path = PathBuf::from(&binary);
   let bin_stem = binary_path.file_stem().unwrap().to_string_lossy();
   let r = regex::Regex::new("(nodejs|node)\\-?([1-9]*)*$").unwrap();
-  let mut is_npm = false;
   if r.is_match(&bin_stem) {
     if let Some(npm_execpath) = var_os("npm_execpath").map(PathBuf::from) {
-      is_npm = true;
       let manager_stem = npm_execpath.file_stem().unwrap().to_os_string();
       binary = if manager_stem == "npm-cli" {
         "npm".into()
@@ -144,20 +142,6 @@ pub fn exec(
       }
     }
   }
-  if is_npm {
-    map.insert(
-      "executable",
-      format!(
-        r#"if (Os.isFamily(Os.FAMILY_WINDOWS)) {{ """{binary}.cmd""" }} else {{ """{binary}""" }}"#,
-        binary = binary.to_string_lossy()
-      ),
-    );
-  } else {
-    map.insert(
-      "executable",
-      format!(r#""""{}""""#, binary.to_string_lossy()),
-    );
-  }
 
   map.insert("tauri-binary", binary.to_string_lossy());
   map.insert("tauri-binary-args", &build_args);

+ 18 - 4
tooling/cli/templates/mobile/android/buildSrc/src/main/kotlin/BuildTask.kt

@@ -22,13 +22,28 @@ open class BuildTask : DefaultTask() {
 
     @TaskAction
     fun build() {
+        val executable = """{{tauri-binary}}""";
+        try {
+            runTauriCli(executable)
+        } catch (e: Exception){
+            if (Os.isFamily(Os.FAMILY_WINDOWS)) {
+                runTauriCli("$executable.cmd")
+            } else {
+                throw e;
+            }
+        }
+    }
+
+    fun runTauriCli(executable: String) {
         val rootDirRel = rootDirRel ?: throw GradleException("rootDirRel cannot be null")
         val target = target ?: throw GradleException("target cannot be null")
         val release = release ?: throw GradleException("release cannot be null")
+        val args = listOf({{quote-and-join tauri-binary-args}});
+
         project.exec {
             workingDir(File(project.projectDir, rootDirRel.path))
-            executable({{executable}})
-            args(listOf({{quote-and-join tauri-binary-args}}))
+            executable(executable)
+            args(args)
             if (project.logger.isEnabled(LogLevel.DEBUG)) {
                 args("-vv")
             } else if (project.logger.isEnabled(LogLevel.INFO)) {
@@ -40,5 +55,4 @@ open class BuildTask : DefaultTask() {
             args(listOf("--target", target))
         }.assertNormalExitValue()
     }
-}
-
+}