arisa 4.0.14 → 4.0.16
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/package.json +1 -1
- package/src/index.js +3 -2
- package/src/runtime/process-ids.js +9 -0
- package/test/process-ids.test.js +14 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { createLogger } from "./runtime/logger.js";
|
|
|
8
8
|
import { getServiceStatus, registerServiceProcess, startService, stopService, unregisterServiceProcess } from "./runtime/service-manager.js";
|
|
9
9
|
import { flushArisaHome } from "./runtime/flush.js";
|
|
10
10
|
import { arisaPackageDir } from "./runtime/paths.js";
|
|
11
|
+
import { parseProcessIds } from "./runtime/process-ids.js";
|
|
11
12
|
|
|
12
13
|
process.env.ARISA_PACKAGE_DIR = arisaPackageDir;
|
|
13
14
|
|
|
@@ -49,11 +50,11 @@ async function runCommand(commandName, args = []) {
|
|
|
49
50
|
async function getListeningPids(port) {
|
|
50
51
|
const lsofOutput = await runCommand("lsof", ["-tiTCP", `-sTCP:LISTEN`, `-iTCP:${port}`]);
|
|
51
52
|
if (lsofOutput) {
|
|
52
|
-
return lsofOutput
|
|
53
|
+
return parseProcessIds(lsofOutput);
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const fuserOutput = await runCommand("fuser", ["-n", "tcp", String(port)]);
|
|
56
|
-
return fuserOutput
|
|
57
|
+
return parseProcessIds(fuserOutput);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
async function getProcessCommand(pid) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { parseProcessIds } from "../src/runtime/process-ids.js";
|
|
4
|
+
|
|
5
|
+
test("ignores empty PID command output", () => {
|
|
6
|
+
assert.deepEqual(parseProcessIds(""), []);
|
|
7
|
+
assert.deepEqual(parseProcessIds(" \n\t"), []);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("parses only positive integer PID tokens", () => {
|
|
11
|
+
assert.deepEqual(parseProcessIds("123\n456"), [123, 456]);
|
|
12
|
+
assert.deepEqual(parseProcessIds("11970/tcp: 1234"), [1234]);
|
|
13
|
+
assert.deepEqual(parseProcessIds("0 nope -12 42"), [42]);
|
|
14
|
+
});
|