From 016a37a61a67a033565494941d57344fdf5a24ac Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 31 Dec 2018 02:27:49 +0100 Subject: [PATCH] Require Node.js 8 --- .editorconfig | 5 +-- .gitattributes | 2 +- .gitignore | 1 + .npmrc | 1 + .travis.yml | 1 - index.js | 23 +++++++------- license | 20 +++--------- package.json | 82 +++++++++++++++++++++++++------------------------- readme.md | 14 ++++----- test.js | 6 ++-- 10 files changed, 70 insertions(+), 85 deletions(-) create mode 100644 .npmrc diff --git a/.editorconfig b/.editorconfig index 8f9d77e..1c6314a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,9 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[{package.json,*.yml}] +[*.yml] indent_style = space indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes index 176a458..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -* text=auto +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index 786a75d..704bef1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,3 @@ language: node_js node_js: - '10' - '8' - - '6' diff --git a/index.js b/index.js index 4fd896d..0c5d54b 100644 --- a/index.js +++ b/index.js @@ -2,37 +2,38 @@ const arrify = require('arrify'); const execa = require('execa'); -module.exports = (input, opts) => { +module.exports = async (input, options = {}) => { input = arrify(input); - opts = opts || {}; if (process.platform !== 'win32') { - return Promise.reject(new Error('Windows only')); + throw new Error('Windows only'); } if (input.length === 0) { - return Promise.reject(new Error('PID or image name required')); + throw new Error('PID or image name required'); } const args = []; - if (opts.system && opts.username && opts.password) { - args.push('/s', opts.system, '/u', opts.username, '/p', opts.password); + if (options.system && options.username && options.password) { + args.push('/s', options.system, '/u', options.username, '/p', options.password); } - if (opts.filter) { - args.push('/fi', opts.filter); + if (options.filter) { + args.push('/fi', options.filter); } - if (opts.force) { + if (options.force) { args.push('/f'); } - if (opts.tree) { + if (options.tree) { args.push('/t'); } - input.forEach(x => args.push(typeof x === 'number' ? '/pid' : '/im', x)); + for (const x of input) { + args.push(typeof x === 'number' ? '/pid' : '/im', x); + } return execa('taskkill', args); }; diff --git a/license b/license index 654d0bf..e7af2f7 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index 9a04ae6..ab51324 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,43 @@ { - "name": "taskkill", - "version": "2.0.0", - "description": "Wrapper for the Windows `taskkill` command. Ends one or more tasks or processes.", - "license": "MIT", - "repository": "sindresorhus/taskkill", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && ava" - }, - "files": [ - "index.js" - ], - "keywords": [ - "taskkill", - "task", - "kill", - "terminate", - "windows", - "win", - "win32", - "pid", - "id", - "process", - "processes", - "services" - ], - "dependencies": { - "arrify": "^1.0.0", - "execa": "^0.1.1" - }, - "devDependencies": { - "ava": "*", - "xo": "*" - } + "name": "taskkill", + "version": "2.0.0", + "description": "Wrapper for the Windows `taskkill` command. Ends one or more tasks or processes.", + "license": "MIT", + "repository": "sindresorhus/taskkill", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "test": "xo && ava" + }, + "files": [ + "index.js" + ], + "keywords": [ + "taskkill", + "task", + "kill", + "terminate", + "windows", + "win", + "win32", + "pid", + "id", + "process", + "processes", + "services" + ], + "dependencies": { + "arrify": "^1.0.0", + "execa": "^1.0.0" + }, + "devDependencies": { + "ava": "^1.0.1", + "xo": "^0.23.0" + } } diff --git a/readme.md b/readme.md index ecf4b51..7bf3b4d 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ ## Install ``` -$ npm install --save taskkill +$ npm install taskkill ``` @@ -15,11 +15,9 @@ $ npm install --save taskkill ```js const taskkill = require('taskkill'); -const input = [4970, 4512]; - -taskkill(input).then(() => { - console.log(`Successfully terminated ${input.join(', ')}`); -}); +(async () => { + await taskkill([4970, 4512]); +})(); ``` @@ -29,11 +27,11 @@ See the [`taskkill` docs](https://technet.microsoft.com/en-us/library/bb491009.a ### taskkill(input, [options]) -Returns a promise. +Returns a `Promise`. #### input -Type: `string`, `array` +Type: `string` `string[]` One or more process IDs or image names, but not mixed. diff --git a/test.js b/test.js index 8da3778..0a41d0f 100644 --- a/test.js +++ b/test.js @@ -1,15 +1,15 @@ import childProcess from 'child_process'; import test from 'ava'; -import m from '.'; +import taskkill from '.'; test('kills a process', async t => { const {pid} = childProcess.spawn(process.execPath); - await m(pid, {force: true}); + await taskkill(pid, {force: true}); // Check if the process exists t.throws(() => process.kill(pid)); }); test('throws on not found', async t => { - await t.throwsAsync(m('not-running.exe')); + await t.throwsAsync(taskkill('not-running.exe')); });