mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:50:45 +00:00
fix(update): filter dist inventory to packed files
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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<string[]> {
|
||||
try {
|
||||
const entries = await fs.readdir(rootDir, { withFileTypes: true });
|
||||
@@ -18,7 +43,7 @@ async function collectRelativeFiles(rootDir: string, baseDir: string): Promise<s
|
||||
}
|
||||
if (entry.isFile() || entry.isSymbolicLink()) {
|
||||
const relativePath = normalizeRelativePath(path.relative(baseDir, entryPath));
|
||||
return relativePath === PACKAGE_DIST_INVENTORY_RELATIVE_PATH ? [] : [relativePath];
|
||||
return isPackagedDistPath(relativePath) ? [relativePath] : [];
|
||||
}
|
||||
return [];
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user