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

refactor: plugin container for Vite 6 #16740

Closed
wants to merge 4 commits into from

Conversation

antfu
Copy link
Member

@antfu antfu commented May 21, 2024

This PR refactors the plugin containers file:

Copy link

stackblitz bot commented May 21, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@antfu
Copy link
Member Author

antfu commented May 21, 2024

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on be9094a: Open

suite result latest scheduled
analogjs failure success
astro failure success
histoire failure success
marko failure success
nuxt failure success
previewjs failure failure
quasar failure success
qwik failure success
rakkas failure success
remix failure success
sveltekit failure success
vike failure success
vite-plugin-svelte failure success
vitepress failure success
vitest failure failure

ladle, laravel, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-pages, vite-plugin-react-swc, vite-plugin-vue, vite-setup-catalogue

@bluwy
Copy link
Member

bluwy commented May 22, 2024

I've yet to thoroughly review this, but wondering, could this be refactored in main? Seems like a nice general refactor otherwise so we keep the environment API changes small. Or does it introduces breaking changes?

@antfu
Copy link
Member Author

antfu commented May 22, 2024

It's based on the new abstraction of the new env pluginConainter - it would require certain efforts to redo it in main - and then solving the conflicts in v6 as well. Do you think that would be worth the effort?

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

After reading the changes, I think making in main and then merging into v6 shouldn't be too hard. Plus we can get the improvements released quicker, and also easily test in ecosystem-ci of this change specifically.

In the future, I'd also like to fix this.load() behaviour not matching Rollup, and it would help reduce the merge conflicts later.

Personally I think it's worth it but it is still your call 😅


addWatchFile(id: string) {
this._container.watchFiles.add(id)
// ;(this._addedImports || (this._addedImports = new Set())).add(id)
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment still needed?

async load(id: string, options?: {}): Promise<LoadResult | null> {
const ssr = this.environment.name !== 'client'
options = options ? { ...options, ssr } : { ssr }
const ctx = new LoadPluginContext(this)
Copy link
Member

Choose a reason for hiding this comment

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

IIUC load() and transform() hooks still need to create its own context everytime? Seems like Rollup does this too with its replaceContext param, so we still need to track _addedImports and call updateModuleLoadAddedImports.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly

Comment on lines +308 to 311
const ctx = this._getPluginContext(plugin)
ctx._resolveSkips = skip
ctx._scan = scan

Copy link
Member

Choose a reason for hiding this comment

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

Re _resolveSkips, is this safe? Wouldn't it leak and share to other hooks too, and then this.resolve() would incorrectly skip the plugin?

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, I fixed it in #17288 by having per-hook context. Rollup does this as well.

@antfu
Copy link
Member Author

antfu commented May 23, 2024

Ok, I will try to redo this on main, so we could also at least ensure it works without env api

@antfu antfu marked this pull request as draft May 23, 2024 14:45
@antfu antfu changed the title refactor: plugin container refactor: plugin container for Vite 6 May 23, 2024
@antfu
Copy link
Member Author

antfu commented May 30, 2024

Made the change/migration in 909782f (#16471)

@antfu antfu closed this May 30, 2024
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.

2 participants