From 141341ad64195d62de219b7be75daf735d266965 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 22 Oct 2019 02:15:03 +0200 Subject: [PATCH] fix: unnecessary terminate logic --- src/run.js | 4 +--- src/util/platform.js | 4 ---- src/util/terminate.js | 42 ------------------------------------------ src/util/terminate.sh | 12 ------------ 4 files changed, 1 insertion(+), 61 deletions(-) delete mode 100644 src/util/platform.js delete mode 100644 src/util/terminate.js delete mode 100755 src/util/terminate.sh diff --git a/src/run.js b/src/run.js index e411105..d4601b7 100644 --- a/src/run.js +++ b/src/run.js @@ -3,7 +3,6 @@ const pty = require('node-pty') const chalk = require('chalk') const consola = require('consola') const nodeCleanup = require('node-cleanup') -const { terminate } = require('./util/terminate') /** @typedef {import('node-pty').IPty} IPty */ @@ -143,8 +142,7 @@ exports.runScript = (script, folder, streaming) => { exports.killAll = () => { for (const child of children) { - terminate(child, process.cwd()) - .then(() => child.kill()) + child.kill() } children.clear() } diff --git a/src/util/platform.js b/src/util/platform.js deleted file mode 100644 index f63af7a..0000000 --- a/src/util/platform.js +++ /dev/null @@ -1,4 +0,0 @@ -// OS -exports.isWindows = process.platform === 'win32' -exports.isMacintosh = process.platform === 'darwin' -exports.isLinux = process.platform === 'linux' diff --git a/src/util/terminate.js b/src/util/terminate.js deleted file mode 100644 index eda2d8e..0000000 --- a/src/util/terminate.js +++ /dev/null @@ -1,42 +0,0 @@ -const util = require('util') -const cp = require('child_process') -const path = require('path') -const { - isWindows, - isLinux, - isMacintosh, -} = require('./platform') - -const execFile = util.promisify(cp.execFile) -const spawn = util.promisify(cp.spawn) - -exports.terminate = async function (childProcess, cwd) { - if (isWindows) { - try { - let options = { - stdio: ['pipe', 'pipe', 'ignore'], - } - if (cwd) { - options.cwd = cwd - } - await execFile('taskkill', ['/T', '/F', '/PID', childProcess.pid.toString()], options) - } catch (err) { - return { success: false, error: err } - } - } else if (isLinux || isMacintosh) { - try { - let cmd = path.resolve(__dirname, './terminate.sh') - let result = await spawn(cmd, [childProcess.pid.toString()], { - cwd, - }) - if (result.error) { - return { success: false, error: result.error } - } - } catch (err) { - return { success: false, error: err } - } - } else { - childProcess.kill('SIGKILL') - } - return { success: true } -} diff --git a/src/util/terminate.sh b/src/util/terminate.sh deleted file mode 100755 index d3b8121..0000000 --- a/src/util/terminate.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -terminateTree() { - for cpid in $(/usr/bin/pgrep -P $1); do - terminateTree $cpid - done - kill -9 $1 > /dev/null 2>&1 -} - -for pid in $*; do - terminateTree $pid -done