Skip to content

Commit 25b5205

Browse files
authored
fix: rollback webpack __vfsModules to use a Set (#507)
1 parent 67edcf4 commit 25b5205

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

src/rspack/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export function getRspackPlugin<UserOptions = Record<string, never>>(
5656
if (plugin.resolveId) {
5757
const vfs = new FakeVirtualModulesPlugin(plugin)
5858
vfs.apply(compiler)
59-
plugin.__vfsModules = new Map()
59+
const vfsModules = new Map<string, Promise<string>>()
60+
plugin.__vfsModules = vfsModules
6061
plugin.__vfs = vfs as any
6162

6263
compiler.hooks.compilation.tap(plugin.name, (compilation, { normalModuleFactory }) => {
@@ -104,15 +105,15 @@ export function getRspackPlugin<UserOptions = Record<string, never>>(
104105
// If the resolved module does not exist,
105106
// we treat it as a virtual module
106107
if (!fs.existsSync(resolved)) {
107-
if (!plugin.__vfsModules!.has(resolved)) {
108+
if (!vfsModules.has(resolved)) {
108109
const fsPromise = vfs.writeModule(resolved)
109-
plugin.__vfsModules!.set(resolved, fsPromise)
110+
vfsModules.set(resolved, fsPromise)
110111
await fsPromise
111112
}
112113
else {
113114
// Ensure that the module is written to the virtual file system
114115
// before we use it.
115-
await plugin.__vfsModules!.get(resolved)
116+
await vfsModules.get(resolved)
116117
}
117118
resolved = encodeVirtualModuleId(resolved, plugin)
118119
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export interface UnpluginOptions {
147147
export interface ResolvedUnpluginOptions extends UnpluginOptions {
148148
// injected internal objects
149149
__vfs?: VirtualModulesPlugin
150-
__vfsModules?: Map<string, Promise<string>>
150+
__vfsModules?: Map<string, Promise<string>> | Set<string>
151151
__virtualModulePrefix: string
152152
}
153153

src/webpack/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export function getWebpackPlugin<UserOptions = Record<string, never>>(
5454
vfs = new VirtualModulesPlugin()
5555
compiler.options.plugins.push(vfs)
5656
}
57-
plugin.__vfsModules = new Map()
57+
const vfsModules = new Set<string>()
58+
plugin.__vfsModules = vfsModules
5859
plugin.__vfs = vfs
5960

6061
const resolverPlugin: ResolvePluginInstance = {
@@ -133,9 +134,9 @@ export function getWebpackPlugin<UserOptions = Record<string, never>>(
133134

134135
// webpack virtual module should pass in the correct path
135136
// https://github.com/unjs/unplugin/pull/155
136-
if (!plugin.__vfsModules!.has(resolved)) {
137+
if (!vfsModules.has(resolved)) {
137138
plugin.__vfs!.writeModule(resolved, '')
138-
plugin.__vfsModules!.set(resolved, Promise.resolve(''))
139+
vfsModules.add(resolved)
139140
}
140141
}
141142

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy