fix: 修复桌面检查脚本的 Windows 路径判断

This commit is contained in:
Cheng Zhou
2026-07-09 09:38:55 +08:00
parent b03e30d0dd
commit f4844aa8f1
2 changed files with 8 additions and 4 deletions
+6 -3
View File
@@ -1,5 +1,5 @@
import { readdir, readFile } from "node:fs/promises";
import { extname, relative, resolve } from "node:path";
import { extname, isAbsolute, relative, resolve } from "node:path";
import { fileURLToPath } from "node:url";
const frontendDir = fileURLToPath(new URL("../", import.meta.url));
@@ -7,6 +7,7 @@ const sourceDir = resolve(frontendDir, "src");
const runtimeDir = resolve(sourceDir, "runtime");
const sourceExtensions = new Set([".ts", ".tsx", ".vue", ".js", ".jsx"]);
const violations = [];
const toPosixPath = (path) => path.split("\\").join("/");
const walk = async (directory) => {
const entries = await readdir(directory, { withFileTypes: true });
@@ -21,10 +22,12 @@ const walk = async (directory) => {
};
for (const path of await walk(sourceDir)) {
if (!sourceExtensions.has(extname(path)) || path.startsWith(`${runtimeDir}/`)) continue;
const runtimeRelativePath = relative(runtimeDir, path);
const isRuntimeFile = Boolean(runtimeRelativePath) && !runtimeRelativePath.startsWith("..") && !isAbsolute(runtimeRelativePath);
if (!sourceExtensions.has(extname(path)) || isRuntimeFile) continue;
const source = await readFile(path, "utf8");
const file = relative(frontendDir, path);
const file = toPosixPath(relative(frontendDir, path));
if (source.includes("@tauri-apps/") || source.includes("__TAURI")) {
violations.push(`${file}: direct Tauri access is only allowed inside src/runtime`);
}