fix(plugins): build package-local npm runtimes

This commit is contained in:
Vincent Koc
2026-05-02 22:36:18 -07:00
parent ac7e7f0512
commit 11a5b30f3e
11 changed files with 621 additions and 91 deletions

View File

@@ -4,10 +4,16 @@ import { performance } from "node:perf_hooks";
import { fileURLToPath, pathToFileURL } from "node:url";
import { copyBundledPluginMetadata } from "./copy-bundled-plugin-metadata.mjs";
import { copyPluginSdkRootAlias } from "./copy-plugin-sdk-root-alias.mjs";
import {
copyStaticExtensionAssets,
listStaticExtensionAssetOutputs,
} from "./lib/static-extension-assets.mjs";
import { writeTextFileIfChanged } from "./runtime-postbuild-shared.mjs";
import { stageBundledPluginRuntime } from "./stage-bundled-plugin-runtime.mjs";
import { writeOfficialChannelCatalog } from "./write-official-channel-catalog.mjs";
export { copyStaticExtensionAssets, listStaticExtensionAssetOutputs };
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const ROOT_RUNTIME_ALIAS_PATTERN = /^(?<base>.+\.(?:runtime|contract))-[A-Za-z0-9_-]+\.js$/u;
const LEGACY_CLI_EXIT_COMPAT_CHUNKS = [
@@ -21,60 +27,6 @@ const LEGACY_CLI_EXIT_COMPAT_CHUNKS = [
},
];
/**
* Copy static (non-transpiled) runtime assets that are referenced by their
* source-relative path inside bundled extension code.
*
* Each entry: { src: repo-root-relative source, dest: dist-relative dest }
*/
const STATIC_EXTENSION_ASSETS = [
// acpx MCP proxy — co-deployed alongside the acpx index bundle so that
// `path.resolve(dirname(import.meta.url), "mcp-proxy.mjs")` resolves correctly
// at runtime from the built ACPX extension directory.
{
src: "extensions/acpx/src/runtime-internals/mcp-proxy.mjs",
dest: "dist/extensions/acpx/mcp-proxy.mjs",
},
{
src: "extensions/acpx/src/runtime-internals/error-format.mjs",
dest: "dist/extensions/acpx/error-format.mjs",
},
{
src: "extensions/acpx/src/runtime-internals/mcp-command-line.mjs",
dest: "dist/extensions/acpx/mcp-command-line.mjs",
},
// diffs viewer runtime bundle — co-deployed inside the plugin package so the
// built bundle can resolve `./assets/viewer-runtime.js` from dist.
{
src: "extensions/diffs/assets/viewer-runtime.js",
dest: "dist/extensions/diffs/assets/viewer-runtime.js",
},
];
export function listStaticExtensionAssetOutputs(params = {}) {
const assets = params.assets ?? STATIC_EXTENSION_ASSETS;
return assets
.map(({ dest }) => dest.replace(/\\/g, "/"))
.toSorted((left, right) => left.localeCompare(right));
}
export function copyStaticExtensionAssets(params = {}) {
const rootDir = params.rootDir ?? ROOT;
const assets = params.assets ?? STATIC_EXTENSION_ASSETS;
const fsImpl = params.fs ?? fs;
const warn = params.warn ?? console.warn;
for (const { src, dest } of assets) {
const srcPath = path.join(rootDir, src);
const destPath = path.join(rootDir, dest);
if (fsImpl.existsSync(srcPath)) {
fsImpl.mkdirSync(path.dirname(destPath), { recursive: true });
fsImpl.copyFileSync(srcPath, destPath);
} else {
warn(`[runtime-postbuild] static asset not found, skipping: ${src}`);
}
}
}
export function writeStableRootRuntimeAliases(params = {}) {
const rootDir = params.rootDir ?? ROOT;
const distDir = path.join(rootDir, "dist");
@@ -126,7 +78,12 @@ export function runRuntimePostBuild(params = {}) {
runPhase("bundled plugin runtime overlay", () => stageBundledPluginRuntime(params));
runPhase("stable root runtime aliases", () => writeStableRootRuntimeAliases(params));
runPhase("legacy CLI exit compat chunks", () => writeLegacyCliExitCompatChunks(params));
runPhase("static extension assets", () => copyStaticExtensionAssets(params));
runPhase("static extension assets", () =>
copyStaticExtensionAssets({
rootDir: ROOT,
...params,
}),
);
}
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {