Skip to content

Commit

Permalink
Merge pull request #286 from pantheon-systems/PCC-1471-we-shouldnt-sa…
Browse files Browse the repository at this point in the history
…y-a-cli-update-is-available-if-the-new-version-is-a-beta-version

PCC-1471 Don't prompt the user to update the CLI if only a prerelease is available
  • Loading branch information
kevinstubbs authored Jul 12, 2024
2 parents fce87af + a388ad0 commit 3b90145
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-melons-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pantheon-systems/pcc-cli": patch
---

Don't notify the user that an update is available, if it is only a pre-release.
22 changes: 20 additions & 2 deletions packages/cli/src/lib/checkUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,26 @@ export function getPackageDetails() {

const checkUpdate = async () => {
const { name, version } = getPackageDetails();
const { version: latestVersion } = await pkgJson(name);
const updateAvailable = semver.lt(version, latestVersion as string);
const { versions: allPublishedVersions } = await pkgJson(name, {
allVersions: true,
});

const versionKeys = Object.keys(allPublishedVersions);
let latestVersion = versionKeys.pop();

while (latestVersion != null) {
if (
!semver.prerelease(latestVersion) &&
semver.gt(latestVersion, version)
) {
break;
}

latestVersion = versionKeys.pop();
}

const updateAvailable =
latestVersion != null && semver.lt(version, latestVersion as string);
if (updateAvailable) {
const msg = {
updateAvailable: `Update available! ${chalk.dim(version)}${chalk.green(
Expand Down

0 comments on commit 3b90145

Please sign in to comment.