Skip to content

Commit 52bb94c

Browse files
authored
fix(dts-plugin): ensure kill fork child process when the task is finished (#2639)
1 parent 3369ecb commit 52bb94c

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

.changeset/green-pants-sip.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/dts-plugin': patch
3+
---
4+
5+
fix(dts-plugin): ensure kill fork child process when the task is finished

packages/dts-plugin/src/core/lib/DtsWorker.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { type RpcWorker, createRpcWorker } from '../rpc/index';
55
import type { RpcMethod } from '../rpc/types';
66
import type { DTSManagerOptions } from '../interfaces/DTSManagerOptions';
77
import type { DTSManager } from './DTSManager';
8+
import { isDebugMode } from './utils';
89

910
export type DtsWorkerOptions = DTSManagerOptions;
1011

@@ -41,9 +42,27 @@ export class DtsWorker {
4142
}
4243

4344
get controlledPromise(): ReturnType<DTSManager['generateTypes']> {
44-
return Promise.resolve(this._res).then(() => {
45-
this.exit();
46-
});
45+
const ensureChildProcessExit = () => {
46+
try {
47+
const pid = this.rpcWorker.process?.pid;
48+
process.kill(pid, 0);
49+
} catch (error) {
50+
if (isDebugMode()) {
51+
console.error(error);
52+
}
53+
}
54+
};
55+
return Promise.resolve(this._res)
56+
.then(() => {
57+
this.exit();
58+
ensureChildProcessExit();
59+
})
60+
.catch((err) => {
61+
if (isDebugMode()) {
62+
console.error(err);
63+
}
64+
ensureChildProcessExit();
65+
});
4766
}
4867

4968
exit(): void {

packages/dts-plugin/src/core/lib/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ export function retrieveTypesAssetsInfo(options: RemoteOptions) {
6969
}
7070

7171
export function isDebugMode() {
72-
return Boolean(process.env['FEDERATION_DEBUG']);
72+
return (
73+
Boolean(process.env['FEDERATION_DEBUG']) ||
74+
process.env['NODE_ENV'] === 'test'
75+
);
7376
}
7477

7578
export const isTSProject = (

0 commit comments

Comments
 (0)