@lsst/pik 0.6.0 → 0.6.1

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.
@@ -0,0 +1,3 @@
1
+ import type { PikPlugin } from '@lsst/pik-core';
2
+ export declare const killportPlugin: PikPlugin;
3
+ //# sourceMappingURL=killport.d.ts.map
@@ -0,0 +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;AAuChD,eAAO,MAAM,cAAc,EAAE,SAsD5B,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { execSync } from 'child_process';
2
+ import { confirm } from '@inquirer/prompts';
3
+ import pc from 'picocolors';
4
+ function getProcessesOnPort(port) {
5
+ try {
6
+ const output = execSync(`lsof -ti:${port}`, { encoding: 'utf-8' });
7
+ const pids = output
8
+ .trim()
9
+ .split('\n')
10
+ .filter(Boolean)
11
+ .map((pid) => parseInt(pid, 10));
12
+ return pids.map((pid) => {
13
+ let command = 'unknown';
14
+ try {
15
+ command = execSync(`ps -p ${pid} -o comm=`, { encoding: 'utf-8' }).trim();
16
+ }
17
+ catch {
18
+ // Process may have already exited
19
+ }
20
+ return { pid, command };
21
+ });
22
+ }
23
+ catch {
24
+ return [];
25
+ }
26
+ }
27
+ function killProcess(pid) {
28
+ try {
29
+ process.kill(pid, 'SIGKILL');
30
+ return true;
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ }
36
+ export const killportPlugin = {
37
+ name: 'Killport',
38
+ description: 'Kill processes on specific ports',
39
+ command: 'killport',
40
+ aliases: ['kp'],
41
+ register(program) {
42
+ program
43
+ .command('killport')
44
+ .alias('kp')
45
+ .description('Kill process running on a specific port')
46
+ .argument('<port>', 'Port number')
47
+ .option('-y, --yes', 'Skip confirmation')
48
+ .action(async (portArg, options) => {
49
+ const port = parseInt(portArg, 10);
50
+ if (isNaN(port) || port < 1 || port > 65535) {
51
+ console.error(pc.red(`Invalid port: ${portArg}`));
52
+ process.exit(1);
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;
71
+ }
72
+ }
73
+ for (const proc of processes) {
74
+ if (killProcess(proc.pid)) {
75
+ console.log(pc.green(`✓ Killed ${proc.pid} (${proc.command})`));
76
+ }
77
+ else {
78
+ console.log(pc.red(`✗ Failed to kill ${proc.pid}`));
79
+ }
80
+ }
81
+ });
82
+ },
83
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA6C3E,eAAO,MAAM,OAAO,SAGG,CAAC;AAExB;;GAEG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAgE9D"}
1
+ {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/lib/program.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA8C3E,eAAO,MAAM,OAAO,SAGG,CAAC;AAExB;;GAEG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAgE9D"}
@@ -4,9 +4,10 @@ import pc from 'picocolors';
4
4
  import { loadConfig, isValidPlugin } from '@lsst/pik-core';
5
5
  import { selectPlugin } from '@lsst/pik-plugin-select';
6
6
  import { worktreePlugin } from '@lsst/pik-plugin-worktree';
7
+ import { killportPlugin } from './plugins/killport.js';
7
8
  import pkg from '../../package.json' with { type: 'json' };
8
9
  // Built-in plugins
9
- const builtinPlugins = [selectPlugin, worktreePlugin];
10
+ const builtinPlugins = [selectPlugin, worktreePlugin, killportPlugin];
10
11
  /**
11
12
  * Get plugins that are enabled in the config.
12
13
  * - Built-in plugins are enabled if their command key exists in config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsst/pik",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "CLI tool for switching config options in source files",
5
5
  "type": "module",
6
6
  "license": "MIT",