fix: WSL Buff 路径支持 + 排除 .blueprint/ 触发 Vite 热重载

This commit is contained in:
lanrtop 2026-04-05 02:38:20 +09:00
parent 30d6823a1f
commit 00a6d4e335
3 changed files with 62 additions and 17 deletions

View File

@ -171,14 +171,45 @@ fn check_project(app: &AppHandle, project_path: &str) -> Result<(), String> {
Ok(())
}
// ── 辅助WSL 路径检测与转换 ─────────────────────────────────────────────────
/// 判断路径是否为 WSL UNC 路径(\\wsl.localhost\... 或 \\wsl$\...
fn is_wsl_path(path: &str) -> bool {
path.starts_with("\\\\wsl.localhost\\") || path.starts_with("\\\\wsl$\\")
}
/// 将 WSL UNC 路径转为 Linux 绝对路径(去掉 \\wsl.localhost\Distro 前缀)
fn unc_to_linux(path: &str) -> Option<String> {
let prefix = if path.starts_with("\\\\wsl.localhost\\") {
"\\\\wsl.localhost\\"
} else if path.starts_with("\\\\wsl$\\") {
"\\\\wsl$\\"
} else {
return None;
};
let rest = &path[prefix.len()..];
let slash_idx = rest.find('\\')?;
Some("/".to_string() + &rest[slash_idx + 1..].replace('\\', "/"))
}
// ── 辅助git 操作 ────────────────────────────────────────────────────────────
fn get_head_commit(root: &Path) -> Result<String, String> {
let out = std::process::Command::new("git")
.args(["rev-parse", "HEAD"])
.current_dir(root)
.output()
.map_err(|e| e.to_string())?;
let path_str = root.to_string_lossy();
let out = if is_wsl_path(&path_str) {
let linux = unc_to_linux(&path_str)
.ok_or_else(|| "无法转换 WSL 路径".to_string())?;
std::process::Command::new("wsl")
.args(["git", "-C", &linux, "rev-parse", "HEAD"])
.output()
.map_err(|e| e.to_string())?
} else {
std::process::Command::new("git")
.args(["rev-parse", "HEAD"])
.current_dir(root)
.output()
.map_err(|e| e.to_string())?
};
if out.status.success() {
Ok(String::from_utf8_lossy(&out.stdout).trim().to_string())
@ -188,19 +219,32 @@ fn get_head_commit(root: &Path) -> Result<String, String> {
}
fn get_changed_files(root: &Path, last_commit: Option<&str>) -> Result<Vec<String>, String> {
// 有上次 commitdiff two commits取最新一次 commit 的变更文件
let args: Vec<&str> = if let Some(prev) = last_commit {
vec!["diff", "--name-only", prev, "HEAD"]
let path_str = root.to_string_lossy();
let out = if is_wsl_path(&path_str) {
let linux = unc_to_linux(&path_str)
.ok_or_else(|| "无法转换 WSL 路径".to_string())?;
let cmd = if let Some(prev) = last_commit {
format!("git -C {linux} diff --name-only {prev} HEAD")
} else {
format!("git -C {linux} diff-tree --no-commit-id -r --name-only HEAD")
};
std::process::Command::new("wsl")
.args(["bash", "-c", &cmd])
.output()
.map_err(|e| e.to_string())?
} else {
vec!["diff-tree", "--no-commit-id", "-r", "--name-only", "HEAD"]
let args: Vec<&str> = if let Some(prev) = last_commit {
vec!["diff", "--name-only", prev, "HEAD"]
} else {
vec!["diff-tree", "--no-commit-id", "-r", "--name-only", "HEAD"]
};
std::process::Command::new("git")
.args(&args)
.current_dir(root)
.output()
.map_err(|e| e.to_string())?
};
let out = std::process::Command::new("git")
.args(&args)
.current_dir(root)
.output()
.map_err(|e| e.to_string())?;
if out.status.success() {
Ok(String::from_utf8_lossy(&out.stdout)
.lines()

View File

@ -1143,3 +1143,4 @@ export const getBuffStatus = (projectPath: string) =>
export const listBuffedProjects = () =>
invoke<BuffStatus[]>("list_buffed_projects");

View File

@ -26,8 +26,8 @@ export default defineConfig(async () => ({
}
: undefined,
watch: {
// 3. tell Vite to ignore watching `src-tauri`
ignored: ["**/src-tauri/**"],
// 3. tell Vite to ignore watching `src-tauri` and blueprint files
ignored: ["**/src-tauri/**", "**/.blueprint/**", "**/CLAUDE.md"],
},
},
}));