Skip to content

Commit 1b343bd

Browse files
meowteclucasfernog
andauthored
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>
1 parent 4d09074 commit 1b343bd

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

.changes/npm-pass-args.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'cli.rs': 'patch'
3+
"cli.js": patch
4+
---
5+
6+
Correctly pass arguments from `npm run` to `tauri`.

tooling/cli/src/mobile/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub fn exec(
134134
// remove script path, we'll use `npm_lifecycle_event` instead
135135
build_args.remove(0);
136136
}
137+
build_args.insert(0, "--".into());
137138
build_args.insert(0, var("npm_lifecycle_event").unwrap());
138139
build_args.insert(0, "run".into());
139140
}

tooling/cli/src/mobile/ios/xcode_script.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
use clap::Parser;
1313
use tauri_mobile::{apple::target::Target, opts::Profile, util};
1414

15-
use std::{collections::HashMap, ffi::OsStr, path::PathBuf};
15+
use std::{collections::HashMap, env::var_os, ffi::OsStr, path::PathBuf};
1616

1717
#[derive(Debug, Parser)]
1818
pub struct Options {
@@ -55,16 +55,18 @@ pub fn command(options: Options) -> Result<()> {
5555
}
5656
}
5757

58-
// `xcode-script` is ran from the `gen/apple` folder.
59-
std::env::set_current_dir(
60-
std::env::current_dir()
61-
.unwrap()
62-
.parent()
63-
.unwrap()
64-
.parent()
65-
.unwrap(),
66-
)
67-
.unwrap();
58+
// `xcode-script` is ran from the `gen/apple` folder when not using NPM.
59+
if var_os("npm_lifecycle_event").is_none() {
60+
std::env::set_current_dir(
61+
std::env::current_dir()
62+
.unwrap()
63+
.parent()
64+
.unwrap()
65+
.parent()
66+
.unwrap(),
67+
)
68+
.unwrap();
69+
}
6870

6971
let profile = profile_from_configuration(&options.configuration);
7072
let macos = macos_from_platform(&options.platform);

tooling/cli/templates/mobile/ios/project.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ targets:
116116
discoveredDependencyFile: {{this.discovered-dependency-file}}{{/if}}
117117
{{~/each}}
118118

119-
- 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:?}
119+
- 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:?}
120120
name: Build Rust Code
121121
basedOnDependencyAnalysis: false
122122
outputFiles:

0 commit comments

Comments
 (0)