diff --git a/messages/diagnostics.md b/messages/diagnostics.md index 50091995..e74a791a 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 + +Uninstall the deprecated 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/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 () => {