@sap/cds-dk 8.2.2 → 8.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
8
  The format is based on [Keep a Changelog](http://keepachangelog.com/).
9
9
 
10
+ ## Version 8.2.3 - 2024-09-25
11
+
12
+ ### Fixed
13
+
14
+ - In `cds.cli.command`, commands now show up in the correct case.
15
+ - `cds add` plugins don't throw a `TypeError` if `cds.cli.options` is `undefined`.
16
+ - `cds watch` no longer ignores `*git/` folders, but only `.git/`.
17
+ - `cds import` updates `package.json` file in `srv` folder if existing. The `srv` folder name is determined by `cds.env.folders.srv` config or parameter `--out`.
18
+ - `cds import` doesn't change existing service configuration data. Now, `destination` credentials are only saved for the `production` profile.
19
+
10
20
  ## Version 8.2.2 - 2024-09-17
11
21
 
12
22
  ### Fixed
package/bin/cds.js CHANGED
@@ -33,6 +33,10 @@ const cli = {
33
33
  if (cmd in this.Shortcuts) cmd = process.argv[2] = this.Shortcuts[cmd]
34
34
  if (argv.some(a => this.Shortcuts[a]==='help')) return this.help (cmd)
35
35
 
36
+ // normalize command case (but not the shortcuts above) so that checks against `cds.cli.command` work
37
+ if (cmd === process.argv[2]) cmd = process.argv[2] = cmd.toLowerCase()
38
+ else if (cmd) cmd = cmd.toLowerCase()
39
+
36
40
  const cds = require('../lib') // make sure to load cds-dk API for plugins
37
41
  DEBUG?.(`[cds] - @sap/cds ${cds.version} loaded: ${cds.home}`)
38
42
 
@@ -69,11 +73,7 @@ const cli = {
69
73
  }
70
74
  const args = this.args(task, argv)
71
75
  args[0].push(...appendArgs)
72
- cds.cli = {
73
- command: cmd,
74
- argv: args[0],
75
- options: args[1],
76
- }
76
+ cds.cli = { command: cmd, argv: args[0], options: args[1] }
77
77
 
78
78
  if (args[1]?.['resolve-bindings']) await _resolveBindings({ silent: cmd === 'env' })
79
79
 
package/bin/watch.js CHANGED
@@ -56,7 +56,7 @@ const fs = require ('fs')
56
56
 
57
57
  const extDefaults = 'cds,csn,csv,ts,mjs,cjs,js,json,properties,edmx,xml,env'
58
58
  const ignore = RegExp(
59
- `(.git|node_modules|_out|@types|@cds-models)\\${sep}` +
59
+ `(\\.git|node_modules|_out|@types|@cds-models)\\${sep}` +
60
60
  `|app(\\${sep}.+)?\\${sep}(` +
61
61
  `(webapp|dist|target)\\${sep}|` +
62
62
  `tsconfig\\.json$|` +
@@ -176,7 +176,7 @@ async function processOptions(cliOptions, options) {
176
176
  options[item] = cliOptions[item];
177
177
  }
178
178
  });
179
-
179
+
180
180
  // reads cli options from environment
181
181
  readEnvVariables(cliOptions, true);
182
182
  }
