mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:01:23 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -70,9 +70,13 @@ const DEFAULT_PACKAGE_NAME = "openclaw";
|
||||
const CORE_PACKAGE_NAMES = new Set([DEFAULT_PACKAGE_NAME]);
|
||||
|
||||
function normalizeDir(value?: string | null) {
|
||||
if (!value) return null;
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) return null;
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
return path.resolve(trimmed);
|
||||
}
|
||||
|
||||
@@ -80,8 +84,12 @@ function resolveNodeModulesBinPackageRoot(argv1: string): string | null {
|
||||
const normalized = path.resolve(argv1);
|
||||
const parts = normalized.split(path.sep);
|
||||
const binIndex = parts.lastIndexOf(".bin");
|
||||
if (binIndex <= 0) return null;
|
||||
if (parts[binIndex - 1] !== "node_modules") return null;
|
||||
if (binIndex <= 0) {
|
||||
return null;
|
||||
}
|
||||
if (parts[binIndex - 1] !== "node_modules") {
|
||||
return null;
|
||||
}
|
||||
const binName = path.basename(normalized);
|
||||
const nodeModulesDir = parts.slice(0, binIndex).join(path.sep);
|
||||
return path.join(nodeModulesDir, binName);
|
||||
@@ -90,15 +98,21 @@ function resolveNodeModulesBinPackageRoot(argv1: string): string | null {
|
||||
function buildStartDirs(opts: UpdateRunnerOptions): string[] {
|
||||
const dirs: string[] = [];
|
||||
const cwd = normalizeDir(opts.cwd);
|
||||
if (cwd) dirs.push(cwd);
|
||||
if (cwd) {
|
||||
dirs.push(cwd);
|
||||
}
|
||||
const argv1 = normalizeDir(opts.argv1);
|
||||
if (argv1) {
|
||||
dirs.push(path.dirname(argv1));
|
||||
const packageRoot = resolveNodeModulesBinPackageRoot(argv1);
|
||||
if (packageRoot) dirs.push(packageRoot);
|
||||
if (packageRoot) {
|
||||
dirs.push(packageRoot);
|
||||
}
|
||||
}
|
||||
const proc = normalizeDir(process.cwd());
|
||||
if (proc) dirs.push(proc);
|
||||
if (proc) {
|
||||
dirs.push(proc);
|
||||
}
|
||||
return Array.from(new Set(dirs));
|
||||
}
|
||||
|
||||
@@ -131,7 +145,9 @@ async function readBranchName(
|
||||
const res = await runCommand(["git", "-C", root, "rev-parse", "--abbrev-ref", "HEAD"], {
|
||||
timeoutMs,
|
||||
}).catch(() => null);
|
||||
if (!res || res.code !== 0) return null;
|
||||
if (!res || res.code !== 0) {
|
||||
return null;
|
||||
}
|
||||
const branch = res.stdout.trim();
|
||||
return branch || null;
|
||||
}
|
||||
@@ -145,7 +161,9 @@ async function listGitTags(
|
||||
const res = await runCommand(["git", "-C", root, "tag", "--list", pattern, "--sort=-v:refname"], {
|
||||
timeoutMs,
|
||||
}).catch(() => null);
|
||||
if (!res || res.code !== 0) return [];
|
||||
if (!res || res.code !== 0) {
|
||||
return [];
|
||||
}
|
||||
return res.stdout
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
@@ -162,10 +180,16 @@ async function resolveChannelTag(
|
||||
if (channel === "beta") {
|
||||
const betaTag = tags.find((tag) => isBetaTag(tag)) ?? null;
|
||||
const stableTag = tags.find((tag) => isStableTag(tag)) ?? null;
|
||||
if (!betaTag) return stableTag;
|
||||
if (!stableTag) return betaTag;
|
||||
if (!betaTag) {
|
||||
return stableTag;
|
||||
}
|
||||
if (!stableTag) {
|
||||
return betaTag;
|
||||
}
|
||||
const cmp = compareSemverStrings(betaTag, stableTag);
|
||||
if (cmp != null && cmp < 0) return stableTag;
|
||||
if (cmp != null && cmp < 0) {
|
||||
return stableTag;
|
||||
}
|
||||
return betaTag;
|
||||
}
|
||||
return tags.find((tag) => isStableTag(tag)) ?? null;
|
||||
@@ -182,7 +206,9 @@ async function resolveGitRoot(
|
||||
});
|
||||
if (res.code === 0) {
|
||||
const root = res.stdout.trim();
|
||||
if (root) return root;
|
||||
if (root) {
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -197,12 +223,16 @@ async function findPackageRoot(candidates: string[]) {
|
||||
const raw = await fs.readFile(pkgPath, "utf-8");
|
||||
const parsed = JSON.parse(raw) as { name?: string };
|
||||
const name = parsed?.name?.trim();
|
||||
if (name && CORE_PACKAGE_NAMES.has(name)) return current;
|
||||
if (name && CORE_PACKAGE_NAMES.has(name)) {
|
||||
return current;
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
const parent = path.dirname(current);
|
||||
if (parent === current) break;
|
||||
if (parent === current) {
|
||||
break;
|
||||
}
|
||||
current = parent;
|
||||
}
|
||||
}
|
||||
@@ -214,15 +244,23 @@ async function detectPackageManager(root: string) {
|
||||
const raw = await fs.readFile(path.join(root, "package.json"), "utf-8");
|
||||
const parsed = JSON.parse(raw) as { packageManager?: string };
|
||||
const pm = parsed?.packageManager?.split("@")[0]?.trim();
|
||||
if (pm === "pnpm" || pm === "bun" || pm === "npm") return pm;
|
||||
if (pm === "pnpm" || pm === "bun" || pm === "npm") {
|
||||
return pm;
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
const files = await fs.readdir(root).catch((): string[] => []);
|
||||
if (files.includes("pnpm-lock.yaml")) return "pnpm";
|
||||
if (files.includes("bun.lockb")) return "bun";
|
||||
if (files.includes("package-lock.json")) return "npm";
|
||||
if (files.includes("pnpm-lock.yaml")) {
|
||||
return "pnpm";
|
||||
}
|
||||
if (files.includes("bun.lockb")) {
|
||||
return "bun";
|
||||
}
|
||||
if (files.includes("package-lock.json")) {
|
||||
return "npm";
|
||||
}
|
||||
return "npm";
|
||||
}
|
||||
|
||||
@@ -276,22 +314,36 @@ async function runStep(opts: RunStepOptions): Promise<UpdateStepResult> {
|
||||
}
|
||||
|
||||
function managerScriptArgs(manager: "pnpm" | "bun" | "npm", script: string, args: string[] = []) {
|
||||
if (manager === "pnpm") return ["pnpm", script, ...args];
|
||||
if (manager === "bun") return ["bun", "run", script, ...args];
|
||||
if (args.length > 0) return ["npm", "run", script, "--", ...args];
|
||||
if (manager === "pnpm") {
|
||||
return ["pnpm", script, ...args];
|
||||
}
|
||||
if (manager === "bun") {
|
||||
return ["bun", "run", script, ...args];
|
||||
}
|
||||
if (args.length > 0) {
|
||||
return ["npm", "run", script, "--", ...args];
|
||||
}
|
||||
return ["npm", "run", script];
|
||||
}
|
||||
|
||||
function managerInstallArgs(manager: "pnpm" | "bun" | "npm") {
|
||||
if (manager === "pnpm") return ["pnpm", "install"];
|
||||
if (manager === "bun") return ["bun", "install"];
|
||||
if (manager === "pnpm") {
|
||||
return ["pnpm", "install"];
|
||||
}
|
||||
if (manager === "bun") {
|
||||
return ["bun", "install"];
|
||||
}
|
||||
return ["npm", "install"];
|
||||
}
|
||||
|
||||
function normalizeTag(tag?: string) {
|
||||
const trimmed = tag?.trim();
|
||||
if (!trimmed) return "latest";
|
||||
if (trimmed.startsWith("openclaw@")) return trimmed.slice("openclaw@".length);
|
||||
if (!trimmed) {
|
||||
return "latest";
|
||||
}
|
||||
if (trimmed.startsWith("openclaw@")) {
|
||||
return trimmed.slice("openclaw@".length);
|
||||
}
|
||||
if (trimmed.startsWith(`${DEFAULT_PACKAGE_NAME}@`)) {
|
||||
return trimmed.slice(`${DEFAULT_PACKAGE_NAME}@`.length);
|
||||
}
|
||||
@@ -537,25 +589,33 @@ export async function runGatewayUpdate(opts: UpdateRunnerOptions = {}): Promise<
|
||||
),
|
||||
);
|
||||
steps.push(checkoutStep);
|
||||
if (checkoutStep.exitCode !== 0) continue;
|
||||
if (checkoutStep.exitCode !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const depsStep = await runStep(
|
||||
step(`preflight deps install (${shortSha})`, managerInstallArgs(manager), worktreeDir),
|
||||
);
|
||||
steps.push(depsStep);
|
||||
if (depsStep.exitCode !== 0) continue;
|
||||
if (depsStep.exitCode !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const lintStep = await runStep(
|
||||
step(`preflight lint (${shortSha})`, managerScriptArgs(manager, "lint"), worktreeDir),
|
||||
);
|
||||
steps.push(lintStep);
|
||||
if (lintStep.exitCode !== 0) continue;
|
||||
if (lintStep.exitCode !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const buildStep = await runStep(
|
||||
step(`preflight build (${shortSha})`, managerScriptArgs(manager, "build"), worktreeDir),
|
||||
);
|
||||
steps.push(buildStep);
|
||||
if (buildStep.exitCode !== 0) continue;
|
||||
if (buildStep.exitCode !== 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
selectedSha = sha;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user