-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
feat: implement hook filters #19602
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: implement hook filters #19602
Conversation
|
/ecosystem-ci run |
commit: |
This comment was marked as outdated.
This comment was marked as outdated.
|
📝 Ran ecosystem CI on
✅ laravel, quasar, histoire, analogjs, marko, ladle, vike, rakkas, qwik, vite-environment-examples, vite-plugin-vue, vite-plugin-cloudflare, react-router, storybook, vite-plugin-react, vite-plugin-svelte, vite-plugin-react-swc, vite-setup-catalogue, sveltekit, astro, previewjs, vuepress, unocss, vitest, vite-plugin-pwa, waku, vitepress |
| const cwd = process.cwd() | ||
| return f | ||
| ? (id) => { | ||
| const normalizedId = normalizePath(path.relative(cwd, id)) |
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.
what happens with virtual ids here? Won't the virtual id end up mingled with the cwd path?
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.
It is passed as-is, probably because path.isAbsolute(id) returns false.
I've added a test for virtual ids 👍 : c3b3f70
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.
Ah, that's right. And it works fine for virtual:module too.
One issue we could have is that some virtual module ids start with a slash. For example, our own /@react-refresh from the plugin react. In this case, you'll end up with something like ../../../@react-refresh and the filter will fail.
Maybe it is fine because when someone adds a filter it is expected that the plugin won't be handling virtual modules and only get paths ids? And given that the relative path is below cwd, they all end up reject (by chance, it feels very hacky but it works).
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.
Yeah, virtual modules starting with a slash would be normalized unintentionally. This was happening with createFilter from pluginutils, so I assume it won't be a problem.
https://github.com/rollup/plugins/blob/master/packages/pluginutils/src/createFilter.ts
| if (idFilter && !idFilter(id)) { | ||
| return | ||
| } |
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.
nice that you can do this without performance penalty over the current environment injection
|
Added one more change to align with pluginutils: 32c1283 |
<!-- Thank you for contributing! --> ### Description Ported tests from vitejs/vite#19602 to ensure the behavior is consistent.
Description
Built on top of #19586This PR implements hook filters that are supported by rolldown.
It does not improve performance unless rolldown is used, but this would improve performance when we migrate to rolldown and would reduce the diff between rolldown powered Vite and rollup powered Vite.