44
55use super :: { get_app, Target } ;
66use crate :: {
7- helpers:: { app_paths :: tauri_dir , config:: get as get_tauri_config, template:: JsonMap } ,
7+ helpers:: { config:: get as get_tauri_config, template:: JsonMap } ,
88 interface:: { AppInterface , Interface } ,
99 Result ,
1010} ;
@@ -18,17 +18,13 @@ use cargo_mobile2::{
1818 util:: {
1919 self ,
2020 cli:: { Report , TextWrapper } ,
21- relativize_path,
2221 } ,
2322} ;
2423use handlebars:: {
2524 Context , Handlebars , Helper , HelperResult , Output , RenderContext , RenderError , RenderErrorReason ,
2625} ;
2726
28- use std:: {
29- env:: { current_dir, var, var_os} ,
30- path:: PathBuf ,
31- } ;
27+ use std:: { env:: var_os, path:: PathBuf } ;
3228
3329pub fn command (
3430 target : Target ,
@@ -87,7 +83,6 @@ pub fn exec(
8783 #[ allow( unused_variables) ] reinstall_deps : bool ,
8884 skip_targets_install : bool ,
8985) -> Result < App > {
90- let current_dir = current_dir ( ) ?;
9186 let tauri_config = get_tauri_config ( target. platform_target ( ) , None ) ?;
9287
9388 let tauri_config_guard = tauri_config. lock ( ) . unwrap ( ) ;
@@ -97,75 +92,49 @@ pub fn exec(
9792
9893 let ( handlebars, mut map) = handlebars ( & app) ;
9994
100- // the CWD used when the the IDE runs the android-studio-script or the xcode-script
101- let ide_run_cwd = if target == Target :: Android {
102- tauri_dir ( )
103- } else {
104- tauri_dir ( ) . join ( "gen/apple" )
105- } ;
106-
10795 let mut args = std:: env:: args_os ( ) ;
108- let mut binary = args
96+
97+ let ( binary, mut build_args) = args
10998 . next ( )
11099 . map ( |bin| {
111- let path = PathBuf :: from ( & bin) ;
112- if path. exists ( ) {
113- let absolute_path = util:: prefix_path ( & current_dir, path) ;
114- return relativize_path ( absolute_path, & ide_run_cwd) . into_os_string ( ) ;
100+ let bin_path = PathBuf :: from ( & bin) ;
101+ let mut build_args = vec ! [ "tauri" ] ;
102+
103+ if let Some ( bin_stem) = bin_path. file_stem ( ) {
104+ let r = regex:: Regex :: new ( "(nodejs|node)\\ -?([1-9]*)*$" ) . unwrap ( ) ;
105+ if r. is_match ( & bin_stem. to_string_lossy ( ) ) {
106+ if let Some ( npm_execpath) = var_os ( "npm_execpath" ) {
107+ let manager_stem = PathBuf :: from ( & npm_execpath)
108+ . file_stem ( )
109+ . unwrap ( )
110+ . to_os_string ( ) ;
111+ let is_npm = manager_stem == "npm-cli" ;
112+ let binary = if is_npm {
113+ "npm" . into ( )
114+ } else if manager_stem == "npx-cli" {
115+ "npx" . into ( )
116+ } else {
117+ manager_stem
118+ } ;
119+
120+ if is_npm {
121+ build_args. insert ( 0 , "run" ) ;
122+ build_args. insert ( 1 , "--" ) ;
123+ }
124+
125+ return ( binary, build_args) ;
126+ }
127+ } else if !cfg ! ( debug_assertions) && bin_stem == "cargo-tauri" {
128+ return ( std:: ffi:: OsString :: from ( "cargo" ) , build_args) ;
129+ }
115130 }
116- bin
131+
132+ ( bin, build_args)
117133 } )
118- . unwrap_or_else ( || std:: ffi:: OsString :: from ( "cargo" ) ) ;
119- let mut build_args = Vec :: new ( ) ;
120- for arg in args {
121- let path = PathBuf :: from ( & arg) ;
122- if path. exists ( ) {
123- let absolute_path = util:: prefix_path ( & current_dir, path) ;
124- build_args. push (
125- relativize_path ( absolute_path, & ide_run_cwd)
126- . to_string_lossy ( )
127- . into_owned ( ) ,
128- ) ;
129- continue ;
130- }
131- let is_mobile_cmd_arg = arg == "android" || arg == "ios" ;
132- build_args. push ( arg. to_string_lossy ( ) . into_owned ( ) ) ;
133- if is_mobile_cmd_arg {
134- break ;
135- }
136- }
137- build_args. push ( target. ide_build_script_name ( ) . into ( ) ) ;
138-
139- let binary_path = PathBuf :: from ( & binary) ;
140- let bin_stem = binary_path. file_stem ( ) . unwrap ( ) . to_string_lossy ( ) ;
141- let r = regex:: Regex :: new ( "(nodejs|node)\\ -?([1-9]*)*$" ) . unwrap ( ) ;
142- if r. is_match ( & bin_stem) {
143- if let Some ( npm_execpath) = var_os ( "npm_execpath" ) . map ( PathBuf :: from) {
144- let manager_stem = npm_execpath. file_stem ( ) . unwrap ( ) . to_os_string ( ) ;
145- let is_npm = manager_stem == "npm-cli" ;
146- let is_npx = manager_stem == "npx-cli" ;
147- binary = if is_npm {
148- "npm" . into ( )
149- } else if is_npx {
150- "npx" . into ( )
151- } else {
152- manager_stem
153- } ;
154- if !( build_args. is_empty ( ) || is_npx) {
155- // remove script path, we'll use `npm_lifecycle_event` instead
156- build_args. remove ( 0 ) ;
157- }
158- if is_npm {
159- build_args. insert ( 0 , "--" . into ( ) ) ;
160- }
161- if !is_npx {
162- build_args. insert ( 0 , var ( "npm_lifecycle_event" ) . unwrap ( ) ) ;
163- }
164- if is_npm {
165- build_args. insert ( 0 , "run" . into ( ) ) ;
166- }
167- }
168- }
134+ . unwrap_or_else ( || ( std:: ffi:: OsString :: from ( "cargo" ) , vec ! [ "tauri" ] ) ) ;
135+
136+ build_args. push ( target. command_name ( ) ) ;
137+ build_args. push ( target. ide_build_script_name ( ) ) ;
169138
170139 map. insert ( "tauri-binary" , binary. to_string_lossy ( ) ) ;
171140 map. insert ( "tauri-binary-args" , & build_args) ;
0 commit comments