@sap/cds-dk 4.6.0 → 4.7.1

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/bin/add.js +2 -1
  3. package/bin/bind.js +121 -48
  4. package/bin/cds.js +8 -0
  5. package/bin/compile/index.js +2 -1
  6. package/bin/env.js +0 -2
  7. package/bin/repl.js +11 -4
  8. package/bin/watch.js +25 -13
  9. package/lib/bind/bindingResolver.js +26 -14
  10. package/lib/bind/bindingUtil.js +144 -0
  11. package/lib/bind/cfKeyProvider.js +2 -80
  12. package/lib/bind/kubernetesCredentialsProvider.js +157 -0
  13. package/lib/bind/userCdsrcJsonStorageProvider.js +7 -7
  14. package/lib/client/activate.js +9 -17
  15. package/lib/client/auth_manager.js +1 -1
  16. package/lib/client/extend.js +4 -9
  17. package/lib/client/settings_manager.js +5 -4
  18. package/lib/import/index.js +3 -2
  19. package/lib/import/internalDoc/edm2cdsTypeMapping.md +38 -0
  20. package/lib/import/utils/MultiMap.js +1 -0
  21. package/lib/import/v2parser.js +102 -37
  22. package/lib/import/v4parser.js +59 -20
  23. package/lib/index.js +6 -5
  24. package/lib/init/constants.js +2 -2
  25. package/lib/init/index.js +1 -0
  26. package/lib/init/template/data/index.js +29 -7
  27. package/lib/init/template/hana/files/common/undeploy.json +5 -0
  28. package/lib/init/template/hana/files/java/package.json +3 -0
  29. package/lib/init/template/hana/index.js +19 -23
  30. package/lib/init/template/lint/index.js +28 -18
  31. package/lib/init/template/mta/files/mta.yaml.hbs +12 -5
  32. package/lib/init/template/mta/projectReader.js +1 -3
  33. package/lib/init/template/nodejs/files/.gitignore.hbs +0 -2
  34. package/lib/init/template/samples/index.js +1 -1
  35. package/lib/init/template/templateBase.js +10 -41
  36. package/lib/init/util/fsUtil.js +1 -1
  37. package/lib/lint/Linter.js +13 -33
  38. package/lib/lint/checks.js +1 -5
  39. package/lib/lint/generators.js +5 -4
  40. package/lib/lint/io.js +23 -31
  41. package/lib/watch/node-watch.js +46 -20
  42. package/npm-shrinkwrap.json +11524 -5622
  43. package/package.json +3 -3
