Skip to content

Commit abf7e88

Browse files
authored
fix(cli): mobile init when using pnpm dlx (#14118)
i noticed this when testing #13180 (though the original issue refers to npx, which I could not reproduce yet)
1 parent b001242 commit abf7e88

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.changes/mobile-pnpm-dlx-init.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tauri-apps/cli": patch:bug
3+
"tauri-cli": patch:bug
4+
---
5+
6+
Fixes mobile project initialization when using `pnpx` or `pnpm dlx`.

crates/tauri-cli/src/mobile/init.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ pub fn exec(
7979
if r.is_match(&bin_stem.to_string_lossy()) {
8080
if var_os("PNPM_PACKAGE_NAME").is_some() {
8181
return ("pnpm".into(), build_args);
82+
} else if is_pnpm_dlx() {
83+
return ("pnpm".into(), vec!["dlx", "@tauri-apps/cli"]);
8284
} else if let Some(npm_execpath) = var_os("npm_execpath") {
8385
let manager_stem = PathBuf::from(&npm_execpath)
8486
.file_stem()
@@ -368,3 +370,17 @@ fn unprefix_path(
368370
)
369371
.map_err(Into::into)
370372
}
373+
374+
fn is_pnpm_dlx() -> bool {
375+
var_os("NODE_PATH")
376+
.map(PathBuf::from)
377+
.is_some_and(|node_path| {
378+
let mut iter = node_path.components().peekable();
379+
while let Some(c) = iter.next() {
380+
if c.as_os_str() == "pnpm" && iter.peek().is_some_and(|c| c.as_os_str() == "dlx") {
381+
return true;
382+
}
383+
}
384+
false
385+
})
386+
}

0 commit comments

Comments
 (0)