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.
Files changed (3) hide show
  1. package/README.md +40 -4
  2. package/index.mjs +38 -69
  3. 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 `filePath` is to identify application processes is _required_
12
- - A `process` ID to *exclude* is _optional_
13
- - A `command` is _optional_
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} filePath
24
+ * @param {string} alpha
25
25
  * @returns {(openFile: Record<string, string>) => boolean}
26
26
  */
27
- function getHasOpenFiles (filePath) {
28
- info('getHasOpenFiles')
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 hasFilePath ({ 'FILE PATH': FILEPATH }) {
35
- info('hasFilePath')
34
+ return function hasName ({ name: omega }) {
35
+ info('hasName')
36
36
 
37
37
  return (
38
- FILEPATH.startsWith(filePath)
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 {string} filePath
44
+ * @param {number} alpha
57
45
  * @returns {(openFile: Record<string, string>) => boolean}
58
46
  */
59
- function getFilterForFilePath (filePath) {
60
- info('getFilterForFilePath')
47
+ function getHasPid (alpha) {
48
+ info('getHasPid')
61
49
 
62
- /**
63
- * @param {Record<string, string>} openFile
64
- * @returns {boolean}
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
- PROCESS !== process
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} command
66
+ * @param {string} alpha
99
67
  * @returns {(openFile: Record<string, string>) => boolean}
100
68
  */
101
- function getFilterForCommand (command) {
102
- info('getFilterForCommand')
69
+ function getHasCmd (alpha) {
70
+ info('getHasCmd')
103
71
 
104
- if (command) {
105
- return function filterForCommand ({ COMMAND }) {
106
- info('filterForCommand')
72
+ if (alpha) {
73
+ return function hasCmd ({ cmd: omega }) {
74
+ info('hasCmd')
107
75
 
108
76
  return (
109
- COMMAND === command
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 forEach ({ PROCESS }) {
124
- info('forEach')
91
+ function killProcess ({ pid }) {
92
+ info('killProcess')
125
93
 
126
94
  try {
127
- log(`Killing process ${PROCESS} ...`)
95
+ log(`Killing process ${pid} ...`)
128
96
 
129
- process.kill(PROCESS)
97
+ process.kill(pid)
130
98
 
131
- log(`Killing process ${PROCESS} succeeded.`)
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 ${PROCESS} failed.`)
107
+ error(`Killing process ${pid} failed.`)
140
108
  }
141
109
  }
142
110
 
143
111
  /**
144
- * @param {string} filePath
145
- * @param {number} [process] Process ID
146
- * @param {string} [command] Command
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 (filePath, process, command) {
117
+ export default async function killMeNow (name, pid, cmd) {
150
118
  const lsof = await getLsofArray()
151
-
152
- if (lsof.some(getHasOpenFiles(filePath))) {
153
- lsof.flat()
154
- .filter(getFilterForFilePath(filePath))
155
- .filter(getFilterForProcess(process))
156
- .filter(getFilterForCommand(command))
157
- .forEach(forEach)
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.1",
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
  }