Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
feat: warn people about salesforcedx during update (#436)
Browse files Browse the repository at this point in the history
* feat: warn people about salesforcedx during update

* Update src/hooks/salesforcedx-check.ts

Co-authored-by: Juliet Shackell <[email protected]>

* style: juliet edits

Co-authored-by: Juliet Shackell <[email protected]>
  • Loading branch information
mshanemc and jshackell-sfdc authored Jan 24, 2022
1 parent 579031a commit 3b076fd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
3 changes: 3 additions & 0 deletions scripts/checkSalesforceDx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import dxCheck from '../dist/hooks/salesforcedx-check.js';

dxCheck();
46 changes: 46 additions & 0 deletions src/hooks/salesforcedx-check.ts
Original file line number Diff line number Diff line change
@@ -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<void> => {
// 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;

0 comments on commit 3b076fd

Please sign in to comment.