@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 +1 -0
- package/dist/node/filesystem.js +1 -0
- package/dist/node/http.js +1 -0
- package/dist/node/system.d.ts +1 -1
- package/dist/node/system.js +35 -6
- package/dist/node/worker.js +1 -0
- package/package.json +2 -1
package/dist/node/cli.js
CHANGED
package/dist/node/filesystem.js
CHANGED
package/dist/node/http.js
CHANGED
package/dist/node/system.d.ts
CHANGED
|
@@ -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
|
|
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>;
|
package/dist/node/system.js
CHANGED
|
@@ -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
|
|
54
|
-
|
|
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,
|
|
121
|
+
export { exec, getPortOrNextOrRandom, getPortProcessName, inferUserPackageManager, isPortAvailable, killPortProcess, open, sleep };
|
package/dist/node/worker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@youcan/cli-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "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",
|