@workflow/utils 4.0.1-beta.3 → 4.0.1-beta.4
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/get-port.d.ts +0 -1
- package/dist/get-port.d.ts.map +1 -1
- package/dist/get-port.js +49 -11
- package/dist/get-port.js.map +1 -1
- package/package.json +3 -3
package/dist/get-port.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Gets the port number that the process is listening on.
|
|
3
3
|
* @returns The port number that the process is listening on, or undefined if the process is not listening on any port.
|
|
4
|
-
* NOTE: Can't move this to @workflow/utils because it's being imported into @workflow/errors for RetryableError (inside workflow runtime)
|
|
5
4
|
*/
|
|
6
5
|
export declare function getPort(): Promise<number | undefined>;
|
|
7
6
|
//# sourceMappingURL=get-port.d.ts.map
|
package/dist/get-port.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-port.d.ts","sourceRoot":"","sources":["../src/get-port.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"get-port.d.ts","sourceRoot":"","sources":["../src/get-port.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAsB,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA+D3D"}
|
package/dist/get-port.js
CHANGED
|
@@ -1,23 +1,61 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { execa } from 'execa';
|
|
2
2
|
/**
|
|
3
3
|
* Gets the port number that the process is listening on.
|
|
4
4
|
* @returns The port number that the process is listening on, or undefined if the process is not listening on any port.
|
|
5
|
-
* NOTE: Can't move this to @workflow/utils because it's being imported into @workflow/errors for RetryableError (inside workflow runtime)
|
|
6
5
|
*/
|
|
7
6
|
export async function getPort() {
|
|
7
|
+
const { pid, platform } = process;
|
|
8
|
+
let port;
|
|
8
9
|
try {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
switch (platform) {
|
|
11
|
+
case 'linux':
|
|
12
|
+
case 'darwin': {
|
|
13
|
+
const lsofResult = await execa('lsof', [
|
|
14
|
+
'-a',
|
|
15
|
+
'-i',
|
|
16
|
+
'-P',
|
|
17
|
+
'-n',
|
|
18
|
+
'-p',
|
|
19
|
+
pid.toString(),
|
|
20
|
+
]);
|
|
21
|
+
const awkResult = await execa('awk', ['/LISTEN/ {split($9,a,":"); print a[length(a)]; exit}'], {
|
|
22
|
+
input: lsofResult.stdout,
|
|
23
|
+
});
|
|
24
|
+
port = parseInt(awkResult.stdout.trim(), 10);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case 'win32': {
|
|
28
|
+
// Use cmd to run the piped command
|
|
29
|
+
const result = await execa('cmd', [
|
|
30
|
+
'/c',
|
|
31
|
+
`netstat -ano | findstr ${pid} | findstr LISTENING`,
|
|
32
|
+
]);
|
|
33
|
+
const stdout = result.stdout.trim();
|
|
34
|
+
if (stdout) {
|
|
35
|
+
const lines = stdout.split('\n');
|
|
36
|
+
for (const line of lines) {
|
|
37
|
+
// Extract port from the local address column
|
|
38
|
+
// Matches both IPv4 (e.g., "127.0.0.1:3000") and IPv6 bracket notation (e.g., "[::1]:3000")
|
|
39
|
+
const match = line
|
|
40
|
+
.trim()
|
|
41
|
+
.match(/^\s*TCP\s+(?:\[[\da-f:]+\]|[\d.]+):(\d+)\s+/i);
|
|
42
|
+
if (match) {
|
|
43
|
+
port = parseInt(match[1], 10);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
13
50
|
}
|
|
14
|
-
const smallest = Math.min(...ports);
|
|
15
|
-
return smallest;
|
|
16
51
|
}
|
|
17
|
-
catch {
|
|
18
|
-
//
|
|
19
|
-
|
|
52
|
+
catch (error) {
|
|
53
|
+
// In dev, it's helpful to know why detection failed
|
|
54
|
+
if (process.env.NODE_ENV === 'development') {
|
|
55
|
+
console.debug('[getPort] Detection failed:', error);
|
|
56
|
+
}
|
|
20
57
|
return undefined;
|
|
21
58
|
}
|
|
59
|
+
return Number.isNaN(port) ? undefined : port;
|
|
22
60
|
}
|
|
23
61
|
//# sourceMappingURL=get-port.js.map
|
package/dist/get-port.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-port.js","sourceRoot":"","sources":["../src/get-port.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"get-port.js","sourceRoot":"","sources":["../src/get-port.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO;IAC3B,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAElC,IAAI,IAAwB,CAAC;IAE7B,IAAI,CAAC;QACH,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,OAAO,CAAC;YACb,KAAK,QAAQ,CAAC,CAAC,CAAC;gBACd,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;oBACrC,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,IAAI;oBACJ,GAAG,CAAC,QAAQ,EAAE;iBACf,CAAC,CAAC;gBACH,MAAM,SAAS,GAAG,MAAM,KAAK,CAC3B,KAAK,EACL,CAAC,sDAAsD,CAAC,EACxD;oBACE,KAAK,EAAE,UAAU,CAAC,MAAM;iBACzB,CACF,CAAC;gBACF,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC7C,MAAM;YACR,CAAC;YAED,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,mCAAmC;gBACnC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,KAAK,EAAE;oBAChC,IAAI;oBACJ,0BAA0B,GAAG,sBAAsB;iBACpD,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;gBAEpC,IAAI,MAAM,EAAE,CAAC;oBACX,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBACjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;wBACzB,6CAA6C;wBAC7C,4FAA4F;wBAC5F,MAAM,KAAK,GAAG,IAAI;6BACf,IAAI,EAAE;6BACN,KAAK,CAAC,8CAA8C,CAAC,CAAC;wBACzD,IAAI,KAAK,EAAE,CAAC;4BACV,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;4BAC9B,MAAM;wBACR,CAAC;oBACH,CAAC;gBACH,CAAC;gBACD,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,oDAAoD;QACpD,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,EAAE,CAAC;YAC3C,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workflow/utils",
|
|
3
3
|
"description": "Utility functions for Workflow DevKit",
|
|
4
|
-
"version": "4.0.1-beta.
|
|
4
|
+
"version": "4.0.1-beta.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"files": [
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"@workflow/tsconfig": "4.0.1-beta.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
36
|
+
"execa": "9.6.0",
|
|
37
|
+
"ms": "2.1.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsc",
|