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

feat: add plugins:post* hooks #932

Merged
merged 2 commits into from
Aug 1, 2024
Merged

feat: add plugins:post* hooks #932

merged 2 commits into from
Aug 1, 2024

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Jul 30, 2024

This PR adds 2 new hooks:

plugins:postinstall: runs after plugins install
plugins:postuninstall: runs after plugins uninstall

Added for the autocomplete refresh-cache hook:
oclif/plugin-autocomplete#753

See QA steps on the linked PR ⬆️

@W-12465784@

await pluginInstance.load()
this.config.plugins.set(pluginInstance.name, pluginInstance)

await this.config.runHook('plugins:postinstall', {})
Copy link
Member Author

Choose a reason for hiding this comment

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

plugin-autocomplete needs config.plugins with the new plugin populated for it to be included in the refreshed autocomplete files:
https://github.com/oclif/plugin-autocomplete/blob/986c6ec238ff3764c78331de7ea7b49e0670a47c/src/commands/autocomplete/create.ts#L95


for (const p of pluginNameToDelete) {
this.config.plugins.delete(p)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I know we do the same here:
https://github.com/oclif/core/blob/213e9203fd7f0f5aaffdcc9eb28d2828f7679373/src/config/config.ts#L475

but for the autocomplete refresh-hook use-case it doesn't work because the hook runs before oclif/core calls plugins.delete:

example with some logs to show order of execution

➜  plugin-plugins git:(cd/post-hooks) ✗ sf plugins uninstall @cristiand391/sf-plugin-fzf-cmp && unfunction _sf && autoload -U _sf
 ›   Warning: @oclif/plugin-autocomplete is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.
 ›   Warning: @oclif/plugin-plugins is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.
@salesforce/cli: Uninstalling @cristiand391/sf-plugin-fzf-cmp... done
running plugins:postuninstall hook
 ›   Warning: @oclif/plugin-autocomplete is a linked ESM module and cannot be auto-transpiled. Existing compiled source will be used instead.
done plugins:postuninstall hook
called `plugins.delete` from oclif/core

maybe we can remove the plugins.delete logic from oclif/core safely?
it was added here to avoid running postrun hooks from uninstalled plugins:
oclif/core#805

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think we can safely remove that once this is merged

@cristiand391 cristiand391 marked this pull request as ready for review July 30, 2024 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants