mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-09 05:19:32 +08:00
Install: cache completion scripts on install/update
This commit is contained in:
@@ -293,13 +293,13 @@ function trySetupCompletion(repoRoot) {
|
||||
try {
|
||||
// Run with OPENCLAW_SKIP_POSTINSTALL to avoid any weird recursion,
|
||||
// though distinct from this script.
|
||||
spawnSync(process.execPath, [binPath, "completion", "--install", "--yes"], {
|
||||
spawnSync(process.execPath, [binPath, "completion", "--install", "--yes", "--write-state"], {
|
||||
cwd: repoRoot,
|
||||
stdio: "inherit",
|
||||
env: { ...process.env, OPENCLAW_SKIP_POSTINSTALL: "1" },
|
||||
});
|
||||
} catch {
|
||||
// Ignore errors to not break install
|
||||
// Ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Command } from "commander";
|
||||
import { confirm, isCancel, select, spinner } from "@clack/prompts";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -200,6 +201,29 @@ async function pathExists(targetPath: string): Promise<boolean> {
|
||||
}
|
||||
}
|
||||
|
||||
async function tryWriteCompletionCache(root: string, jsonMode: boolean): Promise<void> {
|
||||
const binPath = path.join(root, "openclaw.mjs");
|
||||
if (!(await pathExists(binPath))) {
|
||||
return;
|
||||
}
|
||||
const result = spawnSync(resolveNodeRunner(), [binPath, "completion", "--write-state"], {
|
||||
cwd: root,
|
||||
env: { ...process.env, OPENCLAW_SKIP_POSTINSTALL: "1" },
|
||||
encoding: "utf-8",
|
||||
});
|
||||
if (result.error) {
|
||||
if (!jsonMode) {
|
||||
defaultRuntime.log(theme.warn(`Completion cache update failed: ${String(result.error)}`));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (result.status !== 0 && !jsonMode) {
|
||||
const stderr = (result.stderr ?? "").toString().trim();
|
||||
const detail = stderr ? ` (${stderr})` : "";
|
||||
defaultRuntime.log(theme.warn(`Completion cache update failed${detail}.`));
|
||||
}
|
||||
}
|
||||
|
||||
async function isEmptyDir(targetPath: string): Promise<boolean> {
|
||||
try {
|
||||
const entries = await fs.readdir(targetPath);
|
||||
@@ -959,6 +983,8 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
|
||||
defaultRuntime.log(theme.warn("Skipping plugin updates: config is invalid."));
|
||||
}
|
||||
|
||||
await tryWriteCompletionCache(root, Boolean(opts.json));
|
||||
|
||||
// Restart service if requested
|
||||
if (shouldRestart) {
|
||||
if (!opts.json) {
|
||||
|
||||
Reference in New Issue
Block a user