poku
Version:
🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.
40 lines (39 loc) • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.kill = void 0;
const os_js_1 = require("../../parsers/os.js");
const pid_js_1 = require("../../services/pid.js");
const get_pids_js_1 = require("./get-pids.js");
const killPID = async (PID) => {
const PIDs = (0, pid_js_1.setPortsAndPIDs)(PID);
await Promise.all(PIDs.map(async (p) => {
os_js_1.isWindows
? await pid_js_1.killPID.windows(p)
: await pid_js_1.killPID.unix(p);
}));
};
const killPort = async (port) => {
const PIDs = await (0, get_pids_js_1.getPIDs)(port);
for (const PID of PIDs) {
if (!PID)
continue;
await killPID(PID);
}
};
const killRange = async (startsAt, endsAt) => {
const PIDs = await get_pids_js_1.getPIDs.range(startsAt, endsAt);
for (const PID of PIDs) {
if (!PID)
continue;
await killPID(PID);
}
};
/** Kill processes by PIDs, ports and port ranges. */
exports.kill = {
/** Kill the specified process ID */
pid: killPID,
/** Kill all processes listening on the specified port */
port: killPort,
/** Kill all processes listening on the specified range ports */
range: killRange,
};