17
17
import { type SpawnOptions } from 'child_process' ;
18
18
import { access , constants } from 'fs/promises' ;
19
19
import { SERVER_HARNESS_COMMAND } from '../commands/server-harness' ;
20
- import { type RuntimeInfo } from './runtime-detector' ;
20
+ import { type CLIRuntimeInfo } from './runtime-detector' ;
21
21
22
22
/**
23
23
* Configuration for spawning a child process
@@ -60,30 +60,30 @@ function isValidPort(port: number): boolean {
60
60
/**
61
61
* Builds spawn configuration for the server harness based on runtime info
62
62
*
63
- * @param runtime - Runtime information from detector
63
+ * @param cliRuntime - CLI runtime information from detector
64
64
* @param port - Port number for the server (must be valid port 0-65535)
65
65
* @param logPath - Path to the log file
66
66
* @returns Spawn configuration for child_process.spawn
67
67
* @throws Error if port is invalid or runtime info is missing required fields
68
68
*
69
69
* @example
70
70
* ```typescript
71
- * const runtime = detectRuntime();
72
- * const config = buildServerHarnessSpawnConfig(runtime , 4000, '/path/to/log');
71
+ * const cliRuntime = detectRuntime();
72
+ * const config = buildServerHarnessSpawnConfig(cliRuntime , 4000, '/path/to/log');
73
73
* const child = spawn(config.command, config.args, config.options);
74
74
* ```
75
75
*/
76
76
export function buildServerHarnessSpawnConfig (
77
- runtime : RuntimeInfo ,
77
+ cliRuntime : CLIRuntimeInfo ,
78
78
port : number ,
79
79
logPath : string
80
80
) : SpawnConfig {
81
81
// Validate inputs
82
- if ( ! runtime ) {
83
- throw new Error ( 'Runtime info is required' ) ;
82
+ if ( ! cliRuntime ) {
83
+ throw new Error ( 'CLI runtime info is required' ) ;
84
84
}
85
- if ( ! runtime . execPath ) {
86
- throw new Error ( 'Runtime execPath is required' ) ;
85
+ if ( ! cliRuntime . execPath ) {
86
+ throw new Error ( 'CLI runtime execPath is required' ) ;
87
87
}
88
88
if ( ! isValidPort ( port ) ) {
89
89
throw new Error (
@@ -94,16 +94,21 @@ export function buildServerHarnessSpawnConfig(
94
94
throw new Error ( 'Log path is required' ) ;
95
95
}
96
96
97
- let command = runtime . execPath ;
97
+ let command = cliRuntime . execPath ;
98
98
let args : string [ ] ;
99
99
100
- if ( runtime . type === 'compiled-binary' ) {
100
+ if ( cliRuntime . type === 'compiled-binary' ) {
101
101
// For compiled binaries, execute directly with arguments
102
102
args = [ SERVER_HARNESS_COMMAND , port . toString ( ) , logPath ] ;
103
103
} else {
104
104
// For interpreted runtimes (Node.js, Bun), include script path if available
105
- args = runtime . scriptPath
106
- ? [ runtime . scriptPath , SERVER_HARNESS_COMMAND , port . toString ( ) , logPath ]
105
+ args = cliRuntime . scriptPath
106
+ ? [
107
+ cliRuntime . scriptPath ,
108
+ SERVER_HARNESS_COMMAND ,
109
+ port . toString ( ) ,
110
+ logPath ,
111
+ ]
107
112
: [ SERVER_HARNESS_COMMAND , port . toString ( ) , logPath ] ;
108
113
}
109
114
@@ -112,11 +117,11 @@ export function buildServerHarnessSpawnConfig(
112
117
stdio : [ 'ignore' , 'ignore' , 'ignore' ] as const ,
113
118
detached : false ,
114
119
// Use shell on Windows for better compatibility with paths containing spaces
115
- shell : runtime . platform === 'win32' ,
120
+ shell : cliRuntime . platform === 'win32' ,
116
121
} ;
117
122
118
123
// Handles spaces in the command and arguments on Windows
119
- if ( runtime . platform === 'win32' ) {
124
+ if ( cliRuntime . platform === 'win32' ) {
120
125
command = `"${ command } "` ;
121
126
args = args . map ( ( arg ) => `"${ arg } "` ) ;
122
127
}
0 commit comments