From e6a44d8f39467a9d7f2bc42b3082f05083775d88 Mon Sep 17 00:00:00 2001 From: codetypes Date: Wed, 4 Dec 2024 22:54:46 +0800 Subject: [PATCH] use posix path --- src/behavior3 | 2 +- src/contexts/workspace-context.ts | 6 +++--- src/misc/path.ts | 10 +++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/behavior3 b/src/behavior3 index af8eb16..9039934 160000 --- a/src/behavior3 +++ b/src/behavior3 @@ -1 +1 @@ -Subproject commit af8eb167ad3a819b47ba3d794879b3f4e4543841 +Subproject commit 903993458f6a45423d60b8db864f82cd618d1bc6 diff --git a/src/contexts/workspace-context.ts b/src/contexts/workspace-context.ts index fd9780e..f801335 100644 --- a/src/contexts/workspace-context.ts +++ b/src/contexts/workspace-context.ts @@ -172,7 +172,7 @@ export type WorkspaceStore = { }; const loadFileTree = (workdir: string, filename: string) => { - const fullpath = fs.realpathSync(`${workdir}/${filename}`); + const fullpath = Path.posixPath(`${workdir}/${filename}`); if (!fs.existsSync(fullpath) || filename.endsWith(".DS_Store")) { return; @@ -403,7 +403,7 @@ export const useWorkspace = create((set, get) => ({ }, open: (path, selectedNode) => { - path = fs.realpathSync(path); + path = Path.posixPath(path); const workspace = get(); let editor = workspace.editors.find((v) => v.path === path); if (!editor) { @@ -506,7 +506,7 @@ export const useWorkspace = create((set, get) => ({ if (filename === "node-config.b3-setting") { workspace.loadNodeDefs(); } else { - const fullpath = fs.realpathSync(`${workspace.workdir}/${filename}`); + const fullpath = Path.posixPath(`${workspace.workdir}/${filename}`); const editor = workspace.find(fullpath); if (editor && editor.modifiedTime + 500 < fs.statSync(fullpath).mtimeMs) { if (editor.unsave) { diff --git a/src/misc/path.ts b/src/misc/path.ts index 32bb45d..c9b329f 100644 --- a/src/misc/path.ts +++ b/src/misc/path.ts @@ -5,12 +5,16 @@ const Path = path; declare module "path" { interface PlatformPath { basenameWithoutExt(path: string): string; + posixPath(path: string): string; } } -// eslint-disable-next-line @typescript-eslint/no-shadow -path.basenameWithoutExt = (path: string) => { - return Path.basename(path, Path.extname(path)); +path.basenameWithoutExt = (str: string) => { + return Path.basename(str, Path.extname(str)); +}; + +path.posixPath = (str: string) => { + return path.normalize(str).replace(/\\/g, "/"); }; export default Path;