@sap-ux/cap-config-writer 0.9.21 → 0.9.22

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.
@@ -1,8 +1,4 @@
1
1
  import type { Editor } from 'mem-fs-editor';
2
- import type { CdsVersionInfo } from '@sap-ux/project-access';
3
- import { minCdsVersion } from './package-json';
4
- export { satisfiesMinCdsVersion } from './package-json';
5
- import type { CdsUi5PluginInfo } from './types';
6
2
  /**
7
3
  * Enable workspace and cds-plugin-ui5 for given CAP project.
8
4
  *
@@ -11,33 +7,4 @@ import type { CdsUi5PluginInfo } from './types';
11
7
  * @returns Promise<Editor> - memfs editor instance with updated files
12
8
  */
13
9
  export declare function enableCdsUi5Plugin(basePath: string, fs?: Editor): Promise<Editor>;
14
- /**
15
- * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version.
16
- * Overloaded function that returns detailed CAP plugin info.
17
- *
18
- * @param basePath - root path of the CAP project, where package.json is located
19
- * @param [fs] - optional: the memfs editor instance
20
- * @returns true: cds-plugin-ui5 and all prerequisites are fulfilled; false: cds-plugin-ui5 is not enabled or not all prerequisites are fulfilled
21
- */
22
- export declare function checkCdsUi5PluginEnabled(basePath: string, fs?: Editor): Promise<boolean>;
23
- /**
24
- * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version.
25
- *
26
- * @param basePath - root path of the CAP project, where package.json is located
27
- * @param [fs] - optional: the memfs editor instance
28
- * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state
29
- * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info
30
- */
31
- export declare function checkCdsUi5PluginEnabled(basePath: string, fs?: Editor, moreInfo?: boolean): Promise<boolean | CdsUi5PluginInfo>;
32
- /**
33
- * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version.
34
- *
35
- * @param basePath - root path of the CAP project, where package.json is located
36
- * @param [fs] - optional: the memfs editor instance
37
- * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state
38
- * @param {CdsVersionInfo} [cdsVersionInfo] - If provided will be used instead of parsing the package.json file to determine the cds version.
39
- * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info
40
- */
41
- export declare function checkCdsUi5PluginEnabled(basePath: string, fs?: Editor, moreInfo?: boolean, cdsVersionInfo?: CdsVersionInfo): Promise<boolean | CdsUi5PluginInfo>;
42
- export { minCdsVersion };
43
10
  //# sourceMappingURL=index.d.ts.map
@@ -1,16 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.minCdsVersion = exports.satisfiesMinCdsVersion = void 0;
4
3
  exports.enableCdsUi5Plugin = enableCdsUi5Plugin;
5
- exports.checkCdsUi5PluginEnabled = checkCdsUi5PluginEnabled;
6
4
  const path_1 = require("path");
7
5
  const mem_fs_1 = require("mem-fs");
8
6
  const mem_fs_editor_1 = require("mem-fs-editor");
9
7
  const package_json_1 = require("./package-json");
10
- Object.defineProperty(exports, "minCdsVersion", { enumerable: true, get: function () { return package_json_1.minCdsVersion; } });
11
- var package_json_2 = require("./package-json");
12
- Object.defineProperty(exports, "satisfiesMinCdsVersion", { enumerable: true, get: function () { return package_json_2.satisfiesMinCdsVersion; } });
13
- const semver_1 = require("semver");
14
8
  /**
15
9
  * Enable workspace and cds-plugin-ui5 for given CAP project.
16
10
  *
@@ -30,39 +24,4 @@ async function enableCdsUi5Plugin(basePath, fs) {
30
24
  fs.writeJSON(packageJsonPath, packageJson);
31
25
  return fs;
32
26
  }
33
- /**
34
- * Implementation of the overloaded function.
35
- * Check if cds-plugin-ui5 is enabled on a CAP project. Checks also all prerequisites, like minimum @sap/cds version.
36
- *
37
- * @param basePath - root path of the CAP project, where package.json is located
38
- * @param [fs] - optional: the memfs editor instance
39
- * @param [moreInfo] if true return an object specifying detailed info about the cds and workspace state
40
- * @param {CdsVersionInfo} [cdsVersionInfo] - If provided will be used instead of parsing the package.json file to determine the cds version.
41
- * @returns false if package.json is not found at specified path or {@link CdsUi5PluginInfo} with additional info or true if
42
- * cds-plugin-ui5 and all prerequisites are fulfilled
43
- */
44
- async function checkCdsUi5PluginEnabled(basePath, fs, moreInfo, cdsVersionInfo) {
45
- if (!fs) {
46
- fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)());
47
- }
48
- const packageJsonPath = (0, path_1.join)(basePath, 'package.json');
49
- if (!fs.exists(packageJsonPath)) {
50
- return false;
51
- }
52
- const packageJson = fs.readJSON(packageJsonPath);
53
- const { workspaceEnabled } = await (0, package_json_1.getWorkspaceInfo)(basePath, packageJson);
54
- const cdsInfo = {
55
- // Below line checks if 'cdsVersionInfo' is available and contains version information.
56
- // If it does, it uses that version information to determine if it satisfies the minimum CDS version required.
57
- // If 'cdsVersionInfo' is not available or does not contain version information,it falls back to check the version specified in the package.json file.
58
- hasMinCdsVersion: cdsVersionInfo?.version
59
- ? (0, semver_1.satisfies)(cdsVersionInfo?.version, `>=${package_json_1.minCdsVersion}`)
60
- : (0, package_json_1.satisfiesMinCdsVersion)(packageJson),
61
- isWorkspaceEnabled: workspaceEnabled,
62
- hasCdsUi5Plugin: (0, package_json_1.hasCdsPluginUi5)(packageJson),
63
- isCdsUi5PluginEnabled: false
64
- };
65
- cdsInfo.isCdsUi5PluginEnabled = cdsInfo.hasMinCdsVersion && cdsInfo.isWorkspaceEnabled && cdsInfo.hasCdsUi5Plugin;
66
- return moreInfo ? cdsInfo : cdsInfo.isCdsUi5PluginEnabled;
67
- }
68
27
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,4 @@
1
- import type { Package } from '@sap-ux/project-access';
2
- export declare const minCdsVersion = "6.8.2";
1
+ import { type Package } from '@sap-ux/project-access';
3
2
  /**
4
3
  * Ensure a minimum version of @sap/cds in dependencies.
5
4
  *
@@ -19,37 +18,4 @@ export declare function enableWorkspaces(basePath: string, packageJson: Package)
19
18
  * @param packageJson - the parsed package.json
20
19
  */
