Node os, fs & path
(, en)
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
export function expandPath(p: string): string {
const parts = p.split(path.sep);
if (parts[0] === "~") {
parts[0] = os.homedir();
}
return parts.join(path.sep);
}
export function findRepoRoot(): string | null {
const git = spawnSync("git", ["rev-parse", "--show-toplevel"], {
encoding: "utf8",
});
return git.status === 0 ? git.stdout.split("\n")[0] || null : null;
}