瀏覽代碼

fix(cli): only add `--` to generated android template for npm (#6508)

Amr Bashir 2 年之前
父節點
當前提交
c787f749de
共有 3 個文件被更改,包括 24 次插入9 次删除
  1. 6 0
      .changes/cli-pnpm.md
  2. 11 5
      tooling/cli/node/index.js
  3. 7 4
      tooling/cli/src/mobile/init.rs

+ 6 - 0
.changes/cli-pnpm.md

@@ -0,0 +1,6 @@
+---
+'cli.rs': 'patch'
+'cli.js': 'patch'
+---
+
+Fix android project build crashing when using `pnpm` caused by extra `--`.

+ 11 - 5
tooling/cli/node/index.js

@@ -1,7 +1,3 @@
-// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
-// SPDX-License-Identifier: Apache-2.0
-// SPDX-License-Identifier: MIT
-
 const { existsSync, readFileSync } = require('fs')
 const { join } = require('path')
 
@@ -15,7 +11,8 @@ function isMusl() {
   // For Node 10
   if (!process.report || typeof process.report.getReport !== 'function') {
     try {
-      return readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
+      const lddPath = require('child_process').execSync('which ldd').toString().trim();
+      return readFileSync(lddPath, 'utf8').includes('musl')
     } catch (e) {
       return true
     }
@@ -105,6 +102,15 @@ switch (platform) {
     }
     break
   case 'darwin':
+    localFileExisted = existsSync(join(__dirname, 'cli.darwin-universal.node'))
+    try {
+      if (localFileExisted) {
+        nativeBinding = require('./cli.darwin-universal.node')
+      } else {
+        nativeBinding = require('@tauri-apps/cli-darwin-universal')
+      }
+      break
+    } catch {}
     switch (arch) {
       case 'x64':
         localFileExisted = existsSync(join(__dirname, 'cli.darwin-x64.node'))

+ 7 - 4
tooling/cli/src/mobile/init.rs

@@ -124,19 +124,22 @@ pub fn exec(
   if r.is_match(&bin_stem) {
     if let Some(npm_execpath) = var_os("npm_execpath").map(PathBuf::from) {
       let manager_stem = npm_execpath.file_stem().unwrap().to_os_string();
-      let manager = if manager_stem == "npm-cli" {
+      binary = if manager_stem == "npm-cli" {
         "npm".into()
       } else {
         manager_stem
       };
-      binary = manager;
       if !build_args.is_empty() {
         // remove script path, we'll use `npm_lifecycle_event` instead
         build_args.remove(0);
       }
-      build_args.insert(0, "--".into());
+      if binary == "npm" {
+        build_args.insert(0, "--".into());
+      }
       build_args.insert(0, var("npm_lifecycle_event").unwrap());
-      build_args.insert(0, "run".into());
+      if binary == "npm" {
+        build_args.insert(0, "run".into());
+      }
     }
   }
   map.insert("tauri-binary", binary.to_string_lossy());