21
20
  export declare function addCdsPluginUi5(packageJson: Package): void;
22
- /**
23
- * Check if package.json has dependency to the minimum min version of @sap/cds,
24
- * that is required to enable cds-plugin-ui.
25
- *
26
- * @param packageJson - the parsed package.json
27
- * @returns - true: min cds version is present; false: cds version needs update
28
- */
29
- export declare function hasMinCdsVersion(packageJson: Package): boolean;
30
- /**
31
- * Check if package.json has version or version range that satisfies the minimum version of @sap/cds.
32
- *
33
- * @param packageJson - the parsed package.json
34
- * @returns - true: cds version satisfies the min cds version; false: cds version does not satisfy min cds version
35
- */
36
- export declare function satisfiesMinCdsVersion(packageJson: Package): boolean;
37
- /**
38
- * Get information about the workspaces in the CAP project.
39
- *
40
- * @param basePath - root path of the CAP project, where package.json is located
41
- * @param packageJson - the parsed package.json
42
- * @returns - appWorkspace containing the path to the appWorkspace including wildcard; workspaceEnabled: boolean that states whether workspace for apps are enabled
43
- */
44
- export declare function getWorkspaceInfo(basePath: string, packageJson: Package): Promise<{
45
- appWorkspace: string;
46
- workspaceEnabled: boolean;
47
- }>;
48
- /**
49
- * Check if devDependency to cds-plugin-ui5 is present in package.json.
50
- *
51
- * @param packageJson - the parsed package.json
52
- * @returns true: devDependency to cds-plugin-ui5 exists; false: devDependency to cds-plugin-ui5 does not exist
53
- */
54
- export declare function hasCdsPluginUi5(packageJson: Package): boolean;
55
21
  //# sourceMappingURL=package-json.d.ts.map
@@ -1,16 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.minCdsVersion = void 0;
4
3
  exports.ensureMinCdsVersion = ensureMinCdsVersion;
5
4
  exports.enableWorkspaces = enableWorkspaces;
6
5
  exports.addCdsPluginUi5 = addCdsPluginUi5;
7
- exports.hasMinCdsVersion = hasMinCdsVersion;
8
- exports.satisfiesMinCdsVersion = satisfiesMinCdsVersion;
9
- exports.getWorkspaceInfo = getWorkspaceInfo;
10
- exports.hasCdsPluginUi5 = hasCdsPluginUi5;
11
- const semver_1 = require("semver");
12
6
  const project_access_1 = require("@sap-ux/project-access");
13
- exports.minCdsVersion = '6.8.2';
14
7
  const minCdsPluginUi5Version = '0.9.3';
15
8
  /**
16
9
  * Ensure a minimum version of @sap/cds in dependencies.
@@ -18,9 +11,9 @@ const minCdsPluginUi5Version = '0.9.3';
18
11
  * @param packageJson - the parsed package.json
19
12
  */
