From 255e3fa7de8adf3c8c570f386027d78acd240a97 Mon Sep 17 00:00:00 2001 From: heimanba <371510756@qq.com> Date: Thu, 16 Jul 2026 15:12:20 +0800 Subject: [PATCH] fix: support npm 12 pack output [policy] Change-Id: I35767a804287d2b18c59cb2eeac825ce137794bd --- scripts/release/smoke-packed.test.ts | 16 ++++++++++++++++ scripts/release/smoke-packed.ts | 11 ++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 scripts/release/smoke-packed.test.ts diff --git a/scripts/release/smoke-packed.test.ts b/scripts/release/smoke-packed.test.ts new file mode 100644 index 0000000..f503a96 --- /dev/null +++ b/scripts/release/smoke-packed.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, test } from "bun:test"; +import { packedFilename } from "./smoke-packed.ts"; + +describe("npm pack output", () => { + test("accepts the npm 10 and 11 array format", () => { + expect(packedFilename('[{"filename":"sdk.tgz"}]', "sdk")).toBe("sdk.tgz"); + }); + + test("accepts the npm 12 package-map format", () => { + expect(packedFilename('{"@openagentpack/sdk":{"filename":"sdk.tgz"}}', "sdk")).toBe("sdk.tgz"); + }); + + test("rejects ambiguous output", () => { + expect(() => packedFilename("[]", "sdk")).toThrow("Unexpected npm pack output for sdk"); + }); +}); diff --git a/scripts/release/smoke-packed.ts b/scripts/release/smoke-packed.ts index ef090c1..f76dad0 100644 --- a/scripts/release/smoke-packed.ts +++ b/scripts/release/smoke-packed.ts @@ -20,6 +20,13 @@ const root = resolve(import.meta.dirname, "../.."); type PackedPackage = { filename: string }; +export function packedFilename(raw: string, pkg: string): string { + const parsed = JSON.parse(raw) as PackedPackage[] | Record; + const packed = Array.isArray(parsed) ? parsed : Object.values(parsed); + if (packed.length !== 1 || !packed[0]?.filename) throw new Error(`Unexpected npm pack output for ${pkg}`); + return packed[0].filename; +} + function run(command: string[], cwd: string, stdout: "inherit" | "pipe" = "inherit"): string { const result = Bun.spawnSync(command, { cwd, stdout, stderr: "inherit" }); if (result.exitCode !== 0) throw new Error(`Command failed (${result.exitCode}): ${command.join(" ")}`); @@ -38,9 +45,7 @@ function packPackages(destination: string): string[] { licenseStaged = true; originalManifest = rewriteManifestForPublish(pkgDir, versions); const raw = run(["npm", "pack", "--json", "--pack-destination", destination], pkgDir, "pipe"); - const packed = JSON.parse(raw) as PackedPackage[]; - if (packed.length !== 1 || !packed[0]?.filename) throw new Error(`Unexpected npm pack output for ${pkg}`); - return join(destination, packed[0].filename); + return join(destination, packedFilename(raw, pkg)); } finally { if (originalManifest !== undefined) restorePackageJson(pkgDir, originalManifest); if (licenseStaged) restoreLicense(pkgDir, originalLicense);