@@ -312,10 +312,10 @@ async function _write(result, service, cwd) {
312
312
  extension = dest.substring(dest.lastIndexOf('.'));
313
313
  dest = dest.replace(extension, '');
314
314
  if (service.length > 1){
315
- using = `using { ${service.join(', ')}} from './${path.relative('srv', dest).replace(/\\/g, '/')}'`;
315
+ using = `using { ${service.join(', ')}} from './${path.relative(cds.env.folders.srv, dest).replace(/\\/g, '/')}'`;
316
316
  }
317
317
  else{
318
- using = `using { ${service} as external } from './${path.relative('srv', dest).replace(/\\/g, '/')}'`;
318
+ using = `using { ${service} as external } from './${path.relative(cds.env.folders.srv, dest).replace(/\\/g, '/')}'`;
319
319
  }
320
320
  using = require('../util/term').info(using);
321
321
  message = `[cds] - imported API to ${path.relative(cwd, dest)}
@@ -327,21 +327,36 @@ ${using}
327
327
  console.log(message);
328
328
  }
329
329
 
330
- async function _updatePackageJson(dest, services, kind, cwd, config) {
331
- const package_json = path.resolve(cwd, 'package.json');
332
- const conf = await exists(package_json) ? require(package_json) : {};
330
+ async function _updatePackageJson(dest, services, kind, cwd, config, destination) {
331
+ // try to find package.json in the srv folder
332
+ let package_json = _findPackageJson(path.resolve(cwd, dest), cwd);
333
+ let conf = {};
334
+ if (package_json) {
335
+ conf = JSON.parse(await read(package_json, "utf-8"));
336
+ } else {
337
+ package_json = path.resolve(cwd, 'package.json');
338
+ }
333
339
  const requires = ['cds', 'requires'].reduce((p, n) => p[n] || (p[n] = {}), conf);
334
340
  if (kind !== 'rest' && kind !== 'rfc') {
335
341
  kind = (kind === "V2") ? 'odata-v2' : 'odata';
336
342
  }
343
+ // add destination configuration
344
+ if (!config && destination) {
345
+ config = { "[production]": { credentials: { destination } } };
346
+ }
347
+
337
348
  let package_json_updated = false;
338
349
  for (let service of services) {
339
350
  // existing service configuration data can be updated, e.g. in case of delta imports
340
351
  const model = path.relative(cwd, dest).replace(/\\/g, '/'); // cds env must not be platform specific
341
352
  const serviceConfig = { kind, model, ...config }
342
- if (!requires[service] || JSON.stringify(serviceConfig) !== JSON.stringify(requires[service])) {
353
+ if (!requires[service]) {
343
354
  cds.env.requires[service] = requires[service] = serviceConfig;
344
355
  package_json_updated = true;
356
+ } else {
357
+ if (JSON.stringify(serviceConfig) !== JSON.stringify(requires[service])) {
358
+ console.warn(`Service '${service}' already exists in ./package.json with a different configuration, skipping update.\n`);
359
+ }
345
360
  }
346
361
  }
347
362
  if (package_json_updated) {
@@ -350,6 +365,21 @@ async function _updatePackageJson(dest, services, kind, cwd, config) {
350
365
  }
351
366
  }
352
367
 
368
+ function _findPackageJson(dir, cwd) {
369
+ const packageJsonPath = path.join(dir, 'package.json');
370
+ if (fs.existsSync(packageJsonPath)) {
371
+ return packageJsonPath;
372
+ }
373
+ if (dir === cwd) {
374
+ return null;
375
+ }
376
+ const parentDir = path.dirname(dir);
377
+ if (parentDir === dir) {
378
+ return null;
379
+ }
380
+ return _findPackageJson(parentDir, cwd);
381
+ }
382
+
353
383
  function _parseValidJsonConfig(config) {
354
384
  try {
355
385
  if (config) {
@@ -363,19 +393,12 @@ function _parseValidJsonConfig(config) {
363
393
  async function postProcess(filePath, options, csn, cwd) {
364
394
  const services = _getServiceNames(csn);
365
395
  let config = _parseValidJsonConfig(options.config);
366
-
367
- // add destination configuration
368
- if (options.destination) {
369
- config ??= {};
370
- config.credentials = { destination: options.destination };
371
- }
372
-
373
- const destFilePath = path.resolve(cwd, options.out ? path.join(options.out, path.basename(filePath)) : path.join('srv/external/', path.basename(filePath)));
396
+ const destFilePath = path.resolve(cwd, options.out ? path.join(options.out, path.basename(filePath)) : path.join(cds.env.folders.srv, 'external', path.basename(filePath)));
374
397
  if (options.out) options.out = _validateAndComputeOutputFilePath(options.out, options.as, destFilePath);
375
398
  const kind = options.inputFileKind;
376
399
  const result = await _getResult(csn, options.as, options.out || destFilePath.replace(/\.[^.]+$/, ''), options.force, kind);
377
400
  const written = options.dry || await _write(result, services, cwd);
378
- const registered = options.dry || options.no_save || await _updatePackageJson(result[1].replace(/\.[^.]+$/, ''), services, kind, cwd, config);
401
+ const registered = options.dry || options.no_save || await _updatePackageJson(result[1].replace(/\.[^.]+$/, ''), services, kind, cwd, config, options.destination);
379
402
  if (!options.dry && !options.no_copy)
380
403
  await _copyToSrvExternal(filePath, destFilePath, cwd);
381
404
  if (options.dry) return console.log(result[0]);
@@ -13,7 +13,7 @@ module.exports = new class ProjectReader {
13
13
 
14
14
  #setPackageInfo() {
15
15
  // 1. Use project name and static default values
16
- this.appVersion = cds.cli.options.add?.has('java') ? '1.0.0-SNAPSHOT' : '1.0.0'
16
+ this.appVersion = cds.cli.options?.add?.has('java') ? '1.0.0-SNAPSHOT' : '1.0.0'
17
17
  this.appName = this.appId = basename(cds.root)
18
18
  this.appDescription = 'A simple CAP project.'
19
19
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@sap/cds-dk",
3
- "version": "8.2.2",
3
+ "version": "8.2.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@sap/cds-dk",
9
- "version": "8.2.2",
9
+ "version": "8.2.3",
10
10
  "license": "SEE LICENSE IN LICENSE",
11
11
  "dependencies": {
12
12
  "@cap-js/asyncapi": "^1.0.0",
@@ -99,7 +99,7 @@
99
99
  }
100
100
  },
101
101
  "node_modules/@eslint-community/regexpp": {
102
- "version": "4.11.0",
102
+ "version": "4.11.1",
103
103
  "license": "MIT",
104
104
  "engines": {
105
105
  "node": "^12.0.0 || ^14.0.0 || >=16.0.0"
@@ -214,7 +214,7 @@
214
214
  }
215
215
  },
216
216
  "node_modules/@sap/cds": {
217
- "version": "8.2.2",
217
+ "version": "8.2.3",
218
218
  "license": "SEE LICENSE IN LICENSE",
219
219
  "dependencies": {
220
220
  "@sap/cds-compiler": ">=5.1",
@@ -302,13 +302,13 @@
302
302
  }
303
303
  },
304
304
  "node_modules/@sap/hdi": {
305
- "version": "4.5.2",
305
+ "version": "4.6.0",
306
306
  "license": "See LICENSE file",
307
307
  "dependencies": {
308
- "async": "3.2.3"
308
+ "async": "^3.2.3"
309
309
  },
310
310
  "engines": {
311
- "node": ">=12 <=20"
311
+ "node": ">=18 <=20"
312
312
  },
313
313
  "peerDependencies": {
314
314
  "@sap/hana-client": "^2 >= 2.5",
@@ -324,16 +324,16 @@
324
324
  }
325
325
  },
326
326
  "node_modules/@sap/hdi-deploy": {
327
- "version": "5.2.3",
327
+ "version": "5.3.1",
328
328
  "hasInstallScript": true,
329
329
  "license": "See LICENSE file",
330
330
  "dependencies": {
331
- "@sap/hdi": "4.5.2",
332
- "@sap/xsenv": "5.2.0",
333
- "async": "3.2.6",
334
- "dotenv": "16.4.5",
335
- "handlebars": "4.7.8",
336
- "micromatch": "4.0.8"
331
+ "@sap/hdi": "^4.6.0",
332
+ "@sap/xsenv": "^5.2.0",
333
+ "async": "^3.2.6",
334
+ "dotenv": "^16.4.5",
335
+ "handlebars": "^4.7.8",
336
+ "micromatch": "^4.0.8"
337
337
  },
338
338
  "engines": {
339
339
  "node": "^18.0.0 || ^20.0.0"
@@ -351,16 +351,12 @@
351
351
  }
352
352
  }
353
353
  },
354
- "node_modules/@sap/hdi/node_modules/async": {
355
- "version": "3.2.3",
356
- "license": "MIT"
357
- },
358
354
  "node_modules/@sap/xsenv": {
359
- "version": "5.2.0",
355
+ "version": "5.3.0",
360
356
  "license": "SEE LICENSE IN LICENSE file",
361
357
  "dependencies": {
362
- "debug": "4.3.5",
363
- "node-cache": "^5.1.0",
358
+ "debug": "4.3.7",
359
+ "node-cache": "^5.1.2",
364
360
  "verror": "1.10.1"
365
361
  },
366
362
  "engines": {
@@ -734,10 +730,10 @@
734
730
  }
735
731
  },
736
732
  "node_modules/debug": {
737
- "version": "4.3.5",
733
+ "version": "4.3.7",
738
734
  "license": "MIT",
739
735
  "dependencies": {
740
- "ms": "2.1.2"
736
+ "ms": "^2.1.3"
741
737
  },
742
738
  "engines": {
743
739
  "node": ">=6.0"
@@ -1649,7 +1645,7 @@
1649
1645
  "optional": true
1650
1646
  },
1651
1647
  "node_modules/ms": {
1652
- "version": "2.1.2",
1648
+ "version": "2.1.3",
1653
1649
  "license": "MIT"
1654
1650
  },
1655
1651
  "node_modules/mustache": {
@@ -1680,7 +1676,7 @@
1680
1676
  "license": "MIT"
1681
1677
  },
1682
1678
  "node_modules/node-abi": {
1683
- "version": "3.67.0",
1679
+ "version": "3.68.0",
1684
1680
  "license": "MIT",
1685
1681
  "optional": true,
1686
1682
  "dependencies": {
@@ -2089,10 +2085,6 @@
2089
2085
  "node": ">= 0.8"
2090
2086
  }
2091
2087
  },
2092
- "node_modules/send/node_modules/ms": {
2093
- "version": "2.1.3",
2094
- "license": "MIT"
2095
- },
2096
2088
  "node_modules/serve-static": {
2097
2089
  "version": "1.16.2",
2098
2090
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds-dk",
3
- "version": "8.2.2",
3
+ "version": "8.2.3",
4
4
  "description": "Command line client and development toolkit for the SAP Cloud Application Programming Model",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [