fix(types): widen RollupConfig.plugins to accept Rolldown-typed plugins [v3] - #4483
fix(types): widen RollupConfig.plugins to accept Rolldown-typed plugins [v3]#4483dargmuesli wants to merge 2 commits into
Conversation
Vite 8 changed its own Plugin type to extend Rolldown.Plugin, so plugin factories typed against Vite (e.g. @vitejs/plugin-vue's vue()) no longer satisfy rollupConfig.plugins, which is typed against real Rollup's Plugin. rollupConfig is already reused for the rolldown builder internally, so widen the public type and keep the two real rollup() call sites strict via a local cast. Fixes nitrojs#4482
|
@dargmuesli is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesRollup plugin typing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
| // Vite's `Plugin` extends `Rolldown.Plugin` instead of Rollup's own type. | ||
| // `rollupConfig` is also reused for the `rolldown` builder (see | ||
| // `build/vite/bundler.ts`), so accept either shape here. | ||
| plugins?: RollupInputOptions["plugins"] | RolldownInputOptions["plugins"]; |
There was a problem hiding this comment.
Maybe we could allow a mix of both plugins in same array?
There was a problem hiding this comment.
Makes sense! Pushed a commit for this :) let me know if it looks alright
Summary
Fixes #4482.
Vite 8 changed its own
Plugintype toextends Rolldown.Plugin<A>(Vite now bundles Rolldown as its internal bundler instead of Rollup+esbuild). Any plugin factory typed against Vite'sPlugin, e.g.@vitejs/plugin-vue'svue(), is therefore now structurally a Rolldown plugin. Nitro'srollupConfig.pluginsis typed against therolluppackage'sPlugin, so passing a Vite 8 plugin there no longer type-checks.nitro.options.rollupConfigis already deliberately reused across both therollupandrolldownbuilders (see the// Added for backward compatibilitycasts insrc/build/vite/bundler.ts) so this widens the publicpluginsfield to accept either bundler's plugin shape, and adds a narrowas RollupOptionscast at the two places that call therolluppackage (rollup.rollup(),rollup.watch()), which still need the strict, Rollup-only type.Note: this targets main, companion PR for v2 now open there: #4484.
Changes
src/types/build.ts:RollupConfig.pluginsis nowRollupInputOptions["plugins"] | RolldownInputOptions["plugins"]instead of being locked to Rollup's own type.src/build/rollup/prod.ts: castrollupConfigtoRollupOptionsat therollup.rollup()call site.src/build/rollup/dev.ts: same cast at therollup.watch()call site.