kill-me-now 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -4
- package/index.mjs +38 -69
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Kill Me Now
|
|
2
2
|
|
|
3
|
-
Find and kill application processes
|
|
3
|
+
Find and kill application processes by _file path_
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm i -P kill-me-now
|
|
@@ -8,6 +8,42 @@ npm i -P kill-me-now
|
|
|
8
8
|
|
|
9
9
|
## Parameters
|
|
10
10
|
|
|
11
|
-
- A `
|
|
12
|
-
- A `
|
|
13
|
-
-
|
|
11
|
+
- A `name` (which is the _file path_) to identify application processes is _required_
|
|
12
|
+
- A `pid` to *exclude* is _optional_
|
|
13
|
+
- And a `cmd` is _optional_
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
Import `killMeNow`
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
import killMeNow from 'kill-me-now'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Kill all processes on _this path_
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
/**
|
|
27
|
+
* Get the current working directory
|
|
28
|
+
*/
|
|
29
|
+
const cwd = process.cwd()
|
|
30
|
+
|
|
31
|
+
await killMeNow(cwd)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
(This will include the current process represented by `process`)
|
|
35
|
+
|
|
36
|
+
Kill any processes on _this path_ except for _the current process_
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
/**
|
|
40
|
+
* Get the current working directory
|
|
41
|
+
*/
|
|
42
|
+
const cwd = process.cwd()
|
|
43
|
+
/**
|
|
44
|
+
* Get the current process ID
|
|
45
|
+
*/
|
|
46
|
+
const pid = process.pid
|
|
47
|
+
|
|
48
|
+
await killMeNow(cwd, pid)
|
|
49
|
+
```
|
package/index.mjs
CHANGED
|
@@ -21,70 +21,38 @@ const error = debug('kill-me-now:error')
|
|
|
21
21
|
log('`kill-me-now` is awake')
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @param {string}
|
|
24
|
+
* @param {string} alpha
|
|
25
25
|
* @returns {(openFile: Record<string, string>) => boolean}
|
|
26
26
|
*/
|
|
27
|
-
function
|
|
28
|
-
info('
|
|
27
|
+
function getHasName (alpha) {
|
|
28
|
+
info('getHasName')
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* @param {Record<string, string>} openFile
|
|
32
32
|
* @returns {boolean}
|
|
33
33
|
*/
|
|
34
|
-
function
|
|
35
|
-
info('
|
|
34
|
+
return function hasName ({ name: omega }) {
|
|
35
|
+
info('hasName')
|
|
36
36
|
|
|
37
37
|
return (
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @param {Array<Record<string, string>>} openFiles
|
|
44
|
-
* @returns {boolean}
|
|
45
|
-
*/
|
|
46
|
-
return function hasOpenFiles (openFiles) {
|
|
47
|
-
info('hasOpenFiles')
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
openFiles.some(hasFilePath)
|
|
38
|
+
omega.startsWith(alpha)
|
|
51
39
|
)
|
|
52
40
|
}
|
|
53
41
|
}
|
|
54
42
|
|
|
55
43
|
/**
|
|
56
|
-
* @param {
|
|
44
|
+
* @param {number} alpha
|
|
57
45
|
* @returns {(openFile: Record<string, string>) => boolean}
|
|
58
46
|
*/
|
|
59
|
-
function
|
|
60
|
-
info('
|
|
47
|
+
function getHasPid (alpha) {
|
|
48
|
+
info('getHasPid')
|
|
61
49
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
*/
|
|
66
|
-
return function filterForFilePath ({ 'FILE PATH': FILEPATH }) {
|
|
67
|
-
info('filterForFilePath')
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
FILEPATH.startsWith(filePath)
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @param {number} process
|
|
77
|
-
* @returns {(openFile: Record<string, string>) => boolean}
|
|
78
|
-
*/
|
|
79
|
-
function getFilterForProcess (process) {
|
|
80
|
-
info('getFilterForProcess')
|
|
81
|
-
|
|
82
|
-
if (process) {
|
|
83
|
-
return function filterForProcess ({ PROCESS }) {
|
|
84
|
-
info('filterForProcess')
|
|
50
|
+
if (alpha) {
|
|
51
|
+
return function hasPid ({ pid: omega }) {
|
|
52
|
+
info('hasPid')
|
|
85
53
|
|
|
86
54
|
return (
|
|
87
|
-
|
|
55
|
+
omega !== alpha
|
|
88
56
|
)
|
|
89
57
|
}
|
|
90
58
|
}
|
|
@@ -95,18 +63,18 @@ function getFilterForProcess (process) {
|
|
|
95
63
|
}
|
|
96
64
|
|
|
97
65
|
/**
|
|
98
|
-
* @param {string}
|
|
66
|
+
* @param {string} alpha
|
|
99
67
|
* @returns {(openFile: Record<string, string>) => boolean}
|
|
100
68
|
*/
|
|
101
|
-
function
|
|
102
|
-
info('
|
|
69
|
+
function getHasCmd (alpha) {
|
|
70
|
+
info('getHasCmd')
|
|
103
71
|
|
|
104
|
-
if (
|
|
105
|
-
return function
|
|
106
|
-
info('
|
|
72
|
+
if (alpha) {
|
|
73
|
+
return function hasCmd ({ cmd: omega }) {
|
|
74
|
+
info('hasCmd')
|
|
107
75
|
|
|
108
76
|
return (
|
|
109
|
-
|
|
77
|
+
omega === alpha
|
|
110
78
|
)
|
|
111
79
|
}
|
|
112
80
|
}
|
|
@@ -120,15 +88,15 @@ function getFilterForCommand (command) {
|
|
|
120
88
|
* @param {Record<string, string>} openFile
|
|
121
89
|
* @returns {void}
|
|
122
90
|
*/
|
|
123
|
-
function
|
|
124
|
-
info('
|
|
91
|
+
function killProcess ({ pid }) {
|
|
92
|
+
info('killProcess')
|
|
125
93
|
|
|
126
94
|
try {
|
|
127
|
-
log(`Killing process ${
|
|
95
|
+
log(`Killing process ${pid} ...`)
|
|
128
96
|
|
|
129
|
-
process.kill(
|
|
97
|
+
process.kill(pid)
|
|
130
98
|
|
|
131
|
-
log(`Killing process ${
|
|
99
|
+
log(`Killing process ${pid} succeeded.`)
|
|
132
100
|
} catch (e) {
|
|
133
101
|
const {
|
|
134
102
|
code
|
|
@@ -136,24 +104,25 @@ function forEach ({ PROCESS }) {
|
|
|
136
104
|
|
|
137
105
|
if (code !== 'ESRCH') error(e)
|
|
138
106
|
|
|
139
|
-
error(`Killing process ${
|
|
107
|
+
error(`Killing process ${pid} failed.`)
|
|
140
108
|
}
|
|
141
109
|
}
|
|
142
110
|
|
|
143
111
|
/**
|
|
144
|
-
* @param {string}
|
|
145
|
-
* @param {number} [
|
|
146
|
-
* @param {string} [
|
|
112
|
+
* @param {string} name
|
|
113
|
+
* @param {number} [pid] Process ID
|
|
114
|
+
* @param {string} [cmd] Command
|
|
147
115
|
* @returns {Promise<void>}
|
|
148
116
|
*/
|
|
149
|
-
export default async function killMeNow (
|
|
117
|
+
export default async function killMeNow (name, pid, cmd) {
|
|
150
118
|
const lsof = await getLsofArray()
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
.filter(
|
|
156
|
-
.filter(
|
|
157
|
-
.
|
|
119
|
+
const hasName = getHasName(name)
|
|
120
|
+
|
|
121
|
+
if (lsof.some(hasName)) {
|
|
122
|
+
lsof
|
|
123
|
+
.filter(hasName)
|
|
124
|
+
.filter(getHasPid(pid))
|
|
125
|
+
.filter(getHasCmd(cmd))
|
|
126
|
+
.forEach(killProcess)
|
|
158
127
|
}
|
|
159
128
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kill-me-now",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "./index.mjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -11,13 +11,16 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "git://github.com/sequencemedia/kill-me-now.git"
|
|
14
|
+
"url": "git+https://github.com/sequencemedia/kill-me-now.git"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"lint": "eslint .",
|
|
18
18
|
"lint:fix": "npm run lint -- --fix",
|
|
19
19
|
"prepare": "husky"
|
|
20
20
|
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@sequencemedia/lsof": "^0.0.4"
|
|
23
|
+
},
|
|
21
24
|
"devDependencies": {
|
|
22
25
|
"@sequencemedia/eslint-config-standard": "^0.2.52",
|
|
23
26
|
"@sequencemedia/eslint-config-typescript": "^0.1.82",
|
|
@@ -25,8 +28,5 @@
|
|
|
25
28
|
"eslint": "^9.26.0",
|
|
26
29
|
"globals": "^16.0.0",
|
|
27
30
|
"husky": "^9.1.7"
|
|
28
|
-
},
|
|
29
|
-
"dependencies": {
|
|
30
|
-
"@sequencemedia/lsof": "^0.0.2"
|
|
31
31
|
}
|
|
32
32
|
}
|