From 593642a6ee1aa5f5508894925080d648812ff0a3 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Wed, 3 May 2023 15:56:20 -0600 Subject: [PATCH] fix: add doctor test for sf1/sfdx7 and suggest uninstall --- messages/diagnostics.md | 4 +++ src/commands/info/releasenotes/display.ts | 4 +-- src/diagnostics.ts | 21 ++++++++++++ test/diagnostics.test.ts | 42 ++++++++++++++++++++++- 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/messages/diagnostics.md b/messages/diagnostics.md index 50091995..7b34346f 100644 --- a/messages/diagnostics.md +++ b/messages/diagnostics.md @@ -14,3 +14,7 @@ The salesforcedx plugin is deprecated. Uninstall it by running: `%s plugins:unin # linkedPluginWarning Warning: the [%s] plugin is linked. + +# uninstallSuggestion + +Please uninstall the Salesforce CLI (%s) version %s and install the @salesforce/cli version 2. See https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_uninstall.htm for uninstall instructions. diff --git a/src/commands/info/releasenotes/display.ts b/src/commands/info/releasenotes/display.ts index 9117941e..f941275d 100644 --- a/src/commands/info/releasenotes/display.ts +++ b/src/commands/info/releasenotes/display.ts @@ -36,7 +36,7 @@ export default class Display extends SfCommand { public static readonly summary = messages.getMessage('summary'); public static readonly description = messages.getMessage('description'); - public static aliases = ['whatsnew']; + public static readonly aliases = ['whatsnew']; public static readonly examples = messages.getMessages('examples', [Display.helpers.join(', ')]); @@ -57,7 +57,7 @@ export default class Display extends SfCommand { const { flags } = await this.parse(Display); const env = new Env(); - const isHook = !!flags.hook; + const isHook = flags.hook; if (env.getBoolean(HIDE_NOTES) && isHook) { // We don't ever want to exit the process for info:releasenotes:display (whatsnew) diff --git a/src/diagnostics.ts b/src/diagnostics.ts index e0cfb156..80f59e29 100644 --- a/src/diagnostics.ts +++ b/src/diagnostics.ts @@ -89,6 +89,27 @@ export class Diagnostics { }); } + /** + * Checks to see if the cli is outdated and deprecated (sfdx7 sf1) + */ + public async deprecatedCliCheck(): Promise { + const cliName = this.config.name; + const cliVersion = this.config.version; + + if (cliName === 'sfdx-cli' && cliVersion.startsWith('7.')) { + await Lifecycle.getInstance().emit('Doctor:diagnostic', { testName: 'using sfdx-cli version 7', status: 'fail' }); + this.doctor.addSuggestion(messages.getMessage('uninstallSuggestion', [cliName, cliVersion])); + } + + if (cliName === '@salesforce/cli' && cliVersion.startsWith('1.')) { + await Lifecycle.getInstance().emit('Doctor:diagnostic', { + testName: 'using @salesforce/cli version 1', + status: 'fail', + }); + this.doctor.addSuggestion(messages.getMessage('uninstallSuggestion', [cliName, cliVersion])); + } + } + /** * Checks if the salesforcedx plugin is installed and suggests * to uninstall it if there. diff --git a/test/diagnostics.test.ts b/test/diagnostics.test.ts index 5119c53c..5c47355b 100644 --- a/test/diagnostics.test.ts +++ b/test/diagnostics.test.ts @@ -86,7 +86,7 @@ describe('Diagnostics', () => { const results = diagnostics.run(); // This will have to be updated with each new test - expect(results.length).to.equal(3); + expect(results.length).to.equal(4); expect(childProcessExecStub.called).to.be.true; expect(lifecycleEmitSpy.called).to.be.true; expect(lifecycleEmitSpy.args[0][0]).to.equal('Doctor:diagnostic'); @@ -204,6 +204,46 @@ describe('Diagnostics', () => { }); }); }); + describe('deprecatedCliCheck', () => { + it('fails when sfdx 7 installed', async () => { + const dr = Doctor.init(oclifConfig); + const diagnostics = new Diagnostics(dr, oclifConfig); + await diagnostics.deprecatedCliCheck(); + + expect(drAddSuggestionSpy.called).to.be.true; + expect(lifecycleEmitSpy.called).to.be.true; + expect(lifecycleEmitSpy.args[0][1]).to.deep.equal({ + testName: 'using sfdx-cli version 7', + status: 'fail', + }); + }); + + it('fails when sf 1 installed', async () => { + oclifConfig.name = '@salesforce/cli'; + oclifConfig.version = '1.0.0'; + const dr = Doctor.init(oclifConfig); + const diagnostics = new Diagnostics(dr, oclifConfig); + await diagnostics.deprecatedCliCheck(); + + expect(drAddSuggestionSpy.called).to.be.true; + expect(lifecycleEmitSpy.called).to.be.true; + expect(lifecycleEmitSpy.args[0][1]).to.deep.equal({ + testName: 'using @salesforce/cli version 1', + status: 'fail', + }); + }); + + it('passes when sf 2 is installed', async () => { + oclifConfig.name = '@salesforce/cli'; + oclifConfig.version = '2.0.0'; + const dr = Doctor.init(oclifConfig); + const diagnostics = new Diagnostics(dr, oclifConfig); + await diagnostics.deprecatedCliCheck(); + + expect(drAddSuggestionSpy.called).to.be.false; + expect(lifecycleEmitSpy.called).to.be.false; + }); + }); describe('linkedPluginCheck', () => { it('passes when linked plugin not found', async () => {