Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions scripts/release/smoke-packed.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
11 changes: 8 additions & 3 deletions scripts/release/smoke-packed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, PackedPackage>;
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(" ")}`);
Expand All @@ -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);
Expand Down