@sap/cds-dk 9.6.0 → 9.7.0

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 (87) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/bin/add.js +5 -2
  3. package/bin/cds.js +11 -26
  4. package/bin/compile/index.js +3 -2
  5. package/bin/data-products/import.js +3 -0
  6. package/bin/debug.js +76 -16
  7. package/bin/env.js +2 -1
  8. package/bin/export.js +18 -13
  9. package/bin/help/export.md +2 -1
  10. package/bin/import.js +21 -18
  11. package/bin/init.js +8 -1
  12. package/bin/minify.js +11 -12
  13. package/bin/mock.js +17 -9
  14. package/bin/repl.js +2 -2
  15. package/bin/up.js +34 -4
  16. package/bin/version.js +202 -131
  17. package/lib/build/buildTaskEngine.js +4 -0
  18. package/lib/build/buildTaskFactory.js +5 -35
  19. package/lib/build/index.js +10 -10
  20. package/lib/build/plugin.js +6 -3
  21. package/lib/build/plugins/helm/files/subcharts/content-deployment/Chart.yaml +3 -1
  22. package/lib/build/plugins/helm/files/subcharts/content-deployment/templates/_helpers.tpl +1 -1
  23. package/lib/build/plugins/helm/files/subcharts/content-deployment/templates/job.yaml +8 -0
  24. package/lib/build/plugins/helm/files/subcharts/content-deployment/values.schema.json +18 -0
  25. package/lib/build/plugins/helm/files/subcharts/content-deployment/values.yaml +11 -1
  26. package/lib/build/plugins.js +8 -16
  27. package/lib/build/provider/hana/index.js +16 -19
  28. package/lib/build/provider/internalBuildPlugin.js +28 -4
  29. package/lib/build/provider/internalBuildTaskProvider.js +26 -88
  30. package/lib/build/provider/mtx/index.js +0 -8
  31. package/lib/build/provider/mtx-sidecar/index.js +88 -80
  32. package/lib/build/provider/nodejs/index.js +3 -8
  33. package/lib/build/util.js +52 -87
  34. package/lib/deploy/to-hana/hana.js +117 -109
  35. package/lib/env/schemas/cds-rc.js +0 -4
  36. package/lib/import/odata/v4parser.js +80 -56
  37. package/lib/init/constants.js +5 -2
  38. package/lib/init/index.js +44 -41
  39. package/lib/init/merge.js +7 -2
  40. package/lib/init/projectReader.js +4 -10
  41. package/lib/init/template/ams/index.js +1 -4
  42. package/lib/init/template/attachments/files/package.json.hbs +1 -1
  43. package/lib/init/template/data/index.js +1 -1
  44. package/lib/init/template/extension/index.js +4 -4
  45. package/lib/init/template/hana/files/package.json.hbs +3 -3
  46. package/lib/init/template/handler/index.js +1 -1
  47. package/lib/init/template/helm/index.js +3 -3
  48. package/lib/init/template/helm-unified-runtime/index.js +5 -1
  49. package/lib/init/template/html5-repo/files/mta.yaml.hbs +1 -1
  50. package/lib/init/template/ias/files/mta.yaml.hbs +3 -3
  51. package/lib/init/template/initial/files/.vscode/tasks.json +10 -0
  52. package/lib/init/template/{nodejs/files/README.md → initial/files/readme.md} +2 -3
  53. package/lib/init/template/initial/index.js +15 -0
  54. package/lib/init/template/java/index.js +4 -11
  55. package/lib/init/template/kyma/index.js +21 -20
  56. package/lib/init/template/lint/index.js +3 -1
  57. package/lib/init/template/mta/index.js +0 -5
  58. package/lib/init/template/multitenancy/files/package.sidecar.json.hbs +1 -2
  59. package/lib/init/template/multitenancy/files/values.yaml.hbs +30 -0
  60. package/lib/init/template/nodejs/files/.vscode/tasks.json +1 -14
  61. package/lib/init/template/nodejs/files/package.json.hbs +2 -4
  62. package/lib/init/template/nodejs/index.js +8 -12
  63. package/lib/init/template/sample/files/app/common.cds +1 -1
  64. package/lib/init/template/sample/index.js +5 -6
  65. package/lib/init/template/sqlite/files/package.json.hbs +7 -1
  66. package/lib/init/template/test/index.js +1 -1
  67. package/lib/init/template/tiny-sample/files/nodejs/db/data/CatalogService.Books.csv +6 -0
  68. package/lib/init/template/tiny-sample/files/nodejs/srv/cat-service.cds +5 -0
  69. package/lib/init/template/tiny-sample/index.js +2 -2
  70. package/lib/init/template/workzone-standard/files/mta.yaml.hbs +6 -0
  71. package/lib/init/template/workzone-standard/index.js +13 -3
  72. package/lib/init/validate.js +11 -6
  73. package/lib/util/checksum.js +2 -2
  74. package/lib/util/fs.js +109 -53
  75. package/lib/util/glob.js +2 -1
  76. package/lib/util/term.js +4 -8
  77. package/lib/util/write.js +2 -4
  78. package/lib/watch/livereload-server.js +4 -3
  79. package/lib/watch/node-watch.js +5 -8
  80. package/lib/watch/watched.js +1 -1
  81. package/lib/watch/watcher.js +136 -0
  82. package/npm-shrinkwrap.json +245 -284
  83. package/package.json +2 -3
  84. package/lib/init/template/nodejs/files/.vscode/settings.json +0 -11
  85. package/lib/init/template/tiny-sample/files/nodejs/db/data/my.bookshop-Books.csv +0 -3
  86. package/lib/init/template/tiny-sample/files/nodejs/db/schema.cds +0 -7
  87. package/lib/init/template/tiny-sample/files/nodejs/srv/cat-service.cds.hbs +0 -5
