From f07ffe079f883b1583d10cd8bf640f0e15c3f197 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 7 Sep 2023 10:53:29 -0600 Subject: [PATCH 1/3] feat: add version diff prerun hook --- package.json | 3 ++- src/hooks/prerun.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/hooks/prerun.ts diff --git a/package.json b/package.json index e0275ade..124811d1 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..cfcfe1aa --- /dev/null +++ b/src/hooks/prerun.ts @@ -0,0 +1,31 @@ +/* + * 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 ({ config }) { + const jitPlugins = config.pjson.oclif.jitPlugins ?? {}; + const deps = config.pjson.dependencies ?? {}; + for (const plugin of config.getPluginsList()) { + // Skip the root plugin + if (plugin.root === config.root) continue; + // Skip user plugins that are not in the jitPlugins configuration + if (plugin.type === 'user' && !jitPlugins[plugin.name]) continue; + // Skip linked plugins + if (plugin.type === 'link') continue; + + const specifiedVersion = jitPlugins[plugin.name] ?? deps[plugin.name]; + if (plugin.version !== specifiedVersion) { + ux.warn( + `Plugin ${plugin.name} (${plugin.version}) differs from the version specified by ${config.bin} (${specifiedVersion})` + ); + } + } +}; + +export default hook; From f9bc07537e27cc46f6e1ae9a7a8d21c4104ea82e Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Thu, 7 Sep 2023 11:04:23 -0600 Subject: [PATCH 2/3] fix: show warning only for plugin to which the command belongs --- src/hooks/prerun.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/hooks/prerun.ts b/src/hooks/prerun.ts index cfcfe1aa..92edd787 100644 --- a/src/hooks/prerun.ts +++ b/src/hooks/prerun.ts @@ -8,23 +8,21 @@ import { Hook, ux } from '@oclif/core'; // eslint-disable-next-line @typescript-eslint/require-await -const hook: Hook.Prerun = async function ({ config }) { +const hook: Hook.Prerun = async function ({ Command, config }) { + const { plugin } = Command; + if (!plugin) return; + if (plugin.type === 'link') return; + const jitPlugins = config.pjson.oclif.jitPlugins ?? {}; const deps = config.pjson.dependencies ?? {}; - for (const plugin of config.getPluginsList()) { - // Skip the root plugin - if (plugin.root === config.root) continue; - // Skip user plugins that are not in the jitPlugins configuration - if (plugin.type === 'user' && !jitPlugins[plugin.name]) continue; - // Skip linked plugins - if (plugin.type === 'link') continue; - const specifiedVersion = jitPlugins[plugin.name] ?? deps[plugin.name]; - if (plugin.version !== specifiedVersion) { - ux.warn( - `Plugin ${plugin.name} (${plugin.version}) differs from the version specified by ${config.bin} (${specifiedVersion})` - ); - } + 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})` + ); } }; From de7de5eab8ed4fe6f03aa61a587baab8f0de24fc Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 8 Sep 2023 15:38:37 -0600 Subject: [PATCH 3/3] fix: skip if --json flag present --- src/hooks/prerun.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hooks/prerun.ts b/src/hooks/prerun.ts index 92edd787..a6c994cc 100644 --- a/src/hooks/prerun.ts +++ b/src/hooks/prerun.ts @@ -9,6 +9,7 @@ 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;