20
13
  function ensureMinCdsVersion(packageJson) {
21
- if (!hasMinCdsVersion(packageJson)) {
14
+ if (!(0, project_access_1.hasMinCdsVersion)(packageJson)) {
22
15
  packageJson.dependencies ??= {};
23
- packageJson.dependencies['@sap/cds'] = `^${exports.minCdsVersion}`;
16
+ packageJson.dependencies['@sap/cds'] = `^${project_access_1.MinCdsVersionUi5Plugin}`;
24
17
  }
25
18
  }
26
19
  /**
@@ -30,12 +23,11 @@ function ensureMinCdsVersion(packageJson) {
30
23
  * @param packageJson - the parsed package.json
31
24
  */
32
25
  async function enableWorkspaces(basePath, packageJson) {
33
- const { appWorkspace, workspaceEnabled } = await getWorkspaceInfo(basePath, packageJson);
26
+ let { appWorkspace, workspaceEnabled, workspacePackages } = await (0, project_access_1.getWorkspaceInfo)(basePath, packageJson);
34
27
  if (workspaceEnabled) {
35
28
  return;
36
29
  }
37
- let workspacePackages = getWorkspacePackages(packageJson);
38
- if (!workspacePackages) {
30
+ if (workspacePackages.length === 0) {
39
31
  packageJson.workspaces ??= [];
40
32
  if (Array.isArray(packageJson.workspaces)) {
41
33
  workspacePackages = packageJson.workspaces;
@@ -53,69 +45,9 @@ async function enableWorkspaces(basePath, packageJson) {
53
45
  * @param packageJson - the parsed package.json
54
46
  */
55
47
  function addCdsPluginUi5(packageJson) {
56
- if (!hasCdsPluginUi5(packageJson)) {
48
+ if (!(0, project_access_1.hasDependency)(packageJson, 'cds-plugin-ui5')) {
57
49
  packageJson.devDependencies ??= {};
58
50
  packageJson.devDependencies['cds-plugin-ui5'] = `^${minCdsPluginUi5Version}`;
59
51
  }
60
52
  }
61
- /**
62
- * Check if package.json has dependency to the minimum min version of @sap/cds,
63
- * that is required to enable cds-plugin-ui.
64
- *
65
- * @param packageJson - the parsed package.json
66
- * @returns - true: min cds version is present; false: cds version needs update
67
- */
68
- function hasMinCdsVersion(packageJson) {
69
- return (0, semver_1.gte)((0, semver_1.coerce)(packageJson.dependencies?.['@sap/cds']) ?? '0.0.0', exports.minCdsVersion);
70
- }
71
- /**
72
- * Check if package.json has version or version range that satisfies the minimum version of @sap/cds.
73
- *
74
- * @param packageJson - the parsed package.json
75
- * @returns - true: cds version satisfies the min cds version; false: cds version does not satisfy min cds version
76
- */
77
- function satisfiesMinCdsVersion(packageJson) {
78
- return hasMinCdsVersion(packageJson) || (0, semver_1.satisfies)(exports.minCdsVersion, packageJson.dependencies?.['@sap/cds'] ?? '0.0.0');
79
- }
80
- /**
81
- * Get information about the workspaces in the CAP project.
82
- *
83
- * @param basePath - root path of the CAP project, where package.json is located
84
- * @param packageJson - the parsed package.json
85
- * @returns - appWorkspace containing the path to the appWorkspace including wildcard; workspaceEnabled: boolean that states whether workspace for apps are enabled
86
- */
87
- async function getWorkspaceInfo(basePath, packageJson) {
88
- const capPaths = await (0, project_access_1.getCapCustomPaths)(basePath);
89
- const appWorkspace = capPaths.app.endsWith('/') ? `${capPaths.app}*` : `${capPaths.app}/*`;
90
- const workspacePackages = getWorkspacePackages(packageJson) ?? [];
91
- const workspaceEnabled = workspacePackages.includes(appWorkspace);
92
- return { appWorkspace, workspaceEnabled };
93
- }
94
- /**
95
- * Return the reference to the array of workspace packages or undefined if not defined.
96
- * The workspace packages can either be defined directly as workspaces in package.json
97
- * or in workspaces.packages, e.g. in yarn workspaces.
98
- *
99
- * @param packageJson - the parsed package.json
100
- * @returns ref to the packages in workspaces or undefined
101
- */
102
- function getWorkspacePackages(packageJson) {
103
- let workspacePackages;
104
- if (Array.isArray(packageJson.workspaces)) {
105
- workspacePackages = packageJson.workspaces;
106
- }
107
- else if (Array.isArray(packageJson.workspaces?.packages)) {
108
- workspacePackages = packageJson.workspaces?.packages;
109
- }
110
- return workspacePackages;
111
- }
112
- /**
113
- * Check if devDependency to cds-plugin-ui5 is present in package.json.
114
- *
115
- * @param packageJson - the parsed package.json
116
- * @returns true: devDependency to cds-plugin-ui5 exists; false: devDependency to cds-plugin-ui5 does not exist
117
- */
118
- function hasCdsPluginUi5(packageJson) {
119
- return !!packageJson.devDependencies?.['cds-plugin-ui5'];
120
- }
121
53
  //# sourceMappingURL=package-json.js.map
@@ -1,22 +1,4 @@
1
- import type { CdsVersionInfo } from '@sap-ux/project-access';
2
- export type CdsUi5PluginInfo = {
3
- /**
4
- * Convienience property. The CDS UI5 plugin is considered enabled if `hasCdsUi5Plugin`, `hasMinCdsVersion`, `isWorkspaceEnabled` are all true.
5
- */
6
- isCdsUi5PluginEnabled: boolean;
7
- /**
8
- * True if the CDS version satisfies the minimum supported CDS version
9
- */
10
- hasMinCdsVersion: boolean;
11
- /**
12
- * True if NPM workspaces are enabled at the root of a CAP project
13
- */
14
- isWorkspaceEnabled: boolean;
15
- /**
16
- * True if the CDS ui5 plugin is specified as a dependency
17
- */
18
- hasCdsUi5Plugin: boolean;
19
- };
1
+ import type { CdsVersionInfo, CdsUi5PluginInfo } from '@sap-ux/project-access';
20
2
  export type CapRuntime = 'Node.js' | 'Java';
21
3
  export interface CapService {
22
4
  /**
@@ -45,7 +45,7 @@ function updatePackageJsonWithScripts(fs, packageJsonPath, scripts) {
45
45
  * @returns {Promise<void>} A Promise that resolves once the scripts are updated.
46
46
  */
47
47
  async function updateScripts(fs, packageJsonPath, projectName, appId, enableNPMWorkspaces) {
48
- const hasNPMworkspaces = await (0, cap_config_1.checkCdsUi5PluginEnabled)((0, path_1.dirname)(packageJsonPath), fs);
48
+ const hasNPMworkspaces = await (0, project_access_1.checkCdsUi5PluginEnabled)((0, path_1.dirname)(packageJsonPath), fs);
49
49
  let cdsScript;
50
50
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
51
51
  if (enableNPMWorkspaces || hasNPMworkspaces) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- export { checkCdsUi5PluginEnabled, enableCdsUi5Plugin, satisfiesMinCdsVersion } from './cap-config';
1
+ import { checkCdsUi5PluginEnabled } from '@sap-ux/project-access';
2
+ export { checkCdsUi5PluginEnabled };
3
+ export { enableCdsUi5Plugin } from './cap-config';
2
4
  export type { CapService, CapRuntime } from './cap-config/types';
3
- export type { CdsUi5PluginInfo, CapServiceCdsInfo, CapProjectSettings } from './cap-config/types';
5
+ export type { CapServiceCdsInfo, CapProjectSettings } from './cap-config/types';
4
6
  export * from './cap-writer';
5
7
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,10 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.satisfiesMinCdsVersion = exports.enableCdsUi5Plugin = exports.checkCdsUi5PluginEnabled = void 0;
17
+ exports.enableCdsUi5Plugin = exports.checkCdsUi5PluginEnabled = void 0;
18
+ const project_access_1 = require("@sap-ux/project-access");
19
+ Object.defineProperty(exports, "checkCdsUi5PluginEnabled", { enumerable: true, get: function () { return project_access_1.checkCdsUi5PluginEnabled; } });
18
20
  var cap_config_1 = require("./cap-config");
19
- Object.defineProperty(exports, "checkCdsUi5PluginEnabled", { enumerable: true, get: function () { return cap_config_1.checkCdsUi5PluginEnabled; } });
20
21
  Object.defineProperty(exports, "enableCdsUi5Plugin", { enumerable: true, get: function () { return cap_config_1.enableCdsUi5Plugin; } });
21
- Object.defineProperty(exports, "satisfiesMinCdsVersion", { enumerable: true, get: function () { return cap_config_1.satisfiesMinCdsVersion; } });
22
22
  __exportStar(require("./cap-writer"), exports);
23
23
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sap-ux/cap-config-writer",
3
3
  "description": "Add or update configuration for SAP CAP projects",
4
- "version": "0.9.21",
4
+ "version": "0.9.22",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -25,9 +25,9 @@
25
25
  "semver": "7.5.4",
26
26
  "xml-js": "1.6.11",
27
27
  "@sap-ux/logger": "0.6.0",
28
- "@sap-ux/project-access": "1.29.17",
28
+ "@sap-ux/project-access": "1.29.18",
29
29
  "@sap-ux/yaml": "0.16.0",
30
- "@sap-ux/fiori-generator-shared": "0.9.10"
30
+ "@sap-ux/fiori-generator-shared": "0.9.11"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/mem-fs": "1.1.2",