fix(release): restore pnpm package artifacts (#104975)

(cherry picked from commit 0a2a6a2b742e316eaa82ba72d13344f272631e32)
This commit is contained in:
Peter Steinberger
2026-07-11 21:55:00 -07:00
committed by Vincent Koc
parent 38d9f47a2a
commit ff8bb24bb2
2 changed files with 46 additions and 21 deletions
+32 -21
View File
@@ -135,6 +135,7 @@ export function parseArgs(argv) {
outputDir: "",
outputName: "",
packJson: "",
pnpmPack: false,
skipBuild: false,
sourceDir: ROOT_DIR,
};
@@ -177,6 +178,8 @@ export function parseArgs(argv) {
"packJson",
readEqualsOptionValue(arg.slice("--pack-json=".length), "--pack-json"),
);
} else if (arg === "--pnpm-pack") {
setOnce(arg, "pnpmPack", true);
} else if (arg === "--skip-build") {
setOnce(arg, "skipBuild", true);
} else if (arg === "--source-dir") {
@@ -195,6 +198,9 @@ export function parseArgs(argv) {
if (options.outputName) {
validateOutputName(options.outputName);
}
if (options.packJson && options.pnpmPack) {
throw new Error("--pack-json cannot be combined with --pnpm-pack");
}
return options;
}
@@ -646,6 +652,10 @@ export async function packOpenClawPackageForDocker(sourceDir, outputDir, options
}));
const restoreChangelog = options.restoreChangelog ?? restorePackageChangelog;
const prepareBundledAiRuntime = options.prepareBundledAiRuntime ?? prepareBundledAiRuntimePackage;
const packTool = options.pnpmPack ? "pnpm" : "npm";
if (options.packJsonPath && options.pnpmPack) {
throw new Error("packJsonPath cannot be combined with pnpmPack");
}
console.error("==> Packing OpenClaw package");
await prepareChangelog(sourceDir);
let packOutput;
@@ -653,26 +663,24 @@ export async function packOpenClawPackageForDocker(sourceDir, outputDir, options
try {
await cleanPackedOpenClawTarballs(outputDir);
cleanupBundledAiRuntime = await prepareBundledAiRuntime(sourceDir, outputDir, runCaptureImpl);
const packArgs = [
"pack",
...(options.packJsonPath ? ["--json"] : []),
"--silent",
"--ignore-scripts",
"--pack-destination",
outputDir,
];
packOutput = await runCaptureImpl(
"npm",
packArgs,
sourceDir,
{
deferForwardedSignalExit: true,
timeoutMs: resolveTimeoutMs(
"OPENCLAW_DOCKER_PACKAGE_PACK_TIMEOUT_MS",
DEFAULT_PACKAGE_PACK_TIMEOUT_MS,
),
},
);
const packArgs =
packTool === "pnpm"
? ["pack", "--silent", "--config.ignore-scripts=true", "--pack-destination", outputDir]
: [
"pack",
...(options.packJsonPath ? ["--json"] : []),
"--silent",
"--ignore-scripts",
"--pack-destination",
outputDir,
];
packOutput = await runCaptureImpl(packTool, packArgs, sourceDir, {
deferForwardedSignalExit: true,
timeoutMs: resolveTimeoutMs(
"OPENCLAW_DOCKER_PACKAGE_PACK_TIMEOUT_MS",
DEFAULT_PACKAGE_PACK_TIMEOUT_MS,
),
});
} finally {
try {
await cleanupBundledAiRuntime();
@@ -680,7 +688,9 @@ export async function packOpenClawPackageForDocker(sourceDir, outputDir, options
await restoreChangelog(sourceDir);
}
}
let tarball = await newestOpenClawTarball(outputDir, packOutput);
// pnpm reports an absolute destination path. Scan the freshly emptied output directory
// instead of accepting that command output as an artifact path.
let tarball = await newestOpenClawTarball(outputDir, options.pnpmPack ? "" : packOutput);
if (options.outputName) {
const target = path.join(outputDir, options.outputName);
if (target !== tarball) {
@@ -729,6 +739,7 @@ async function main() {
allowUnreleasedChangelog: options.allowUnreleasedChangelog,
outputName: options.outputName,
packJsonPath: options.packJson,
pnpmPack: options.pnpmPack,
});
console.error("==> Checking OpenClaw package tarball");
@@ -98,6 +98,7 @@ describe("package-openclaw-for-docker", () => {
outputDir: ".artifacts/docker",
outputName: "openclaw-current.tgz",
packJson: ".artifacts/docker/pack.json",
pnpmPack: false,
skipBuild: true,
sourceDir: "/repo",
});
@@ -132,6 +133,19 @@ describe("package-openclaw-for-docker", () => {
}
});
it("rejects pnpm pack with npm metadata output", async () => {
expect(parseArgs(["--pnpm-pack"]).pnpmPack).toBe(true);
expect(() => parseArgs(["--pnpm-pack", "--pack-json", "pack.json"])).toThrow(
"--pack-json cannot be combined with --pnpm-pack",
);
await expect(
packOpenClawPackageForDocker("/repo", "/out", {
packJsonPath: "pack.json",
pnpmPack: true,
}),
).rejects.toThrow("packJsonPath cannot be combined with pnpmPack");
});
it("rejects package artifact output names that escape the output directory", () => {
for (const outputName of [
"../openclaw-current.tgz",