-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
refactor: [hookName].handler
in plugins
#19586
base: main
Are you sure you want to change the base?
Conversation
// for backward compat, make `plugin.transform` a function | ||
// but still keep the `handler` property | ||
// so that we can use `filter` property in the future | ||
plugin.transform = transformHook.handler | ||
;(plugin.transform as any).handler = transformHook.handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, to handle this line:
https://github.com/unocss/unocss/blob/94efa2edc9897dcfb5f40059c11ba22ec9ca0631/packages-integrations/vite/src/modes/global/build.ts#L45
/ecosystem-ci run |
commit: |
This comment was marked as outdated.
This comment was marked as outdated.
📝 Ran ecosystem CI on
✅ analogjs, astro, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, react-router, storybook, unocss, vike, vite-environment-examples, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-vue, vite-plugin-cloudflare, vite-setup-catalogue, vitepress, vitest, vuepress, waku |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should merge this one in Vite 6.3, just to play safe. But I'm ok if you'd like to go with it in a patch to avoid blocking other work.
The diff is massive. Adding a filter would be a common pattern in the future, and I think the boat already sailed but I wonder if it would have been better to keep the hooks as function only and add new properties for each to configure them. It would also have avoided all the indirections to deal with the hook being an object or a function.
transformConfig: {
filter: /x/,
order: 'pre'
}
transform(code, id) {
return transformed(code)
}
I'm fine with merging in 6.3 👌
Yeah, maybe that would have made some places easier to handle. |
9ea022a
to
576695a
Compare
I rebased this PR on top of #19588 as that one should be safe to merge in a patch and this PR conflicts with that one. |
576695a
to
6566f12
Compare
Description
Moves some
plugin[hookName]
toplugin[hookName].handler
so that we can addfilter
without a big diff.This PR has a big diff, but it only moves the hooks under
.handler
so it shouldn't change any behavior unless the 3rd party plugin / framework calls the plugin manually.