Преглед изворни кода

fix(cli): use `npm run tauri -- foo` for correctly passing args to tauri (#6448)

* fix(cli): use `npm run tauri -- foo` for correctly pass args to tauri

* fix xcode-script current dir, GCC_PREPROCESSOR_DEFINITIONS optional

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.app>
Bo пре 2 година
родитељ
комит
1b343bd116

+ 6 - 0
.changes/npm-pass-args.md

@@ -0,0 +1,6 @@
+---
+'cli.rs': 'patch'
+"cli.js": patch
+---
+
+Correctly pass arguments from `npm run` to `tauri`.

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

@@ -134,6 +134,7 @@ pub fn exec(
         // remove script path, we'll use `npm_lifecycle_event` instead
         build_args.remove(0);
       }
+      build_args.insert(0, "--".into());
       build_args.insert(0, var("npm_lifecycle_event").unwrap());
       build_args.insert(0, "run".into());
     }

+ 13 - 11
tooling/cli/src/mobile/ios/xcode_script.rs

@@ -12,7 +12,7 @@ use crate::{
 use clap::Parser;
 use tauri_mobile::{apple::target::Target, opts::Profile, util};
 
-use std::{collections::HashMap, ffi::OsStr, path::PathBuf};
+use std::{collections::HashMap, env::var_os, ffi::OsStr, path::PathBuf};
 
 #[derive(Debug, Parser)]
 pub struct Options {
@@ -55,16 +55,18 @@ pub fn command(options: Options) -> Result<()> {
     }
   }
 
-  // `xcode-script` is ran from the `gen/apple` folder.
-  std::env::set_current_dir(
-    std::env::current_dir()
-      .unwrap()
-      .parent()
-      .unwrap()
-      .parent()
-      .unwrap(),
-  )
-  .unwrap();
+  // `xcode-script` is ran from the `gen/apple` folder when not using NPM.
+  if var_os("npm_lifecycle_event").is_none() {
+    std::env::set_current_dir(
+      std::env::current_dir()
+        .unwrap()
+        .parent()
+        .unwrap()
+        .parent()
+        .unwrap(),
+    )
+    .unwrap();
+  }
 
   let profile = profile_from_configuration(&options.configuration);
   let macos = macos_from_platform(&options.platform);

+ 1 - 1
tooling/cli/templates/mobile/ios/project.yml

@@ -116,7 +116,7 @@ targets:
         discoveredDependencyFile: {{this.discovered-dependency-file}}{{/if}}
       {{~/each}}
 
-      - script: {{ tauri-binary }} {{ tauri-binary-args-str }} -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths "${FRAMEWORK_SEARCH_PATHS:?}" --header-search-paths "${HEADER_SEARCH_PATHS:?}" --gcc-preprocessor-definitions "${GCC_PREPROCESSOR_DEFINITIONS:?}" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}
+      - script: {{ tauri-binary }} {{ tauri-binary-args-str }} -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths "${FRAMEWORK_SEARCH_PATHS:?}" --header-search-paths "${HEADER_SEARCH_PATHS:?}" --gcc-preprocessor-definitions "${GCC_PREPROCESSOR_DEFINITIONS:-}" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}
         name: Build Rust Code
         basedOnDependencyAnalysis: false
         outputFiles: