mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 22:48:27 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -39,10 +39,14 @@ export async function resolveGlobalRoot(
|
||||
runCommand: CommandRunner,
|
||||
timeoutMs: number,
|
||||
): Promise<string | null> {
|
||||
if (manager === "bun") return resolveBunGlobalRoot();
|
||||
if (manager === "bun") {
|
||||
return resolveBunGlobalRoot();
|
||||
}
|
||||
const argv = manager === "pnpm" ? ["pnpm", "root", "-g"] : ["npm", "root", "-g"];
|
||||
const res = await runCommand(argv, { timeoutMs }).catch(() => null);
|
||||
if (!res || res.code !== 0) return null;
|
||||
if (!res || res.code !== 0) {
|
||||
return null;
|
||||
}
|
||||
const root = res.stdout.trim();
|
||||
return root || null;
|
||||
}
|
||||
@@ -53,7 +57,9 @@ export async function resolveGlobalPackageRoot(
|
||||
timeoutMs: number,
|
||||
): Promise<string | null> {
|
||||
const root = await resolveGlobalRoot(manager, runCommand, timeoutMs);
|
||||
if (!root) return null;
|
||||
if (!root) {
|
||||
return null;
|
||||
}
|
||||
return path.join(root, PRIMARY_PACKAGE_NAME);
|
||||
}
|
||||
|
||||
@@ -74,13 +80,19 @@ export async function detectGlobalInstallManagerForRoot(
|
||||
|
||||
for (const { manager, argv } of candidates) {
|
||||
const res = await runCommand(argv, { timeoutMs }).catch(() => null);
|
||||
if (!res || res.code !== 0) continue;
|
||||
if (!res || res.code !== 0) {
|
||||
continue;
|
||||
}
|
||||
const globalRoot = res.stdout.trim();
|
||||
if (!globalRoot) continue;
|
||||
if (!globalRoot) {
|
||||
continue;
|
||||
}
|
||||
const globalReal = await tryRealpath(globalRoot);
|
||||
for (const name of ALL_PACKAGE_NAMES) {
|
||||
const expected = path.join(globalReal, name);
|
||||
if (path.resolve(expected) === path.resolve(pkgReal)) return manager;
|
||||
if (path.resolve(expected) === path.resolve(pkgReal)) {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +100,9 @@ export async function detectGlobalInstallManagerForRoot(
|
||||
const bunGlobalReal = await tryRealpath(bunGlobalRoot);
|
||||
for (const name of ALL_PACKAGE_NAMES) {
|
||||
const bunExpected = path.join(bunGlobalReal, name);
|
||||
if (path.resolve(bunExpected) === path.resolve(pkgReal)) return "bun";
|
||||
if (path.resolve(bunExpected) === path.resolve(pkgReal)) {
|
||||
return "bun";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -100,21 +114,31 @@ export async function detectGlobalInstallManagerByPresence(
|
||||
): Promise<GlobalInstallManager | null> {
|
||||
for (const manager of ["npm", "pnpm"] as const) {
|
||||
const root = await resolveGlobalRoot(manager, runCommand, timeoutMs);
|
||||
if (!root) continue;
|
||||
if (!root) {
|
||||
continue;
|
||||
}
|
||||
for (const name of ALL_PACKAGE_NAMES) {
|
||||
if (await pathExists(path.join(root, name))) return manager;
|
||||
if (await pathExists(path.join(root, name))) {
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bunRoot = resolveBunGlobalRoot();
|
||||
for (const name of ALL_PACKAGE_NAMES) {
|
||||
if (await pathExists(path.join(bunRoot, name))) return "bun";
|
||||
if (await pathExists(path.join(bunRoot, name))) {
|
||||
return "bun";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function globalInstallArgs(manager: GlobalInstallManager, spec: string): string[] {
|
||||
if (manager === "pnpm") return ["pnpm", "add", "-g", spec];
|
||||
if (manager === "bun") return ["bun", "add", "-g", spec];
|
||||
if (manager === "pnpm") {
|
||||
return ["pnpm", "add", "-g", spec];
|
||||
}
|
||||
if (manager === "bun") {
|
||||
return ["bun", "add", "-g", spec];
|
||||
}
|
||||
return ["npm", "i", "-g", spec];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user