Skip to content

Commit

Permalink
Merge pull request #1127 from salesforcecli/mdonnalley/warn-about-ver…
Browse files Browse the repository at this point in the history
…sion-diffs

feat: add version diff prerun hook
  • Loading branch information
iowillhoit authored Sep 8, 2023
2 parents 8b91906 + de7de5e commit e489685
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"hooks": {
"command_incomplete": "./dist/hooks/incomplete",
"plugins:preinstall": "./dist/hooks/pluginsPreinstall.js",
"update": "./dist/hooks/display-release-notes.js"
"update": "./dist/hooks/display-release-notes.js",
"prerun": "./dist/hooks/prerun"
},
"update": {
"s3": {
Expand Down
30 changes: 30 additions & 0 deletions src/hooks/prerun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023, 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 { Hook, ux } from '@oclif/core';

// eslint-disable-next-line @typescript-eslint/require-await
const hook: Hook.Prerun = async function ({ Command, config }) {
if (process.argv.includes('--json')) return;
const { plugin } = Command;
if (!plugin) return;
if (plugin.type === 'link') return;

const jitPlugins = config.pjson.oclif.jitPlugins ?? {};
const deps = config.pjson.dependencies ?? {};

const specifiedVersion = jitPlugins[plugin.name] ?? deps[plugin.name];
if (!specifiedVersion) return;

if (plugin.version !== specifiedVersion) {
ux.warn(
`Plugin ${plugin.name} (${plugin.version}) differs from the version specified by ${config.bin} (${specifiedVersion})`
);
}
};

export default hook;

0 comments on commit e489685

Please sign in to comment.