From a3de8f9e41a98589b12eb47e6e449be8631fb623 Mon Sep 17 00:00:00 2001 From: Til Weber Date: Tue, 3 Mar 2026 10:16:41 +0100 Subject: [PATCH 1/2] fix for path in package json --- lib/processImport.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/processImport.ts b/lib/processImport.ts index 69d396f..eb3e4d4 100644 --- a/lib/processImport.ts +++ b/lib/processImport.ts @@ -135,7 +135,14 @@ function getModelPathFromFilePath(filePath: string): string { } // Normalize path separators - return relativePath.replace(/\\/g, '/'); + 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 { From 62dbeb5a112b5064dca22a725665e77fa041a582 Mon Sep 17 00:00:00 2001 From: I569192 Date: Tue, 3 Mar 2026 13:10:28 +0100 Subject: [PATCH 2/2] fix --- cds-plugin.ts | 6 ++ lib/processImport.ts | 56 ------------------- tests/bookshop/package.json | 4 +- ...me.sdshipmentprocessor.shipmentHandler.cds | 13 ++++- 4 files changed, 18 insertions(+), 61 deletions(-) diff --git a/cds-plugin.ts b/cds-plugin.ts index 593cf03..0757799 100644 --- a/cds-plugin.ts +++ b/cds-plugin.ts @@ -24,6 +24,12 @@ 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' }; +// until above is not released for cds-dk, use: +// cds-tsx import --from process ./workflows/eu12.bpm-horizon-walkme.sdshipmentprocessor.shipmentHandler.json --force --config kind=rest --no-copy --as cds // @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 eb3e4d4..548e57d 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; @@ -538,28 +504,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..4c4aadb 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" } } @@ -39,4 +39,4 @@ "imports": { "#cds-models/*": "./@cds-models/*/index.js" } -} +} \ No newline at end of file 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 480a613..99aec71 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 : 599270b792f9fe49fe94c62583c09a3e */ +/* checksum : 80b8cb79ed30de92aa919cc984a784f6 */ namespace eu12.![bpm-horizon-walkme].sdshipmentprocessor; /** DO NOT EDIT. THIS IS A GENERATED SERVICE THAT WILL BE OVERRIDDEN ON NEXT IMPORT. */ @@ -42,13 +42,20 @@ service ShipmentHandlerService { shipmentProcessResultOutput : ShipmentProcessResult; }; - type ProcessAttributes { }; + type ProcessAttribute { + id : String not null; + label : String not null; + value : String; + type : String not null; + }; + + type ProcessAttributes : many ProcessAttribute; type ProcessInstance { definitionId : String; definitionVersion : String; id : String; - status: String; + status : String; startedAt : String; startedBy : String; };