| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ export function getRspackPlugin<UserOptions = Record<string, never>>( | |||
| 32 | 32 | apply(compiler) { | |
| 33 | 33 | // We need the prefix of virtual modules to be an absolute path so rspack lets us load them (even if it's made up) | |
| 34 | 34 | // In the loader we strip the made up prefix path again | |
| 35 | - const VIRTUAL_MODULE_PREFIX = resolve(compiler.options.context ?? process.cwd(), 'node_modules/.virtual') | ||
| 35 | + const VIRTUAL_MODULE_PREFIX = resolve(compiler.options.context ?? process.cwd(), 'node_modules/.virtual', process.pid.toString()) | ||
| 36 | 36 | ||
| 37 | 37 | const meta: UnpluginContextMeta = { | |
| 38 | 38 | framework: 'rspack', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,19 +17,37 @@ export function isVirtualModuleId(encoded: string, plugin: ResolvedUnpluginOptio | |||
| 17 | 17 | ||
| 18 | 18 | export class FakeVirtualModulesPlugin { | |
| 19 | 19 | name = 'FakeVirtualModulesPlugin' | |
| 20 | - static counter = 0 | ||
| 20 | + static counters: Map<string, number> = new Map<string, number>() | ||
| 21 | + | ||
| 22 | + static { | ||
| 23 | + ['SIGINT', 'SIGTERM', 'SIGQUIT', 'exit'].forEach((event) => { | ||
| 24 | + process.once(event, () => { | ||
| 25 | + this.counters.forEach((_, dir) => { | ||
| 26 | + fs.rmSync(dir, { recursive: true, force: true }) | ||
| 27 | + }) | ||
| 28 | + }) | ||
| 29 | + }) | ||
| 30 | + } | ||
| 31 | + | ||
| 21 | 32 | constructor(private plugin: ResolvedUnpluginOptions) {} | |
| 22 | 33 | ||
| 23 | 34 | apply(compiler: Compiler): void { | |
| 24 | - FakeVirtualModulesPlugin.counter++ | ||
| 25 | 35 | const dir = this.plugin.__virtualModulePrefix | |
| 26 | 36 | if (!fs.existsSync(dir)) { | |
| 27 | 37 | fs.mkdirSync(dir, { recursive: true }) | |
| 28 | 38 | } | |
| 39 | + const counter = FakeVirtualModulesPlugin.counters.get(dir) ?? 0 | ||
| 40 | + FakeVirtualModulesPlugin.counters.set(dir, counter + 1) | ||
| 41 | + | ||
| 29 | 42 | compiler.hooks.shutdown.tap(this.name, () => { | |
| 30 | - if (--FakeVirtualModulesPlugin.counter === 0) { | ||
| 43 | + const counter = (FakeVirtualModulesPlugin.counters.get(dir) ?? 1) - 1 | ||
| 44 | + if (counter === 0) { | ||
| 45 | + FakeVirtualModulesPlugin.counters.delete(dir) | ||
| 31 | 46 | fs.rmSync(dir, { recursive: true, force: true }) | |
| 32 | 47 | } | |
| 48 | + else { | ||
| 49 | + FakeVirtualModulesPlugin.counters.set(dir, counter) | ||
| 50 | + } | ||
| 33 | 51 | }) | |
| 34 | 52 | } | |
| 35 | 53 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments