DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix: bind direct pnpm repair to executable
Justin Skowyra2eb4efe84890
diff --git a/src-tauri/src/service/cli/mod.rs b/src-tauri/src/service/cli/mod.rsindex dab37a69..24ab15ee 100644--- a/src-tauri/src/service/cli/mod.rs+++ b/src-tauri/src/service/cli/mod.rs@@ -27,4 +27,6 @@ mod shim;pub use core::{ensure, ensure_shims, get_status, remove, CliLinkStatus};pub use path::{find_user_pnpm, get_bin_dir, pnpm_env_value};+#[cfg(windows)]+pub(crate) use path::find_user_pnpm_executable;pub use shim::is_generated_shim;diff --git a/src-tauri/src/service/cli/path.rs b/src-tauri/src/service/cli/path.rsindex 71e1c6cf..e6da1d13 100644--- a/src-tauri/src/service/cli/path.rs+++ b/src-tauri/src/service/cli/path.rs@@ -115,6 +115,19 @@ pub fn path_registered(app_handle: &AppHandle) -> bool {/// 捆绑安装;Unix GUI 额外检查 mise 标准数据目录,生成的 `pnpm` shim 也会/// 优先转发到探测出的精确路径。pub fn find_user_pnpm(app_handle: &AppHandle) -> Option<PathBuf> {+ let dirs = user_pnpm_dirs(app_handle);+ find_pnpm_in_dirs(&get_bin_dir(app_handle), &dirs)+}++/// Windows 直接创建进程时不能执行 `.cmd`/`.bat`;为无需 shell 的修复流程单独+/// 查找原生 `pnpm.exe`,不改变常规 shim 对 `.cmd` 的既有优先级。+#[cfg(windows)]+pub(crate) fn find_user_pnpm_executable(app_handle: &AppHandle) -> Option<PathBuf> {+ let dirs = user_pnpm_dirs(app_handle);+ find_windows_executable_pnpm_in_dirs(&get_bin_dir(app_handle), &dirs)+}++fn user_pnpm_dirs(_app_handle: &AppHandle) -> Vec<PathBuf> {let mut dirs: Vec<PathBuf> =std::env::split_paths(&std::env::var_os("PATH").unwrap_or_default()).collect();#[cfg(windows)]@@ -123,7 +136,7 @@ pub fn find_user_pnpm(app_handle: &AppHandle) -> Option<PathBuf> {{let mise_data = std::env::var_os("MISE_DATA_DIR").map(PathBuf::from);let xdg_data = std::env::var_os("XDG_DATA_HOME").map(PathBuf::from);- let home = app_handle.path().home_dir().ok();+ let home = _app_handle.path().home_dir().ok();append_unix_mise_dirs(&mut dirs,mise_data.as_deref(),@@ -131,7 +144,7 @@ pub fn find_user_pnpm(app_handle: &AppHandle) -> Option<PathBuf> {home.as_deref(),);}- find_pnpm_in_dirs(&get_bin_dir(app_handle), &dirs)+ dirs}/// Unix 图形进程不会读取交互式 shell 配置;在继承 PATH 之后补充 mise 的@@ -186,6 +199,19 @@ fn find_pnpm_in_dirs(bin_dir: &Path, dirs: &[PathBuf]) -> Option<PathBuf> {} else {&["pnpm"]};+ find_pnpm_candidates_in_dirs(bin_dir, dirs, candidates)+}++#[cfg(windows)]+fn find_windows_executable_pnpm_in_dirs(bin_dir: &Path, dirs: &[PathBuf]) -> Option<PathBuf> {+ find_pnpm_candidates_in_dirs(bin_dir, dirs, &["pnpm.exe"])+}++fn find_pnpm_candidates_in_dirs(+ bin_dir: &Path,+ dirs: &[PathBuf],+ candidates: &[&str],+) -> Option<PathBuf> {let bin_dir = pnpm_env_path(bin_dir);for dir in dirs {if dir.as_os_str().is_empty() {@@ -683,6 +709,33 @@ mod tests {let _ = std::fs::remove_dir_all(root);}+ #[cfg(windows)]+ #[test]+ fn direct_discovery_uses_exe_when_cmd_and_exe_share_a_directory() {+ let root = temp_dir("pnpm-direct-exe");+ let desktop_bin = root.join("desktop-bin");+ let user_bin = root.join("user-bin");+ std::fs::create_dir_all(&desktop_bin).unwrap();+ std::fs::create_dir_all(&user_bin).unwrap();+ let cmd = user_bin.join("pnpm.cmd");+ let exe = user_bin.join("pnpm.exe");+ std::fs::write(&cmd, "cmd").unwrap();+ std::fs::write(&exe, "exe").unwrap();++ assert_eq!(+ find_pnpm_in_dirs(&desktop_bin, std::slice::from_ref(&user_bin)),+ Some(pnpm_env_path(&cmd))+ );+ assert_eq!(+ find_windows_executable_pnpm_in_dirs(+ &desktop_bin,+ std::slice::from_ref(&user_bin)+ ),+ Some(pnpm_env_path(&exe))+ );+ let _ = std::fs::remove_dir_all(root);+ }+#[test]fn mise_dirs_follow_path_and_dedupe_in_source_order() {let root = temp_dir("pnpm-mise-dirs");diff --git a/src-tauri/src/service/plugin/install.rs b/src-tauri/src/service/plugin/install.rsindex cbdadf3e..8a4dcf62 100644--- a/src-tauri/src/service/plugin/install.rs+++ b/src-tauri/src/service/plugin/install.rs@@ -769,11 +769,16 @@ async fn ensure_pnpm(app_handle: &AppHandle, window: &WebviewWindow) -> Result<b/// 供 [`ensure_pnpm`] 选版与 [`super::verify`] 的修复选版共用(store 主版本匹配)。pub(crate) fn user_pnpm_major_version(app_handle: &AppHandle) -> Option<u32> {let pnpm = cli::find_user_pnpm(app_handle)?;+ pnpm_major_version_at(&pnpm)+}++/// 探测精确 pnpm 可执行路径的主版本,供直接执行路径校验实际将运行的文件。+pub(crate) fn pnpm_major_version_at(pnpm: &Path) -> Option<u32> {// 打包版是 GUI 进程(无控制台):直接运行 pnpm(控制台子系统)会新建一个// 可见的黑色 cmd 窗口。`harness_prefer_bundled_pnpm` 在每次服务启动都会调本// 函数探测用户 pnpm,若不隐藏窗口则每次打开应用都会闪一个黑窗。此处与// `config::runtime::node_version_output` 的 CREATE_NO_WINDOW 处理保持一致。- let mut cmd = std::process::Command::new(&pnpm);+ let mut cmd = std::process::Command::new(pnpm);cmd.arg("--version");#[cfg(windows)]{@@ -1316,6 +1321,38 @@ pub(crate) fn harness_prefer_bundled_pnpm(app_handle: &AppHandle) -> bool {mod tests {use std::path::PathBuf;use super::{append_command_output, apply_allow_build_keys, collapse_allow_builds_duplicates, dep_path_to_name, extract_allow_line_key, extract_only_builds_git_name, git_transport_hint, normalize_git_spec, parse_allowlist_keys, parse_store_major_from_modules_yaml, preset_spec_for_install, shell_quote_spec, silent_install_failure_detail, PreinstallPluginInfo};+ #[cfg(unix)]+ use super::pnpm_major_version_at;++ #[cfg(unix)]+ #[test]+ fn pnpm_major_version_at_probes_the_exact_selected_path() {+ use std::os::unix::fs::PermissionsExt;+ use std::time::{SystemTime, UNIX_EPOCH};++ let nonce = SystemTime::now()+ .duration_since(UNIX_EPOCH)+ .unwrap()+ .as_nanos();+ let root = std::env::temp_dir().join(format!(+ "dsh-pnpm-major-{}-{nonce}",+ std::process::id()+ ));+ std::fs::create_dir_all(&root).unwrap();+ let selected = root.join("selected-pnpm");+ let other = root.join("other-pnpm");+ std::fs::write(&selected, "#!/bin/sh\nprintf '11.2.0\\n'\n").unwrap();+ std::fs::write(&other, "#!/bin/sh\nprintf '10.9.0\\n'\n").unwrap();+ for path in [&selected, &other] {+ let mut permissions = std::fs::metadata(path).unwrap().permissions();+ permissions.set_mode(0o700);+ std::fs::set_permissions(path, permissions).unwrap();+ }++ assert_eq!(pnpm_major_version_at(&selected), Some(11));+ assert_eq!(pnpm_major_version_at(&other), Some(10));+ let _ = std::fs::remove_dir_all(root);+ }/// 构造预设条目的测试助手(internal 由各用例显式指定)fn preset(id: &str, spec: &str, internal: bool) -> PreinstallPluginInfo {diff --git a/src-tauri/src/service/plugin/verify.rs b/src-tauri/src/service/plugin/verify.rsindex 2ee41be5..41f5d728 100644--- a/src-tauri/src/service/plugin/verify.rs+++ b/src-tauri/src/service/plugin/verify.rs@@ -170,7 +170,9 @@ const REPAIR_OUTPUT_LIMIT: usize = 4000;/// Windows 上 `.cmd`/`.bat` 无法被 CreateProcess 直接执行(需 cmd.exe 解析),/// 用户 pnpm 只接受 `.exe`。fn pnpm_direct(app_handle: &AppHandle) -> Option<(PathBuf, Vec<OsString>)> {- use super::install::{bundled_pnpm_major, profile_store_major, user_pnpm_major_version};+ use super::install::{+ bundled_pnpm_major, pnpm_major_version_at, profile_store_major,+ };let bundled = config::get_pnpm_binary_path(app_handle);let bundled_ready = bundled.exists();@@ -182,13 +184,14 @@ fn pnpm_direct(app_handle: &AppHandle) -> Option<(PathBuf, Vec<OsString>)> {return Some((node, vec![bundled.into_os_string()]));}- // 用户 pnpm 主版本与 store 一致(或 store 未知)都可直接用- if let Some(user) = cli::find_user_pnpm(app_handle) {- #[cfg(windows)]- let spawnable = user.extension().and_then(|e| e.to_str()) == Some("exe");- #[cfg(not(windows))]- let spawnable = true;- if spawnable && store.is_none_or(|s| user_pnpm_major_version(app_handle) == Some(s)) {+ // 用户 pnpm 主版本与 store 一致(或 store 未知)都可直接用。Windows+ // CreateProcess 不能直接执行 `.cmd`/`.bat`,因此专门查找原生 pnpm.exe。+ #[cfg(windows)]+ let user_pnpm = cli::find_user_pnpm_executable(app_handle);+ #[cfg(not(windows))]+ let user_pnpm = cli::find_user_pnpm(app_handle);+ if let Some(user) = user_pnpm {+ if store.is_none_or(|s| pnpm_major_version_at(&user) == Some(s)) {return Some((user, Vec::new()));}}@@ -392,4 +395,4 @@ mod tests {assert_eq!(missing, vec!["dsh-session-context-menu"]);fs::remove_dir_all(&root).ok();}-}\ No newline at end of file+}