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

Plugin depending on another plugin #1938

Closed
pksunkara opened this issue Jul 25, 2018 · 8 comments · Fixed by #2337
Closed

Plugin depending on another plugin #1938

pksunkara opened this issue Jul 25, 2018 · 8 comments · Fixed by #2337

Comments

@pksunkara
Copy link
Contributor

What problem does this feature solve?

Some plugins might want to depend on other plugins. Currently, there is no way to do this.

What does the proposed API look like?

If the package.json dependencies of vue-cli-plugin-a contains vue-cli-plugin-b, then:

  1. vue add a will run vue add b and then vue add a
  2. vue invoke a will run vue invoke b and then vue invoke a (Optionally configured by a)

We can do this multiple deep levels.

Issues

  1. If a depends on b and c, what's the order of b and c to be run?
  2. What about circular dependencies?
@redskyburning
Copy link

@pksunkara thanks for taking the time to add this feature, it looks exactly like what i need, but I'm a bit confused as to how to use it. I've got a cli plugin i'm working on and I'd like it to invoke vue-cli-plugin-style-resources-loader before it runs as you describe above. I've tried added it to the dependencies of my plugin, but that doesn't seem to have any effect on invoke. I've also tried reading through PR #2337 but I haven't been able to find anything obviously related to this feature, same with the docs. Any chance you can explain usage here or point me to where it's explained in the docs? I found this issue via google so I'm sure others will find it while trying to solve this problem.

@pksunkara
Copy link
Contributor Author

In the above case, you can simple depend on it and invoke it from your code. You don't need hooks.

@redskyburning
Copy link

@pksunkara What do you mean by 'invoke it in your code'? Within the cli plugin code somehow? Or by a second manual invoke on the cli for the project using the plugin? I've added the dependency to the plugin so this must be what I'm missing. I was assuming it would be added automagically. I've done plenty of Vue but this is my first cli plugin so please forgive my ignorance.

@radek-altof
Copy link

Same issue as @redskyburning, I am scratching my head and trying various options, looking through #2337, but I can't figure it out. How does one invoke some Vue CLI plugin from another Vue CLI plugin? An example in docs would be very helpful.

@pksunkara
Copy link
Contributor Author

Just as a normal node dependency. If you need some logic from vue-cli-plugin-a to be ran, you just depend on it and call the relevant functions from that dependency during your invocation.

@redskyburning
Copy link

@radek-altof I ended up adding instructions to my readme asking the user to invoke the plugin in question. I don't think this feature exists in the way we think it does. If I understand @pksunkara correctly, they're saying we can use any function from a dependent package, such as another plugin, which isn't what I need at all. I need to actually invoke another plugin and have the user go through the prompts etc for that plugin before my plugin runs. Afaik this can't be done, but @pksunkara please let me know if I'm wrong and post an example of usage.

@pksunkara
Copy link
Contributor Author

You are right. But you can load the prompts easily and add them to your invocation. This is what I mean by using the other plugin as a normal dependency. Everything that you need can easily be loaded by you to be given to vue-cli.

@radek-altof
Copy link

@redskyburning Yes, spot on, exactly my case. I added a check to my generator file and if the plugin is missing, I cancel the installation and ask the user to install that plugin first.

@pksunkara Thanks, I get what you mean now. Personally, I don't consider it to be a feasible solution. You need to understand the internal mechanisms of that dependency and call everything accordingly. But I digress, it's an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants