@sap/cds 6.0.1 → 6.0.2

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
@@ -4,6 +4,13 @@
4
4
  - The format is based on [Keep a Changelog](http://keepachangelog.com/).
5
5
  - This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## Version 6.0.2 - 2022-07-06
8
+
9
+ ### Fixed
10
+
11
+ - Jest tests do not fail any longer because of logs during app shutdown
12
+ - `cds build` now uses correct `mtx/sidecar` context. This avoids redundant `cds-mtxs` npm dependency for Java projects.
13
+
7
14
  ## Version 6.0.1 - 2022-07-05
8
15
 
9
16
  ### Added
@@ -5,6 +5,7 @@ const BuildTaskHandlerInternal = require('../buildTaskHandlerInternal')
5
5
  const NodeCfModuleBuilder = require('../nodejs')
6
6
  const ResourcesTarProvider = require('../mtx/resourcesTarBuilder')
7
7
  const { INFO } = require('../buildTaskHandlerInternal')
8
+ const { relativePaths } = require('@sap/cds/bin/build/util')
8
9
 
9
10
  const DEFAULT_MAIN_FOLDER = "_main"
10
11
 
@@ -20,47 +21,50 @@ class MtxSidecarModuleBuilder extends NodeCfModuleBuilder {
20
21
  }
21
22
  }
22
23
 
24
+ /**
25
+ * Builds the mtx sidecar app consisting of:
26
+ * - nodejs app model defined by the required sidecar services
27
+ * - main app model defined by the build task's model options including feature models and resources TAR
28
+ *
29
+ * build.target=".": 'dest' -> 'model-provider/gen'
30
+ * build.target="gen": 'dest' -> 'gen/model-provider'
31
+ */
23
32
  async build() {
24
- // Sidecar scenario: model-provider is implemented as separate Nodejs app.
25
- // Create resources TAR AND and compiled CSN(s) for the sidecar app.
26
- // build.target=".": 'dest' -> 'model-provider/gen'
27
- // build.target="gen": 'dest' -> 'gen/model-provider'
33
+ // nodejs app parts have to be built using sidecar env
28
34
  const sidecarEnv = this.env.for("cds", this.task.src)
29
-
30
- // 1. build node application
31
- await this._buildNodeApp(sidecarEnv)
32
-
33
- // 2. build main application
35
+ // build main application
34
36
  await this._buildMainApp(sidecarEnv)
37
+ // build node application
38
+ await this._buildNodeApp(sidecarEnv)
35
39
  }
36
40
 
41
+ /**
42
+ * Builds the mtx sidecar nodejs app parts.
43
+ * @param {object} sidecarEnv cds env based on the sidecar dir
44
+ */
37
45
  async _buildNodeApp(sidecarEnv) {
38
- const sources = []
39
- for (const name in sidecarEnv.requires) {
40
- const service = sidecarEnv.requires[name]
41
- if (service.model) {
42
- sources.push(service.model)
43
- }
44
- }
45
- const model = await this.cds.load(sources, this.options)
46
46
  const destSidecar = this.task.dest
47
47
  const destSidecarSrc = path.join(destSidecar, this.env.folders.srv)
48
-
48
+ const model = this._compileSidecarSync(sidecarEnv)
49
49
  await this.compileToJson(model, destSidecarSrc)
50
50
  await this.collectLanguageBundles(model, destSidecarSrc)
51
51
  await this._copyProjectRootContent(this.task.src, destSidecar)
52
52
  }
53
53
 
54
+ /**
55
+ * Builds the main app parts containing base model CSN with feature CSNs and resources TAR.
56
+ * @param {object} sidecarEnv cds env based on the sidecar dir
57
+ */
54
58
  async _buildMainApp(sidecarEnv) {
55
59
  let main = sidecarEnv.requires['cds.xt.ModelProviderService']?.root
56
60
  if (!main) {
57
- throw new Error("Invalid sidecar configuration - model-provider.root configuration missing")
61
+ throw new Error("Invalid sidecar configuration - {\"model-provider\": \"in-sidecar\"} configuration missing")
58
62
  }
59
63
  const profiles = this.env.get("profiles") || []
60
64
  if (!profiles.includes("production") && !profiles.includes("prod")) {
61
65
  main = DEFAULT_MAIN_FOLDER
62
66
  // root should represent the production use case and not development
63
- this.pushMessage(`Sidecar main application build results are created in folder '${main}'. Use the 'production' profile if the folder is configured differently.`, INFO)
67
+ this.pushMessage(`Sidecar main application build results are created in folder '${main}'. Enable the 'production' or 'prod' profile if the folder is configured differently.`, INFO)
64
68
  }
65
69
  const destRoot = this.task.dest
66
70
  const destMain = path.join(destRoot, main)
@@ -76,5 +80,31 @@ class MtxSidecarModuleBuilder extends NodeCfModuleBuilder {
76
80
  // resources are determined based on available database build task, SQLite as fallback
77
81
  await new ResourcesTarProvider(this).writeTar(destMain, csn)
78
82
  }
83
+
84
+ /**
85
+ * Synchronous compilation using the sidecar context.
86
+ * @param {object} sidecarEnv cds env based on the sidecar dir
87
+ * @returns the compiled mtx sidecar CSN
88
+ */
89
+ _compileSidecarSync(sidecarEnv) {
90
+ const env = this.env
91
+ try {
92
+ this.cds.root = this.task.src
93
+ this.cds.env = sidecarEnv
94
+ let modelPaths = this.cds.resolve('*', false)
95
+ modelPaths = this.cds.resolve(modelPaths)
96
+ if (!modelPaths || modelPaths.length === 0) {
97
+ throw new Error("No model found for MTX sidecar app")
98
+ }
99
+ this._logger._debug && this._logger.debug(`sidecar model: ${relativePaths(this.buildOptions.root, modelPaths).join(", ")}`)
100
+
101
+ // synchronous compilation
102
+ return this.cds.load(modelPaths, { sync: true, ...this.options() })
103
+ } finally {
104
+ // restore project scope
105
+ this.cds.root = this.buildOptions.root
106
+ this.cds.env = env
107
+ }
108
+ }
79
109
  }
80
110
  module.exports = MtxSidecarModuleBuilder
package/bin/serve.js CHANGED
@@ -203,7 +203,7 @@ async function serve (all=[], o={}) { // NOSONAR
203
203
  const shutdown = async sig => {
204
204
  if (shutdownCalled) return
205
205
  shutdownCalled = true
206
- global.jest || cds.watched || console.log() // blank line makes the ^C look pretty in terminals
206
+ global.it || cds.watched || console.log() // blank line makes the ^C look pretty in terminals
207
207
  debug && debug(`${sig}, shutting down, calling ${cds.listeners('shutdown').length} listeners`)
208
208
  await Promise.all(cds.listeners('shutdown').map((fn) => fn()))
209
209
  if (process.env.NODE_ENV !== 'test' && !global.it) process.exit()
@@ -193,6 +193,7 @@ const _mtx_services = {
193
193
  },
194
194
  "cds.xt.SaasProvisioningService": {
195
195
  model: "@sap/cds-mtxs/srv/cf/saas-provisioning-service",
196
+ kind: "saas-registry",
196
197
  },
197
198
  "cds.xt.DeploymentService": {
198
199
  model: "@sap/cds-mtxs/srv/deployment-service",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds",
3
- "version": "6.0.1",
3
+ "version": "6.0.2",
4
4
  "description": "SAP Cloud Application Programming Model - CDS for Node.js",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [