From 3b076fdaac2901e112b5d5900715d647ba985dcc Mon Sep 17 00:00:00 2001 From: Shane McLaughlin Date: Mon, 24 Jan 2022 14:21:34 -0800 Subject: [PATCH] feat: warn people about salesforcedx during update (#436) * feat: warn people about salesforcedx during update * Update src/hooks/salesforcedx-check.ts Co-authored-by: Juliet Shackell <63259011+jshackell-sfdc@users.noreply.github.com> * style: juliet edits Co-authored-by: Juliet Shackell <63259011+jshackell-sfdc@users.noreply.github.com> --- package.json | 3 ++- scripts/checkSalesforceDx.ts | 3 +++ src/hooks/salesforcedx-check.ts | 46 +++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 scripts/checkSalesforceDx.ts create mode 100644 src/hooks/salesforcedx-check.ts diff --git a/package.json b/package.json index 5b87abe8..2bea395e 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,8 @@ "update": [ "./dist/hooks/lazyRequire.js", "./dist/hooks/postupdate.js", - "./dist/hooks/displayReleaseNotes.js" + "./dist/hooks/displayReleaseNotes.js", + "./dist/hooks/salesforcedx-check.js" ] }, "plugins": [ diff --git a/scripts/checkSalesforceDx.ts b/scripts/checkSalesforceDx.ts new file mode 100644 index 00000000..09a17da2 --- /dev/null +++ b/scripts/checkSalesforceDx.ts @@ -0,0 +1,3 @@ +import dxCheck from '../dist/hooks/salesforcedx-check.js'; + +dxCheck(); diff --git a/src/hooks/salesforcedx-check.ts b/src/hooks/salesforcedx-check.ts new file mode 100644 index 00000000..ede47c9f --- /dev/null +++ b/src/hooks/salesforcedx-check.ts @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import * as path from 'path'; +import Plugins from '@oclif/plugin-plugins'; +import { Config } from '@oclif/config'; +import { AnyJson, get } from '@salesforce/ts-types'; +import { cli } from 'cli-ux'; +import { compareVersions } from '../versions'; + +const salesforcedxError = `You still have the deprecated salesforcedx plugin installed in Salesforce CLI. If you continue using this plugin, you'll be running old and out-of-date versions of sfdx commands. + Uninstall the plugin with this command: 'sfdx plugins:uninstall salesforcedx'. + See https://github.com/forcedotcom/cli/blob/main/releasenotes/sfdx/README.md#71063-june-17-2021 for more information about this change.`; + +const MAX_VERSION = '7.107.0'; + +const hook = async (): Promise => { + // PART 1: is the CLI recent enough that we don't allow salesforcedx? + const root = path.resolve(__dirname, '..', '..'); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const pjson = require(path.resolve(root, 'package.json')) as AnyJson; + const config = new Config({ name: get(pjson, 'oclif.bin') as string | undefined, root }); + await config.load(); + + // early exit for old CLIs that shouldn't bother inspecting their plugins + if (compareVersions(config.version, MAX_VERSION) < 0) { + return; + } + + // PART 2: is the salesforcedx plugin installed? + const plugins = new Plugins(config); + + const installedUserPlugins = (await plugins.list()) + .filter((plugin) => plugin.type === 'user') + .map((plugin) => plugin.name); + cli.log(`user plugins are ${installedUserPlugins.join(', ')}`); + + if (installedUserPlugins.includes('salesforcedx')) { + cli.warn(salesforcedxError); + } +}; + +export default hook;