Skip to content

Commit

Permalink
fix: kill child process on exit (swc)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jun 15, 2023
1 parent bd80c60 commit 54ed833
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/compiler/swc/swc-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { readFileSync } from 'fs';
import { join } from 'path';
import { Configuration } from '../../configuration';
import { ERROR_PREFIX } from '../../ui';
import { treeKillSync } from '../../utils/tree-kill';
import { BaseCompiler } from '../base-compiler';
import { swcDefaultsFactory } from '../defaults/swc-defaults';
import { PluginMetadataGenerator } from '../plugins/plugin-metadata-generator';
Expand Down Expand Up @@ -73,9 +74,17 @@ export class SwcCompiler extends BaseCompiler {
JSON.stringify(configuration.compilerOptions.plugins ?? []),
];

fork(join(__dirname, 'forked-type-checker.js'), args, {
cwd: process.cwd(),
});
const childProcessRef = fork(
join(__dirname, 'forked-type-checker.js'),
args,
{
cwd: process.cwd(),
},
);
process.on(
'exit',
() => childProcessRef && treeKillSync(childProcessRef.pid!),
);
} else {
const { readonlyVisitors } = this.loadPlugins(
configuration,
Expand Down Expand Up @@ -155,7 +164,7 @@ export class SwcCompiler extends BaseCompiler {
ERROR_PREFIX +
' Failed to load "@swc/cli" and "@swc/core" packages. Please, install them by running "npm i -D @swc/cli @swc/core".',
);
throw err;
process.exit(1);
}
}

Expand Down

0 comments on commit 54ed833

Please sign in to comment.