fix: keep browser asset build package-local

This commit is contained in:
Shakker
2026-07-18 06:42:27 +01:00
committed by Shakker
parent 309a97bb3d
commit 3fd448c559
@@ -1,14 +1,30 @@
#!/usr/bin/env node
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { build } from "esbuild";
import { writeGeneratedTextAsset } from "../../../scripts/lib/generated-text-asset.mjs";
const modulePath = fileURLToPath(import.meta.url);
const pluginDir = path.resolve(path.dirname(modulePath), "..");
const repoRoot = path.resolve(pluginDir, "../..");
const outfile = path.join(pluginDir, "chrome-extension", "modules", "copilot-runtime.js");
async function writeCopilotRuntimeIfChanged(filePath, contents) {
try {
if ((await fs.readFile(filePath, "utf8")) === contents) {
return false;
}
} catch (error) {
if (error?.code !== "ENOENT") {
throw error;
}
}
await fs.mkdir(path.dirname(filePath), { recursive: true });
await fs.writeFile(filePath, contents, "utf8");
return true;
}
/** Builds the copilot runtime without rewriting an identical generated asset. */
export async function buildCopilotRuntime(params = {}) {
const buildImpl = params.build ?? build;
@@ -31,7 +47,7 @@ export async function buildCopilotRuntime(params = {}) {
throw new Error("esbuild did not produce the Browser copilot runtime bundle");
}
return writeGeneratedTextAsset(outputPath, outputFile.text);
return writeCopilotRuntimeIfChanged(outputPath, outputFile.text);
}
if (process.argv[1] === modulePath) {