Skip to content

Commit 6315a49

Browse files
committed
Remove "--parse" from CDS compile command
Removes an unintended change in CDS compile (to .cds.json) behavior due to the (mis)use of the "--parse" command. Fixes a regression in the expected query results in at least one case: `javascript/frameworks/cap/src/sensitive-exposure/SensitiveExposure.ql`
1 parent bc82815 commit 6315a49

File tree

3 files changed

+13
-78
lines changed

3 files changed

+13
-78
lines changed

extractors/cds/tools/src/cds/compiler/functions.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,18 @@ export function compileCdsToJson(
219219
'warn',
220220
];
221221

222-
// For root CDS files in project-aware mode, add --parse flag to ensure complete model
223-
if (projectBasedCompilation) {
224-
compileArgs.push('--parse');
225-
}
222+
/**
223+
* using the `--parse` flag changes how the data is shown in the generated .cds.json file,
224+
* where annotations and other metadata will show up under the `extensions` property instead
225+
* of the `definitions` property, as used in previous versions of the CDS extractor.
226+
*
227+
* DELETE this comment if the `--parse` flag is definitely not needed in the future.
228+
*
229+
* // For root CDS files in project-aware mode, add --parse flag to ensure complete model
230+
*if (projectBasedCompilation) {
231+
* compileArgs.push('--parse');
232+
*}
233+
*/
226234

227235
const result = spawnSync(cdsCommand, compileArgs, spawnOptions);
228236

extractors/cds/tools/test/src/cds/compiler.test.ts

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -72,78 +72,6 @@ describe('cdsCompiler', () => {
7272
(path.relative as jest.Mock).mockImplementation((_from, _to) => 'relative/path');
7373
});
7474

75-
it('should use --parse-csn flag for root CDS files in project-aware mode', () => {
76-
const cdsFilePath = '/path/to/main.cds';
77-
const sourceRoot = '/path/to';
78-
const cdsCommand = 'cds';
79-
const resolvedCdsPath = `/resolved/${cdsFilePath}`;
80-
const expectedJsonPath = `${resolvedCdsPath}.json`;
81-
82-
// Create a test project map with main.cds as a root file
83-
const projectDir = 'test-project';
84-
const projectMap = new Map();
85-
const importsMap = new Map();
86-
importsMap.set('main.cds', [{ resolvedPath: 'imported-model.cds' }]);
87-
88-
projectMap.set(projectDir, {
89-
projectDir,
90-
cdsFiles: ['main.cds', 'imported-model.cds'],
91-
imports: importsMap,
92-
});
93-
94-
// Mock filesystem.fileExists to return true for CDS file
95-
(filesystem.fileExists as jest.Mock).mockImplementation(path => path === resolvedCdsPath);
96-
97-
// Mock successful compilation
98-
(childProcess.spawnSync as jest.Mock).mockReturnValue({
99-
status: 0,
100-
stderr: null,
101-
error: null,
102-
});
103-
104-
// Mock that the output JSON file exists
105-
(filesystem.fileExists as jest.Mock).mockImplementation(
106-
path => path === resolvedCdsPath || path === expectedJsonPath,
107-
);
108-
109-
// Mock that the output is not a directory
110-
(filesystem.dirExists as jest.Mock).mockReturnValue(false);
111-
112-
// Call the function with project information
113-
const result = compileCdsToJson(
114-
cdsFilePath,
115-
sourceRoot,
116-
cdsCommand,
117-
undefined,
118-
projectMap,
119-
projectDir,
120-
);
121-
122-
expect(result).toEqual({
123-
success: true,
124-
outputPath: expectedJsonPath,
125-
compiledAsProject: true,
126-
});
127-
128-
// Check that --parse flag was added for root file
129-
expect(childProcess.spawnSync).toHaveBeenCalledWith(
130-
cdsCommand,
131-
[
132-
'compile',
133-
resolvedCdsPath,
134-
'--to',
135-
'json',
136-
'--dest',
137-
expectedJsonPath,
138-
'--locations',
139-
'--log-level',
140-
'warn',
141-
'--parse',
142-
],
143-
expect.anything(),
144-
);
145-
});
146-
14775
it('should successfully compile CDS file to JSON file', () => {
14876
const cdsFilePath = '/path/to/model.cds';
14977
const sourceRoot = '/path/to';

extractors/cds/tools/test/src/cds/compiler/functions.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,9 @@ describe('cds compiler functions', () => {
234234
expect(result.outputPath).toBe(cdsJsonOutPath);
235235
expect(result.compiledAsProject).toBe(true);
236236

237-
// Verify the --parse flag was added for project compilation
238237
expect(childProcess.spawnSync).toHaveBeenCalledWith(
239238
'cds',
240-
expect.arrayContaining(['compile', resolvedCdsPath, '--to', 'json', '--parse']),
239+
expect.arrayContaining(['compile', resolvedCdsPath, '--to', 'json']),
241240
expect.any(Object),
242241
);
243242
});

0 commit comments

Comments
 (0)