mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 09:01:22 +00:00
refactor(infra): dedupe openclaw root candidate scan
This commit is contained in:
@@ -87,19 +87,7 @@ export async function resolveOpenClawPackageRoot(opts: {
|
|||||||
argv1?: string;
|
argv1?: string;
|
||||||
moduleUrl?: string;
|
moduleUrl?: string;
|
||||||
}): Promise<string | null> {
|
}): Promise<string | null> {
|
||||||
const candidates: string[] = [];
|
for (const candidate of buildCandidates(opts)) {
|
||||||
|
|
||||||
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) {
|
|
||||||
const found = await findPackageRoot(candidate);
|
const found = await findPackageRoot(candidate);
|
||||||
if (found) {
|
if (found) {
|
||||||
return found;
|
return found;
|
||||||
@@ -114,6 +102,17 @@ export function resolveOpenClawPackageRootSync(opts: {
|
|||||||
argv1?: string;
|
argv1?: string;
|
||||||
moduleUrl?: string;
|
moduleUrl?: string;
|
||||||
}): string | null {
|
}): 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[] = [];
|
const candidates: string[] = [];
|
||||||
|
|
||||||
if (opts.moduleUrl) {
|
if (opts.moduleUrl) {
|
||||||
@@ -126,12 +125,5 @@ export function resolveOpenClawPackageRootSync(opts: {
|
|||||||
candidates.push(opts.cwd);
|
candidates.push(opts.cwd);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const candidate of candidates) {
|
return candidates;
|
||||||
const found = findPackageRootSync(candidate);
|
|
||||||
if (found) {
|
|
||||||
return found;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user