@@ -13,10 +13,16 @@ declare let __RUST_CLI_VERSION__: string
1313
1414const currentDirName = dirname ( fileURLToPath ( import . meta. url ) )
1515
16+ interface Options {
17+ cwd ?: string
18+ }
19+
1620export async function runOnRustCli (
1721 command : string ,
18- args : string [ ]
22+ args : string [ ] ,
23+ options : Options = { }
1924) : Promise < { pid : number ; promise : Promise < void > } > {
25+ const cwd = options . cwd ?? process . cwd ( )
2026 const targetPath = resolve ( currentDirName , '../..' )
2127 const targetCliPath = join (
2228 targetPath ,
@@ -39,20 +45,10 @@ export async function runOnRustCli(
3945 }
4046
4147 if ( existsSync ( targetCliPath ) ) {
42- pid = spawn (
43- targetCliPath ,
44- [ 'tauri' , command , ...args ] ,
45- process . cwd ( ) ,
46- onClose
47- )
48+ pid = spawn ( targetCliPath , [ 'tauri' , command , ...args ] , cwd , onClose )
4849 } else if ( process . env . NODE_ENV === 'production' ) {
4950 await downloadCli ( )
50- pid = spawn (
51- targetCliPath ,
52- [ 'tauri' , command , ...args ] ,
53- process . cwd ( ) ,
54- onClose
55- )
51+ pid = spawn ( targetCliPath , [ 'tauri' , command , ...args ] , cwd , onClose )
5652 } else {
5753 if ( existsSync ( resolve ( targetPath , 'test' ) ) ) {
5854 // running local CLI since test directory exists
@@ -62,12 +58,7 @@ export async function runOnRustCli(
6258 targetPath ,
6359 '../cli.rs/target/release/cargo-tauri'
6460 )
65- pid = spawn (
66- localCliPath ,
67- [ 'tauri' , command , ...args ] ,
68- process . cwd ( ) ,
69- onClose
70- )
61+ pid = spawn ( localCliPath , [ 'tauri' , command , ...args ] , cwd , onClose )
7162 } else {
7263 spawnSync (
7364 'cargo' ,
@@ -79,14 +70,9 @@ export async function runOnRustCli(
7970 '--version' ,
8071 __RUST_CLI_VERSION__
8172 ] ,
82- process . cwd ( )
83- )
84- pid = spawn (
85- targetCliPath ,
86- [ 'tauri' , command , ...args ] ,
87- process . cwd ( ) ,
88- onClose
73+ cwd
8974 )
75+ pid = spawn ( targetCliPath , [ 'tauri' , command , ...args ] , cwd , onClose )
9076 }
9177 }
9278
0 commit comments