fix: 当lint检查出问题后,不能在终端终止

master^2
xingyu4j 2026-05-20 16:39:03 +08:00
parent fda4b39c01
commit 4d3c481a93
1 changed files with 21 additions and 13 deletions

View File

@ -1,5 +1,7 @@
import type { CAC } from 'cac'; import type { CAC } from 'cac';
import { execSync } from 'node:child_process';
import { execaCommand } from '@vben/node-utils'; import { execaCommand } from '@vben/node-utils';
interface LintCommandOptions { interface LintCommandOptions {
@ -32,26 +34,32 @@ async function runLint({ format, threads }: LintCommandOptions) {
}); });
return; return;
} }
const controller = new AbortController(); const subprocesses = [
const { signal: cancelSignal } = controller; execaCommand(`oxfmt --check${threadsArg}`, { stdio: 'inherit' }),
execaCommand(`oxlint${threadsArg}`, { stdio: 'inherit' }),
const commands = [ execaCommand(`eslint . --cache`, { stdio: 'inherit' }),
execaCommand(`oxfmt --check${threadsArg}`, {
cancelSignal,
stdio: 'inherit',
}),
execaCommand(`oxlint${threadsArg}`, { cancelSignal, stdio: 'inherit' }),
execaCommand(`eslint . --cache`, { cancelSignal, stdio: 'inherit' }),
execaCommand(`stylelint "**/*.{vue,css,less,scss}" --cache`, { execaCommand(`stylelint "**/*.{vue,css,less,scss}" --cache`, {
cancelSignal,
stdio: 'inherit', stdio: 'inherit',
}), }),
]; ];
try { try {
await Promise.all(commands); await Promise.all(subprocesses);
} catch (error) { } catch (error) {
controller.abort(); for (const subprocess of subprocesses) {
try {
if (process.platform === 'win32' && subprocess.pid) {
execSync(`taskkill /F /T /PID ${subprocess.pid}`, {
stdio: 'ignore',
});
} else {
subprocess.kill('SIGKILL');
}
} catch {
// process may have already exited
}
}
await Promise.allSettled(subprocesses);
throw error; throw error;
} }
} }