-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathverify-release.ts
More file actions
57 lines (51 loc) · 1.62 KB
/
verify-release.ts
File metadata and controls
57 lines (51 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import execa from 'execa';
import { readFileSync } from 'fs';
import path from 'path';
import { getLernaModules, getDistTags } from './prepareRelease';
let lernaModuleLocations: string[] = [];
async function getLernaModuleLocations(): Promise<void> {
const modules = await getLernaModules();
lernaModuleLocations = modules.map(({ location }) => location);
}
async function verifyPackage(dir: string, preid = 'beta'): Promise<boolean> {
const cwd = dir;
const json = JSON.parse(
readFileSync(path.join(cwd, 'package.json'), { encoding: 'utf-8' }),
);
if (json.private) {
return true;
}
try {
const distTags = await getDistTags(json.name);
if (json.version !== distTags[preid]) {
console.log(
`${json.name} missing. Expected ${json.version}, latest is ${distTags[preid]}`,
);
const { stdout, exitCode } = await execa(
'npm',
['publish', '--tag', preid, '--provenance'],
{ cwd },
);
console.log(stdout);
return exitCode === 0;
} else {
console.log(`${json.name} matches expected version ${json.version}`);
}
return true;
} catch (e) {
console.warn(`Failed to fetch dist tags for ${json.name}`, e);
return false;
}
}
async function verify(preid?: string) {
await getLernaModuleLocations();
for (let i = 0; i < lernaModuleLocations.length; i++) {
const dir = lernaModuleLocations[i];
if (!(await verifyPackage(dir, preid))) {
console.error('Failed to verify outstanding packages.');
return;
}
}
}
// e.g. for alpha releases: `npx tsx ./scripts/verify-beta.ts alpha`
verify(process.argv.slice(2)[0]);