fix: support npm 12 pack JSON output (#10680)

fixes #10633
This commit is contained in:
Christian Klotz 2026-10-08 17:26:34 +02:00 • committed by GitHub
parent ce950d78f4
commit 6fb2e78151
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View file

@ -31,10 +31,10 @@ function packPackages(packages, tarballDirectory) {
stdio: ["inherit", "pipe", "inherit"],
});
const parsed = JSON.parse(output);
if (!Array.isArray(parsed) || parsed.length !== 1 || !parsed[0]?.filename) {
const packed = Array.isArray(parsed) ? (parsed.length === 1 ? parsed[0] : undefined) : parsed?.[pkg.name];
if (packed?.name !== pkg.name || typeof packed.filename !== "string") {
throw new Error(`npm pack returned an unexpected result for ${pkg.name}`);
}
const packed = parsed[0];
const originalPath = join(tarballDirectory, packed.filename);
const contents = readFileSync(originalPath);

View file

@ -15,6 +15,7 @@ function writePackage(directory, manifest, files) {
}
}
// #10633: Covers npm 12's package-keyed `npm pack --json` output only when npm 12 is on PATH.
test("produces a verified, content-addressed artifact set", (t) => {
const temporaryRoot = mkdtempSync(join(tmpdir(), "pi-package-artifacts-test-"));
t.after(() => rmSync(temporaryRoot, { recursive: true, force: true }));