Files
openclaw/scripts/build-diffs-viewer-runtime.mjs
samzong 316fd5b625 [Fix] Warm provider auth off main thread (#86281)
* fix(agents): warm provider auth off main thread

Signed-off-by: samzong <samzong.lu@gmail.com>

* fix(agents): keep provider auth warm read-only

* fix(ci): unblock provider auth landing

* ci: serialize gateway watch artifact check

* fix(ci): stabilize diffs viewer asset generation

* fix(agents): avoid stale plugin auth warm results

* fix(agents): keep partial auth warm cache

---------

Signed-off-by: samzong <samzong.lu@gmail.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-05-27 23:24:55 +01:00

84 lines
2.1 KiB
JavaScript

#!/usr/bin/env node
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { build } from "esbuild";
const modulePath = fileURLToPath(import.meta.url);
const repoRoot = path.resolve(path.dirname(modulePath), "..");
const targets = {
curated: {
entry: "extensions/diffs/src/viewer-client.ts",
output: "extensions/diffs/assets/viewer-runtime.js",
shikiAlias: "scripts/diffs-shiki-curated.ts",
},
full: {
entry: "extensions/diffs/src/viewer-client.ts",
output: "extensions/diffs-language-pack/assets/viewer-runtime.js",
},
};
export async function buildDiffsViewerRuntime(targetName) {
const target = targets[targetName];
if (!target) {
throw new Error(
`Usage: node scripts/build-diffs-viewer-runtime.mjs ${Object.keys(targets).join("|")}`,
);
}
const outputPath = path.join(repoRoot, target.output);
await fs.mkdir(path.dirname(outputPath), { recursive: true });
const result = await build({
entryPoints: [path.join(repoRoot, target.entry)],
bundle: true,
platform: "browser",
target: "es2020",
format: "esm",
minify: true,
define: {
NaN: "Number.NaN",
},
legalComments: "none",
outfile: outputPath,
write: false,
plugins: target.shikiAlias
? [
{
name: "openclaw-diffs-curated-shiki",
setup(buildContext) {
buildContext.onResolve({ filter: /^shiki$/ }, () => ({
path: path.join(repoRoot, target.shikiAlias),
}));
},
},
]
: [],
});
const outputFile = result.outputFiles?.[0];
if (!outputFile) {
throw new Error(`esbuild did not produce ${target.output}`);
}
const runtime = outputFile.text.replace(/[ \t]+$/gm, "");
let previousRuntime = null;
try {
previousRuntime = await fs.readFile(outputPath, "utf8");
} catch (error) {
if (error?.code !== "ENOENT") {
throw error;
}
}
if (previousRuntime !== runtime) {
await fs.writeFile(outputPath, runtime);
}
}
if (process.argv[1] === modulePath) {
await buildDiffsViewerRuntime(process.argv[2]);
}