Skip to content

Commit

Permalink
feat: use parse to prevent --jit on non-jit plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 14, 2023
1 parent 26c5d4c commit 71c7453
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/commands/plugins/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ e.g. If you have a core plugin that has a 'hello' command, installing a user-ins
}),
jit: Flags.boolean({
hidden: true,
parse: async (input, ctx) => {
if (input === false || input === undefined) return input

const requestedPlugins = ctx.argv.filter(a => !a.startsWith('-'))
if (requestedPlugins.length === 0) return input

const jitPluginsConfig = ctx.config.pjson.oclif.jitPlugins ?? {}
if (Object.keys(jitPluginsConfig).length === 0) return input

const plugins = new Plugins(ctx.config)

const nonJitPlugins = await Promise.all(requestedPlugins.map(async plugin => {
const name = await plugins.maybeUnfriendlyName(plugin)
return {name, jit: Boolean(jitPluginsConfig[name])}
}))

const nonJitPluginsNames = nonJitPlugins.filter(p => !p.jit).map(p => p.name)
if (nonJitPluginsNames.length > 0) {
throw new Errors.CLIError(`The following plugins are not JIT plugins: ${nonJitPluginsNames.join(', ')}`)
}

return input
},
}),
};

Expand Down

0 comments on commit 71c7453

Please sign in to comment.