From 9950a88e762848d82bd5e439d27b65530f9e79b8 Mon Sep 17 00:00:00 2001 From: I569192 Date: Wed, 11 Mar 2026 13:54:33 +0100 Subject: [PATCH 1/2] use default options from dk --- cds-plugin.ts | 4 ++ lib/processImport.ts | 56 ------------------- tests/bookshop/package.json | 2 +- ...me.sdshipmentprocessor.shipmentHandler.cds | 8 ++- 4 files changed, 10 insertions(+), 60 deletions(-) diff --git a/cds-plugin.ts b/cds-plugin.ts index b179f12..cec8cf3 100644 --- a/cds-plugin.ts +++ b/cds-plugin.ts @@ -29,6 +29,10 @@ cds.build?.register?.('process-validation', ProcessValidationPlugin); // Register import handler for: cds import --from process // @ts-expect-error: import does not exist on cds type cds.import ??= {}; +//@ts-expect-error: cds type does not exist +cds.import.options ??= {}; +//@ts-expect-error: cds type does not exist +cds.import.options.process = { no_copy: true, as: 'cds', config: 'kind=rest' }; // @ts-expect-error: process does not exist on cds.import type cds.import.from ??= {}; // @ts-expect-error: from does not exist on cds.import type diff --git a/lib/processImport.ts b/lib/processImport.ts index 76e7e3d..af50ae3 100644 --- a/lib/processImport.ts +++ b/lib/processImport.ts @@ -79,9 +79,6 @@ async function fetchAndSaveProcessDefinition(processName: string): Promise { const processHeader = loadProcessHeader(jsonFilePath); const csnModel = buildCsnModel(processHeader); - // Register service in package.json for local imports too - const serviceName = `${processHeader.projectId}.${capitalize(processHeader.identifier)}Service`; - const modelPath = getModelPathFromFilePath(jsonFilePath); - await addServiceToPackageJson(serviceName, modelPath); - return csnModel; } -/** - * Convert absolute/relative file path to model path for package.json - * e.g., "./srv/external/foo.json" -> "srv/external/foo" - * "/abs/path/srv/external/foo.json" -> "srv/external/foo" - */ -function getModelPathFromFilePath(filePath: string): string { - // Resolve to absolute, then make relative to cds.root - const absolutePath = path.resolve(filePath); - let relativePath = path.relative(cds.root, absolutePath); - - // Remove .json extension - if (relativePath.endsWith('.json')) { - relativePath = relativePath.slice(0, -5); - } - - // Normalize path separators - relativePath = relativePath.replace(/\\/g, '/'); - - // Replace "workflows" prefix with "srv/external" - if (relativePath.startsWith('workflows/')) { - relativePath = 'srv/external/' + relativePath.slice('workflows/'.length); - } - - return relativePath; -} - function loadProcessHeader(filePath: string): ProcessHeader { const content = fs.readFileSync(path.resolve(filePath), 'utf-8'); const header = JSON.parse(content) as ProcessHeader; @@ -542,28 +508,6 @@ function ensureObjectSchema(schema?: JsonSchema): JsonSchema { return { type: 'object', properties: {}, required: [] }; } -// ============================================================================ -// PACKAGE.JSON UPDATE -// ============================================================================ - -async function addServiceToPackageJson(serviceName: string, modelPath: string): Promise { - const packagePath = path.join(cds.root, 'package.json'); - - try { - const content = await fs.promises.readFile(packagePath, 'utf8'); - const pkg = JSON.parse(content); - - pkg.cds ??= {}; - pkg.cds.requires ??= {}; - pkg.cds.requires[serviceName] = { kind: 'external', model: modelPath }; - - await fs.promises.writeFile(packagePath, JSON.stringify(pkg, null, 2) + '\n', 'utf8'); - LOG.debug(`Added ${serviceName} to package.json`); - } catch (error) { - LOG.warn(`Could not update package.json: ${error}`); - } -} - // ============================================================================ // UTILITIES // ============================================================================ diff --git a/tests/bookshop/package.json b/tests/bookshop/package.json index edc39e5..b9d09bd 100644 --- a/tests/bookshop/package.json +++ b/tests/bookshop/package.json @@ -31,7 +31,7 @@ } }, "eu12.bpm-horizon-walkme.sdshipmentprocessor.ShipmentHandlerService": { - "kind": "external", + "kind": "rest", "model": "srv/external/eu12.bpm-horizon-walkme.sdshipmentprocessor.shipmentHandler" } } diff --git a/tests/bookshop/srv/external/eu12.bpm-horizon-walkme.sdshipmentprocessor.shipmentHandler.cds b/tests/bookshop/srv/external/eu12.bpm-horizon-walkme.sdshipmentprocessor.shipmentHandler.cds index 6c08660..7d92b3e 100644 --- a/tests/bookshop/srv/external/eu12.bpm-horizon-walkme.sdshipmentprocessor.shipmentHandler.cds +++ b/tests/bookshop/srv/external/eu12.bpm-horizon-walkme.sdshipmentprocessor.shipmentHandler.cds @@ -1,4 +1,4 @@ -/* checksum : ba13b7a95c8d1c3567a2bdb109bd687d */ +/* checksum : 060851d153c6463bb8c4fb247ccfd927 */ namespace eu12.![bpm-horizon-walkme].sdshipmentprocessor; /** DO NOT EDIT. THIS IS A GENERATED SERVICE THAT WILL BE OVERRIDDEN ON NEXT IMPORT. */ @@ -39,7 +39,7 @@ service ShipmentHandlerService { }; type ProcessOutputs { - shipmentProcessResultOutput : ShipmentProcessResult not null; + shipmentProcessResultOutput : ShipmentProcessResult; }; type ProcessAttribute { @@ -62,6 +62,8 @@ service ShipmentHandlerService { type ProcessInstances : many ProcessInstance; + type ProcessInstanceStatus : many String; + action start( inputs : ProcessInputs not null ); @@ -76,7 +78,7 @@ service ShipmentHandlerService { function getInstancesByBusinessKey( businessKey : String not null, - status : many String + status : ProcessInstanceStatus ) returns ProcessInstances; action suspend( From 61b889dd20c0b5b38ef520e71aa686cd7641b926 Mon Sep 17 00:00:00 2001 From: I569192 Date: Thu, 12 Mar 2026 15:14:45 +0100 Subject: [PATCH 2/2] remove unused tests --- .../process-import/process-import.test.ts | 86 ------------------- 1 file changed, 86 deletions(-) diff --git a/tests/integration/process-import/process-import.test.ts b/tests/integration/process-import/process-import.test.ts index 2df70ae..154beb8 100644 --- a/tests/integration/process-import/process-import.test.ts +++ b/tests/integration/process-import/process-import.test.ts @@ -363,92 +363,6 @@ describe('Process Import Integration Tests', () => { }); }); - describe('Package.json Update', () => { - it('should add service to package.json with kind external', async () => { - const targetPath = path.join(tempDir, 'srv', 'external', 'test.project.simpleProcess.json'); - await fs.promises.copyFile(simpleProcessPath, targetPath); - - await importProcess(targetPath); - - const packageJsonPath = path.join(tempDir, 'package.json'); - const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8')); - - expect(packageJson.cds).toBeDefined(); - expect(packageJson.cds.requires).toBeDefined(); - expect(packageJson.cds.requires['test.project.SimpleProcessService']).toBeDefined(); - expect(packageJson.cds.requires['test.project.SimpleProcessService'].kind).toBe('external'); - expect(packageJson.cds.requires['test.project.SimpleProcessService'].model).toBe( - 'srv/external/test.project.simpleProcess', - ); - }); - - it('should compute correct model path from absolute file path', async () => { - const targetPath = path.join(tempDir, 'srv', 'external', 'my.custom.path.json'); - await fs.promises.copyFile(simpleProcessPath, targetPath); - - await importProcess(targetPath); - - const packageJsonPath = path.join(tempDir, 'package.json'); - const packageJson = JSON.parse(await fs.promises.readFile(packageJsonPath, 'utf8')); - - expect(packageJson.cds.requires['test.project.SimpleProcessService'].model).toBe( - 'srv/external/my.custom.path', - ); - }); - - it('should preserve existing package.json content', async () => { - const existingPackageJson = { - name: 'test-project', - version: '1.0.0', - dependencies: { '@sap/cds': '^7.0.0' }, - cds: { - requires: { - ExistingService: { kind: 'external', model: 'srv/existing' }, - }, - }, - }; - await fs.promises.writeFile( - path.join(tempDir, 'package.json'), - JSON.stringify(existingPackageJson, null, 2), - ); - - const targetPath = path.join(tempDir, 'srv', 'external', 'test.json'); - await fs.promises.copyFile(simpleProcessPath, targetPath); - - await importProcess(targetPath); - - const packageJson = JSON.parse( - await fs.promises.readFile(path.join(tempDir, 'package.json'), 'utf8'), - ); - - expect(packageJson.name).toBe('test-project'); - expect(packageJson.dependencies['@sap/cds']).toBe('^7.0.0'); - expect(packageJson.cds.requires['ExistingService']).toBeDefined(); - expect(packageJson.cds.requires['test.project.SimpleProcessService']).toBeDefined(); - }); - - it('should create cds.requires if not present', async () => { - const packageJson = { name: 'test-project', version: '1.0.0' }; - await fs.promises.writeFile( - path.join(tempDir, 'package.json'), - JSON.stringify(packageJson, null, 2), - ); - - const targetPath = path.join(tempDir, 'srv', 'external', 'test.json'); - await fs.promises.copyFile(simpleProcessPath, targetPath); - - await importProcess(targetPath); - - const updatedPackageJson = JSON.parse( - await fs.promises.readFile(path.join(tempDir, 'package.json'), 'utf8'), - ); - - expect(updatedPackageJson.cds).toBeDefined(); - expect(updatedPackageJson.cds.requires).toBeDefined(); - expect(updatedPackageJson.cds.requires['test.project.SimpleProcessService']).toBeDefined(); - }); - }); - describe('Edge Cases', () => { it('should handle process with empty inputs', async () => { const emptyInputsProcess = {