Parcourir la source

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

xingyu4j il y a 3 semaines
Parent
commit
4d3c481a93
1 fichiers modifiés avec 21 ajouts et 13 suppressions
  1. 21 13
      scripts/vsh/src/lint/index.ts

+ 21 - 13
scripts/vsh/src/lint/index.ts

@@ -1,5 +1,7 @@
 import type { CAC } from 'cac';
 
+import { execSync } from 'node:child_process';
+
 import { execaCommand } from '@vben/node-utils';
 
 interface LintCommandOptions {
@@ -32,26 +34,32 @@ async function runLint({ format, threads }: LintCommandOptions) {
     });
     return;
   }
-  const controller = new AbortController();
-  const { signal: cancelSignal } = controller;
-
-  const commands = [
-    execaCommand(`oxfmt --check${threadsArg}`, {
-      cancelSignal,
-      stdio: 'inherit',
-    }),
-    execaCommand(`oxlint${threadsArg}`, { cancelSignal, stdio: 'inherit' }),
-    execaCommand(`eslint . --cache`, { cancelSignal, stdio: 'inherit' }),
+  const subprocesses = [
+    execaCommand(`oxfmt --check${threadsArg}`, { stdio: 'inherit' }),
+    execaCommand(`oxlint${threadsArg}`, { stdio: 'inherit' }),
+    execaCommand(`eslint . --cache`, { stdio: 'inherit' }),
     execaCommand(`stylelint "**/*.{vue,css,less,scss}" --cache`, {
-      cancelSignal,
       stdio: 'inherit',
     }),
   ];
 
   try {
-    await Promise.all(commands);
+    await Promise.all(subprocesses);
   } 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;
   }
 }