@sap-ux/project-access 1.16.0 → 1.16.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.
@@ -1,5 +1,6 @@
1
1
  export declare const FileName: {
2
2
  readonly AdaptationConfig: "config.json";
3
+ readonly CapJavaApplicationYaml: "application.yaml";
3
4
  readonly ExtConfigJson: ".extconfig.json";
4
5
  readonly Manifest: "manifest.json";
5
6
  readonly ManifestAppDescrVar: "manifest.appdescr_variant";
package/dist/constants.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileName = void 0;
4
4
  exports.FileName = {
5
5
  AdaptationConfig: 'config.json',
6
+ CapJavaApplicationYaml: 'application.yaml',
6
7
  ExtConfigJson: '.extconfig.json',
7
8
  Manifest: 'manifest.json',
8
9
  ManifestAppDescrVar: 'manifest.appdescr_variant',
@@ -1,4 +1,5 @@
1
1
  import type { CapCustomPaths, CapProjectType, CdsEnvironment, csn, Package, ServiceDefinitions } from '../types';
2
+ import type { Logger } from '@sap-ux/logger';
2
3
  interface ServiceInfo {
3
4
  name: string;
4
5
  urlPath: string;
@@ -34,12 +35,15 @@ export declare function getCapProjectType(projectRoot: string): Promise<CapProje
34
35
  */
35
36
  export declare function getCapCustomPaths(capProjectPath: string): Promise<CapCustomPaths>;
36
37
  /**
37
- * Return the CAP model and all services.
38
+ * Return the CAP model and all services. The cds.root will be set to the provided project root path.
38
39
  *
39
- * @param projectRoot - CAP project root where package.json resides
40
+ * @param projectRoot - CAP project root where package.json resides or object specifying project root and optional logger to log additonal info
40
41
  * @returns {*} {Promise<{ model: csn; services: ServiceInfo[] }>} - CAP Model and Services
41
42
  */
42
- export declare function getCapModelAndServices(projectRoot: string): Promise<{
43
+ export declare function getCapModelAndServices(projectRoot: string | {
44
+ projectRoot: string;
45
+ logger?: Logger;
46
+ }): Promise<{
43
47
  model: csn;
44
48
  services: ServiceInfo[];
45
49
  }>;
@@ -37,7 +37,7 @@ function isCapJavaProject(projectRoot, capCustomPaths) {
37
37
  var _a;
38
38
  return __awaiter(this, void 0, void 0, function* () {
39
39
  const srv = (_a = capCustomPaths === null || capCustomPaths === void 0 ? void 0 : capCustomPaths.srv) !== null && _a !== void 0 ? _a : (yield getCapCustomPaths(projectRoot)).srv;
40
- return (0, file_1.fileExists)((0, path_1.join)(projectRoot, srv, 'src', 'main', 'resources', 'application.yaml'));
40
+ return (0, file_1.fileExists)((0, path_1.join)(projectRoot, srv, 'src', 'main', 'resources', constants_1.FileName.CapJavaApplicationYaml));
41
41
  });
42
42
  }
43
43
  exports.isCapJavaProject = isCapJavaProject;
@@ -99,23 +99,35 @@ function getCapCustomPaths(capProjectPath) {
99
99
  }
100
100
  exports.getCapCustomPaths = getCapCustomPaths;
101
101
  /**
102
- * Return the CAP model and all services.
102
+ * Return the CAP model and all services. The cds.root will be set to the provided project root path.
103
103
  *
104
- * @param projectRoot - CAP project root where package.json resides
104
+ * @param projectRoot - CAP project root where package.json resides or object specifying project root and optional logger to log additonal info
105
105
  * @returns {*} {Promise<{ model: csn; services: ServiceInfo[] }>} - CAP Model and Services
106
106
  */
107
107
  function getCapModelAndServices(projectRoot) {
108
108
  var _a;
109
109
  return __awaiter(this, void 0, void 0, function* () {
110
- const cds = yield loadCdsModuleFromProject(projectRoot);
111
- const capProjectPaths = yield getCapCustomPaths(projectRoot);
110
+ let _projectRoot;
111
+ let _logger;
112
+ if (typeof projectRoot === 'object') {
113
+ _projectRoot = projectRoot.projectRoot;
114
+ _logger = projectRoot.logger;
115
+ }
116
+ else {
117
+ _projectRoot = projectRoot;
118
+ }
119
+ const cds = yield loadCdsModuleFromProject(_projectRoot);
120
+ _logger === null || _logger === void 0 ? void 0 : _logger.info(`@sap-ux/project-access:getCapModelAndServices - Using 'cds.home': ${cds.home}`);
121
+ _logger === null || _logger === void 0 ? void 0 : _logger.info(`@sap-ux/project-access:getCapModelAndServices - Using 'cds.version': ${cds.version}`);
122
+ _logger === null || _logger === void 0 ? void 0 : _logger.info(`@sap-ux/project-access:getCapModelAndServices - Using 'cds.root': ${cds.root}`);
123
+ const capProjectPaths = yield getCapCustomPaths(_projectRoot);
112
124
  const modelPaths = [
113
- (0, path_1.join)(projectRoot, capProjectPaths.app),
114
- (0, path_1.join)(projectRoot, capProjectPaths.srv),
115
- (0, path_1.join)(projectRoot, capProjectPaths.db)
125
+ (0, path_1.join)(_projectRoot, capProjectPaths.app),
126
+ (0, path_1.join)(_projectRoot, capProjectPaths.srv),
127
+ (0, path_1.join)(_projectRoot, capProjectPaths.db)
116
128
  ];
117
129
  const model = yield cds.load(modelPaths);
118
- let services = (_a = cds.compile.to.serviceinfo(model, { root: projectRoot })) !== null && _a !== void 0 ? _a : [];
130
+ let services = (_a = cds.compile.to.serviceinfo(model, { root: _projectRoot })) !== null && _a !== void 0 ? _a : [];
119
131
  if (services.map) {
120
132
  services = services.map((value) => {
121
133
  return {
@@ -359,6 +371,8 @@ function loadCdsModuleFromProject(capProjectPath) {
359
371
  if (global) {
360
372
  global.cds = cds;
361
373
  }
374
+ // Ensure we use a known root path, otherwise `cwd` is used which varies between invocations.
375
+ cds.root = capProjectPath;
362
376
  return cds;
363
377
  });
364
378
  }
@@ -96,17 +96,21 @@ exports.getAppType = getAppType;
96
96
  function getApplicationType(application) {
97
97
  return __awaiter(this, void 0, void 0, function* () {
98
98
  let appType;
99
- const packageJson = yield (0, file_1.readJSON)((0, path_1.join)(application.projectRoot, constants_1.FileName.Package));
99
+ const rootPackageJsonPath = (0, path_1.join)(application.projectRoot, constants_1.FileName.Package);
100
+ const packageJson = (yield (0, file_1.fileExists)(rootPackageJsonPath)) ? yield (0, file_1.readJSON)(rootPackageJsonPath) : null;
100
101
  if (application.projectRoot === application.appRoot) {
101
- appType = packageJson.sapux ? 'SAP Fiori elements' : 'SAPUI5 freestyle';
102
+ appType = (packageJson === null || packageJson === void 0 ? void 0 : packageJson.sapux) ? 'SAP Fiori elements' : 'SAPUI5 freestyle';
102
103
  }
103
- else {
104
+ else if (packageJson) {
104
105
  appType =
105
106
  Array.isArray(packageJson.sapux) &&
106
107
  packageJson.sapux.find((relAppPath) => (0, path_1.join)(application.projectRoot, ...relAppPath.split(/[/\\]/)) === application.appRoot)
107
108
  ? 'SAP Fiori elements'
108
109
  : 'SAPUI5 freestyle';
109
110
  }
111
+ else {
112
+ appType = 'SAPUI5 freestyle';
113
+ }
110
114
  return appType;
111
115
  });
112
116
  }
@@ -185,29 +185,44 @@ function findRootsForPath(path) {
185
185
  };
186
186
  }
187
187
  // Project must be CAP, find project root
188
- try {
189
- const { root } = (0, path_1.parse)(appRoot);
190
- let projectRoot = (0, path_1.dirname)(appRoot);
191
- while (projectRoot !== root) {
192
- if (yield (0, cap_1.getCapProjectType)(projectRoot)) {
193
- // We have found a CAP project as root. Check if the found app is not directly in CAP's 'app/' folder.
194
- // Sometime there is a <CAP_ROOT>/app/package.json file that is used for app router (not an app)
195
- if ((0, path_1.join)(projectRoot, 'app') !== appRoot) {
196
- return {
197
- appRoot,
198
- projectRoot
199
- };
200
- }
188
+ const projectRoot = yield findCapProjectRoot(appRoot);
189
+ if (projectRoot) {
190
+ return {
191
+ appRoot,
192
+ projectRoot
193
+ };
194
+ }
195
+ }
196
+ catch (_a) {
197
+ // Finding root should not throw error. Return null instead.
198
+ }
199
+ return null;
200
+ });
201
+ }
202
+ /**
203
+ * Find CAP project root path.
204
+ *
205
+ * @param path - path inside CAP project
206
+ * @returns - CAP project root path
207
+ */
208
+ function findCapProjectRoot(path) {
209
+ return __awaiter(this, void 0, void 0, function* () {
210
+ try {
211
+ const { root } = (0, path_1.parse)(path);
212
+ let projectRoot = (0, path_1.dirname)(path);
213
+ while (projectRoot !== root) {
214
+ if (yield (0, cap_1.getCapProjectType)(projectRoot)) {
215
+ // We have found a CAP project as root. Check if the found app is not directly in CAP's 'app/' folder.
216
+ // Sometime there is a <CAP_ROOT>/app/package.json file that is used for app router (not an app)
217
+ if ((0, path_1.join)(projectRoot, 'app') !== path) {
218
+ return projectRoot;
201
219
  }
202
- projectRoot = (0, path_1.dirname)(projectRoot);
203
220
  }
204
- }
205
- catch (_a) {
206
- // No project root can be found at parent folder.
221
+ projectRoot = (0, path_1.dirname)(projectRoot);
207
222
  }
208
223
  }
209
- catch (_b) {
210
- // Finding root should not throw error. Return null instead.
224
+ catch (_a) {
225
+ // No project root can be found at parent folder.
211
226
  }
212
227
  return null;
213
228
  });
@@ -418,8 +433,8 @@ exports.findFioriArtifacts = findFioriArtifacts;
418
433
  function findCapProjects(options) {
419
434
  return __awaiter(this, void 0, void 0, function* () {
420
435
  const result = new Set();
421
- const excludeFolders = ['node_modules', 'dist', 'src', 'webapp', 'MDKModule', 'gen'];
422
- const fileNames = [constants_1.FileName.Pom, constants_1.FileName.Package];
436
+ const excludeFolders = ['node_modules', 'dist', 'webapp', 'MDKModule', 'gen'];
437
+ const fileNames = [constants_1.FileName.Pom, constants_1.FileName.Package, constants_1.FileName.CapJavaApplicationYaml];
423
438
  const wsRoots = wsFoldersToRootPaths(options.wsFolders);
424
439
  for (const root of wsRoots) {
425
440
  const filesToCheck = yield (0, file_1.findBy)({
@@ -427,7 +442,18 @@ function findCapProjects(options) {
427
442
  root,
428
443
  excludeFolders
429
444
  });
430
- const foldersToCheck = Array.from(new Set(filesToCheck.map((file) => (0, path_1.dirname)(file)))); //only directories without duplicates
445
+ const appYamlsToCheck = Array.from(new Set(filesToCheck
446
+ .filter((file) => (0, path_1.basename)(file) === constants_1.FileName.CapJavaApplicationYaml)
447
+ .map((file) => (0, path_1.dirname)(file))));
448
+ const foldersToCheck = Array.from(new Set(filesToCheck
449
+ .filter((file) => (0, path_1.basename)(file) !== constants_1.FileName.CapJavaApplicationYaml)
450
+ .map((file) => (0, path_1.dirname)(file))));
451
+ for (const appYamlToCheck of appYamlsToCheck) {
452
+ const capRoot = yield findCapProjectRoot(appYamlToCheck);
453
+ if (capRoot) {
454
+ result.add(capRoot);
455
+ }
456
+ }
431
457
  for (const folderToCheck of foldersToCheck) {
432
458
  if ((yield (0, cap_1.getCapProjectType)(folderToCheck)) !== undefined) {
433
459
  result.add(folderToCheck);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/project-access",
3
- "version": "1.16.0",
3
+ "version": "1.16.2",
4
4
  "description": "Library to access SAP Fiori tools projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,8 @@
33
33
  "@types/mem-fs": "1.1.2",
34
34
  "@types/mem-fs-editor": "7.0.1",
35
35
  "@ui5/manifest": "1.61.0",
36
- "vscode-uri": "3.0.7"
36
+ "vscode-uri": "3.0.7",
37
+ "@sap-ux/logger": "0.4.0"
37
38
  },
38
39
  "scripts": {
39
40
  "build": "tsc --build",