@sap/cds-dk 7.2.0 → 7.3.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 (56) hide show
  1. package/bin/activate.js +2 -2
  2. package/bin/build.js +6 -3
  3. package/bin/compile/index.js +9 -5
  4. package/bin/env.js +0 -3
  5. package/bin/extend.js +25 -3
  6. package/bin/import.js +7 -3
  7. package/bin/push.js +10 -6
  8. package/bin/watch.js +1 -1
  9. package/lib/build/{buildTaskHandler.js → buildPlugin.js} +23 -25
  10. package/lib/build/buildTaskEngine.js +73 -73
  11. package/lib/build/buildTaskFactory.js +6 -23
  12. package/lib/build/buildTaskProvider.js +24 -19
  13. package/lib/build/buildTaskProviderFactory.js +170 -57
  14. package/lib/build/constants.js +4 -4
  15. package/lib/build/index.js +3 -2
  16. package/lib/build/provider/{buildTaskHandlerEdmx.js → edmxBuildPlugin.js} +6 -6
  17. package/lib/build/provider/{buildTaskHandlerFeatureToggles.js → featureToggleBuildPlugin.js} +3 -3
  18. package/lib/build/provider/fiori/index.js +5 -6
  19. package/lib/build/provider/hana/index.js +54 -30
  20. package/lib/build/provider/{buildTaskHandlerInternal.js → internalBuildPlugin.js} +10 -10
  21. package/lib/build/provider/{buildTaskProviderInternal.js → internalBuildTaskProvider.js} +27 -28
  22. package/lib/build/provider/java/index.js +24 -24
  23. package/lib/build/provider/mtx/index.js +4 -4
  24. package/lib/build/provider/mtx/resourcesTarBuilder.js +8 -8
  25. package/lib/build/provider/mtx-extension/index.js +17 -9
  26. package/lib/build/provider/mtx-sidecar/index.js +17 -11
  27. package/lib/build/provider/nodejs/index.js +14 -13
  28. package/lib/client/auth_manager.js +6 -12
  29. package/lib/client/base_command.js +1 -1
  30. package/lib/client/download_legacy.js +48 -0
  31. package/lib/client/params.js +5 -0
  32. package/lib/client/push.js +41 -1
  33. package/lib/client/settings_manager.js +12 -3
  34. package/lib/env/schema.js +36 -0
  35. package/lib/env/schemas/cds-rc.json +101 -0
  36. package/lib/import/common.js +23 -10
  37. package/lib/import/importapi.js +2 -2
  38. package/lib/import/message.js +3 -1
  39. package/lib/import/odata/v4parser.js +23 -7
  40. package/lib/index.js +5 -0
  41. package/lib/init/constants.js +4 -2
  42. package/lib/init/index.js +2 -3
  43. package/lib/init/template/_merging/registry-mta.js +21 -0
  44. package/lib/init/template/approuter/files/mta.yaml.hbs +1 -1
  45. package/lib/init/template/approuter/index.js +9 -9
  46. package/lib/init/template/connectivity/index.js +5 -4
  47. package/lib/init/template/destination/index.js +2 -5
  48. package/lib/init/template/html5-repo/index.js +27 -3
  49. package/lib/init/template/mta/index.js +9 -3
  50. package/lib/init/template/postgres/files/mta.yaml.hbs +27 -0
  51. package/lib/init/template/postgres/files/package.json.hbs +5 -0
  52. package/lib/init/template/postgres/index.js +52 -0
  53. package/lib/init/util/projectReader.js +0 -1
  54. package/lib/util/pruneAxiosErrors.js +22 -8
  55. package/npm-shrinkwrap.json +1829 -23
  56. package/package.json +1 -1
@@ -5,7 +5,7 @@ const { sortMessagesSeverityAware, deduplicateMessages, CompilationError } = cds
5
5
  const { relativePaths, BuildError, resolveRequiredSapModels } = require('./util')
