refactor(infra): dedupe openclaw root candidate scan
This commit is contained in:
@@ -87,19 +87,7 @@ export async function resolveOpenClawPackageRoot(opts: {
|
||||
argv1?: string;
|
||||
moduleUrl?: string;
|
||||
}): Promise<string | null> {
|
||||
const candidates: string[] = [];
|
||||
|
||||
if (opts.moduleUrl) {
|
||||
candidates.push(path.dirname(fileURLToPath(opts.moduleUrl)));
|
||||
}
|
||||
if (opts.argv1) {
|
||||
candidates.push(...candidateDirsFromArgv1(opts.argv1));
|
||||
}
|
||||
if (opts.cwd) {
|
||||
candidates.push(opts.cwd);
|
||||
}
|
||||
|
||||
for (const candidate of candidates) {
|
||||
for (const candidate of buildCandidates(opts)) {
|
||||
const found = await findPackageRoot(candidate);
|
||||
if (found) {
|
||||
return found;
|
||||
@@ -114,6 +102,17 @@ export function resolveOpenClawPackageRootSync(opts: {
|
||||
argv1?: string;
|
||||
moduleUrl?: string;
|
||||
}): string | null {
|
||||
for (const candidate of buildCandidates(opts)) {
|
||||
const found = findPackageRootSync(candidate);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function buildCandidates(opts: { cwd?: string; argv1?: string; moduleUrl?: string }): string[] {
|
||||
const candidates: string[] = [];
|
||||
|
||||
if (opts.moduleUrl) {
|
||||
@@ -126,12 +125,5 @@ export function resolveOpenClawPackageRootSync(opts: {
|
||||
candidates.push(opts.cwd);
|
||||
}
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const found = findPackageRootSync(candidate);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return candidates;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user