Updates
This commit is contained in:
parent
7bcddc9517
commit
7e320c87f5
2
dist/tsconfig.tsbuildinfo
vendored
2
dist/tsconfig.tsbuildinfo
vendored
File diff suppressed because one or more lines are too long
10
dist/utils/kill-child.d.ts
vendored
10
dist/utils/kill-child.d.ts
vendored
@ -4,4 +4,12 @@ import { ChildProcess } from "child_process";
|
|||||||
* @param {string | number | (string | number)[]} [port]
|
* @param {string | number | (string | number)[]} [port]
|
||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
export default function killChild(childProcess?: ChildProcess, port?: string | number | (string | number)[]): Promise<boolean>;
|
export default function killChild(
|
||||||
|
/**
|
||||||
|
* Child Process to be killed
|
||||||
|
*/
|
||||||
|
childProcess?: ChildProcess,
|
||||||
|
/**
|
||||||
|
* Port/ports to be killed
|
||||||
|
*/
|
||||||
|
port?: string | number | (string | number)[]): Promise<boolean>;
|
||||||
|
42
dist/utils/kill-child.js
vendored
42
dist/utils/kill-child.js
vendored
@ -20,15 +20,46 @@ const kill_port_1 = __importDefault(require("kill-port"));
|
|||||||
* @param {string | number | (string | number)[]} [port]
|
* @param {string | number | (string | number)[]} [port]
|
||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
function killChild(childProcess, port) {
|
function killChild(
|
||||||
|
/**
|
||||||
|
* Child Process to be killed
|
||||||
|
*/
|
||||||
|
childProcess,
|
||||||
|
/**
|
||||||
|
* Port/ports to be killed
|
||||||
|
*/
|
||||||
|
port) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (!childProcess)
|
if (!childProcess)
|
||||||
return false;
|
return false;
|
||||||
try {
|
try {
|
||||||
childProcess.kill();
|
const childKilled = childProcess.kill();
|
||||||
|
if (childKilled) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return yield killPortFn(childProcess, port);
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
yield killPortFn(childProcess, port);
|
||||||
|
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Child Process couldn't be killed! ${error.message}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function killPortFn(
|
||||||
|
/**
|
||||||
|
* Child Process to be killed
|
||||||
|
*/
|
||||||
|
childProcess,
|
||||||
|
/**
|
||||||
|
* Port/ports to be killed
|
||||||
|
*/
|
||||||
|
port) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (!childProcess)
|
||||||
|
return false;
|
||||||
try {
|
try {
|
||||||
if (typeof port == "object" && (port === null || port === void 0 ? void 0 : port[0])) {
|
if (typeof port == "object" && (port === null || port === void 0 ? void 0 : port[0])) {
|
||||||
for (let i = 0; i < port.length; i++) {
|
for (let i = 0; i < port.length; i++) {
|
||||||
@ -43,9 +74,12 @@ function killChild(childProcess, port) {
|
|||||||
childProcess.kill();
|
childProcess.kill();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch (_err) { }
|
}
|
||||||
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Child Process couldn't be killed! ${error.message}`);
|
catch (_err) {
|
||||||
|
console.log(`${console_colors_1.default.FgRed}Error:${console_colors_1.default.Reset} Child Process PORT couldn't be killed! ${_err.message}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@moduletrace/buncid",
|
"name": "@moduletrace/buncid",
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"author": "Benjamin Toby",
|
"author": "Benjamin Toby",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -8,15 +8,48 @@ import killPort from "kill-port";
|
|||||||
* @returns {Promise<boolean>}
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
export default async function killChild(
|
export default async function killChild(
|
||||||
|
/**
|
||||||
|
* Child Process to be killed
|
||||||
|
*/
|
||||||
childProcess?: ChildProcess,
|
childProcess?: ChildProcess,
|
||||||
|
/**
|
||||||
|
* Port/ports to be killed
|
||||||
|
*/
|
||||||
port?: string | number | (string | number)[]
|
port?: string | number | (string | number)[]
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if (!childProcess) return false;
|
if (!childProcess) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
childProcess.kill();
|
const childKilled = childProcess.kill();
|
||||||
|
|
||||||
|
if (childKilled) {
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return await killPortFn(childProcess, port);
|
||||||
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
await killPortFn(childProcess, port);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`${colors.FgRed}Error:${colors.Reset} Child Process couldn't be killed! ${error.message}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function killPortFn(
|
||||||
|
/**
|
||||||
|
* Child Process to be killed
|
||||||
|
*/
|
||||||
|
childProcess?: ChildProcess,
|
||||||
|
/**
|
||||||
|
* Port/ports to be killed
|
||||||
|
*/
|
||||||
|
port?: string | number | (string | number)[]
|
||||||
|
): Promise<boolean> {
|
||||||
|
if (!childProcess) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (typeof port == "object" && port?.[0]) {
|
if (typeof port == "object" && port?.[0]) {
|
||||||
for (let i = 0; i < port.length; i++) {
|
for (let i = 0; i < port.length; i++) {
|
||||||
@ -29,13 +62,13 @@ export default async function killChild(
|
|||||||
await killPort(Number(port), "tcp");
|
await killPort(Number(port), "tcp");
|
||||||
childProcess.kill();
|
childProcess.kill();
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} catch (_err) {}
|
} catch (_err: any) {
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`${colors.FgRed}Error:${colors.Reset} Child Process couldn't be killed! ${error.message}`
|
`${colors.FgRed}Error:${colors.Reset} Child Process PORT couldn't be killed! ${_err.message}`
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user