Skip to content

Commit

Permalink
feat: use tree-kill instead of terminate (#169)
Browse files Browse the repository at this point in the history
tree-kill license is more permissive.
  • Loading branch information
Dilatorily authored and gregberge committed Dec 11, 2018
1 parent be650a3 commit bb2e27b
Show file tree
Hide file tree
Showing 5 changed files with 1,022 additions and 69 deletions.
2 changes: 1 addition & 1 deletion packages/jest-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"find-process": "^1.2.1",
"inquirer": "^6.2.0",
"spawnd": "^3.5.2",
"terminate": "^2.1.2",
"tree-kill": "^1.2.1",
"wait-port": "^0.2.2"
}
}
6 changes: 3 additions & 3 deletions packages/jest-dev-server/src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import cwd from 'cwd'
import waitPort from 'wait-port'
import findProcess from 'find-process'
import { promisify } from 'util'
import terminate from 'terminate'
import treeKill from 'tree-kill'
import inquirer from 'inquirer'

const DEFAULT_CONFIG = {
Expand All @@ -20,7 +20,7 @@ const DEFAULT_CONFIG = {
usedPortAction: 'ask',
}

const pterminate = promisify(terminate)
const pTreeKill = promisify(treeKill)

const serverLogPrefixer = new stream.Transform({
transform(chunk, encoding, callback) {
Expand Down Expand Up @@ -51,7 +51,7 @@ function logProcDetection(proc, port) {

async function killProc(proc) {
console.log(chalk.yellow(`Killing process ${proc.name}...`))
await pterminate(proc.pid)
await pTreeKill(proc.pid)
console.log(chalk.green(`Successfully killed process ${proc.name}`))
}

Expand Down
2 changes: 1 addition & 1 deletion packages/spawnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"exit": "^0.1.2",
"signal-exit": "^3.0.2",
"terminate": "^2.1.2",
"tree-kill": "^1.2.1",
"wait-port": "^0.2.2"
}
}
8 changes: 4 additions & 4 deletions packages/spawnd/src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { promisify } from 'util'
import { spawn } from 'child_process'
import terminate from 'terminate'
import treeKill from 'tree-kill'
import exit from 'exit'
import onExit from 'signal-exit'

const pterminate = promisify(terminate)
const pTreeKill = promisify(treeKill)

function spawnd(command, options) {
function cleanExit(code = 1) {
if (proc && proc.pid) {
terminate(proc.pid, () => exit(code))
treeKill(proc.pid, () => exit(code))
} else {
exit(code)
}
Expand All @@ -28,7 +28,7 @@ function spawnd(command, options) {
removeExitHandler()
proc.removeAllListeners('exit')
proc.removeAllListeners('error')
return pterminate(proc.pid).catch(() => {
return pTreeKill(proc.pid).catch(() => {
/* ignore error */
})
}
Expand Down
Loading

0 comments on commit bb2e27b

Please sign in to comment.