diff --git a/package.json b/package.json index 1e9e246a..fd66adb4 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/hooks/prerun.ts b/src/hooks/prerun.ts new file mode 100644 index 00000000..a6c994cc --- /dev/null +++ b/src/hooks/prerun.ts @@ -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;