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 nested plugin #4657

Merged
merged 6 commits into from Oct 12, 2022
Merged

feat: support nested plugin #4657

merged 6 commits into from Oct 12, 2022

Conversation

sxzz
Copy link
Contributor

@sxzz sxzz commented Oct 10, 2022

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Support nested plugin

{
  plugins: [[p1, p2], p3, p4],
}

Since Vite supported this feature already. I think Rollup should have it too.

Consider the case:

const plugin = {
  buildStart: {
    order: 'pre',
    handler() {
      // actual implementation
    }
  }
}

When using object hooks, there's no way to put order both pre and post in the one plugin ATM.


After this PR:

const plugin = [
	{
	  buildStart: {
	    order: 'pre',
	    handler() {
	      // actual implementation
	    }
	  }
	},
	{
	  buildStart: {
	    order: 'post',
	    handler() {
	      // actual implementation
	    }
	  }
	}
]

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Very nice! See my comment. We would also need some documentation for this, though. You should update the types and mention array support in the plugins and output.plugins sections of the 999-big-list-of-options.md.

One last thing to consider is that ideally, the --configPlugin option should support arrays as well. Which means we should probably replace

const plugins = Array.isArray(commandPlugin) ? commandPlugin : [commandPlugin];
with something like

const plugins = ensureArray(commandPlugin).flat(Infinity).filter(Boolean);

as well.

src/utils/options/normalizeInputOptions.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 12, 2022

Codecov Report

Merging #4657 (1558295) into master (e52bea3) will not change coverage.
The diff coverage is 80.00%.

@@           Coverage Diff           @@
##           master    #4657   +/-   ##
=======================================
  Coverage   99.06%   99.06%           
=======================================
  Files         214      214           
  Lines        7558     7558           
  Branches     2098     2097    -1     
=======================================
  Hits         7487     7487           
  Misses         23       23           
  Partials       48       48           
Impacted Files Coverage Δ
src/utils/options/mergeOptions.ts 100.00% <ø> (ø)
src/utils/options/normalizeInputOptions.ts 100.00% <ø> (ø)
src/utils/options/normalizeOutputOptions.ts 100.00% <ø> (ø)
src/utils/timers.ts 92.15% <ø> (ø)
cli/run/commandPlugins.ts 93.02% <75.00%> (-0.16%) ⬇️
src/utils/options/options.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Very nice!

@lukastaegert lukastaegert enabled auto-merge (squash) October 12, 2022 08:16
@sxzz
Copy link
Contributor Author

sxzz commented Oct 12, 2022

Thanks for your guidance. I was very impressed with your presentation at ViteConf!

@sxzz
Copy link
Contributor Author

sxzz commented Oct 12, 2022

@lukastaegert Coverage seems to have failed. I just removed ! type assertion and formatted it.
image

@lukastaegert lukastaegert merged commit f7b7689 into rollup:master Oct 12, 2022
@sxzz sxzz deleted the feat/nested-plugin branch October 12, 2022 08:36
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.1.0. You can test it via npm install rollup.

@lukastaegert
Copy link
Member

Coverage seems to have failed

No worries. At some point I guess we should add the missing test, but this was indeed unrelated to your PR.

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.

None yet

3 participants