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: correctly load legacy plugins #713

Merged
merged 1 commit into from
Jun 15, 2023

Conversation

cristiand391
Copy link
Member

@cristiand391 cristiand391 commented Jun 15, 2023

This PR fixes an issue where CLIs that includes @oclif/plugin-legacy and at least one old, invalid plugin would get legacy plugins as the only ones installed.

left: ci-v5 plugin installed, shows as the only plugin (--core should show core plugins too), plugins:inspect webhooks fails even though @heroku-cli/plugin-webhooks is a core plugin.
right: with oclif fix, plugins:inspect is able to find it.
Screenshot 2023-06-15 at 13 31 52

plugin-legacy init hook where invalid, legacy plugins are converted:
https://github.com/oclif/plugin-legacy/blob/main/src/hooks/init.ts

Repro

  1. install Heroku CLI: npm i -g heroku
  2. check core plugins: heroku plugins --core, this only returns addons-v5 8.1.7 (core) because it's the first invalid plugin found.
  3. modify the splice line in the JS code
  4. run heroku plugins --core again, should get all core plugins.

[skip-validate-pr]

private insertLegacyPlugins(plugins: IPlugin[]) {
for (const plugin of plugins) {
const idx = this.plugins.findIndex(p => p.name === plugin.name)
if (idx !== -1) this.plugins = this.plugins.splice(idx, 1, plugin)
Copy link
Member Author

Choose a reason for hiding this comment

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

Array.splice mutates the array and returns an array of deleted items in this case, see:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice#return_value

so, this.plugins was set to the non-compatible version of the plugin loaded here:

await this.loadPluginsAndCommands()

Copy link

@k80bowman k80bowman left a comment

Choose a reason for hiding this comment

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

Great find, thank you!

@WillieRuemmele
Copy link
Contributor

QA Notes


npm i -g heroku

 ➜  heroku plugins --core
addons-v5 8.1.7 (core)

modify /Users/william.ruemmele/.nvm/versions/node/v18.16.0/lib/heroku/node_modules/@oclif/core/config.js L 649 to be

            if (idx !== -1)
                 this.plugins.splice(idx, 1, plugin);
            this.loadCommands(plugin);

instead of

            if (idx !== -1)
                this.plugins = this.plugins.splice(idx, 1, plugin);
            this.loadCommands(plugin);

and then run heroku plugins --core again, and get

 ➜  heroku plugins --core                                                                      
@oclif/plugin-commands 2.2.2 (core)
@oclif/plugin-help 5.2.9 (core)
@oclif/plugin-legacy 1.3.0 (core)
@oclif/plugin-not-found 2.3.16 (core)
@oclif/plugin-plugins 2.4.7 (core)
@oclif/plugin-update 3.1.10 (core)
@oclif/plugin-version 1.3.4 (core)
@oclif/plugin-warn-if-update-available 2.0.29 (core)
@oclif/plugin-which 2.2.8 (core)
addons-v5 8.1.7 (core)
apps 8.1.8 (core)
apps-v5 8.1.8 (core)
auth 8.1.7 (core)
autocomplete 8.1.7 (core)
buildpacks 8.1.7 (core)
certs 8.1.7 (core)
certs-v5 8.1.7 (core)
ci 8.1.7 (core)
ci-v5 8.1.8 (core)
config 8.1.7 (core)
container-registry-v5 8.1.7 (core)
git 8.1.8 (core)
heroku 8.1.8 (core)
local 8.1.8 (core)
oauth-v5 8.1.8 (core)
orgs-v5 8.1.4 (core)
pg-v5 8.1.7 (core)
pipelines 8.1.7 (core)
ps 8.1.7 (core)
ps-exec 2.4.0 (core)
redis-v5 8.1.7 (core)
run 8.1.4 (core)
spaces 8.1.7 (core)
status 8.1.7 (core)
webhooks 8.1.7 (core)

verified some other plugin commands

 ➜  heroku plugins:inspect run
failed
    Error: @heroku-cli/plugin-run not installed

vs

 ➜  heroku plugins:inspect run
└─ @heroku-cli/plugin-run
   ├─ version 8.1.4
   ├─ homepage https://github.com/heroku/cli
   ├─ location /Users/william.ruemmele/.nvm/versions/node/v18.16.0/lib/node_modules/heroku/node_modules/@heroku-cli/plugin-run
   ├─ commands

couldn't find any other plugin:* commands that were broken

@WillieRuemmele WillieRuemmele merged commit 7ea3bb9 into main Jun 15, 2023
@WillieRuemmele WillieRuemmele deleted the cd/fix-insert-legacy-plugins branch June 15, 2023 17:26
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.

3 participants