From abf7e8850ba41e7173e9e9a3fdd6dfb8f357d72d Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 6 Oct 2025 13:12:00 -0300 Subject: [PATCH] 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) --- .changes/mobile-pnpm-dlx-init.md | 6 ++++++ crates/tauri-cli/src/mobile/init.rs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 .changes/mobile-pnpm-dlx-init.md diff --git a/.changes/mobile-pnpm-dlx-init.md b/.changes/mobile-pnpm-dlx-init.md new file mode 100644 index 000000000..f9a0f3925 --- /dev/null +++ b/.changes/mobile-pnpm-dlx-init.md @@ -0,0 +1,6 @@ +--- +"@tauri-apps/cli": patch:bug +"tauri-cli": patch:bug +--- + +Fixes mobile project initialization when using `pnpx` or `pnpm dlx`. diff --git a/crates/tauri-cli/src/mobile/init.rs b/crates/tauri-cli/src/mobile/init.rs index 4ffa328ad..a81822a5f 100644 --- a/crates/tauri-cli/src/mobile/init.rs +++ b/crates/tauri-cli/src/mobile/init.rs @@ -79,6 +79,8 @@ pub fn exec( if r.is_match(&bin_stem.to_string_lossy()) { if var_os("PNPM_PACKAGE_NAME").is_some() { return ("pnpm".into(), build_args); + } else if is_pnpm_dlx() { + return ("pnpm".into(), vec!["dlx", "@tauri-apps/cli"]); } else if let Some(npm_execpath) = var_os("npm_execpath") { let manager_stem = PathBuf::from(&npm_execpath) .file_stem() @@ -368,3 +370,17 @@ fn unprefix_path( ) .map_err(Into::into) } + +fn is_pnpm_dlx() -> bool { + var_os("NODE_PATH") + .map(PathBuf::from) + .is_some_and(|node_path| { + let mut iter = node_path.components().peekable(); + while let Some(c) = iter.next() { + if c.as_os_str() == "pnpm" && iter.peek().is_some_and(|c| c.as_os_str() == "dlx") { + return true; + } + } + false + }) +}