package/lib/lint/io.js CHANGED
@@ -33,14 +33,14 @@ module.exports = {
33
33
  break;
34
34
  case ".eslintrc.json":
35
35
  case ".eslintrc":
36
+ config = JSON.parse(await fsp.readFile(configPath, "utf8"));
37
+ break;
36
38
  case "package.json":
37
- try {
38
- config = JSON.parse(await fsp.readFile(configPath, "utf8"));
39
- if (configFile === "package.json" && "eslintConfig" in config) {
40
- config = config["eslintConfig"];
41
- }
42
- } catch (err) {
43
- // Do nothing
39
+ config = JSON.parse(await fsp.readFile(configPath, "utf8"));
40
+ if ("eslintConfig" in config) {
41
+ config = config["eslintConfig"];
42
+ } else {
43
+ config = {}
44
44
  }
45
45
  break;
46
46
  default:
@@ -71,7 +71,9 @@ module.exports = {
71
71
  configContents["extends"].push(extendsValue);
72
72
  }
73
73
  } else {
74
- configContents["extends"] = [configContents["extends"], extendsValue];
74
+ if (configContents["extends"] !== extendsValue) {
75
+ configContents["extends"] = [configContents["extends"], extendsValue];
76
+ }
75
77
  }
76
78
  } else {
77
79
  configContents["extends"] = extendsValue;
@@ -136,21 +138,20 @@ module.exports = {
136
138
  break;
137
139
  case ".eslintrc.json":
138
140
  case ".eslintrc":
141
+ await fsUtil.writeFile(configPath, `${JSON.stringify(configContents, null, 2)}`);
142
+ break;
139
143
  case "package.json":
140
- if (configFile === "package.json") {
141
- if (await fsp.access(configPath)) {
142
- contents = JSON.parse(await fsp.readFile(configPath, "utf8"));
143
- } else {
144
- contents = {};
145
- }
146
- if (!("eslintConfig" in configContents)) {
147
- contents["eslintConfig"] = configContents;
148
- } else {
149
- contents["eslintConfig"] = [...configContents, ...contents["eslintConfig"]];
150
- }
151
- configContents = contents;
144
+ if (await fsUtil.pathExists(configPath)) {
145
+ contents = JSON.parse(await fsp.readFile(configPath, "utf8"));
146
+ } else {
147
+ contents = {};
152
148
  }
153
- await fsUtil.writeFile(configPath, `${JSON.stringify(configContents, null, 2)}`);
149
+ if (!("eslintConfig" in configContents)) {
150
+ contents["eslintConfig"] = configContents;
151
+ } else {
152
+ contents["eslintConfig"] = [...configContents, ...contents["eslintConfig"]];
153
+ }
154
+ await fsUtil.writeFile(configPath, `${JSON.stringify(contents, null, 2)}`);
154
155
  break;
155
156
  default:
156
157
  break;
@@ -200,18 +201,9 @@ module.exports = {
200
201
  * (3) "Global" case adds configFile and removes rulePaths
201
202
  * @param {*} settingsPath VS Code settings file
202
203
  */
203
- async sanitizeVscodeSettings(projectPath, settingsPath, lintType, customRuleExample = false) {
204
+ async sanitizeVscodeSettings(projectPath, settingsPath, lintType, lintFileTypes, customRuleExample = false) {
204
205
  let settings = (await this.readVscodeSettings(settingsPath)) || {};
205
- const lintFileTypes = ["cds", "csn"];
206
206
  const rulePaths = [path.join(".eslint/rules")];
207
- const configFile = path.join(__dirname, ".eslintrc.js");
208
-
209
- function _addArrayOrString(array) {
210
- if (array.length === 1) {
211
- return array[0];
212
- }
213
- return array;
214
- }
215
207
 
216
208
  if (settings["eslint.validate"]) {
217
209
  settings["eslint.validate"] = this.mergeArrays(settings["eslint.validate"], lintFileTypes);
@@ -1,3 +1,5 @@
1
+ const DEBUG = /\bwatch\b/.test(process.env.DEBUG) && console.debug
2
+
1
3
  module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, options={} })=>{
2
4
 
3
5
  let child
@@ -5,19 +7,23 @@ module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, option
5
7
  // Phoning home...
6
8
  const EventEmitter = require('events')
7
9
  const emitter = new EventEmitter
8
- process.on('exit', () => { gracefullyKill (child); emitter.emit('quit') })
10
+ process.on('exit', () => { _kill (child); emitter.emit('quit') })
9
11
 
10
12
  // Re-starting child process...
11
13
  const { fork } = require('child_process')
12
- const restart = (evt, name)=>{
13
- gracefullyKill (child, () => {
14
+ const restart = _coalesceEvents(delay, (events) => {
15
+ DEBUG && DEBUG('>> Events:', events)
16
+ _kill (child, () => {
14
17
  const execArgv = [...process.execArgv]
15
- if (evt && evt.startsWith('--')) execArgv.push(evt)
16
- if (name && name.startsWith('--')) execArgv.push(name)
18
+ events.forEach(evt => {
19
+ if (evt.type && evt.type.startsWith('--')) execArgv.push(evt.type)
20
+ if (evt.name && evt.name.startsWith('--')) execArgv.push(evt.name)
21
+ })
17
22
  if (options.debug) execArgv.push('--inspect')
18
23
  if (options['debug-brk']) execArgv.push('--inspect-brk')
19
- const files = evt === "update" ? [ name ] : undefined
20
- emitter.emit ('restart', files)
24
+
25
+ const updated = events.filter(evt => evt.type && evt.type === 'update').map(evt => evt.name)
26
+ emitter.emit ('restart', updated)
21
27
  child = fork (script, { cwd, env, stdio:'inherit', execArgv }, (err)=>{
22
28
  if (err) console.error (err)
23
29
  })
@@ -26,14 +32,16 @@ module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, option
26
32
  emitter.emit('message', msg)
27
33
  })
28
34
  })
29
- }
35
+
36
+ })
37
+
30
38
  restart()
31
39
 
32
40
  // Watching for touched files...
33
41
  const watch = require('node-watch')
34
42
  const include = RegExp(`\\.(${ext.replace(/,/g,'|')})$`)
35
43
  const filter = f => !ignore.test(f) && include.test(f)
36
- watch (process.cwd(),{ recursive:true, filter, delay }, restart)
44
+ watch (process.cwd(),{ recursive:true, filter, delay:0 }, restart)
37
45
 
38
46
  // Live commands...
39
47
  const readline = require('readline')
@@ -44,12 +52,12 @@ module.exports = ({ cwd, script, ext, ignore=RegExp(), env={}, delay=200, option
44
52
  else if (input === 'break' || input === 'brk') restart('--inspect-brk')
45
53
  else if (input === 'debug-brk') restart('--inspect-brk')
46
54
  else if (input === 'ps') ps(child,env)
47
- else if (input === 'bye' || input.match(/^n$/i)) { gracefullyKill (child, () => process.exit()) }
55
+ else if (input === 'bye' || input.match(/^n$/i)) { _kill (child, () => process.exit()) }
48
56
  else console.log ('?\n')
49
57
  })
50
58
 
51
59
  emitter.restart = restart
52
- emitter.stop = () => { gracefullyKill(child, () => false); child = undefined; }
60
+ emitter.stop = () => { _kill(child, () => false); child = undefined; }
53
61
  emitter.setEnv = (name, value) => {
54
62
  if (typeof value === "undefined") {
55
63
  delete env[name]
@@ -67,14 +75,32 @@ const ps = (child,env) => console.log (`\x1b[32m
67
75
  \x1b[0m`
68
76
  )
69
77
 
70
- // On Windows, kill() abruptly kills the child process (https://nodejs.org/api/child_process.html#subprocesskillsignal)
71
- // Send a custom message an wait a bit to give cleanup code a chance to execute.
72
- const isWindows = (process.platform === 'win32')
73
- const waitTime = parseInt(process.env.CDS_WATCH_KILL_DELAY) || (isWindows ? 500 : 0)
74
- function gracefullyKill (proc, fn=()=>{}) {
75
- if (proc) {
76
- proc.send({ exit: true })
77
- setTimeout(()=> { proc.kill(); fn()}, waitTime)
78
+ // reduces mutiple node-watch events in a time frame into a bulk
79
+ function _coalesceEvents(delay, fn) {
80
+ let timer, cache = []
81
+ function handle() {
82
+ fn(cache)
83
+ timer = null
84
+ cache = []
85
+ }
86
+ return function(type, name) { // node-watch callback signature
87
+ cache.push({type, name})
88
+ if (!timer) {
89
+ timer = setTimeout(handle, delay);
90
+ }
91
+ }
92
+ }
93
+
94
+ function _kill (proc, fn=()=>{}) {
95
+ if (!proc) return fn()
96
+
97
+ // On Windows, child_process.kill() abruptly kills the process (https://nodejs.org/api/child_process.html#subprocesskillsignal)
98
+ // Server has cleanup code to run, so send a custom message and give it a bit time.
99
+ if (process.platform === 'win32') {
100
+ proc.send({ exit: true }, () => {})
101
+ const waitTime = parseInt(process.env.CDS_WATCH_KILL_DELAY) || 500
102
+ setTimeout(()=> { proc.kill(); fn() }, waitTime)
103
+ } else {
104
+ proc.kill(); fn()
78
105
  }
79
- else fn()
80
106
  }