@lsst/pik 0.6.1 → 0.6.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"killport.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/killport.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"killport.d.ts","sourceRoot":"","sources":["../../../src/lib/plugins/killport.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAyEhD,eAAO,MAAM,cAAc,EAAE,SAgD5B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execSync } from 'child_process';
|
|
2
|
-
import { confirm } from '@inquirer/prompts';
|
|
2
|
+
import { confirm, input } from '@inquirer/prompts';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
4
|
function getProcessesOnPort(port) {
|
|
5
5
|
try {
|
|
@@ -33,6 +33,35 @@ function killProcess(pid) {
|
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
async function killPortInteractive(port, skipConfirm) {
|
|
37
|
+
const processes = getProcessesOnPort(port);
|
|
38
|
+
if (processes.length === 0) {
|
|
39
|
+
console.log(pc.yellow(`No process found on port ${port}`));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
console.log(pc.bold(`Processes on port ${port}:`));
|
|
43
|
+
for (const proc of processes) {
|
|
44
|
+
console.log(` ${pc.cyan(proc.pid.toString())} - ${proc.command}`);
|
|
45
|
+
}
|
|
46
|
+
if (!skipConfirm) {
|
|
47
|
+
const shouldKill = await confirm({
|
|
48
|
+
message: `Kill ${processes.length} process${processes.length > 1 ? 'es' : ''}?`,
|
|
49
|
+
default: true,
|
|
50
|
+
});
|
|
51
|
+
if (!shouldKill) {
|
|
52
|
+
console.log(pc.dim('Cancelled'));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const proc of processes) {
|
|
57
|
+
if (killProcess(proc.pid)) {
|
|
58
|
+
console.log(pc.green(`✓ Killed ${proc.pid} (${proc.command})`));
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.log(pc.red(`✗ Failed to kill ${proc.pid}`));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
36
65
|
export const killportPlugin = {
|
|
37
66
|
name: 'Killport',
|
|
38
67
|
description: 'Kill processes on specific ports',
|
|
@@ -43,39 +72,38 @@ export const killportPlugin = {
|
|
|
43
72
|
.command('killport')
|
|
44
73
|
.alias('kp')
|
|
45
74
|
.description('Kill process running on a specific port')
|
|
46
|
-
.argument('
|
|
75
|
+
.argument('[port]', 'Port number (interactive if not provided)')
|
|
47
76
|
.option('-y, --yes', 'Skip confirmation')
|
|
48
77
|
.action(async (portArg, options) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const processes = getProcessesOnPort(port);
|
|
55
|
-
if (processes.length === 0) {
|
|
56
|
-
console.log(pc.yellow(`No process found on port ${port}`));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
console.log(pc.bold(`Processes on port ${port}:`));
|
|
60
|
-
for (const proc of processes) {
|
|
61
|
-
console.log(` ${pc.cyan(proc.pid.toString())} - ${proc.command}`);
|
|
62
|
-
}
|
|
63
|
-
if (!options.yes) {
|
|
64
|
-
const shouldKill = await confirm({
|
|
65
|
-
message: `Kill ${processes.length} process${processes.length > 1 ? 'es' : ''}?`,
|
|
66
|
-
default: true,
|
|
67
|
-
});
|
|
68
|
-
if (!shouldKill) {
|
|
69
|
-
console.log(pc.dim('Cancelled'));
|
|
70
|
-
return;
|
|
78
|
+
if (portArg) {
|
|
79
|
+
const port = parseInt(portArg, 10);
|
|
80
|
+
if (isNaN(port) || port < 1 || port > 65535) {
|
|
81
|
+
console.error(pc.red(`Invalid port: ${portArg}`));
|
|
82
|
+
process.exit(1);
|
|
71
83
|
}
|
|
84
|
+
await killPortInteractive(port, options.yes ?? false);
|
|
72
85
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
86
|
+
else {
|
|
87
|
+
// Interactive mode - prompt for port number
|
|
88
|
+
try {
|
|
89
|
+
const portInput = await input({
|
|
90
|
+
message: 'Port number:',
|
|
91
|
+
validate: (value) => {
|
|
92
|
+
const num = parseInt(value, 10);
|
|
93
|
+
if (isNaN(num) || num < 1 || num > 65535) {
|
|
94
|
+
return 'Please enter a valid port number (1-65535)';
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
const port = parseInt(portInput, 10);
|
|
100
|
+
await killPortInteractive(port, options.yes ?? false);
|
|
76
101
|
}
|
|
77
|
-
|
|
78
|
-
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error instanceof Error && error.name === 'ExitPromptError') {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
throw error;
|
|
79
107
|
}
|
|
80
108
|
}
|
|
81
109
|
});
|