Skip to content

Expose pendingRequests #4294

@KaelWD

Description

@KaelWD

Feature Use Case

I'm writing a plugin that needs to make modifications to a file based on other files in the project. In vite I'm using the transform hook with server._pendingRequests to check if I'm the only module left, but there's nothing like this exposed in rollup.

Feature Proposal

Something similar to vite: https://github.com/vitejs/vite/blob/b625a2cf3730fda94d934b23bcec0c859bfa0b24/packages/vite/src/node/server/transformRequest.ts#L49-L52

ModuleLoader:

+    public pendingRequests = new Map()
     async fetchModule({ id, meta, moduleSideEffects, syntheticNamedExports }, importer, isEntry) {
...
         this.graph.watchFiles[id] = true;
-        await this.addModuleSource(id, importer, module);
+        const promise = this.addModuleSource(id, importer, module)
+        this.pendingRequests.set(id, promise.then(() => module))
+        await promise;
+        this.pendingRequests.delete(id)
         const resolveStaticDependencyPromises = this.getResolveStaticDependencyPromises(module)

PluginContext:

    const context = {
+       pendingRequests: graph.moduleLoader.pendingRequests,
        addWatchFile(id) {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions