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: support async plugins #8574

Merged
merged 11 commits into from
Jun 18, 2022
Merged

feat: support async plugins #8574

merged 11 commits into from
Jun 18, 2022

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jun 13, 2022

Description

Based on discussion: #8509

Support config.plugins: (Plugin | Plugin[] | Promise<Plugin | Plugin[]>)[]

Additional context

Turns out deep flattening an array of promises only take 3 lines 😄

Side note:

@poyoho it looks like config.worker.plugins isn't flatten and being handled with falsy, apply prop etc like:

const rawUserPlugins = (config.plugins || []).flat(Infinity).filter((p) => {
if (!p) {
return false
} else if (!p.apply) {
return true
} else if (typeof p.apply === 'function') {
return p.apply({ ...config, mode }, configEnv)
} else {
return p.apply === command
}
}) as Plugin[]

Is it intentional?


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy marked this pull request as draft June 13, 2022 18:25
@bluwy
Copy link
Member Author

bluwy commented Jun 13, 2022

Marked as draft. There’s one more case in asyncFlatten that I’ll fix tomorrow.

@poyoho
Copy link
Member

poyoho commented Jun 14, 2022

I think config.worker.plugins needs to flatten and handled apply prop too. 😁

packages/vite/src/node/ssr/ssrTransform.ts Outdated Show resolved Hide resolved
packages/vite/src/node/config.ts Show resolved Hide resolved
packages/vite/src/node/config.ts Outdated Show resolved Hide resolved
@bluwy bluwy marked this pull request as ready for review June 14, 2022 06:34
@bluwy bluwy added the p2-to-be-discussed Enhancement under consideration (priority) label Jun 14, 2022
@bluwy bluwy modified the milestone: 3.0 Jun 14, 2022
@patak-dev patak-dev added p3-significant High priority enhancement (priority) and removed p2-to-be-discussed Enhancement under consideration (priority) labels Jun 17, 2022
patak-dev
patak-dev previously approved these changes Jun 17, 2022
@patak-dev
Copy link
Member

We talked about the PR in today's meeting and we decided to move forward. @bluwy once you resolve the conflicts you can merge it 👍🏼

@antfu
Copy link
Member

antfu commented Jun 18, 2022

Love it! 🔥

@patak-dev patak-dev merged commit caa8a58 into vitejs:main Jun 18, 2022
@bluwy bluwy deleted the feat-async-plugins branch June 18, 2022 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-significant High priority enhancement (priority)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants