-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Expose pendingRequests #6011
Comments
Some background:
So now I'm using it in |
Answer from rollup side: rollup/rollup#4294 (comment)
@KaelWD does getModuleIds() work in Vite also? Or should we rename this issue to implement/fix it? |
|
I think I managed the same result without return (await Promise.all(
- Array.from(server._pendingRequests, ([k, v]) => {
- const module = server.moduleGraph.urlToModuleMap.get(k)
- return module?.id && !blockingModules.has(module.id)
- ? v.then(() => module.id)
+ Array.from(server.moduleGraph.urlToModuleMap.entries(), ([k, v]) => {
+ return !k.startsWith('/@id/') && v.transformResult == null && !blockingModules.has(v.id!)
+ ? server.transformRequest(k).then(() => module.id)
: null
}).filter(v => v != null) |
This might have the same problem as rollup/rollup#4296 |
@KaelWD I'm wondering what's the status of the feature request now. Vite 2.9 had made changes to |
FWIW the signature for |
Not sure, I've been using the urlToModuleMap + server.transformRequest solution since december: https://github.com/vuetifyjs/vuetify-loader/blob/ac5af823f1bfd8bc79dc3eb353eed64adef34421/packages/vite-plugin/src/stylesPlugin.ts#L44-L56 I haven't tried vite 3 yet to see if this still works, having both vite and the plugin waiting for files sounds like it could cause some problems. |
2.8.6 had the above problem ( |
I still don't have a stable version of this, everything I've tried eventually gets stuck on random files. The rollup version on the other hand is pretty simple and works great: const modules = Array.from(context.getModuleIds())
.filter(id => {
return !blockingModules.has(id) && // Ignore the current file
!/\w\.(s[ac]|c)ss/.test(id) // Ignore stylesheets
})
.map(id => context.getModuleInfo(id)!)
.filter(module => module.code == null) // Ignore already loaded modules
pendingModules = modules.map(module => module.id)
if (!pendingModules.length) return 0
const promises = modules.map(module => context.load(module))
await Promise.all(promises) |
I actually had to this something like this for my plugin, and thanks to your issue and code @KaelWD I implemented something similar like so: // wait for all modules loaded before getting the entry ids
const seen = new Set()
let modulesToWait = []
do {
modulesToWait = []
for (const id of this.getModuleIds()) {
if (seen.has(id)) continue
seen.add(id)
if (id.startsWith('\0')) continue
const info = this.getModuleInfo(id)
if (info?.isExternal) continue
modulesToWait.push(this.load({ id }).catch(() => {}))
}
// TODO: timeout if too long
await Promise.all(modulesToWait)
} while (modulesToWait.length > 0) Besides the TODO, and that I've only tested it on a small project, it seems to be working well. I suppose this would work for Rollup too and I hope we can find a trick that works in both without Vite exposing |
I think the trick above should be good for now. Since we can't guarantee the stability of |
Clear and concise description of the problem
I'm writing a plugin that collects a list of all the imported sass files and writes them to a single file instead. I can't write them one by one because sass throws "variable not defined", so the transform request for the combined file has to be stalled until no other modules are waiting to be resolved.
Suggested solution
Currently I'm using
server._pendingRequests
which is exactly what I was looking for, but it is a private property so really needs to be documented and exposed in a way that would be compatible with rollup. I proposed usingthis.pendingRequests
in rollup/rollup#4294.Alternative
No response
Additional context
https://github.com/vuetifyjs/vuetify-loader/blob/274ce9ced8da65107b7544f9cdb2d82d463be313/packages/vite-plugin/src/stylesPlugin.ts
vuetifyjs/vuetify-loader#225
rollup/rollup#4294
Validations
The text was updated successfully, but these errors were encountered: