fix(workbench): Windows 风格 DSH_HOME 在 POSIX 上按 Windows 语义拼账本路径
This commit is contained in:
parent
d479c12eaa
commit
6f660ff2b4
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { homedir } from 'node:os'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { dirname, join, resolve, win32 } from 'node:path'
|
||||
import { createIdFactory, isIdOf, newId } from './ids.mjs'
|
||||
import { ROLES, isRoleId } from './roles.mjs'
|
||||
import { assertTransition, isTerminal, isState } from './states.mjs'
|
||||
|
|
@ -80,8 +80,15 @@ export class StoreError extends Error {
|
|||
}
|
||||
}
|
||||
|
||||
// DSH_HOME 是 Windows 绝对路径(盘符或 UNC)时按 Windows 语义拼:在 POSIX 上
|
||||
// 直接 resolve 会把 C:\… 当相对路径拼到当前目录后面,账本就落错地方了。
|
||||
const WINDOWS_ABSOLUTE = /^[A-Za-z]:[\\/]/
|
||||
|
||||
export function defaultStorePath(env = process.env) {
|
||||
const home = env.DSH_HOME && String(env.DSH_HOME).trim() !== '' ? env.DSH_HOME : join(homedir(), '.dsh')
|
||||
if (typeof home === 'string' && (WINDOWS_ABSOLUTE.test(home) || home.startsWith('\\\\'))) {
|
||||
return win32.join(home, 'sansheng-liubu', 'workbench.json')
|
||||
}
|
||||
return join(resolve(home), 'sansheng-liubu', 'workbench.json')
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue