mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 00:27:26 +00:00
refactor: share openclaw root package parsing
This commit is contained in:
@@ -5,11 +5,14 @@ import { fileURLToPath } from "node:url";
|
|||||||
|
|
||||||
const CORE_PACKAGE_NAMES = new Set(["openclaw"]);
|
const CORE_PACKAGE_NAMES = new Set(["openclaw"]);
|
||||||
|
|
||||||
|
function parsePackageName(raw: string): string | null {
|
||||||
|
const parsed = JSON.parse(raw) as { name?: unknown };
|
||||||
|
return typeof parsed.name === "string" ? parsed.name : null;
|
||||||
|
}
|
||||||
|
|
||||||
async function readPackageName(dir: string): Promise<string | null> {
|
async function readPackageName(dir: string): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const raw = await fs.readFile(path.join(dir, "package.json"), "utf-8");
|
return parsePackageName(await fs.readFile(path.join(dir, "package.json"), "utf-8"));
|
||||||
const parsed = JSON.parse(raw) as { name?: unknown };
|
|
||||||
return typeof parsed.name === "string" ? parsed.name : null;
|
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -17,9 +20,7 @@ async function readPackageName(dir: string): Promise<string | null> {
|
|||||||
|
|
||||||
function readPackageNameSync(dir: string): string | null {
|
function readPackageNameSync(dir: string): string | null {
|
||||||
try {
|
try {
|
||||||
const raw = fsSync.readFileSync(path.join(dir, "package.json"), "utf-8");
|
return parsePackageName(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 {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user