From 198101c8d90a375846450f07de91cacb1b76bb44 Mon Sep 17 00:00:00 2001 From: Richard Lindner Date: Wed, 18 Oct 2023 11:00:32 +0200 Subject: [PATCH] Fix/cds 7 3 0 breaking api (#32) * upgrade deps * add version check and change cds plugin export appropriately * export promise instead of function * re-order --- cds-plugin.js | 14 +++++++++++--- example-cap-server/package.json | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cds-plugin.js b/cds-plugin.js index 5fd6742..fce97fe 100644 --- a/cds-plugin.js +++ b/cds-plugin.js @@ -2,6 +2,7 @@ "use strict"; const cds = require("@sap/cds"); +const cdsPackage = require("@sap/cds/package.json"); const { initializeFeatures } = require("./src/singleton"); const activate = async () => { @@ -27,6 +28,13 @@ const activate = async () => { } }; -module.exports = { - activate, -}; +// NOTE: for sap/cds < 7.3.0 it was expected to export activate as function property, otherwise export the promise of +// running activate +const doExportActivateAsProperty = + cdsPackage.version.localeCompare("7.3.0", undefined, { numeric: true, sensitivity: "base" }) < 0; + +module.exports = doExportActivateAsProperty + ? { + activate, + } + : activate(); diff --git a/example-cap-server/package.json b/example-cap-server/package.json index 366ebf0..32a024a 100644 --- a/example-cap-server/package.json +++ b/example-cap-server/package.json @@ -20,11 +20,11 @@ }, "dependencies": { "@cap-js-community/feature-toggle-library": "*", - "@sap/cds": "^7.2.0", + "@sap/cds": "^7.3.0", "express": "^4.18.2" }, "devDependencies": { - "@sap/cds-dk": "^7.2.0" + "@sap/cds-dk": "^7.3.0" }, "cds": { "featureToggles": {