8000 fix: rollback webpack __vfsModules to a Set by elbywan · Pull Request #507 · unjs/unplugin · GitHub
[go: up one dir, main page]

Skip to content

fix: rollback webpack __vfsModules to a Set #507

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

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/rspack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export function getRspackPlugin<UserOptions = Record<string, never>>(
if (plugin.resolveId) {
const vfs = new FakeVirtualModulesPlugin(plugin)
vfs.apply(compiler)
plugin.__vfsModules = new Map()
const vfsModules = new Map<string, Promise<string>>()
plugin.__vfsModules = vfsModules
plugin.__vfs = vfs as any

compiler.hooks.compilation.tap(plugin.name, (compilation, { normalModuleFactory }) => {
Expand Down Expand Up @@ -104,15 +105,15 @@ export function getRspackPlugin<UserOptions = Record<string, never>>(
// If the resolved module does not exist,
// we treat it as a virtual module
if (!fs.existsSync(resolved)) {
if (!plugin.__vfsModules!.has(resolved)) {
if (!vfsModules.has(resolved)) {
const fsPromise = vfs.writeModule(resolved)
plugin.__vfsModules!.set(resolved, fsPromise)
vfsModules.set(resolved, fsPromise)
await fsPromise
}
else {
// Ensure that the module is written to the virtual file system
// before we use it.
await plugin.__vfsModules!.get(resolved)
await vfsModules.get(resolved)
}
resolved = encodeVirtualModuleId(resolved, plugin)
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export interface UnpluginOptions {
export interface ResolvedUnpluginOptions extends UnpluginOptions {
// injected internal objects
__vfs?: VirtualModulesPlugin
__vfsModules?: Map<string, Promise<string>>
__vfsModules?: Map<string, Promise<string>> | Set<string>
__virtualModulePrefix: string
}

Expand Down
7 changes: 4 additions & 3 deletions src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export function getWebpackPlugin<UserOptions = Record<string, never>>(
vfs = new VirtualModulesPlugin()
compiler.options.plugins.push(vfs)
}
plugin.__vfsModules = new Map()
const vfsModules = new Set<string>()
plugin.__vfsModules = vfsModules
plugin.__vfs = vfs

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

// webpack virtual module should pass in the correct path
// https://github.com/unjs/unplugin/pull/155
if (!plugin.__vfsModules!.has(resolved)) {
if (!vfsModules.has(resolved)) {
plugin.__vfs!.writeModule(resolved, '')
plugin.__vfsModules!.set(resolved, Promise.resolve(''))
vfsModules.add(resolved)
}
}

Expand Down
0