@@ -0,0 +1,136 @@
1
+ const fs = require('node:fs')
2
+ const { resolve, sep } = require('node:path')
3
+ const { EventEmitter } = require('node:events')
4
+
5
+ module.exports = function watch(paths, { filter, ignore } = {}) {
6
+ const ee = new EventEmitter()
7
+ const roots = [...new Set((Array.isArray(paths) ? paths : [paths]).filter(Boolean).map(p => resolve(p)))]
8
+ const ac = new AbortController() // eslint-disable-line no-undef
9
+ let closed = false
10
+
11
+ const _allow = p => !filter || (filter instanceof RegExp ? filter.test(p) : filter(p))
12
+
13
+ const useNativeRecursive = process.platform === 'darwin' || process.platform === 'win32'
14
+ if (useNativeRecursive) {
15
+ const _watch = async root => {
16
+ try {
17
+ if (!fs.existsSync(root)) return
18
+ const watcher = fs.promises.watch(root, { recursive: true, signal: ac.signal })
19
+ for await (const event of watcher) {
20
+ if (closed) break
21
+ const name = event.filename?.toString?.() ?? event.filename ?? ''
22
+ const fullPath = resolve(root, name)
23
+ if (_allow(fullPath)) {
24
+ ee.emit('change', fs.existsSync(fullPath) ? 'update' : 'remove', fullPath)
25
+ }
26
+ }
27
+ } catch (e) {
28
+ if (e.name !== 'AbortError') ee.emit('error', e)
29
+ }
30
+ }
31
+
32
+ roots.forEach(r => _watch(r).catch(e => ee.emit('error', e)))
33
+
34
+ ee.close = () => {
35
+ if (closed) return
36
+ closed = true
37
+ ac.abort()
38
+ ee.emit('close')
39
+ }
40
+
41
+ return ee
42
+ } else {
43
+ return _linuxCompat()
44
+ }
45
+
46
+ // On Linux, recursive watchers allocates OS watchers for the whole tree,
47
+ // so we avoid it to skip ignored dirs before allocating watchers.
48
+ function _linuxCompat() {
49
+ const watching = new Set()
50
+ const queued = new Set()
51
+ const queue = []
52
+ const active = new Set()
53
+ const max = 32
54
+
55
+ const _ignored = p => {
56
+ if (!ignore) return false
57
+ const test = ignore instanceof RegExp ? s => ignore.test(s) : ignore
58
+ return test(p) || test(p + sep) // allow trailing sep
59
+ }
60
+ const _enqueue = d => {
61
+ if (closed) return
62
+ const dir = resolve(d)
63
+ if (_ignored(dir)) return
64
+ if (watching.has(dir) || queued.has(dir)) return
65
+ queued.add(dir)
66
+ queue.push(dir)
67
+ _pump()
68
+ }
69
+ const _startWatch = dir => {
70
+ if (watching.has(dir)) return
71
+ watching.add(dir)
72
+ ;(async () => {
73
+ try {
74
+ if (!fs.existsSync(dir)) return
75
+ const watcher = fs.promises.watch(dir, { signal: ac.signal }) // non-recursive
76
+ for await (const event of watcher) {
77
+ if (closed) break
78
+ const name = event.filename?.toString?.() ?? event.filename ?? ''
79
+ const fullPath = name ? resolve(dir, name) : dir
80
+
81
+ // if a new dir appears, start watching it (unless ignored)
82
+ if (name && !_ignored(fullPath) && fs.existsSync(fullPath)) {
83
+ try {
84
+ if (fs.lstatSync(fullPath).isDirectory()) _enqueue(fullPath)
85
+ } catch { /* ignore */ }
86
+ }
87
+ if (_allow(fullPath)) {
88
+ ee.emit('change', fs.existsSync(fullPath) ? 'update' : 'remove', fullPath)
89
+ }
90
+ }
91
+ } catch (e) {
92
+ if (e.name !== 'AbortError' && !closed) ee.emit('error', e)
93
+ }
94
+ })().catch(e => ee.emit('error', e))
95
+ }
96
+
97
+ const _scan = async dir => {
98
+ _startWatch(dir)
99
+
100
+ let entries = []
101
+ try { entries = await fs.promises.readdir(dir, { withFileTypes: true }) }
102
+ catch { return }
103
+
104
+ for (const e of entries) {
105
+ if (e.isSymbolicLink?.()) continue
106
+ if (!e.isDirectory?.()) continue
107
+ const child = resolve(dir, e.name)
108
+ if (!_ignored(child)) _enqueue(child)
109
+ }
110
+ }
111
+
112
+ const _pump = () => {
113
+ while (!closed && queue.length && active.size < max) {
114
+ const dir = queue.shift()
115
+ queued.delete(dir)
116
+
117
+ const p = _scan(dir)
118
+ .catch(e => ee.emit('error', e))
119
+ .finally(() => {
120
+ active.delete(p)
121
+ _pump()
122
+ })
123
+
124
+ active.add(p)
125
+ }
126
+ }
127
+ roots.forEach(_enqueue)
128
+ ee.close = () => {
129
+ if (closed) return
130
+ closed = true
131
+ ac.abort()
132
+ ee.emit('close')
133
+ }
134
+ return ee
135
+ }
136
+ }