@youcan/cli-kit 2.3.2 → 2.4.0

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/dist/node/cli.js CHANGED
@@ -10,6 +10,7 @@ import 'formdata-node/file-from-path';
10
10
  import 'simple-git';
11
11
  import 'execa';
12
12
  import 'find-process';
13
+ import 'get-port';
13
14
  import 'tcp-port-used';
14
15
  import 'node-fetch';
15
16
  import 'ramda';
@@ -17,6 +17,7 @@ import 'formdata-node/file-from-path';
17
17
  import 'simple-git';
18
18
  import 'execa';
19
19
  import 'find-process';
20
+ import 'get-port';
20
21
  import 'tcp-port-used';
21
22
  import 'node-fetch';
22
23
  import 'ramda';
package/dist/node/http.js CHANGED
@@ -10,6 +10,7 @@ import 'formdata-node/file-from-path';
10
10
  import 'simple-git';
11
11
  import 'execa';
12
12
  import 'find-process';
13
+ import 'get-port';
13
14
  import 'tcp-port-used';
14
15
  import { get as get$2 } from './session.js';
15
16
  import 'kleur';
@@ -17,7 +17,7 @@ export interface ExecOptions {
17
17
  }
18
18
  export declare function exec(command: string, args: string[], options?: ExecOptions): Promise<void>;
19
19
  export declare function isPortAvailable(port: number): Promise<boolean>;
20
- export declare function getNextAvailablePort(port: number): Promise<number>;
20
+ export declare function getPortOrNextOrRandom(port: number): Promise<number>;
21
21
  export declare function getPortProcessName(port: number): Promise<string>;
22
22
  export declare function killPortProcess(port: number): Promise<void>;
23
23
  export declare function open(url: string): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  import process from 'node:process';
2
2
  import { execa } from 'execa';
3
3
  import findProcess from 'find-process';
4
+ import getPort, { portNumbers } from 'get-port';
4
5
  import tpu from 'tcp-port-used';
5
6
 
6
7
  function buildExec(command, args, options) {
@@ -27,10 +28,41 @@ async function exec(command, args, options) {
27
28
  commandProcess.stdout?.pipe(options.stdout, { end: false });
28
29
  }
29
30
  let aborted = false;
31
+ process.once('SIGINT', () => {
32
+ if (commandProcess.pid) {
33
+ try {
34
+ commandProcess.kill('SIGTERM');
35
+ }
36
+ catch (err) {
37
+ }
38
+ }
39
+ });
40
+ process.once('SIGTERM', () => {
41
+ if (commandProcess.pid) {
42
+ try {
43
+ commandProcess.kill('SIGTERM');
44
+ }
45
+ catch (err) {
46
+ }
47
+ }
48
+ });
30
49
  options?.signal?.addEventListener('abort', () => {
31
50
  const pid = commandProcess.pid;
32
51
  if (pid) {
33
52
  aborted = true;
53
+ try {
54
+ const killProcess = () => {
55
+ try {
56
+ commandProcess.kill('SIGKILL');
57
+ }
58
+ catch (err) {
59
+ }
60
+ };
61
+ commandProcess.kill('SIGTERM');
62
+ setTimeout(killProcess, 500);
63
+ }
64
+ catch (err) {
65
+ }
34
66
  }
35
67
  });
36
68
  try {
@@ -50,11 +82,8 @@ async function exec(command, args, options) {
50
82
  async function isPortAvailable(port) {
51
83
  return !await tpu.check(port);
52
84
  }
53
- async function getNextAvailablePort(port) {
54
- if (await isPortAvailable(port)) {
55
- return port;
56
- }
57
- return await getNextAvailablePort(port + 1);
85
+ async function getPortOrNextOrRandom(port) {
86
+ return await getPort({ port: portNumbers(port, port + 1000) });
58
87
  }
59
88
  async function getPortProcessName(port) {
60
89
  const info = await findProcess('port', port);
@@ -89,4 +118,4 @@ function inferUserPackageManager() {
89
118
  return defaultPackageManager;
90
119
  }
91
120
 
92
- export { exec, getNextAvailablePort, getPortProcessName, inferUserPackageManager, isPortAvailable, killPortProcess, open, sleep };
121
+ export { exec, getPortOrNextOrRandom, getPortProcessName, inferUserPackageManager, isPortAvailable, killPortProcess, open, sleep };
@@ -11,6 +11,7 @@ import 'formdata-node/file-from-path';
11
11
  import 'simple-git';
12
12
  import 'execa';
13
13
  import 'find-process';
14
+ import 'get-port';
14
15
  import 'tcp-port-used';
15
16
  import 'node-fetch';
16
17
  import 'ramda';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@youcan/cli-kit",
3
3
  "type": "module",
4
- "version": "2.3.2",
4
+ "version": "2.4.0",
5
5
  "description": "Utilities for the YouCan CLI",
6
6
  "author": "YouCan <contact@youcan.shop> (https://youcan.shop)",
7
7
  "license": "MIT",
@@ -30,6 +30,7 @@
30
30
  "find-process": "^1.4.7",
31
31
  "formdata-node": "^6.0.3",
32
32
  "fs-extra": "^11.1.1",
33
+ "get-port": "^7.1.0",
33
34
  "glob": "^11.0.0",
34
35
  "ink": "^5.1.0",
35
36
  "kill-port-process": "^3.2.0",