Skip to content

Commit

Permalink
fix: Make doctor aware of the next tag (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager authored Nov 26, 2024
1 parent 522d0bf commit da37b4b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 3 additions & 2 deletions lib/__tests__/dependencyManagement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ describe('lib/dependencyManagement', () => {
describe('getLatestCliVersion', () => {
it('should return the version correctly', async () => {
const latest = '1.0.0';
const next = '1.0.0.beta.1';
execMock = jest
.fn()
.mockResolvedValueOnce({ stdout: JSON.stringify({ latest }) });
.mockResolvedValueOnce({ stdout: JSON.stringify({ latest, next }) });

util.promisify = jest.fn().mockReturnValueOnce(execMock);
const actual = await getLatestCliVersion();
expect(actual).toBe(latest);
expect(actual).toEqual({ latest, next });
});

it('should throw any errors that encounter with the check', async () => {
Expand Down
6 changes: 3 additions & 3 deletions lib/dependencyManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export async function isGloballyInstalled(command) {
}
}

export async function getLatestCliVersion(): string {
export async function getLatestCliVersion(): { latest: string; next: string } {
const exec = util.promisify(execAsync);
const { stdout } = await exec(`npm info ${pkg.name} dist-tags --json`);
const { latest } = JSON.parse(stdout);
return latest;
const { latest, next } = JSON.parse(stdout);
return { latest, next };
}

async function installPackages({ packages, installLocations }) {
Expand Down
11 changes: 8 additions & 3 deletions lib/doctor/Doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,12 @@ export class Doctor {

private async checkCLIVersion(): Promise<void> {
let latestCLIVersion;
let nextCliVersion;

try {
latestCLIVersion = await getLatestCliVersion();
const { latest, next } = await getLatestCliVersion();
latestCLIVersion = latest;
nextCliVersion = next;
} catch (e) {
return this.diagnosis?.addCliSection({
type: 'error',
Expand All @@ -245,14 +249,15 @@ export class Doctor {
});
}

if (latestCLIVersion !== pkg.version) {
if (latestCLIVersion !== pkg.version && nextCliVersion !== pkg.version) {
const onNextTag = pkg.version.includes('beta');
this.diagnosis?.addCliSection({
type: 'warning',
message: i18n(`${i18nKey}.hsChecks.notLatest`, {
hsVersion: pkg.version,
}),
secondaryMessaging: i18n(`${i18nKey}.hsChecks.notLatestSecondary`, {
hsVersion: pkg.version,
hsVersion: onNextTag ? nextCliVersion : latestCLIVersion,
command: uiCommandReference(`npm install -g ${pkg.name}`),
}),
});
Expand Down

0 comments on commit da37b4b

Please sign in to comment.