diff --git a/src/infra/package-dist-inventory.test.ts b/src/infra/package-dist-inventory.test.ts index b2beaf55395..459e3c9ef11 100644 --- a/src/infra/package-dist-inventory.test.ts +++ b/src/infra/package-dist-inventory.test.ts @@ -34,6 +34,27 @@ describe("package dist inventory", () => { }); }); + it("keeps npm-omitted dist artifacts out of the inventory", async () => { + await withTempDir({ prefix: "openclaw-dist-inventory-pack-" }, async (packageRoot) => { + const packagedQaRuntime = path.join( + packageRoot, + "dist", + "extensions", + "qa-channel", + "runtime-api.js", + ); + const omittedQaChunk = path.join(packageRoot, "dist", "extensions", "qa-channel", "cli.js"); + const omittedMap = path.join(packageRoot, "dist", "feature.runtime.js.map"); + await fs.mkdir(path.dirname(packagedQaRuntime), { recursive: true }); + await fs.writeFile(packagedQaRuntime, "export {};\n", "utf8"); + await fs.writeFile(omittedQaChunk, "export {};\n", "utf8"); + await fs.writeFile(omittedMap, "{}", "utf8"); + + await expect(writePackageDistInventory(packageRoot)).resolves.toEqual([ + "dist/extensions/qa-channel/runtime-api.js", + ]); + }); + }); it("fails closed when the inventory is missing", async () => { await withTempDir({ prefix: "openclaw-dist-inventory-missing-" }, async (packageRoot) => { await fs.mkdir(path.join(packageRoot, "dist"), { recursive: true }); diff --git a/src/infra/package-dist-inventory.ts b/src/infra/package-dist-inventory.ts index 8f7d245ef55..e83640b1688 100644 --- a/src/infra/package-dist-inventory.ts +++ b/src/infra/package-dist-inventory.ts @@ -2,11 +2,36 @@ import fs from "node:fs/promises"; import path from "node:path"; export const PACKAGE_DIST_INVENTORY_RELATIVE_PATH = "dist/postinstall-inventory.json"; +const PACKAGED_QA_RUNTIME_PATHS = new Set([ + "dist/extensions/qa-channel/runtime-api.js", + "dist/extensions/qa-lab/runtime-api.js", +]); function normalizeRelativePath(value: string): string { return value.replace(/\\/g, "/"); } +function isPackagedDistPath(relativePath: string): boolean { + if (!relativePath.startsWith("dist/")) { + return false; + } + if (relativePath === PACKAGE_DIST_INVENTORY_RELATIVE_PATH) { + return false; + } + if (relativePath.endsWith(".map")) { + return false; + } + if (relativePath === "dist/plugin-sdk/.tsbuildinfo") { + return false; + } + if ( + relativePath.startsWith("dist/extensions/qa-channel/") || + relativePath.startsWith("dist/extensions/qa-lab/") + ) { + return PACKAGED_QA_RUNTIME_PATHS.has(relativePath); + } + return true; +} async function collectRelativeFiles(rootDir: string, baseDir: string): Promise { try { const entries = await fs.readdir(rootDir, { withFileTypes: true }); @@ -18,7 +43,7 @@ async function collectRelativeFiles(rootDir: string, baseDir: string): Promise