@youcan/cli-kit 2.3.2 → 2.3.3

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';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ import 'change-case';
2
+ import '../node/cli.js';
3
+ import 'conf';
4
+ import 'env-paths';
5
+ import '../node/filesystem.js';
6
+ import 'formdata-node';
7
+ import 'formdata-node/file-from-path';
8
+ import 'simple-git';
9
+ import 'execa';
10
+ import 'find-process';
11
+ import 'get-port';
12
+ import 'tcp-port-used';
13
+ import 'node-fetch';
14
+ import 'ramda';
15
+ import 'kleur';
16
+ import 'dayjs';
17
+ import { Cloudflared } from '../services/cloudflared.js';
18
+ import '../ui/components/DevOutput.js';
19
+ import 'react';
20
+ import 'ink';
21
+
22
+ const cloudflared = new Cloudflared();
23
+ console.log('Installing Cloudflared...');
24
+ await cloudflared.install();
25
+ console.log('Successfully Installed Cloudflared');
@@ -4,7 +4,7 @@ export declare class Cloudflared {
4
4
  private readonly output;
5
5
  constructor();
6
6
  tunnel(port: number, host?: string): Promise<void>;
7
- private install;
7
+ install(): Promise<void>;
8
8
  private composeTunnelingCommand;
9
9
  private exec;
10
10
  getUrl(): string | null;
@@ -164,7 +164,6 @@ class Cloudflared {
164
164
  this.system = { platform, arch };
165
165
  }
166
166
  async tunnel(port, host = 'localhost') {
167
- await this.install();
168
167
  const { bin, args } = this.composeTunnelingCommand(port, host);
169
168
  this.exec(bin, args);
170
169
  }
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.3.3",
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",
@@ -60,6 +61,7 @@
60
61
  "build": "shx rm -rf dist && tsc --noEmit && rollup --config rollup.config.js",
61
62
  "dev": "shx rm -rf dist && rollup --config rollup.config.js --watch",
62
63
  "release": "pnpm publish --access public",
63
- "type-check": "tsc --noEmit"
64
+ "type-check": "tsc --noEmit",
65
+ "postinstall": "node -e \"import('fs').then(fs => { if (fs.existsSync('./dist/scripts/install-cloudflared.js')) import('./dist/scripts/install-cloudflared.js'); });\""
64
66
  }
65
67
  }