This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]> * style: juliet edits Co-authored-by: Juliet Shackell <[email protected]>
- Loading branch information
1 parent
579031a
commit 3b076fd
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import dxCheck from '../dist/hooks/salesforcedx-check.js'; | ||
|
||
dxCheck(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |