@sap-ux/project-access 1.25.0 → 1.25.3

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { FileName, DirName, FioriToolsSettings } from './constants';
2
2
  export { getFilePaths } from './file';
3
- export { addPackageDevDependency, clearCdsModuleCache, createApplicationAccess, createProjectAccess, findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getCapI18nFolderNames, getSpecification, getI18nPropertiesPaths, getMinUI5VersionFromManifest, getMinUI5VersionAsArray, getMinimumUI5Version, getMtaPath, getNodeModulesPath, getProject, getProjectType, getWebappPath, isCapProject, isCapJavaProject, isCapNodeJsProject, loadModuleFromProject, readCapServiceMetadataEdmx, readUi5Yaml, refreshSpecificationDistTags, toReferenceUri, filterDataSourcesByType, updatePackageScript } from './project';
3
+ export { addPackageDevDependency, clearCdsModuleCache, createApplicationAccess, createProjectAccess, findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getCapI18nFolderNames, getSpecification, getSpecificationPath, getI18nPropertiesPaths, getMinUI5VersionFromManifest, getMinUI5VersionAsArray, getMinimumUI5Version, getMtaPath, getNodeModulesPath, getProject, getProjectType, getWebappPath, isCapProject, isCapJavaProject, isCapNodeJsProject, loadModuleFromProject, readCapServiceMetadataEdmx, readUi5Yaml, refreshSpecificationDistTags, toReferenceUri, filterDataSourcesByType, updatePackageScript } from './project';
4
4
  export * from './types';
5
5
  export * from './library';
6
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ 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.updatePackageScript = exports.filterDataSourcesByType = exports.toReferenceUri = exports.refreshSpecificationDistTags = exports.readUi5Yaml = exports.readCapServiceMetadataEdmx = exports.loadModuleFromProject = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.isCapProject = exports.getWebappPath = exports.getProjectType = exports.getProject = exports.getNodeModulesPath = exports.getMtaPath = exports.getMinimumUI5Version = exports.getMinUI5VersionAsArray = exports.getMinUI5VersionFromManifest = exports.getI18nPropertiesPaths = exports.getSpecification = exports.getCapI18nFolderNames = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapEnvironment = exports.getCapCustomPaths = exports.getAppType = exports.getAppProgrammingLanguage = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.createProjectAccess = exports.createApplicationAccess = exports.clearCdsModuleCache = exports.addPackageDevDependency = exports.getFilePaths = exports.FioriToolsSettings = exports.DirName = exports.FileName = void 0;
17
+ exports.updatePackageScript = exports.filterDataSourcesByType = exports.toReferenceUri = exports.refreshSpecificationDistTags = exports.readUi5Yaml = exports.readCapServiceMetadataEdmx = exports.loadModuleFromProject = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.isCapProject = exports.getWebappPath = exports.getProjectType = exports.getProject = exports.getNodeModulesPath = exports.getMtaPath = exports.getMinimumUI5Version = exports.getMinUI5VersionAsArray = exports.getMinUI5VersionFromManifest = exports.getI18nPropertiesPaths = exports.getSpecificationPath = exports.getSpecification = exports.getCapI18nFolderNames = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapEnvironment = exports.getCapCustomPaths = exports.getAppType = exports.getAppProgrammingLanguage = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.createProjectAccess = exports.createApplicationAccess = exports.clearCdsModuleCache = exports.addPackageDevDependency = exports.getFilePaths = exports.FioriToolsSettings = exports.DirName = exports.FileName = void 0;
18
18
  var constants_1 = require("./constants");
19
19
  Object.defineProperty(exports, "FileName", { enumerable: true, get: function () { return constants_1.FileName; } });
20
20
  Object.defineProperty(exports, "DirName", { enumerable: true, get: function () { return constants_1.DirName; } });
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "getCdsRoots", { enumerable: true, get: function
42
42
  Object.defineProperty(exports, "getCdsServices", { enumerable: true, get: function () { return project_1.getCdsServices; } });
43
43
  Object.defineProperty(exports, "getCapI18nFolderNames", { enumerable: true, get: function () { return project_1.getCapI18nFolderNames; } });
44
44
  Object.defineProperty(exports, "getSpecification", { enumerable: true, get: function () { return project_1.getSpecification; } });
45
+ Object.defineProperty(exports, "getSpecificationPath", { enumerable: true, get: function () { return project_1.getSpecificationPath; } });
45
46
  Object.defineProperty(exports, "getI18nPropertiesPaths", { enumerable: true, get: function () { return project_1.getI18nPropertiesPaths; } });
46
47
  Object.defineProperty(exports, "getMinUI5VersionFromManifest", { enumerable: true, get: function () { return project_1.getMinUI5VersionFromManifest; } });
47
48
  Object.defineProperty(exports, "getMinUI5VersionAsArray", { enumerable: true, get: function () { return project_1.getMinUI5VersionAsArray; } });
@@ -9,5 +9,5 @@ export { getWebappPath, readUi5Yaml } from './ui5-config';
9
9
  export { getMtaPath } from './mta';
10
10
  export { createApplicationAccess, createProjectAccess } from './access';
11
11
  export { updatePackageScript } from './script';
12
- export { getSpecification, refreshSpecificationDistTags } from './specification';
12
+ export { getSpecification, getSpecificationPath, refreshSpecificationDistTags } from './specification';
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.refreshSpecificationDistTags = exports.getSpecification = exports.updatePackageScript = exports.createProjectAccess = exports.createApplicationAccess = exports.getMtaPath = exports.readUi5Yaml = exports.getWebappPath = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.loadModuleFromProject = exports.getProjectType = exports.getProject = exports.getMinimumUI5Version = exports.getMinUI5VersionAsArray = exports.getMinUI5VersionFromManifest = exports.getAppType = exports.getAppProgrammingLanguage = exports.getI18nPropertiesPaths = exports.getCapI18nFolderNames = exports.getNodeModulesPath = exports.addPackageDevDependency = exports.filterDataSourcesByType = exports.clearCdsModuleCache = exports.toReferenceUri = exports.readCapServiceMetadataEdmx = exports.getCapEnvironment = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.isCapProject = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapCustomPaths = void 0;
3
+ exports.refreshSpecificationDistTags = exports.getSpecificationPath = exports.getSpecification = exports.updatePackageScript = exports.createProjectAccess = exports.createApplicationAccess = exports.getMtaPath = exports.readUi5Yaml = exports.getWebappPath = exports.getAppRootFromWebappPath = exports.findProjectRoot = exports.findFioriArtifacts = exports.findCapProjects = exports.findAllApps = exports.loadModuleFromProject = exports.getProjectType = exports.getProject = exports.getMinimumUI5Version = exports.getMinUI5VersionAsArray = exports.getMinUI5VersionFromManifest = exports.getAppType = exports.getAppProgrammingLanguage = exports.getI18nPropertiesPaths = exports.getCapI18nFolderNames = exports.getNodeModulesPath = exports.addPackageDevDependency = exports.filterDataSourcesByType = exports.clearCdsModuleCache = exports.toReferenceUri = exports.readCapServiceMetadataEdmx = exports.getCapEnvironment = exports.isCapNodeJsProject = exports.isCapJavaProject = exports.isCapProject = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapProjectType = exports.getCapModelAndServices = exports.getCapCustomPaths = void 0;
4
4
  var cap_1 = require("./cap");
5
5
  Object.defineProperty(exports, "getCapCustomPaths", { enumerable: true, get: function () { return cap_1.getCapCustomPaths; } });
6
6
  Object.defineProperty(exports, "getCapModelAndServices", { enumerable: true, get: function () { return cap_1.getCapModelAndServices; } });
@@ -51,5 +51,6 @@ var script_1 = require("./script");
51
51
  Object.defineProperty(exports, "updatePackageScript", { enumerable: true, get: function () { return script_1.updatePackageScript; } });
52
52
  var specification_1 = require("./specification");
53
53
  Object.defineProperty(exports, "getSpecification", { enumerable: true, get: function () { return specification_1.getSpecification; } });
54
+ Object.defineProperty(exports, "getSpecificationPath", { enumerable: true, get: function () { return specification_1.getSpecificationPath; } });
54
55
  Object.defineProperty(exports, "refreshSpecificationDistTags", { enumerable: true, get: function () { return specification_1.refreshSpecificationDistTags; } });
55
56
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,12 @@
1
1
  import type { Logger } from '@sap-ux/logger';
2
+ /**
3
+ * Get the module path from project or app. Throws error if module is not installed.
4
+ *
5
+ * @param projectRoot - root path of the project/app.
6
+ * @param moduleName - name of the node module.
7
+ * @returns - path to module.
8
+ */
9
+ export declare function getModulePath(projectRoot: string, moduleName: string): Promise<string>;
2
10
  /**
3
11
  * Load module from project or app. Throws error if module is not installed.
4
12
  *
@@ -23,13 +23,27 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.deleteModule = exports.getModule = exports.loadModuleFromProject = void 0;
26
+ exports.deleteModule = exports.getModule = exports.loadModuleFromProject = exports.getModulePath = void 0;
27
27
  const fs_1 = require("fs");
28
28
  const promises_1 = require("fs/promises");
29
29
  const path_1 = require("path");
30
30
  const dependencies_1 = require("./dependencies");
31
31
  const constants_1 = require("../constants");
32
32
  const command_1 = require("../command");
33
+ /**
34
+ * Get the module path from project or app. Throws error if module is not installed.
35
+ *
36
+ * @param projectRoot - root path of the project/app.
37
+ * @param moduleName - name of the node module.
38
+ * @returns - path to module.
39
+ */
40
+ async function getModulePath(projectRoot, moduleName) {
41
+ if (!(0, dependencies_1.getNodeModulesPath)(projectRoot, moduleName)) {
42
+ throw Error('Path to module not found.');
43
+ }
44
+ return require.resolve(moduleName, { paths: [projectRoot] });
45
+ }
46
+ exports.getModulePath = getModulePath;
33
47
  /**
34
48
  * Load module from project or app. Throws error if module is not installed.
35
49
  *
@@ -46,10 +60,7 @@ const command_1 = require("../command");
46
60
  async function loadModuleFromProject(projectRoot, moduleName) {
47
61
  let module;
48
62
  try {
49
- if (!(0, dependencies_1.getNodeModulesPath)(projectRoot, moduleName)) {
50
- throw Error('Path to module not found.');
51
- }
52
- const modulePath = require.resolve(moduleName, { paths: [projectRoot] });
63
+ const modulePath = await getModulePath(projectRoot, moduleName);
53
64
  module = (await Promise.resolve(`${modulePath}`).then(s => __importStar(require(s))));
54
65
  }
55
66
  catch (error) {
@@ -21,4 +21,16 @@ export declare function getSpecification<T>(root: string, options?: {
21
21
  export declare function refreshSpecificationDistTags(options?: {
22
22
  logger?: Logger;
23
23
  }): Promise<void>;
24
+ /**
25
+ * Returns the path to the specification used.
26
+ * Can be path to node_modules in project, or cache.
27
+ *
28
+ * @param root - root path of the project/app
29
+ * @param [options] - optional options
30
+ * @param [options.logger] - optional logger instance
31
+ * @returns - path to specification
32
+ */
33
+ export declare function getSpecificationPath(root: string, options?: {
34
+ logger?: Logger;
35
+ }): Promise<string>;
24
36
  //# sourceMappingURL=specification.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.refreshSpecificationDistTags = exports.getSpecification = void 0;
3
+ exports.getSpecificationPath = exports.refreshSpecificationDistTags = exports.getSpecification = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const promises_1 = require("fs/promises");
6
6
  const path_1 = require("path");
@@ -13,29 +13,14 @@ const file_1 = require("../file");
13
13
  const command_1 = require("../command");
14
14
  const specificationDistTagPath = (0, path_1.join)(constants_1.fioriToolsDirectory, constants_1.FileName.SpecificationDistTags);
15
15
  /**
16
- * Loads and return specification from project or cache.
17
- * 1. if package.json contains devDependency to specification, attempts to load from project.
18
- * 2. if not in package.json of project, attempts to load from cache.
16
+ * Gets the dist-tag for the provided project/app and returns it.
19
17
  *
20
18
  * @param root - root path of the project/app
21
19
  * @param [options] - optional options
22
20
  * @param [options.logger] - logger instance
23
21
  * @returns - specification instance
24
22
  */
25
- async function getSpecification(root, options) {
26
- let specification;
27
- const logger = options?.logger;
28
- try {
29
- const packageJson = await (0, file_1.readJSON)((0, path_1.join)(root, constants_1.FileName.Package));
30
- if (packageJson.devDependencies?.['@sap/ux-specification']) {
31
- logger?.debug(`Specification found in devDependencies of project '${root}', trying to load`);
32
- // Early return with load module from project. If it throws an error it is not handled here.
33
- return (0, module_loader_1.loadModuleFromProject)(root, '@sap/ux-specification');
34
- }
35
- }
36
- catch {
37
- logger?.debug(`Specification not found in project '${root}', trying to load from cache`);
38
- }
23
+ async function getProjectDistTag(root, options) {
39
24
  let distTag = 'latest';
40
25
  try {
41
26
  const webappPath = await (0, ui5_config_1.getWebappPath)(root);
@@ -47,11 +32,35 @@ async function getSpecification(root, options) {
47
32
  }
48
33
  }
49
34
  catch (error) {
50
- logger?.error(`Failed to get minimum UI5 version from manifest: ${error} using 'latest'`);
35
+ options?.logger?.error(`Failed to get minimum UI5 version from manifest: ${error} using 'latest'`);
51
36
  }
37
+ return distTag;
38
+ }
39
+ /**
40
+ * Checks if package.json contains dev dependency to specification.
41
+ *
42
+ * @param root - root path of the project/app
43
+ * @returns If dev dependency to specification is found in package.json
44
+ */
45
+ async function hasSpecificationDevDependency(root) {
46
+ const packageJson = await (0, file_1.readJSON)((0, path_1.join)(root, constants_1.FileName.Package));
47
+ return !!packageJson.devDependencies?.['@sap/ux-specification'];
48
+ }
49
+ /**
50
+ * Loads the specification module from cache and returns it.
51
+ *
52
+ * @param root - root path of the project/app
53
+ * @param [options] - optional options
54
+ * @param [options.logger] - logger instance
55
+ * @returns - specification instance
56
+ */
57
+ async function getSpecificationModule(root, options) {
58
+ const logger = options?.logger;
59
+ let specification;
60
+ const version = await getSpecificationVersion(root, { logger });
52
61
  try {
53
- specification = await getSpecificationByDistTag(distTag, { logger });
54
- logger?.debug(`Specification loaded from cache using dist-tag '${distTag}'`);
62
+ specification = await getSpecificationByVersion(version, { logger });
63
+ logger?.debug(`Specification loaded from cache using version '${version}'`);
55
64
  }
56
65
  catch (error) {
57
66
  logger?.error(`Failed to load specification: ${error}`);
@@ -59,6 +68,30 @@ async function getSpecification(root, options) {
59
68
  }
60
69
  return specification;
61
70
  }
71
+ /**
72
+ * Loads and return specification from project or cache.
73
+ * 1. if package.json contains devDependency to specification, attempts to load from project.
74
+ * 2. if not in package.json of project, attempts to load from cache.
75
+ *
76
+ * @param root - root path of the project/app
77
+ * @param [options] - optional options
78
+ * @param [options.logger] - logger instance
79
+ * @returns - specification instance
80
+ */
81
+ async function getSpecification(root, options) {
82
+ const logger = options?.logger;
83
+ try {
84
+ if (await hasSpecificationDevDependency(root)) {
85
+ logger?.debug(`Specification found in devDependencies of project '${root}', trying to load`);
86
+ // Early return with load module from project. If it throws an error it is not handled here.
87
+ return (0, module_loader_1.loadModuleFromProject)(root, '@sap/ux-specification');
88
+ }
89
+ }
90
+ catch {
91
+ logger?.debug(`Specification not found in project '${root}', trying to load from cache`);
92
+ }
93
+ return await getSpecificationModule(root, { logger });
94
+ }
62
95
  exports.getSpecification = getSpecification;
63
96
  /**
64
97
  * Refreshes the specification dist-tags cache. Also cleans specification modules in cache that are not required anymore.
@@ -95,16 +128,15 @@ async function refreshSpecificationDistTags(options) {
95
128
  }
96
129
  exports.refreshSpecificationDistTags = refreshSpecificationDistTags;
97
130
  /**
98
- * Loads and return specification from cache by dist-tag.
131
+ * Loads and return specification from cache by version.
99
132
  *
100
- * @param distTag - dist-tag of the specification, like 'latest' or 'UI5-1.71'
133
+ * @param version - version of the specification
101
134
  * @param [options] - optional options
102
135
  * @param [options.logger] - optional logger instance
103
136
  * @returns - specification instance
104
137
  */
105
- async function getSpecificationByDistTag(distTag, options) {
138
+ async function getSpecificationByVersion(version, options) {
106
139
  const logger = options?.logger;
107
- const version = await convertDistTagToVersion(distTag, { logger });
108
140
  const specification = await (0, module_loader_1.getModule)('@sap/ux-specification', version, { logger });
109
141
  return specification;
110
142
  }
@@ -126,4 +158,42 @@ async function convertDistTagToVersion(distTag, options) {
126
158
  const version = specificationDistTags[distTag] ?? specificationDistTags.latest;
127
159
  return version;
128
160
  }
161
+ /**
162
+ * Gets the dist-tag of a project specification and returns the version from it.
163
+ *
164
+ * @param root - root path of the project/app
165
+ * @param [options] - optional options
166
+ * @param [options.logger] - optional logger instance
167
+ * @returns - version of specification
168
+ */
169
+ async function getSpecificationVersion(root, options) {
170
+ const logger = options?.logger;
171
+ const distTag = await getProjectDistTag(root, { logger });
172
+ return await convertDistTagToVersion(distTag, { logger });
173
+ }
174
+ /**
175
+ * Returns the path to the specification used.
176
+ * Can be path to node_modules in project, or cache.
177
+ *
178
+ * @param root - root path of the project/app
179
+ * @param [options] - optional options
180
+ * @param [options.logger] - optional logger instance
181
+ * @returns - path to specification
182
+ */
183
+ async function getSpecificationPath(root, options) {
184
+ const logger = options?.logger;
185
+ const moduleName = '@sap/ux-specification';
186
+ if (await hasSpecificationDevDependency(root)) {
187
+ const modulePath = await (0, module_loader_1.getModulePath)(root, moduleName);
188
+ logger?.debug(`Specification root found in project '${root}'`);
189
+ return modulePath.slice(0, modulePath.lastIndexOf((0, path_1.join)(moduleName)) + (0, path_1.join)(moduleName).length);
190
+ }
191
+ await getSpecificationModule(root, { logger });
192
+ const version = await getSpecificationVersion(root, { logger });
193
+ logger?.debug(`Specification not found in project '${root}', using path from cache with version '${version}'`);
194
+ const moduleRoot = (0, path_1.join)(constants_1.moduleCacheRoot, moduleName, version);
195
+ const modulePath = await (0, module_loader_1.getModulePath)(moduleRoot, moduleName);
196
+ return modulePath.slice(0, modulePath.lastIndexOf((0, path_1.join)(moduleName)) + (0, path_1.join)(moduleName).length);
197
+ }
198
+ exports.getSpecificationPath = getSpecificationPath;
129
199
  //# sourceMappingURL=specification.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/project-access",
3
- "version": "1.25.0",
3
+ "version": "1.25.3",
4
4
  "description": "Library to access SAP Fiori tools projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "mem-fs-editor": "9.4.0",
31
31
  "semver": "7.5.4",
32
32
  "@sap-ux/i18n": "0.1.0",
33
- "@sap-ux/ui5-config": "0.23.0"
33
+ "@sap-ux/ui5-config": "0.23.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/mem-fs": "1.1.2",