6
6
  const { SEVERITIES, LOG_LEVELS } = require('./constants')
7
7
  const BuildTaskFactory = require('./buildTaskFactory')
8
- const BuildTaskHandlerInternal = require('./provider/buildTaskHandlerInternal')
8
+ const InternalBuildPlugin = require('./provider/internalBuildPlugin')
9
9
 
10
10
  const COMPILATION_ERROR = 'CompilationError'
11
11
  const COMPILE_MESSAGE = 'CompileMessage'
@@ -40,66 +40,66 @@ class BuildTaskEngine {
40
40
  throw new BuildError(`Required CDS models [${unresolved.join(', ')}] cannot be resolved. Make sure up-to-date versions of the missing modules are installed.`)
41
41
  }
42
42
 
43
- // create build task handlers
44
- const handlers = []
43
+ // create build plugins
44
+ const plugins = []
45
45
  tasks.forEach((task) => {
46
46
  if (task) {
47
- const handler = this._createHandler(task)
48
- handlers.push(handler)
47
+ const plugin = this._createPlugin(task)
48
+ plugins.push(plugin)
49
49
  }
50
50
  })
51
51
 
52
52
  try {
53
- await this._executePrepare(handlers)
54
- await this._executeCleanBuildTasks(handlers)
53
+ await this._executePrepare(plugins)
54
+ await this._executeCleanBuildTasks(plugins)
55
55
 
56
56
  // throwing Exception in case of compilation errors
57
- const buildResult = await this._executeBuildTasks(handlers)
57
+ const buildResult = await this._executeBuildTasks(plugins)
58
58
 
59
- await this._writeGenerationLog(handlers)
60
- this._logBuildOutput(handlers)
61
- this._logMessages(BuildTaskEngine._getHandlerMessages(handlers))
59
+ await this._writeGenerationLog(plugins)
60
+ this._logOutput(plugins)
61
+ this._logMessages(BuildTaskEngine._getMessages(plugins))
62
62
  this._logTimer(startTime, Date.now())
63
63
 
64
64
  return buildResult
65
65
  } catch (error) {
66
- this._logBuildOutput(handlers)
66
+ this._logOutput(plugins)
67
67
  throw error
68
68
  }
69
69
  }
70
70
 
71
71
  /**
72
- * BuildTaskHandler#prepare has been deprecated and was never part of the public API.
73
- * Currently only used by internal FioriBuildTaskHandler.
72
+ * BuildPlugin#prepare has been deprecated and was never part of the public API.
73
+ * Currently only used by internal FioriBuildPlugin.
74
74
  * @deprecated
75
- * @param {*} handlers
75
+ * @param {*} plugins
76
76
  * @returns
77
77
  */
