From a74108ade7fd92d4310f3e6e28aac8c279f4d0e7 Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Tue, 23 Jun 2020 21:26:05 -0400 Subject: [PATCH] chore(repo): update checkversions script to also check for invalid versions (#3225) --- scripts/check-versions.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/check-versions.ts b/scripts/check-versions.ts index 51683d81e7..8db88172f8 100644 --- a/scripts/check-versions.ts +++ b/scripts/check-versions.ts @@ -47,6 +47,8 @@ function checkFiles(files: string[]) { console.log(` - ${files.join('\n - ')}\n`); const maxFileNameLength = Math.max(...files.map((f) => f.length)); + let hasError = false; + files.forEach((f) => { const versions = getVersions(f); const npmPackages = getPackages(versions); @@ -60,8 +62,19 @@ function checkFiles(files: string[]) { )} has new version ${chalk.bold(r.latest)} (current: ${r.prev})` ); } + if (r.invalid) { + hasError = true; + console.log( + `${logContext} ⚠️ ${chalk.bold(r.package)} has an invalid version (${ + r.prev + }) specified. Latest is ${r.latest}.` + ); + } }); }); + + if (hasError) + throw new Error('Invalid versions of packages found (please see above).'); } function getVersions(path: string) { @@ -101,16 +114,25 @@ function getNpmName(name: string): string { function getVersionData( p: string, v: string -): { package: string; outdated: boolean; latest: string; prev?: string } { +): { + package: string; + outdated: boolean; + invalid: boolean; + latest: string; + prev?: string; +} { try { const latest = JSON.parse( shell.exec(`npm view ${p} version --json --silent`, { silent: true }) ); if (gt(latest, v)) { - return { package: p, outdated: true, latest, prev: v }; + return { package: p, outdated: true, invalid: false, latest, prev: v }; + } + if (gt(v, latest)) { + return { package: p, outdated: false, invalid: true, latest, prev: v }; } } catch { // ignored } - return { package: p, outdated: false, latest: v }; + return { package: p, outdated: false, invalid: false, latest: v }; }