update deno commons mod

This commit is contained in:
2026-02-11 01:14:45 +08:00
parent 7da86515df
commit 0023ac9677

View File

@@ -115,9 +115,9 @@ export async function execCommandShell(
shell: false,
stdio: ["inherit", "inherit", "inherit"],
});
ps.on('close', (code) => {
ps.on("close", (code) => {
resolve(code);
})
});
});
}
}
@@ -174,7 +174,7 @@ export function parseIntVal(val: any, defaultVal: number): number {
}
export function getEnv(envKey: string): string | null {
const homeDir = getHomeDir();
const homeDir = homeDir();
if ((homeDir !== null) && envKey) {
const envValue = readFileToStringSync(
`${homeDir}/.config/envs/${envKey}`,
@@ -653,7 +653,11 @@ class Logger {
export const log = new Logger();
export function getHomeDirOrDie(): string {
const homeDir = getHomeDir();
return homeDirOrDie();
}
export function homeDirOrDie(): string {
const homeDir = homeDir();
if (homeDir === null) {
throw new Error("Cannot find home dir");
}
@@ -661,6 +665,10 @@ export function getHomeDirOrDie(): string {
}
export function getHomeDir(): string | null {
return homeDir();
}
export function homeDir(): string | null {
// if (Deno.build.os === "windows") {
// const userProfile = Deno.env.get("USERPROFILE");
// if (userProfile) {
@@ -673,12 +681,12 @@ export function getHomeDir(): string | null {
// }
// return null;
// }
return osEnv("HOME") || null;
return osEnv("HOME") ?? null;
}
export function resolveFilename(filename: string): string {
if (filename.startsWith("~/")) {
return getHomeDir() + filename.substring(1);
return homeDir() + filename.substring(1);
}
return filename;
}