src / utils / path.ts
import path from "node:path";
import fs from "node:fs";
export function resolveInside(baseDir: string, userPath: string): string {
const resolved = path.resolve(baseDir, userPath);
const base = path.resolve(baseDir);
const relative = path.relative(base, resolved);
if (relative.startsWith("..") || path.isAbsolute(relative)) {
throw new Error(`Path escapes workspace: ${userPath}`);
}
return resolved;
}
export function ensureDirExists(p: string): void {
fs.mkdirSync(p, { recursive: true });
}
export function isHidden(name: string): boolean {
return name.startsWith(".");
}