Smarter fix to get the help from the plugin (#4465)

This commit is contained in:
Peter Hedenskog 2025-03-05 21:01:41 +01:00 committed by GitHub
parent 0ce768d2a4
commit e33e635f89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 6 deletions

View File

@ -11,16 +11,23 @@ export async function registerPluginOptions(yargsInstance, plugins) {
for (const pluginName of plugins) {
try {
// Dynamically import the plugin
let { default: plugin } = await importGlobalSilent(pluginName);
let plugin = await importGlobalSilent(pluginName);
// If the plugin exports a function to get CLI options, merge them
if (plugin && typeof plugin.getCliOptions === 'function') {
const options = plugin.getCliOptions();
if (
plugin &&
plugin.default & (typeof plugin.default.getCliOptions === 'function')
) {
const options = plugin.default.getCliOptions();
yargsInstance.options(options);
} else {
try {
const { default: plugin } = await import(pluginName);
if (plugin && typeof plugin.getCliOptions === 'function') {
const options = plugin.getCliOptions();
const plugin = await import(pluginName);
if (
plugin &&
plugin.default &&
typeof plugin.default.getCliOptions === 'function'
) {
const options = plugin.default.getCliOptions();
yargsInstance.options(options);
}
} catch {