fix: resolve Control UI assets for global installs (#4909) (thanks @YuriNachos)
Co-authored-by: YuriNachos <YuriNachos@users.noreply.github.com>
This commit is contained in:
@@ -74,6 +74,7 @@ Status: stable.
|
|||||||
- **BREAKING:** Gateway auth mode "none" is removed; gateway now requires token/password (Tailscale Serve identity still allowed).
|
- **BREAKING:** Gateway auth mode "none" is removed; gateway now requires token/password (Tailscale Serve identity still allowed).
|
||||||
|
|
||||||
### Fixes
|
### Fixes
|
||||||
|
- Infra: resolve Control UI assets for npm global installs. (#4909) Thanks @YuriNachos.
|
||||||
- Gateway: prevent blank token prompts from storing "undefined". (#4873) Thanks @Hisleren.
|
- Gateway: prevent blank token prompts from storing "undefined". (#4873) Thanks @Hisleren.
|
||||||
- Telegram: use undici fetch for per-account proxy dispatcher. (#4456) Thanks @spiceoogway.
|
- Telegram: use undici fetch for per-account proxy dispatcher. (#4456) Thanks @spiceoogway.
|
||||||
- Telegram: fix HTML nesting for overlapping styles and links. (#4578) Thanks @ThanhNguyxn.
|
- Telegram: fix HTML nesting for overlapping styles and links. (#4578) Thanks @ThanhNguyxn.
|
||||||
|
|||||||
@@ -37,11 +37,46 @@ describe("control UI assets helpers", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("resolves dist control-ui index path for dist argv1", () => {
|
it("resolves dist control-ui index path for dist argv1", async () => {
|
||||||
const argv1 = path.resolve("/tmp", "pkg", "dist", "index.js");
|
const argv1 = path.resolve("/tmp", "pkg", "dist", "index.js");
|
||||||
const distDir = path.dirname(argv1);
|
const distDir = path.dirname(argv1);
|
||||||
expect(resolveControlUiDistIndexPath(argv1)).toBe(
|
expect(await resolveControlUiDistIndexPath(argv1)).toBe(
|
||||||
path.join(distDir, "control-ui", "index.html"),
|
path.join(distDir, "control-ui", "index.html"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("resolves dist control-ui index path from package root argv1", async () => {
|
||||||
|
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
|
||||||
|
try {
|
||||||
|
await fs.writeFile(path.join(tmp, "package.json"), JSON.stringify({ name: "openclaw" }));
|
||||||
|
await fs.writeFile(path.join(tmp, "openclaw.mjs"), "export {};\n");
|
||||||
|
await fs.mkdir(path.join(tmp, "dist", "control-ui"), { recursive: true });
|
||||||
|
await fs.writeFile(path.join(tmp, "dist", "control-ui", "index.html"), "<html></html>\n");
|
||||||
|
|
||||||
|
expect(await resolveControlUiDistIndexPath(path.join(tmp, "openclaw.mjs"))).toBe(
|
||||||
|
path.join(tmp, "dist", "control-ui", "index.html"),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await fs.rm(tmp, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resolves dist control-ui index path from .bin argv1", async () => {
|
||||||
|
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ui-"));
|
||||||
|
try {
|
||||||
|
const binDir = path.join(tmp, "node_modules", ".bin");
|
||||||
|
const pkgRoot = path.join(tmp, "node_modules", "openclaw");
|
||||||
|
await fs.mkdir(binDir, { recursive: true });
|
||||||
|
await fs.mkdir(path.join(pkgRoot, "dist", "control-ui"), { recursive: true });
|
||||||
|
await fs.writeFile(path.join(binDir, "openclaw"), "#!/usr/bin/env node\n");
|
||||||
|
await fs.writeFile(path.join(pkgRoot, "package.json"), JSON.stringify({ name: "openclaw" }));
|
||||||
|
await fs.writeFile(path.join(pkgRoot, "dist", "control-ui", "index.html"), "<html></html>\n");
|
||||||
|
|
||||||
|
expect(await resolveControlUiDistIndexPath(path.join(binDir, "openclaw"))).toBe(
|
||||||
|
path.join(pkgRoot, "dist", "control-ui", "index.html"),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
await fs.rm(tmp, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import path from "node:path";
|
|||||||
|
|
||||||
import { runCommandWithTimeout } from "../process/exec.js";
|
import { runCommandWithTimeout } from "../process/exec.js";
|
||||||
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
|
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
|
||||||
|
import { resolveOpenClawPackageRoot } from "./openclaw-root.js";
|
||||||
|
|
||||||
export function resolveControlUiRepoRoot(
|
export function resolveControlUiRepoRoot(
|
||||||
argv1: string | undefined = process.argv[1],
|
argv1: string | undefined = process.argv[1],
|
||||||
@@ -32,9 +33,9 @@ export function resolveControlUiRepoRoot(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveControlUiDistIndexPath(
|
export async function resolveControlUiDistIndexPath(
|
||||||
argv1: string | undefined = process.argv[1],
|
argv1: string | undefined = process.argv[1],
|
||||||
): string | null {
|
): Promise<string | null> {
|
||||||
if (!argv1) return null;
|
if (!argv1) return null;
|
||||||
const normalized = path.resolve(argv1);
|
const normalized = path.resolve(argv1);
|
||||||
|
|
||||||
@@ -44,32 +45,9 @@ export function resolveControlUiDistIndexPath(
|
|||||||
return path.join(distDir, "control-ui", "index.html");
|
return path.join(distDir, "control-ui", "index.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Case 2: npm global install - entrypoint is at package root (e.g., openclaw.mjs)
|
const packageRoot = await resolveOpenClawPackageRoot({ argv1: normalized });
|
||||||
// or in node_modules/.bin/. Walk up to find package.json with dist/control-ui/
|
if (!packageRoot) return null;
|
||||||
const parts = normalized.split(path.sep);
|
return path.join(packageRoot, "dist", "control-ui", "index.html");
|
||||||
|
|
||||||
// Handle .bin symlink: node_modules/.bin/openclaw -> node_modules/openclaw/...
|
|
||||||
const binIndex = parts.lastIndexOf(".bin");
|
|
||||||
if (binIndex > 0 && parts[binIndex - 1] === "node_modules") {
|
|
||||||
const binName = path.basename(normalized);
|
|
||||||
const nodeModulesDir = parts.slice(0, binIndex).join(path.sep);
|
|
||||||
const pkgPath = path.join(nodeModulesDir, binName, "dist", "control-ui", "index.html");
|
|
||||||
if (fs.existsSync(pkgPath)) return pkgPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Walk up from entrypoint looking for package with dist/control-ui/
|
|
||||||
let dir = path.dirname(normalized);
|
|
||||||
for (let i = 0; i < 8; i++) {
|
|
||||||
const candidate = path.join(dir, "dist", "control-ui", "index.html");
|
|
||||||
if (fs.existsSync(path.join(dir, "package.json")) && fs.existsSync(candidate)) {
|
|
||||||
return candidate;
|
|
||||||
}
|
|
||||||
const parent = path.dirname(dir);
|
|
||||||
if (parent === dir) break;
|
|
||||||
dir = parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EnsureControlUiAssetsResult = {
|
export type EnsureControlUiAssetsResult = {
|
||||||
@@ -93,7 +71,7 @@ export async function ensureControlUiAssetsBuilt(
|
|||||||
runtime: RuntimeEnv = defaultRuntime,
|
runtime: RuntimeEnv = defaultRuntime,
|
||||||
opts?: { timeoutMs?: number },
|
opts?: { timeoutMs?: number },
|
||||||
): Promise<EnsureControlUiAssetsResult> {
|
): Promise<EnsureControlUiAssetsResult> {
|
||||||
const indexFromDist = resolveControlUiDistIndexPath(process.argv[1]);
|
const indexFromDist = await resolveControlUiDistIndexPath(process.argv[1]);
|
||||||
if (indexFromDist && fs.existsSync(indexFromDist)) {
|
if (indexFromDist && fs.existsSync(indexFromDist)) {
|
||||||
return { ok: true, built: false };
|
return { ok: true, built: false };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user