Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent postrun hook from running on uninstalled plugins #805

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,13 @@ export class Config implements IConfig {
await this.runHook('prerun', {Command: command, argv})

const result = (await command.run(argv, this)) as T
// If plugins:uninstall was run, we need to remove all the uninstalled plugins
// from this.plugins so that the postrun hook doesn't attempt to run any
// hooks that might have existed in the uninstalled plugins.
if (c.id === 'plugins:uninstall') {
for (const arg of argv) this.plugins.delete(arg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugins uninstall only accepts 1 arg but I'm guessing argv could also include --verbose. this.plugins is a map and delete doesn't throw if an element doesn't exist so this seems safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I think plugins uninstall is supposed to take multiple arguments: https://github.com/oclif/plugin-plugins/blob/main/src/commands/plugins/uninstall.ts#L16

I'm assuming at some point variableArgs = true was changed to strict = false but the command was never updated. Iterating over the args now future proofs us from that being fixed eventually

}

await this.runHook('postrun', {Command: command, argv, result})

marker?.addDetails({command: id, plugin: c.pluginName!})
Expand Down
Loading