mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
ea2c6a63c9
* refactor(scripts): adopt shared scaffolding * fix(scripts): satisfy strict tooling checks * fix(scripts): preserve scaffolding contracts
21 lines
666 B
JavaScript
21 lines
666 B
JavaScript
import { existsSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
/** Resolves the repository root by walking upward from the caller module. */
|
|
export function resolveRepoRoot(importMetaUrl) {
|
|
let dir = path.dirname(fileURLToPath(importMetaUrl));
|
|
const { root } = path.parse(dir);
|
|
while (dir !== root) {
|
|
if (
|
|
existsSync(path.join(dir, ".git")) ||
|
|
(existsSync(path.join(dir, "package.json")) &&
|
|
existsSync(path.join(dir, "pnpm-workspace.yaml")))
|
|
) {
|
|
return dir;
|
|
}
|
|
dir = path.dirname(dir);
|
|
}
|
|
return path.resolve(path.dirname(fileURLToPath(importMetaUrl)), "..", "..");
|
|
}
|