@@ -9,6 +9,18 @@ import { fileExists, dirExists, recursivelyRenameJsonFiles } from '../../filesys
99import { cdsExtractorLog } from '../../logging' ;
1010import { BasicCdsProject } from '../parser/types' ;
1111
12+ /**
13+ * Parses a command string for use with spawnSync, handling multi-word commands like 'npx cds'.
14+ * @param commandString The command string to parse (e.g., 'npx cds' or 'cds')
15+ * @returns Object with executable and args arrays for spawnSync
16+ */
17+ function parseCommandForSpawn ( commandString : string ) : { executable : string ; baseArgs : string [ ] } {
18+ const parts = commandString . trim ( ) . split ( / \s + / ) ;
19+ const executable = parts [ 0 ] ;
20+ const baseArgs = parts . slice ( 1 ) ;
21+ return { executable, baseArgs } ;
22+ }
23+
1224/**
1325 * Compiles a CDS file to JSON using robust, project-aware compilation only.
1426 * This function has been refactored to align with the autobuild.md vision by removing all
@@ -100,7 +112,6 @@ export function compileCdsToJson(
100112 projectDir ,
101113 cdsCommand ,
102114 spawnOptions ,
103- versionInfo ,
104115 ) ;
105116 }
106117 } catch ( error ) {
@@ -126,11 +137,11 @@ function compileProjectLevel(
126137 projectDir : string ,
127138 cdsCommand : string ,
128139 spawnOptions : SpawnSyncOptions ,
129- _versionInfo : string ,
140+ versionInfo : string ,
130141) : CdsCompilationResult {
131142 cdsExtractorLog (
132143 'info' ,
133- `${ resolvedCdsFilePath } is part of a CAP project - using project-aware compilation ${ _versionInfo } ...` ,
144+ `${ resolvedCdsFilePath } is part of a CAP project - using project-aware compilation ${ versionInfo } ...` ,
134145 ) ;
135146
136147 // For project-level compilation, compile the entire project together
@@ -190,7 +201,7 @@ function compileProjectLevel(
190201 '--to' ,
191202 'json' ,
192203 '--dest' ,
193- 'model.cds.json' , // TODO : replace `model.cds.json` with `model.<session_id>.cds.json`
204+ 'model.cds.json' , // TODO: Replace `model.cds.json` with `model.<session_id>.cds.json`
194205 '--locations' ,
195206 '--log-level' ,
196207 'warn' ,
@@ -202,7 +213,11 @@ function compileProjectLevel(
202213 `Running compilation task for CDS project '${ projectDir } ': command='${ cdsCommand } ' args='${ JSON . stringify ( compileArgs ) } '` ,
203214 ) ;
204215
205- const result = spawnSync ( cdsCommand , compileArgs , spawnOptions ) ;
216+ // Parse command for proper spawnSync execution
217+ const { executable, baseArgs } = parseCommandForSpawn ( cdsCommand ) ;
218+ const allArgs = [ ...baseArgs , ...compileArgs ] ;
219+
220+ const result = spawnSync ( executable , allArgs , spawnOptions ) ;
206221
207222 if ( result . error ) {
208223 cdsExtractorLog ( 'error' , `SpawnSync error: ${ result . error . message } ` ) ;
@@ -242,7 +257,7 @@ function compileProjectLevel(
242257 `CDS compiler generated JSON to output directory: ${ projectJsonOutPath } ` ,
243258 ) ;
244259 // Recursively rename generated .json files to have a .cds.json extension
245- // TODO : replace or remove this in favor of session-specific file suffixes (i.e. `.<session_id>.cds.json`).
260+ // TODO: Replace or remove this in favor of session-specific file suffixes (i.e. `.<session_id>.cds.json`).
246261 recursivelyRenameJsonFiles ( projectJsonOutPath ) ;
247262 } else {
248263 cdsExtractorLog ( 'info' , `CDS compiler generated JSON to file: ${ projectJsonOutPath } ` ) ;
@@ -266,15 +281,14 @@ function compileProjectLevel(
266281 * @param cdsCommand The CDS command to use
267282 * @param spawnOptions Pre-configured spawn options
268283 * @param versionInfo Version information for logging
269- * @returns Compilation result
284+ * @returns The { @link CdsCompilationResult}
270285 */
271286function compileRootFileAsProject (
272287 resolvedCdsFilePath : string ,
273288 sourceRoot : string ,
274289 projectDir : string ,
275290 cdsCommand : string ,
276291 spawnOptions : SpawnSyncOptions ,
277- _versionInfo : string ,
278292) : CdsCompilationResult {
279293 // Calculate project base directory and file path relative to project
280294 const projectBaseDir = join ( sourceRoot , projectDir ) ;
@@ -304,7 +318,11 @@ function compileRootFileAsProject(
304318 ) ;
305319
306320 // Execute the compilation
307- const result = spawnSync ( cdsCommand , compileArgs , spawnOptions ) ;
321+ // Parse command for proper spawnSync execution
322+ const { executable, baseArgs } = parseCommandForSpawn ( cdsCommand ) ;
323+ const allArgs = [ ...baseArgs , ...compileArgs ] ;
324+
325+ const result = spawnSync ( executable , allArgs , spawnOptions ) ;
308326
309327 if ( result . error ) {
310328 cdsExtractorLog ( 'error' , `SpawnSync error: ${ result . error . message } ` ) ;
0 commit comments