Comparing version
45
index.js
'use strict'; | ||
const arrify = require('arrify'); | ||
@@ -10,3 +9,17 @@ const taskkill = require('taskkill'); | ||
const winKill = (input, options) => { | ||
const missingBinaryError = async (command, arguments_) => { | ||
try { | ||
return await execa(command, arguments_); | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
const newError = new Error(`\`${command}\` doesn't seem to be installed and is required by fkill`); | ||
newError.sourceError = error; | ||
throw newError; | ||
} | ||
throw error; | ||
} | ||
}; | ||
const windowsKill = (input, options) => { | ||
return taskkill(input, { | ||
@@ -18,16 +31,16 @@ force: options.force, | ||
const macOSKill = (input, options) => { | ||
const macosKill = (input, options) => { | ||
const killByName = typeof input === 'string'; | ||
const cmd = killByName ? 'pkill' : 'kill'; | ||
const args = [input]; | ||
const command = killByName ? 'pkill' : 'kill'; | ||
const arguments_ = [input]; | ||
if (options.force) { | ||
args.unshift('-9'); | ||
arguments_.unshift('-9'); | ||
} | ||
if (killByName && options.ignoreCase) { | ||
args.unshift('-i'); | ||
arguments_.unshift('-i'); | ||
} | ||
return execa(cmd, args); | ||
return missingBinaryError(command, arguments_); | ||
}; | ||
@@ -37,14 +50,14 @@ | ||
const killByName = typeof input === 'string'; | ||
const cmd = killByName ? 'killall' : 'kill'; | ||
const args = [input]; | ||
const command = killByName ? 'killall' : 'kill'; | ||
const arguments_ = [input]; | ||
if (options.force) { | ||
args.unshift('-9'); | ||
arguments_.unshift('-9'); | ||
} | ||
if (killByName && options.ignoreCase) { | ||
args.unshift('-I'); | ||
arguments_.unshift('-I'); | ||
} | ||
return execa(cmd, args); | ||
return missingBinaryError(command, arguments_); | ||
}; | ||
@@ -54,7 +67,7 @@ | ||
if (process.platform === 'darwin') { | ||
return macOSKill; | ||
return macosKill; | ||
} | ||
if (process.platform === 'win32') { | ||
return winKill; | ||
return windowsKill; | ||
} | ||
@@ -103,3 +116,3 @@ | ||
if (errors.length > 0) { | ||
if (errors.length > 0 && !options.silent) { | ||
throw new AggregateError(errors); | ||
@@ -106,0 +119,0 @@ } |
{ | ||
"name": "fkill", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"description": "Fabulously kill processes. Cross-platform.", | ||
@@ -40,8 +40,8 @@ "license": "MIT", | ||
"dependencies": { | ||
"aggregate-error": "^2.2.0", | ||
"arrify": "^1.0.1", | ||
"aggregate-error": "^3.0.0", | ||
"arrify": "^2.0.1", | ||
"execa": "^1.0.0", | ||
"pid-from-port": "^1.1.3", | ||
"process-exists": "^3.1.0", | ||
"taskkill": "^2.0.0" | ||
"taskkill": "^3.0.0" | ||
}, | ||
@@ -51,3 +51,3 @@ "devDependencies": { | ||
"delay": "^4.1.0", | ||
"get-port": "^4.2.0", | ||
"get-port": "^5.0.0", | ||
"noop-process": "^3.1.0", | ||
@@ -54,0 +54,0 @@ "tsd": "^0.7.1", |
@@ -56,3 +56,3 @@ <h1 align="center"> | ||
Type: `Object` | ||
Type: `object` | ||
@@ -82,3 +82,10 @@ ##### force | ||
##### silent | ||
Type: `boolean`<br> | ||
Default: `false` | ||
Suppress all error messages. For example: `Process doesn't exist`. | ||
## Related | ||
@@ -88,6 +95,1 @@ | ||
- [alfred-fkill](https://github.com/SamVerschueren/alfred-fkill) - Alfred workflow for this module | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
7409
7.5%142
9.23%93
2.2%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated