mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-16 20:40:45 +00:00
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 89dce69f50
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Reviewed-by: @steipete
21 lines
663 B
TypeScript
21 lines
663 B
TypeScript
import path from "node:path";
|
|
import { resolveUserPath } from "../utils.js";
|
|
|
|
export function normalizeWorkspaceDir(workspaceDir?: string): string | null {
|
|
const trimmed = workspaceDir?.trim();
|
|
if (!trimmed) {
|
|
return null;
|
|
}
|
|
const expanded = trimmed.startsWith("~") ? resolveUserPath(trimmed) : trimmed;
|
|
const resolved = path.resolve(expanded);
|
|
// Refuse filesystem roots as "workspace" (too broad; almost always a bug).
|
|
if (resolved === path.parse(resolved).root) {
|
|
return null;
|
|
}
|
|
return resolved;
|
|
}
|
|
|
|
export function resolveWorkspaceRoot(workspaceDir?: string): string {
|
|
return normalizeWorkspaceDir(workspaceDir) ?? process.cwd();
|
|
}
|