Merged via squash. Prepared head SHA: 27241bd0898d9ed1f13a5aaf3113be345d3002be Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com> Reviewed-by: @gumadeiras
17 lines
551 B
TypeScript
17 lines
551 B
TypeScript
import path from "node:path";
|
|
|
|
export function resolveRepoRelativeOutputDir(repoRoot: string, outputDir?: string) {
|
|
if (!outputDir) {
|
|
return undefined;
|
|
}
|
|
if (path.isAbsolute(outputDir)) {
|
|
throw new Error("--output-dir must be a relative path inside the repo root.");
|
|
}
|
|
const resolved = path.resolve(repoRoot, outputDir);
|
|
const relative = path.relative(repoRoot, resolved);
|
|
if (relative.startsWith("..") || path.isAbsolute(relative)) {
|
|
throw new Error("--output-dir must stay within the repo root.");
|
|
}
|
|
return resolved;
|
|
}
|