Skip to content

Commit cf2a415

Browse files
author
DevBot
committed
fix(tools): verify npm releases for stable versions
The release verifier rejected stable x.y.z versions outright (prereleaseTag threw), so the 0.41.0 publish run died at 'verify npm versions and dist-tags' even though all five packages published correctly. prereleaseTag now returns null for stable versions; the verifier asserts version + dist-tags.latest in that case (prerelease line tags are only checked for prerelease publishes). Stable cases added to the verifier tests.
1 parent 25e820c commit cf2a415

2 files changed

Lines changed: 45 additions & 16 deletions

File tree

tools/lib/npm-release-verifier.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,26 @@ Deno.test('prereleaseTag accepts alpha beta and rc lines', () => {
9494
assertEquals(prereleaseTag('1.2.3-beta.4'), 'beta');
9595
assertEquals(prereleaseTag('1.2.3-rc.4'), 'rc');
9696
});
97+
98+
Deno.test('prereleaseTag returns null for stable versions and rejects malformed ones', () => {
99+
assertEquals(prereleaseTag('0.41.0'), null);
100+
assertEquals(prereleaseTag('0.41.0-alpha.19'), 'alpha');
101+
});
102+
103+
Deno.test('verifyNpmRelease verifies stable releases against latest only', async () => {
104+
const calls: string[] = [];
105+
await verifyNpmRelease({
106+
version: '0.41.0',
107+
packages: ['element'],
108+
delaysMs: [0],
109+
sleep: () => Promise.resolve(),
110+
query: (specifier, field) => {
111+
calls.push(`${specifier}:${field}`);
112+
return Promise.resolve('0.41.0');
113+
},
114+
});
115+
assertEquals(calls, [
116+
'@openelement/element@0.41.0:version',
117+
'@openelement/element:dist-tags.latest',
118+
]);
119+
});

tools/lib/npm-release-verifier.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ export interface VerifyNpmReleaseOptions {
1818
log?: (message: string) => void;
1919
}
2020

21-
export function prereleaseTag(version: string): 'alpha' | 'beta' | 'rc' {
21+
export function prereleaseTag(version: string): 'alpha' | 'beta' | 'rc' | null {
2222
const match = version.match(/^\d+\.\d+\.\d+-(alpha|beta|rc)\.\d+$/u);
23-
if (!match) {
24-
throw new Error('Expected prerelease version x.y.z-alpha|beta|rc.n');
25-
}
26-
return match[1] as 'alpha' | 'beta' | 'rc';
23+
if (match) return match[1] as 'alpha' | 'beta' | 'rc';
24+
if (/^\d+\.\d+\.\d+$/u.test(version)) return null;
25+
throw new Error(`Expected version x.y.z or x.y.z-alpha|beta|rc.n, got: ${version}`);
2726
}
2827

2928
async function verifyField(
@@ -79,16 +78,19 @@ export async function verifyNpmRelease(options: VerifyNpmReleaseOptions): Promis
7978
options.version,
8079
runtime,
8180
);
82-
await verifyField(
83-
`${packageName} dist-tags.${tag}`,
84-
packageName,
85-
`dist-tags.${tag}`,
86-
options.version,
87-
runtime,
88-
);
89-
// latest dist-tag policy (alpha line): prerelease publishes also move
90-
// `latest` (see tools/publish-npm.ts), so `latest` must equal the
91-
// just-published version — it must never lag the active release line.
81+
if (tag) {
82+
await verifyField(
83+
`${packageName} dist-tags.${tag}`,
84+
packageName,
85+
`dist-tags.${tag}`,
86+
options.version,
87+
runtime,
88+
);
89+
}
90+
// latest dist-tag policy: prerelease publishes also move `latest` (see
91+
// tools/publish-npm.ts); stable publishes keep the npm default of tagging
92+
// `latest`. Either way `latest` must equal the just-published version —
93+
// it must never lag the active release line.
9294
// Chosen invariant: dist-tags.latest === <published version> (exact match,
9395
// not semver >=), so a stale `latest` fails verification immediately.
9496
await verifyField(
@@ -98,6 +100,10 @@ export async function verifyNpmRelease(options: VerifyNpmReleaseOptions): Promis
98100
options.version,
99101
runtime,
100102
);
101-
options.log?.(`${packageName}@${options.version}: ${tag} and latest dist-tags verified`);
103+
options.log?.(
104+
tag
105+
? `${packageName}@${options.version}: ${tag} and latest dist-tags verified`
106+
: `${packageName}@${options.version}: latest dist-tag verified (stable)`,
107+
);
102108
}
103109
}

0 commit comments

Comments
 (0)