@vibe-validate/utils 0.18.0 → 0.18.2-rc.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.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/process-check.d.ts +27 -0
- package/dist/process-check.d.ts.map +1 -0
- package/dist/process-check.js +102 -0
- package/dist/process-check.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export { safeExecSync, safeExecFromString, safeExecResult, isToolAvailable, getToolVersion, hasShellSyntax, CommandExecutionError, type SafeExecOptions, type SafeExecResult } from './safe-exec.js';
|
|
10
10
|
export { normalizedTmpdir, mkdirSyncReal, normalizePath } from './path-helpers.js';
|
|
11
|
+
export { isProcessRunning } from './process-check.js';
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACd,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACd,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,gBAAgB,EACjB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,4 +10,6 @@
|
|
|
10
10
|
export { safeExecSync, safeExecFromString, safeExecResult, isToolAvailable, getToolVersion, hasShellSyntax, CommandExecutionError } from './safe-exec.js';
|
|
11
11
|
// Cross-platform path helpers (Windows 8.3 short name handling)
|
|
12
12
|
export { normalizedTmpdir, mkdirSyncReal, normalizePath } from './path-helpers.js';
|
|
13
|
+
// Process checking (cross-platform)
|
|
14
|
+
export { isProcessRunning } from './process-check.js';
|
|
13
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6CAA6C;AAC7C,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,qBAAqB,EAGtB,MAAM,gBAAgB,CAAC;AAExB,gEAAgE;AAChE,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACd,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,6CAA6C;AAC7C,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,cAAc,EACd,cAAc,EACd,qBAAqB,EAGtB,MAAM,gBAAgB,CAAC;AAExB,gEAAgE;AAChE,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B,oCAAoC;AACpC,OAAO,EACL,gBAAgB,EACjB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a process is currently running
|
|
3
|
+
*
|
|
4
|
+
* Cross-platform implementation:
|
|
5
|
+
* - Windows: Uses `tasklist /FI "PID eq ${pid}" /NH` command
|
|
6
|
+
* - Unix/Mac: Uses `process.kill(pid, 0)` (signal 0 = check existence only)
|
|
7
|
+
*
|
|
8
|
+
* Security: Uses safeExecSync for Windows (no shell injection risk)
|
|
9
|
+
*
|
|
10
|
+
* @param pid - Process ID to check
|
|
11
|
+
* @returns true if process is running, false otherwise
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Check if process exists
|
|
16
|
+
* if (isProcessRunning(12345)) {
|
|
17
|
+
* console.log('Process 12345 is running');
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Check current process (always returns true)
|
|
21
|
+
* if (isProcessRunning(process.pid)) {
|
|
22
|
+
* console.log('Current process is running');
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function isProcessRunning(pid: number): boolean;
|
|
27
|
+
//# sourceMappingURL=process-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-check.d.ts","sourceRoot":"","sources":["../src/process-check.ts"],"names":[],"mappings":"AA4EA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAIrD"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { safeExecSync } from './safe-exec.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if PID matches in Windows tasklist output
|
|
4
|
+
*
|
|
5
|
+
* Parses tasklist output line and extracts PID from second column.
|
|
6
|
+
* Avoids false positives from partial string matching.
|
|
7
|
+
*
|
|
8
|
+
* @param line - Single line from tasklist output
|
|
9
|
+
* @param pid - Target PID to match
|
|
10
|
+
* @returns true if line contains matching PID in correct column
|
|
11
|
+
*/
|
|
12
|
+
function matchesPidInTasklist(line, pid) {
|
|
13
|
+
// Skip empty lines and error messages
|
|
14
|
+
if (!line.trim() || line.includes('INFO:')) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
// Split by whitespace and extract second column (PID)
|
|
18
|
+
const columns = line.trim().split(/\s+/);
|
|
19
|
+
if (columns.length >= 2) {
|
|
20
|
+
const linePid = Number.parseInt(columns[1], 10);
|
|
21
|
+
return linePid === pid;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Check if a process is currently running (Windows implementation)
|
|
27
|
+
*
|
|
28
|
+
* Uses tasklist command to check process existence.
|
|
29
|
+
* Parses output correctly to avoid false positives from partial PID matches.
|
|
30
|
+
*
|
|
31
|
+
* @param pid - Process ID to check
|
|
32
|
+
* @returns true if process is running, false otherwise
|
|
33
|
+
*/
|
|
34
|
+
function isProcessRunningWindows(pid) {
|
|
35
|
+
try {
|
|
36
|
+
const result = safeExecSync('tasklist', ['/FI', `PID eq ${pid}`, '/NH'], {
|
|
37
|
+
encoding: 'utf8',
|
|
38
|
+
});
|
|
39
|
+
// Parse tasklist output format (columns separated by whitespace):
|
|
40
|
+
// Image Name PID Session Name Session# Mem Usage
|
|
41
|
+
// node.exe 12345 Console 1 45,678 K
|
|
42
|
+
const lines = result.split('\n');
|
|
43
|
+
return lines.some((line) => matchesPidInTasklist(line, pid));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// Command failed (process not found or tasklist unavailable)
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if a process is currently running (Unix/Mac implementation)
|
|
52
|
+
*
|
|
53
|
+
* Uses process.kill(pid, 0) which checks process existence without sending a signal.
|
|
54
|
+
*
|
|
55
|
+
* @param pid - Process ID to check
|
|
56
|
+
* @returns true if process is running, false otherwise
|
|
57
|
+
*/
|
|
58
|
+
function isProcessRunningUnix(pid) {
|
|
59
|
+
try {
|
|
60
|
+
process.kill(pid, 0);
|
|
61
|
+
return true; // Process exists (no error thrown)
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
// EPERM = process exists but no permission (still running)
|
|
65
|
+
// EACCES = permission denied (similar to EPERM on some platforms)
|
|
66
|
+
// ESRCH = process does not exist
|
|
67
|
+
// Other errors = treat as not running
|
|
68
|
+
const error = err;
|
|
69
|
+
return error.code === 'EPERM' || error.code === 'EACCES';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Check if a process is currently running
|
|
74
|
+
*
|
|
75
|
+
* Cross-platform implementation:
|
|
76
|
+
* - Windows: Uses `tasklist /FI "PID eq ${pid}" /NH` command
|
|
77
|
+
* - Unix/Mac: Uses `process.kill(pid, 0)` (signal 0 = check existence only)
|
|
78
|
+
*
|
|
79
|
+
* Security: Uses safeExecSync for Windows (no shell injection risk)
|
|
80
|
+
*
|
|
81
|
+
* @param pid - Process ID to check
|
|
82
|
+
* @returns true if process is running, false otherwise
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* // Check if process exists
|
|
87
|
+
* if (isProcessRunning(12345)) {
|
|
88
|
+
* console.log('Process 12345 is running');
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* // Check current process (always returns true)
|
|
92
|
+
* if (isProcessRunning(process.pid)) {
|
|
93
|
+
* console.log('Current process is running');
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export function isProcessRunning(pid) {
|
|
98
|
+
return process.platform === 'win32'
|
|
99
|
+
? isProcessRunningWindows(pid)
|
|
100
|
+
: isProcessRunningUnix(pid);
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=process-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-check.js","sourceRoot":"","sources":["../src/process-check.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