mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:08:27 +00:00
fix(ui): fix web UI after tsdown migration and typing changes
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import fsSync from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -14,6 +15,16 @@ async function readPackageName(dir: string): Promise<string | null> {
|
||||
}
|
||||
}
|
||||
|
||||
function readPackageNameSync(dir: string): string | null {
|
||||
try {
|
||||
const raw = fsSync.readFileSync(path.join(dir, "package.json"), "utf-8");
|
||||
const parsed = JSON.parse(raw) as { name?: unknown };
|
||||
return typeof parsed.name === "string" ? parsed.name : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function findPackageRoot(startDir: string, maxDepth = 12): Promise<string | null> {
|
||||
let current = path.resolve(startDir);
|
||||
for (let i = 0; i < maxDepth; i += 1) {
|
||||
@@ -30,6 +41,22 @@ async function findPackageRoot(startDir: string, maxDepth = 12): Promise<string
|
||||
return null;
|
||||
}
|
||||
|
||||
function findPackageRootSync(startDir: string, maxDepth = 12): string | null {
|
||||
let current = path.resolve(startDir);
|
||||
for (let i = 0; i < maxDepth; i += 1) {
|
||||
const name = readPackageNameSync(current);
|
||||
if (name && CORE_PACKAGE_NAMES.has(name)) {
|
||||
return current;
|
||||
}
|
||||
const parent = path.dirname(current);
|
||||
if (parent === current) {
|
||||
break;
|
||||
}
|
||||
current = parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function candidateDirsFromArgv1(argv1: string): string[] {
|
||||
const normalized = path.resolve(argv1);
|
||||
const candidates = [path.dirname(normalized)];
|
||||
@@ -69,3 +96,30 @@ export async function resolveOpenClawPackageRoot(opts: {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function resolveOpenClawPackageRootSync(opts: {
|
||||
cwd?: string;
|
||||
argv1?: string;
|
||||
moduleUrl?: string;
|
||||
}): 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) {
|
||||
const found = findPackageRootSync(candidate);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user