Skip to content

feat: implement plugin execution order #6411

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

Merged
merged 1 commit into from
Jun 7, 2021

Conversation

fangbinwei
Copy link
Collaborator

@fangbinwei fangbinwei commented Apr 9, 2021

  • test
  • doc

If there is nothing wrong with the code and design, I can try to add documentation

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Underlying tools
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

By default, the plugins are executed in the same order as before I believe

Other information:

related to #5106, #6251

Design

interface

interface Plugin {
  (): any
  after?: string|Array<string>
}

Example

vue-cli-plugin-foo/generator/index.js

module.exports = api => {
  api.render('./template')
}

vue-cli-plugin-bar/generator/index.js

module.exports = api => {
  api.render('./template')
}
module.exports.after = 'vue-cli-plugin-bar'

the 'after' can be used to fine-tune the execution order

Implement

Topological Sort Algorithm sorts the plugins by 'after'. see leetcode 210

@fangbinwei fangbinwei changed the title feat(wip): implement generator execution order feat(wip): implement plugin execution order Apr 15, 2021
@fangbinwei fangbinwei changed the title feat(wip): implement plugin execution order feat: implement plugin execution order Apr 19, 2021
@fangbinwei fangbinwei marked this pull request as ready for review April 19, 2021 18:37
@haoqunjiang
Copy link
Member

I like this idea! after will be very useful.

But I'm not so sure about stage. To actually use it we need to export quite a lot of stage constants and then the internal workflow of Vue CLI becomes somehow public. I'm not sure it's maintainable.

@fangbinwei
Copy link
Collaborator Author

stage is just to ensure that the generator of @vue/cli-service is invoked firstly, and it's a substitution of sortObject. Even without 'stage', 'after' can work with the current code. Or we can just mention 'after' in the documentation?

@haoqunjiang
Copy link
Member

haoqunjiang commented Apr 28, 2021

Yeah, I think it can be kept as an implementation detail until we figure out a better way to use it.

In the current state, I feel it's like z-index in CSS, and z-index is very hard to manage unless there's a design system to put some constraint on it…

Copy link
Member

@haoqunjiang haoqunjiang left a comment

Choose a reason for hiding this comment

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

The implementation looks great to me.
Let's ship it first and add documentation in another PR later.

@haoqunjiang haoqunjiang merged commit 4be4bb3 into vuejs:dev Jun 7, 2021
@leookun
Copy link

leookun commented Feb 4, 2024

hey,wonderful realization!
But I can't seem to put some plugin ahead of built-in:commands/serve, built-in:commands/serve is the first

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

Successfully merging this pull request may close these issues.

3 participants