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
11 changes: 8 additions & 3 deletions scripts/root-release-guard.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ export async function inspectPackedFiles(options = {}) {
{ cwd: rootDir },
);
const packArtifacts = extractPackJsonPayload(packRun.stdout);
const files = Array.isArray(packArtifacts)
? packArtifacts[0]?.files?.map((entry) => entry.path).filter((entry) => typeof entry === "string")
: [];
const files = extractPackFilePaths(packArtifacts);

if (files.length === 0) {
throw new Error("npm pack --dry-run did not report any packaged files.");
Expand All @@ -131,6 +129,13 @@ export function extractPackJsonPayload(stdout) {
return JSON.parse(jsonPayload);
}

export function extractPackFilePaths(packArtifacts) {
const artifact = Array.isArray(packArtifacts) ? packArtifacts[0] : packArtifacts;
return Array.isArray(artifact?.files)
? artifact.files.map((entry) => entry.path).filter((entry) => typeof entry === "string")
: [];
}

export async function assertVendoredCliManifest(rootDir) {
const manifestPath = path.join(rootDir, "dist", "vendor", "cli", "package.json");
const rootManifest = JSON.parse(await readFile(path.join(rootDir, "package.json"), "utf8"));
Expand Down
11 changes: 11 additions & 0 deletions scripts/tests/root-release-guard.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
assertPackedSurface,
assertRootVersionPolicy,
assertVendoredCliManifest,
extractPackFilePaths,
runRootReleaseGuard,
} from "../root-release-guard.mjs";

Expand Down Expand Up @@ -85,6 +86,16 @@ test("assertPackedSurface rejects forbidden vendored implementation paths", () =
);
});

test("extractPackFilePaths accepts npm pack object and array envelopes", () => {
const artifact = {
filename: "martin-loop-0.5.0.tgz",
files: [{ path: "package.json" }, { path: "dist/index.js" }],
};

assert.deepEqual(extractPackFilePaths([artifact]), ["package.json", "dist/index.js"]);
assert.deepEqual(extractPackFilePaths(artifact), ["package.json", "dist/index.js"]);
});

test("assertVendoredCliManifest accepts the sanitized vendored CLI package manifest", async () => {
await withTempRoot(async (tempRoot) => {
await writeFile(
Expand Down
Loading