Skip to content

Commit ca42080

Browse files
authored
fix(rspack): remove virtual plugin cleanup signal handlers (#541)
* fix(rspack): remove virtual plugin cleanup signal handlers * chore: make cleanup listener register lazily
1 parent 91df19a commit ca42080

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/rspack/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ export function isVirtualModuleId(encoded: string, plugin: ResolvedUnpluginOptio
1818
export class FakeVirtualModulesPlugin {
1919
name = 'FakeVirtualModulesPlugin'
2020
static counters: Map<string, number> = new Map<string, number>()
21+
static initCleanup: boolean = false
2122

22-
static {
23-
['SIGINT', 'SIGTERM', 'SIGQUIT', 'exit'].forEach((event) => {
24-
process.once(event, () => {
25-
this.counters.forEach((_, dir) => {
23+
constructor(private plugin: ResolvedUnpluginOptions) {
24+
if (!FakeVirtualModulesPlugin.initCleanup) {
25+
FakeVirtualModulesPlugin.initCleanup = true
26+
process.once('exit', () => {
27+
FakeVirtualModulesPlugin.counters.forEach((_, dir) => {
2628
fs.rmSync(dir, { recursive: true, force: true })
2729
})
2830
})
29-
})
31+
}
3032
}
3133

32-
constructor(private plugin: ResolvedUnpluginOptions) {}
33-
3434
apply(compiler: Compiler): void {
3535
const dir = this.plugin.__virtualModulePrefix
3636
if (!fs.existsSync(dir)) {

0 commit comments

Comments
 (0)