78
- async _executePrepare(handlers) {
79
- const handlerGroups = new Map()
78
+ async _executePrepare(plugins) {
79
+ const pluginGroups = new Map()
80
80
 
81
- // group handlers by type
82
- handlers.forEach(handler => {
83
- handlerGroups.has(handler.task.for) ? handlerGroups.get(handler.task.for).push(handler) : handlerGroups.set(handler.task.for, [handler])
81
+ // group plugins by type
82
+ plugins.forEach(plugin => {
83
+ pluginGroups.has(plugin.task.for) ? pluginGroups.get(plugin.task.for).push(plugin) : pluginGroups.set(plugin.task.for, [plugin])
84
84
  })
85
85
 
86
86
  const promises = []
87
- for (let handlerGroup of handlerGroups.values()) {
88
- promises.push(this._doPrepare(handlerGroup))
87
+ for (let pluginGroup of pluginGroups.values()) {
88
+ promises.push(this._doPrepare(pluginGroup))
89
89
  }
90
90
  return Promise.all(promises)
91
91
  }
92
92
 
93
93
  /**
94
94
  * @deprecated
95
- * @param {*} handlerGroup
95
+ * @param {*} pluginGroup
96
96
  */
97
- async _doPrepare(handlerGroup) {
98
- for (let handler of handlerGroup) {
97
+ async _doPrepare(pluginGroup) {
98
+ for (let plugin of pluginGroup) {
99
99
  // prepare has been deprecated
100
- if (handler instanceof BuildTaskHandlerInternal) {
101
- this.logger._debug && this.logger.debug(`preparing, handler [${handler.constructor.name}], src [${relativePaths(cds.root, handler.task.src)}]`)
102
- const result = await handler.prepare()
100
+ if (plugin instanceof InternalBuildPlugin) {
101
+ this.logger._debug && this.logger.debug(`preparing, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
102
+ const result = await plugin.prepare()
103
103
  if (result === false) {
104
104
  break
105
105
  }
@@ -107,7 +107,7 @@ class BuildTaskEngine {
107
107
  }
108
108
  }
109
109
 
110
- async _executeCleanBuildTasks(handlers) {
110
+ async _executeCleanBuildTasks(plugins) {
111
111
  if (this.options.clean) {
112
112
  // clean entire build staging folder once
113
113
  if (cds.env.build.target !== '.') {
@@ -116,30 +116,30 @@ class BuildTaskEngine {
116
116
  await fs.promises.rm(target, { force: true, recursive: true })
117
117
  }
118
118
 
119
- const results = await Promise.allSettled(handlers.map((handler) => {
120
- this.logger._debug && this.logger.debug(`cleaning, handler [${handler.constructor.name}], src [${relativePaths(cds.root, handler.task.src)}]`)
121
- return handler.clean()
119
+ const results = await Promise.allSettled(plugins.map((plugin) => {
120
+ this.logger._debug && this.logger.debug(`cleaning, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
121
+ return plugin.clean()
122
122
  }))
123
123
  // check for errors and throw exception
124
124
  this._resolveHandlerResponse(results)
125
125
  }
126
126
  }
127
127
 
128
- async _executeBuildTasks(handlers) {
129
- // sort handlers based on priority in
130
- handlers = handlers.sort((a, b) => {
128
+ async _executeBuildTasks(plugins) {
129
+ // sort plugins based on priority in
130
+ plugins = plugins.sort((a, b) => {
131
131
  return a.priority === b.priority ? 0 : a.priority > b.priority ? -1 : 1
132
132
  })
133
- // group handlers with same priority in order to execute in parallel
134
- const buildPipeline = handlers.reduce((acc, handler) => {
133
+ // group plugins with same priority in order to execute in parallel
134
+ const buildPipeline = plugins.reduce((acc, plugin) => {
135
135
  if (acc.length === 0) {
136
- acc.push([handler])
136
+ acc.push([plugin])
137
137
  } else {
138
138
  const currGroup = acc[acc.length - 1]
139
- if (currGroup[0].priority === handler.priority) {
140
- currGroup.push(handler)
139
+ if (currGroup[0].priority === plugin.priority) {
140
+ currGroup.push(plugin)
141
141
  } else {
142
- acc.push([handler])
142
+ acc.push([plugin])
143
143
  }
144
144
  }
145
145
  return acc
@@ -148,20 +148,20 @@ class BuildTaskEngine {
148
148
  const results = await this._executePipeline(buildPipeline)
149
149
 
150
150
  // check for errors and throw exception - return results otherwise including any compiler and build status messages
151
- return this._resolveHandlerResponse(results, BuildTaskEngine._getHandlerMessages(handlers))
151
+ return this._resolveHandlerResponse(results, BuildTaskEngine._getMessages(plugins))
152
152
  }
153
153
 
154
154
  async _executePipeline(pipeline) {
155
155
  let allResults = []
156
156
  for (const group of pipeline) {
157
- const results = await Promise.allSettled(group.map((handler) => {
158
- this.logger._debug && this.logger.debug(`building, handler [${handler.constructor.name}], src [${relativePaths(cds.root, handler.task.src)}]`)
159
- return handler.build()
160
- .then(handlerResult => {
157
+ const results = await Promise.allSettled(group.map((plugin) => {
158
+ this.logger._debug && this.logger.debug(`building, plugin [${plugin.constructor.name}], src [${relativePaths(cds.root, plugin.task.src)}]`)
159
+ return plugin.build()
160
+ .then(pluginResult => {
161
161
  return Promise.resolve({
162
- task: handler.task,
163
- result: handlerResult,
164
- messages: this._sortMessagesUnique(handler.messages)
162
+ task: plugin.task,
163
+ result: pluginResult,
164
+ messages: this._sortMessagesUnique(plugin.messages)
165
165
  })
166
166
  })
167
167
  }))
@@ -170,7 +170,7 @@ class BuildTaskEngine {
170
170
  return allResults
171
171
  }
172
172
 
173
- _resolveHandlerResponse(results, handlerMessages = []) {
173
+ _resolveHandlerResponse(results, pluginMessages = []) {
174
174
  const errors = []
175
175
  const resolvedResults = results.reduce((acc, r) => {
176
176
  if (r.status === 'fulfilled') {
@@ -192,9 +192,9 @@ class BuildTaskEngine {
192
192
 
193
193
  // propagate existing CompilationErrors
194
194
  // merge all existing compilation messages into a single CompilationError
195
- // compiler warning and info messages are returned as handler messages
195
+ // compiler warning and info messages are returned as plugin messages
196
196
  const compileErrors = errors.filter(e => e.constructor.name === COMPILATION_ERROR)
197
- const compileMessages = handlerMessages.filter(message => message.constructor.name === COMPILE_MESSAGE)
197
+ const compileMessages = pluginMessages.filter(message => message.constructor.name === COMPILE_MESSAGE)
198
198
  if (compileErrors.length) {
199
199
  throw new CompilationError(this._sortMessagesUnique(BuildTaskEngine._getErrorMessages(compileErrors), compileMessages))
200
200
  }
@@ -202,31 +202,31 @@ class BuildTaskEngine {
202
202
  return resolvedResults
203
203
  }
204
204
 
205
- _createHandler(task) {
206
- const handler = this.taskFactory.createHandler(task)
207
- handler.init()
205
+ _createPlugin(task) {
206
+ const plugin = this.taskFactory.createPlugin(task)
207
+ plugin.init()
208
208
 
209
- if (!(handler instanceof BuildTaskHandlerInternal) && handler.priority !== 1) {
210
- // Custom build handlers are executed before internal handlers to ensure
209
+ if (!(plugin instanceof InternalBuildPlugin) && plugin.priority !== 1) {
210
+ // Custom build plugins are executed before internal plugins to ensure
211
211
  // that generated content cannot be overwritten by mistake
212
- throw new Error(`Illegal priority for ${handler.constructor.name} encountered for custom handler - in this version only priority value '1' is allowed`)
212
+ throw new Error(`Illegal priority for ${plugin.constructor.name} encountered for custom plugin - in this version only priority value '1' is allowed`)
213
213
  }
214
- this._logTaskHandler(handler)
215
- return handler
214
+ this._logTaskHandler(plugin)
215
+ return plugin
216
216
  }
217
217
 
218
- _logBuildOutput(handlers) {
218
+ _logOutput(plugins) {
219
219
  // log all generated files
220
- const files = BuildTaskEngine._getBuildOutput(handlers)
220
+ const files = BuildTaskEngine._getOutput(plugins)
221
221
  if (files.length > 0) {
222
222
  this.logger.log(`done > wrote output to:\n ${files.join("\n ")}\n`)
223
223
  }
224
224
  }
225
225
 
226
- async _writeGenerationLog(handlers) {
226
+ async _writeGenerationLog(plugins) {
227
227
  const outputFile = cds.env.build.outputfile || process.env.GENERATION_LOG
228
228
  if (outputFile) {
229
- const files = BuildTaskEngine._getBuildOutput(handlers)
229
+ const files = BuildTaskEngine._getOutput(plugins)
230
230
  this.logger.log(`writing generation log to [${outputFile}]\n`)
231
231
  try {
232
232
  await fs.promises.mkdir(path.dirname(outputFile), { recursive: true })
@@ -238,8 +238,8 @@ class BuildTaskEngine {
238
238
  }
239
239
  }
240
240
 
241
- static _getBuildOutput(handlers) {
242
- const files = handlers.reduce((acc, handler) => acc.concat(handler.files), []).sort()
241
+ static _getOutput(plugins) {
242
+ const files = plugins.reduce((acc, plugin) => acc.concat(plugin.files), []).sort()
243
243
  return files.map(file => {
244
244
  if (path.isAbsolute(cds.env.build.target)) {
245
245
  return file
@@ -252,9 +252,9 @@ class BuildTaskEngine {
252
252
  this.logger.log(`build completed in ${end - start} ms\n`)
253
253
  }
254
254
 
255
- _logTaskHandler(handler) {
256
- this.logger._debug && this.logger.debug(`handler ${handler.constructor.name}`)
257
- this.logger._debug && this.logger.debug(`details src [${relativePaths(cds.root, handler.task.src)}], dest [${relativePaths(cds.root, handler.task.dest)}], use [${handler.task.use}], options [${JSON.stringify(handler.task.options)}]`) //NOSONAR
255
+ _logTaskHandler(plugin) {
256
+ this.logger._debug && this.logger.debug(`plugin ${plugin.constructor.name}`)
257
+ this.logger._debug && this.logger.debug(`details src [${relativePaths(cds.root, plugin.task.src)}], dest [${relativePaths(cds.root, plugin.task.dest)}], use [${plugin.task.use}], options [${JSON.stringify(plugin.task.options)}]`) //NOSONAR
258
258
  }
259
259
 
260
260
  _logMessages(messages) {
@@ -303,11 +303,11 @@ class BuildTaskEngine {
303
303
  }
304
304
 
305
305
  /**
306
- * Returns compiler messages and validation messages issued by handlers.
307
- * @param {Array<BuildTaskHandler>} handlers
306
+ * Returns compiler messages and validation messages issued by plugins.
307
+ * @param {Array<BuildPlugin>} plugins
308
308
  */
309
- static _getHandlerMessages(handlers) {
310
- return handlers.reduce((acc, handler) => acc.concat(handler.messages), [])
309
+ static _getMessages(plugins) {
310
+ return plugins.reduce((acc, plugin) => acc.concat(plugin.messages), [])
311
311
  }
312
312
 
313
313
  /**
@@ -47,8 +47,8 @@ class BuildTaskFactory {
47
47
  return tasks
48
48
  }
49
49
 
50
- createHandler(task) {
51
- return this.providerFactory.createHandler(task)
50
+ createPlugin(task) {
51
+ return this.providerFactory.createPlugin(task)
52
52
  }
53
53
 
54
54
  async _createTasks() {
@@ -65,7 +65,7 @@ class BuildTaskFactory {
65
65
  // 1. apply default values including task.for and task.use and ensure that for all tasks a provider exists - throwing error otherwise
66
66
  await this.providerFactory.applyTaskDefaults(tasks)
67
67
  // ensure that dependencies get wired up before filtering
68
- await this.providerFactory.lookupTasks(tasks)
68
+ await this.providerFactory.lookupTasks(tasks, true)
69
69
  }
70
70
 
71
71
  // 3. filters the list of build tasks and adapts according to given CLI options
@@ -83,7 +83,7 @@ class BuildTaskFactory {
83
83
 
84
84
  // 2. add dependencies
85
85
  existingTasks = [...tasks]
86
- await this.providerFactory.lookupTasks(tasks)
86
+ await this.providerFactory.lookupTasks(tasks, true)
87
87
  if (tasks.length > existingTasks.length) {
88
88
  const newTasks = tasks.filter(task => !existingTasks.includes(task))
89
89
  // a dependant task was added
@@ -93,9 +93,6 @@ class BuildTaskFactory {
93
93
  // obligatory task defaults shared by all tasks
94
94
  BuildTaskFactory._applyCommonTaskDefaults(tasks)
95
95
 
96
- // ensure correct values for optional build task properties, error for missing mandatory properties
97
- BuildTaskFactory._validateBuildTasks(tasks)
98
-
99
96
  this._setDefaultBuildTargetFolder(tasks)
100
97
  return tasks
101
98
  }
@@ -115,14 +112,6 @@ class BuildTaskFactory {
115
112
  })
116
113
  }
117
114
 
118
- static _validateBuildTasks(tasks) {
119
- tasks.forEach(task => {
120
- if (!task.src) {
121
- throw new Error(`Invalid build task definition - value of property 'src' is missing in [${task.for || task.use}].`)
122
- }
123
- })
124
- }
125
-
126
115
  _setDefaultBuildTargetFolder(tasks) {
127
116
  const task = tasks.find(task => task.for === BUILD_TASK_JAVA_CF || task.for === BUILD_TASK_JAVA)
128
117
  const srv = task ? task.src : BuildTaskFactory._getModuleFolder(flatten([cds.env.folders.srv])) || "srv"
@@ -161,19 +150,13 @@ class BuildTaskFactory {
161
150
  })
162
151
  if (resultTasks.length === 0) {
163
152
  if (options.for || options.use) {
164
- const task = {}
165
- if ((options.for)) {
166
- task.for = options.for
167
- }
168
- if ((options.use)) {
169
- task.use = options.use
170
- }
153
+ const task = this.providerFactory.getTask(options.for ? { for: options.for } : { use: options.use })
171
154
  if (options.src) {
172
155
  task.src = options.src
173
156
  }
174
157
  resultTasks.push(task)
175
158
  }
176
- } else if (resultTasks.length < tasks.length) {
159
+ } else if (resultTasks.length <= tasks.length) {
177
160
  // return the same array as long as it contains a subset of the given tasks
178
161
  tasks.length = 0
179
162
  resultTasks.forEach(task => tasks.push(task))
@@ -1,22 +1,27 @@
1
1
  /* eslint-disable no-unused-vars */
2
+ /**
3
+ * @abstract
4
+ */
2
5
  module.exports = class BuildTaskProvider {
3
- constructor() {
4
- //injected by framework
5
- this._plugin = null
6
- }
7
- canHandleTask(task) {
8
- // return this._plugin.provides.includes(task.for || task.use && this._getTaskId(task.use))
9
- }
10
- loadHandler(task) {
11
- // return module.require(`${this._plugin.path}/${task.for || this._getTaskId(task.use)}`)
12
- }
13
- async lookupTasks(tasks) { }
14
- async applyTaskDefaults(task) {
15
- // task.for = task.for || this._getTaskId(task.use)
16
- }
17
- _getTaskId(use) {
18
- if (this._plugin && this._plugin.id) {
19
- return use.substring(this._plugin.id.length + 1)
20
- }
21
- }
6
+ /**
7
+ * @param {object} task
8
+ */
9
+ providesTask(key) { }
10
+ /**
11
+ * @returns {object} task
12
+ */
13
+ getTask(key) { return key }
14
+ /**
15
+ * @param {object} task
16
+ */
17
+ loadPlugin(task) { }
18
+ /**
19
+ * @param {Array} tasks
20
+ * @param {boolean} dependencies
21
+ */
22
+ async lookupTasks(tasks, dependencies) { }
23
+ /**
24
+ * @param {object} task
25
+ */
26
+ async applyTaskDefaults(task) { }
22
27
  }