@sap-ux/project-access 1.19.6 → 1.19.7
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/library/constants.d.ts +2 -0
- package/dist/library/constants.js +28 -0
- package/dist/library/helpers.d.ts +48 -0
- package/dist/library/helpers.js +284 -0
- package/dist/library/index.d.ts +3 -0
- package/dist/library/index.js +22 -0
- package/dist/library/types.d.ts +17 -0
- package/dist/library/types.js +3 -0
- package/dist/project/cap.d.ts +6 -2
- package/dist/project/cap.js +56 -6
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ export { FileName, DirName } from './constants';
|
|
|
2
2
|
export { getFilePaths } from './file';
|
|
3
3
|
export { createApplicationAccess, createProjectAccess, findAllApps, findCapProjects, findFioriArtifacts, findProjectRoot, getAppRootFromWebappPath, getAppProgrammingLanguage, getAppType, getCapCustomPaths, getCapEnvironment, getCapModelAndServices, getCapProjectType, getCdsFiles, getCdsRoots, getCdsServices, getCapI18nFolderNames, getI18nPropertiesPaths, getMtaPath, getNodeModulesPath, getProject, getProjectType, getWebappPath, isCapProject, isCapJavaProject, isCapNodeJsProject, loadModuleFromProject, readCapServiceMetadataEdmx, readUi5Yaml, toReferenceUri } from './project';
|
|
4
4
|
export * from './types';
|
|
5
|
+
export * from './library';
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -52,4 +52,5 @@ Object.defineProperty(exports, "readCapServiceMetadataEdmx", { enumerable: true,
|
|
|
52
52
|
Object.defineProperty(exports, "readUi5Yaml", { enumerable: true, get: function () { return project_1.readUi5Yaml; } });
|
|
53
53
|
Object.defineProperty(exports, "toReferenceUri", { enumerable: true, get: function () { return project_1.toReferenceUri; } });
|
|
54
54
|
__exportStar(require("./types"), exports);
|
|
55
|
+
__exportStar(require("./library"), exports);
|
|
55
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ui5Libs = void 0;
|
|
4
|
+
exports.ui5Libs = [
|
|
5
|
+
'sap.apf',
|
|
6
|
+
'sap.base',
|
|
7
|
+
'sap.chart',
|
|
8
|
+
'sap.collaboration',
|
|
9
|
+
'sap.f',
|
|
10
|
+
'sap.fe',
|
|
11
|
+
'sap.fileviewer',
|
|
12
|
+
'sap.gantt',
|
|
13
|
+
'sap.landvisz',
|
|
14
|
+
'sap.m',
|
|
15
|
+
'sap.ndc',
|
|
16
|
+
'sap.ovp',
|
|
17
|
+
'sap.rules',
|
|
18
|
+
'sap.suite',
|
|
19
|
+
'sap.tnt',
|
|
20
|
+
'sap.ui',
|
|
21
|
+
'sap.uiext',
|
|
22
|
+
'sap.ushell',
|
|
23
|
+
'sap.uxap',
|
|
24
|
+
'sap.viz',
|
|
25
|
+
'sap.webanalytics',
|
|
26
|
+
'sap.zen'
|
|
27
|
+
];
|
|
28
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { LibraryResults, Manifest } from '../types';
|
|
2
|
+
import { type ReuseLib } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of the reuse libraries found in the folders.
|
|
5
|
+
*
|
|
6
|
+
* @param libs - array of libraries found in the workspace folders.
|
|
7
|
+
* @returns list of reuse library
|
|
8
|
+
*/
|
|
9
|
+
export declare const getReuseLibs: (libs?: LibraryResults[]) => Promise<ReuseLib[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Checks for missing dependencies in the selected reuse libraries.
|
|
12
|
+
*
|
|
13
|
+
* @param answers - reuse libraries selected by the user
|
|
14
|
+
* @param reuseLibs - all available reuse libraries
|
|
15
|
+
* @returns a string with the missing dependencies
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkDependencies(answers: ReuseLib[], reuseLibs: ReuseLib[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the library description.
|
|
20
|
+
*
|
|
21
|
+
* @param library - library object
|
|
22
|
+
* @param projectPath - project path
|
|
23
|
+
* @returns library description
|
|
24
|
+
*/
|
|
25
|
+
export declare function getLibraryDesc(library: any, projectPath: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the library dependencies.
|
|
28
|
+
*
|
|
29
|
+
* @param library - library object
|
|
30
|
+
* @returns array of dependencies
|
|
31
|
+
*/
|
|
32
|
+
export declare function getLibraryDependencies(library: any): string[];
|
|
33
|
+
/**
|
|
34
|
+
* Returns the manifest description.
|
|
35
|
+
*
|
|
36
|
+
* @param manifest - manifest object
|
|
37
|
+
* @param manifestPath - manifestPath path
|
|
38
|
+
* @returns manifest description
|
|
39
|
+
*/
|
|
40
|
+
export declare function getManifestDesc(manifest: Manifest, manifestPath: string): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Returns the manifest dependencies.
|
|
43
|
+
*
|
|
44
|
+
* @param manifest - manifest object
|
|
45
|
+
* @returns array of dependencies
|
|
46
|
+
*/
|
|
47
|
+
export declare function getManifestDependencies(manifest: Manifest): string[];
|
|
48
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getManifestDependencies = exports.getManifestDesc = exports.getLibraryDependencies = exports.getLibraryDesc = exports.checkDependencies = exports.getReuseLibs = void 0;
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
const file_1 = require("../file");
|
|
16
|
+
const constants_2 = require("../constants");
|
|
17
|
+
const fs_1 = require("fs");
|
|
18
|
+
const fast_xml_parser_1 = require("fast-xml-parser");
|
|
19
|
+
const i18n_1 = require("../project/i18n");
|
|
20
|
+
const i18n_2 = require("@sap-ux/i18n");
|
|
21
|
+
/**
|
|
22
|
+
* Reads the manifest file and returns the reuse library.
|
|
23
|
+
*
|
|
24
|
+
* @param manifest - manifest file content
|
|
25
|
+
* @param manifestPath - path to the manifest file
|
|
26
|
+
* @param reuseLibs - existing reuse libraries
|
|
27
|
+
* @param projectRoot - root of the project
|
|
28
|
+
* @returns reuse library or undefined
|
|
29
|
+
*/
|
|
30
|
+
const getLibraryFromManifest = (manifest, manifestPath, reuseLibs, projectRoot) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
let reuseLib;
|
|
33
|
+
const manifestType = (_a = manifest['sap.app']) === null || _a === void 0 ? void 0 : _a.type;
|
|
34
|
+
if ((manifestType === 'component' || manifestType === 'library') && manifestPath) {
|
|
35
|
+
const reuseType = getReuseType(manifestPath);
|
|
36
|
+
const libDeps = getManifestDependencies(manifest);
|
|
37
|
+
const description = yield getManifestDesc(manifest, manifestPath);
|
|
38
|
+
const libIndex = reuseLibs.findIndex((reuseLib) => reuseLib.name === (manifest === null || manifest === void 0 ? void 0 : manifest['sap.app'].id));
|
|
39
|
+
if (libIndex === -1) {
|
|
40
|
+
reuseLib = {
|
|
41
|
+
name: `${manifest['sap.app'].id}`,
|
|
42
|
+
path: manifestPath,
|
|
43
|
+
type: reuseType,
|
|
44
|
+
uri: (_c = (_b = manifest['sap.platform.abap']) === null || _b === void 0 ? void 0 : _b.uri) !== null && _c !== void 0 ? _c : '',
|
|
45
|
+
dependencies: libDeps,
|
|
46
|
+
libRoot: projectRoot,
|
|
47
|
+
description
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return reuseLib;
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* Reads library file and returns a reuse lib object.
|
|
55
|
+
*
|
|
56
|
+
* @param library - library file content
|
|
57
|
+
* @param libraryPath - path to the library file
|
|
58
|
+
* @param projectRoot - root of the project
|
|
59
|
+
* @returns reuse library or undefined
|
|
60
|
+
*/
|
|
61
|
+
const getLibraryFromLibraryFile = (library, libraryPath, projectRoot) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
var _d, _e, _f, _g, _h;
|
|
63
|
+
let libEntry;
|
|
64
|
+
const parsedFile = new fast_xml_parser_1.XMLParser({ removeNSPrefix: true }).parse(library, false);
|
|
65
|
+
if ((_d = parsedFile === null || parsedFile === void 0 ? void 0 : parsedFile.library) === null || _d === void 0 ? void 0 : _d.name) {
|
|
66
|
+
const manifestType = (parsedFile === null || parsedFile === void 0 ? void 0 : parsedFile.library) ? 'library' : 'component';
|
|
67
|
+
if (manifestType === 'component' || manifestType === 'library') {
|
|
68
|
+
const reuseType = getReuseType(libraryPath);
|
|
69
|
+
const libDeps = getLibraryDependencies(parsedFile);
|
|
70
|
+
const description = yield getLibraryDesc(parsedFile, libraryPath);
|
|
71
|
+
libEntry = {
|
|
72
|
+
name: `${parsedFile.library.name}`,
|
|
73
|
+
path: libraryPath,
|
|
74
|
+
type: reuseType,
|
|
75
|
+
uri: ((_h = (_g = (_f = (_e = parsedFile.library) === null || _e === void 0 ? void 0 : _e.appData) === null || _f === void 0 ? void 0 : _f.manifest) === null || _g === void 0 ? void 0 : _g['sap.platform.abap']) === null || _h === void 0 ? void 0 : _h.uri) || '',
|
|
76
|
+
dependencies: libDeps,
|
|
77
|
+
libRoot: projectRoot,
|
|
78
|
+
description
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return libEntry;
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* Updates the library options with the new library.
|
|
86
|
+
*
|
|
87
|
+
* @param reuseLibs - existing library options
|
|
88
|
+
* @param reuseLib - new library
|
|
89
|
+
*/
|
|
90
|
+
const updateLibOptions = (reuseLibs, reuseLib) => {
|
|
91
|
+
if (reuseLib) {
|
|
92
|
+
const libIndex = reuseLibs.findIndex((lib) => lib.name === reuseLib.name);
|
|
93
|
+
if (libIndex >= 0) {
|
|
94
|
+
// replace
|
|
95
|
+
reuseLibs[libIndex] = reuseLib;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
reuseLibs.push(reuseLib);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Returns an array of the reuse libraries found in the folders.
|
|
104
|
+
*
|
|
105
|
+
* @param libs - array of libraries found in the workspace folders.
|
|
106
|
+
* @returns list of reuse library
|
|
107
|
+
*/
|
|
108
|
+
const getReuseLibs = (libs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
|
+
const reuseLibs = [];
|
|
110
|
+
if (libs) {
|
|
111
|
+
for (const lib of libs) {
|
|
112
|
+
const excludeFolders = ['.git', 'node_modules', 'dist'];
|
|
113
|
+
const manifestPaths = yield (0, file_1.findFiles)('manifest.json', lib.projectRoot, excludeFolders);
|
|
114
|
+
const libraryPaths = yield (0, file_1.findFiles)('library.js', lib.projectRoot, excludeFolders);
|
|
115
|
+
for (const manifestPath of manifestPaths) {
|
|
116
|
+
const manifest = JSON.parse(yield fs_1.promises.readFile((0, path_1.join)(manifestPath, constants_2.FileName.Manifest), { encoding: 'utf8' }));
|
|
117
|
+
const library = yield getLibraryFromManifest(manifest, (0, path_1.join)(manifestPath, constants_2.FileName.Manifest), reuseLibs, lib.projectRoot);
|
|
118
|
+
if (library) {
|
|
119
|
+
reuseLibs.push(library);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const libraryPath of libraryPaths) {
|
|
123
|
+
const library = (yield fs_1.promises.readFile((0, path_1.join)(libraryPath, constants_2.FileName.Library), { encoding: 'utf8' })).toString();
|
|
124
|
+
const libFile = yield getLibraryFromLibraryFile(library, libraryPath, lib.projectRoot);
|
|
125
|
+
updateLibOptions(reuseLibs, libFile);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return reuseLibs;
|
|
130
|
+
});
|
|
131
|
+
exports.getReuseLibs = getReuseLibs;
|
|
132
|
+
/**
|
|
133
|
+
* Gets the type of reuse library.
|
|
134
|
+
*
|
|
135
|
+
* @param libraryPath - path to the reuse library
|
|
136
|
+
* @returns the type of reuse library
|
|
137
|
+
*/
|
|
138
|
+
function getReuseType(libraryPath) {
|
|
139
|
+
return (0, fs_1.existsSync)((0, path_1.join)(libraryPath, '/library.js')) || (0, fs_1.existsSync)((0, path_1.join)(libraryPath, '/library.ts'))
|
|
140
|
+
? "library" /* ReuseLibType.Library */
|
|
141
|
+
: "component" /* ReuseLibType.Component */;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Checks for missing dependencies in the selected reuse libraries.
|
|
145
|
+
*
|
|
146
|
+
* @param answers - reuse libraries selected by the user
|
|
147
|
+
* @param reuseLibs - all available reuse libraries
|
|
148
|
+
* @returns a string with the missing dependencies
|
|
149
|
+
*/
|
|
150
|
+
function checkDependencies(answers, reuseLibs) {
|
|
151
|
+
const missingDeps = [];
|
|
152
|
+
answers.forEach((answer) => {
|
|
153
|
+
const dependencies = answer.dependencies;
|
|
154
|
+
if (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length) {
|
|
155
|
+
dependencies.forEach((dependency) => {
|
|
156
|
+
if (!reuseLibs.some((lib) => {
|
|
157
|
+
return dependency === lib.name;
|
|
158
|
+
})) {
|
|
159
|
+
missingDeps.push(dependency);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return missingDeps.join();
|
|
165
|
+
}
|
|
166
|
+
exports.checkDependencies = checkDependencies;
|
|
167
|
+
/**
|
|
168
|
+
* Returns the library description.
|
|
169
|
+
*
|
|
170
|
+
* @param library - library object
|
|
171
|
+
* @param projectPath - project path
|
|
172
|
+
* @returns library description
|
|
173
|
+
*/
|
|
174
|
+
function getLibraryDesc(library, projectPath) {
|
|
175
|
+
var _a, _b, _c, _d, _e;
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
let libraryDesc = (_a = library === null || library === void 0 ? void 0 : library.library) === null || _a === void 0 ? void 0 : _a.documentation;
|
|
178
|
+
if (typeof libraryDesc === 'string' && libraryDesc.startsWith('{{')) {
|
|
179
|
+
const key = libraryDesc.substring(2, libraryDesc.length - 2);
|
|
180
|
+
libraryDesc = yield geti18nPropertyValue((0, path_1.join)(projectPath, (_e = (_d = (_c = (_b = library.library) === null || _b === void 0 ? void 0 : _b.appData) === null || _c === void 0 ? void 0 : _c.manifest) === null || _d === void 0 ? void 0 : _d.i18n) === null || _e === void 0 ? void 0 : _e.toString()), key);
|
|
181
|
+
}
|
|
182
|
+
return libraryDesc.toString();
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
exports.getLibraryDesc = getLibraryDesc;
|
|
186
|
+
/**
|
|
187
|
+
* Returns the library dependencies.
|
|
188
|
+
*
|
|
189
|
+
* @param library - library object
|
|
190
|
+
* @returns array of dependencies
|
|
191
|
+
*/
|
|
192
|
+
function getLibraryDependencies(library) {
|
|
193
|
+
var _a, _b;
|
|
194
|
+
const result = [];
|
|
195
|
+
if ((_b = (_a = library === null || library === void 0 ? void 0 : library.library) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b.dependency) {
|
|
196
|
+
let deps = library.library.dependencies.dependency;
|
|
197
|
+
if (!Array.isArray(deps)) {
|
|
198
|
+
deps = [deps];
|
|
199
|
+
}
|
|
200
|
+
deps.forEach((lib) => {
|
|
201
|
+
// ignore libs that start with SAPUI5 delivered namespaces
|
|
202
|
+
if (!constants_1.ui5Libs.some((substring) => {
|
|
203
|
+
return lib.libraryName === substring || lib.libraryName.startsWith(substring + '.');
|
|
204
|
+
})) {
|
|
205
|
+
result.push(lib.libraryName);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return result;
|
|
210
|
+
}
|
|
211
|
+
exports.getLibraryDependencies = getLibraryDependencies;
|
|
212
|
+
/**
|
|
213
|
+
* Returns the i18n property value.
|
|
214
|
+
*
|
|
215
|
+
* @param i18nPath - i18n path
|
|
216
|
+
* @param key - property key
|
|
217
|
+
* @returns i18n property value
|
|
218
|
+
*/
|
|
219
|
+
function geti18nPropertyValue(i18nPath, key) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
let value = '';
|
|
222
|
+
try {
|
|
223
|
+
const bundle = yield (0, i18n_2.getPropertiesI18nBundle)(i18nPath);
|
|
224
|
+
const node = bundle[key].find((i) => i.key.value === key);
|
|
225
|
+
if (node) {
|
|
226
|
+
value = node.value.value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (e) {
|
|
230
|
+
// ignore exception
|
|
231
|
+
}
|
|
232
|
+
return value;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Returns the manifest description.
|
|
237
|
+
*
|
|
238
|
+
* @param manifest - manifest object
|
|
239
|
+
* @param manifestPath - manifestPath path
|
|
240
|
+
* @returns manifest description
|
|
241
|
+
*/
|
|
242
|
+
function getManifestDesc(manifest, manifestPath) {
|
|
243
|
+
var _a;
|
|
244
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
245
|
+
let manifestDesc = (_a = manifest['sap.app']) === null || _a === void 0 ? void 0 : _a.description;
|
|
246
|
+
if (typeof manifestDesc === 'string' && manifestDesc.startsWith('{{')) {
|
|
247
|
+
const key = manifestDesc.substring(2, manifestDesc.length - 2);
|
|
248
|
+
const { 'sap.app': i18nPath } = yield (0, i18n_1.getI18nPropertiesPaths)(manifestPath, manifest);
|
|
249
|
+
manifestDesc = yield geti18nPropertyValue(i18nPath, key);
|
|
250
|
+
}
|
|
251
|
+
const x = (manifestDesc !== null && manifestDesc !== void 0 ? manifestDesc : '').toString();
|
|
252
|
+
return x;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
exports.getManifestDesc = getManifestDesc;
|
|
256
|
+
/**
|
|
257
|
+
* Returns the manifest dependencies.
|
|
258
|
+
*
|
|
259
|
+
* @param manifest - manifest object
|
|
260
|
+
* @returns array of dependencies
|
|
261
|
+
*/
|
|
262
|
+
function getManifestDependencies(manifest) {
|
|
263
|
+
const result = [];
|
|
264
|
+
Object.values(['libs', 'components']).forEach((reuseType) => {
|
|
265
|
+
var _a, _b, _c, _d;
|
|
266
|
+
const dependencies = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b[reuseType];
|
|
267
|
+
if (dependencies) {
|
|
268
|
+
const libs = (_d = (_c = manifest === null || manifest === void 0 ? void 0 : manifest['sap.ui5']) === null || _c === void 0 ? void 0 : _c.dependencies) === null || _d === void 0 ? void 0 : _d.libs;
|
|
269
|
+
if (libs) {
|
|
270
|
+
Object.keys(libs).forEach((manifestLibKey) => {
|
|
271
|
+
// ignore libs that start with SAPUI5 delivered namespaces
|
|
272
|
+
if (!constants_1.ui5Libs.some((substring) => {
|
|
273
|
+
return manifestLibKey === substring || manifestLibKey.startsWith(substring + '.');
|
|
274
|
+
})) {
|
|
275
|
+
result.push(manifestLibKey);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
exports.getManifestDependencies = getManifestDependencies;
|
|
284
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.checkDependencies = exports.getReuseLibs = void 0;
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
var helpers_1 = require("./helpers");
|
|
20
|
+
Object.defineProperty(exports, "getReuseLibs", { enumerable: true, get: function () { return helpers_1.getReuseLibs; } });
|
|
21
|
+
Object.defineProperty(exports, "checkDependencies", { enumerable: true, get: function () { return helpers_1.checkDependencies; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare const enum ReuseLibType {
|
|
2
|
+
Library = "library",
|
|
3
|
+
Component = "component"
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Reuse library
|
|
7
|
+
*/
|
|
8
|
+
export interface ReuseLib {
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
type: ReuseLibType;
|
|
12
|
+
uri: string;
|
|
13
|
+
dependencies: string[];
|
|
14
|
+
libRoot: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
package/dist/project/cap.d.ts
CHANGED
|
@@ -44,8 +44,8 @@ export declare function getCapCustomPaths(capProjectPath: string): Promise<CapCu
|
|
|
44
44
|
/**
|
|
45
45
|
* Return the CAP model and all services. The cds.root will be set to the provided project root path.
|
|
46
46
|
*
|
|
47
|
-
* @param projectRoot - CAP project root where package.json resides or object specifying project root and optional logger to log
|
|
48
|
-
* @returns {
|
|
47
|
+
* @param projectRoot - CAP project root where package.json resides or object specifying project root and optional logger to log additional info
|
|
48
|
+
* @returns {Promise<{ model: csn; services: ServiceInfo[] }>} - CAP Model and Services
|
|
49
49
|
*/
|
|
50
50
|
export declare function getCapModelAndServices(projectRoot: string | {
|
|
51
51
|
projectRoot: string;
|
|
@@ -112,5 +112,9 @@ export declare const toAbsoluteUri: (projectRoot: string, relativeUri: string) =
|
|
|
112
112
|
* @returns {Promise<string>} - reference uri
|
|
113
113
|
*/
|
|
114
114
|
export declare const toReferenceUri: (projectRoot: string, relativeUriFrom: string, relativeUriTo: string) => Promise<string>;
|
|
115
|
+
/**
|
|
116
|
+
* Clear cache of path to global cds module.
|
|
117
|
+
*/
|
|
118
|
+
export declare function clearGlobalCdsPathCache(): void;
|
|
115
119
|
export {};
|
|
116
120
|
//# sourceMappingURL=cap.d.ts.map
|
package/dist/project/cap.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.toReferenceUri = exports.toAbsoluteUri = exports.getCapEnvironment = exports.readCapServiceMetadataEdmx = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapModelAndServices = exports.getCapCustomPaths = exports.isCapProject = exports.getCapProjectType = exports.isCapJavaProject = exports.isCapNodeJsProject = void 0;
|
|
12
|
+
exports.clearGlobalCdsPathCache = exports.toReferenceUri = exports.toAbsoluteUri = exports.getCapEnvironment = exports.readCapServiceMetadataEdmx = exports.getCdsServices = exports.getCdsRoots = exports.getCdsFiles = exports.getCapModelAndServices = exports.getCapCustomPaths = exports.isCapProject = exports.getCapProjectType = exports.isCapJavaProject = exports.isCapNodeJsProject = void 0;
|
|
13
13
|
const child_process_1 = require("child_process");
|
|
14
14
|
const path_1 = require("path");
|
|
15
15
|
const constants_1 = require("../constants");
|
|
@@ -113,8 +113,8 @@ exports.getCapCustomPaths = getCapCustomPaths;
|
|
|
113
113
|
/**
|
|
114
114
|
* Return the CAP model and all services. The cds.root will be set to the provided project root path.
|
|
115
115
|
*
|
|
116
|
-
* @param projectRoot - CAP project root where package.json resides or object specifying project root and optional logger to log
|
|
117
|
-
* @returns {
|
|
116
|
+
* @param projectRoot - CAP project root where package.json resides or object specifying project root and optional logger to log additional info
|
|
117
|
+
* @returns {Promise<{ model: csn; services: ServiceInfo[] }>} - CAP Model and Services
|
|
118
118
|
*/
|
|
119
119
|
function getCapModelAndServices(projectRoot) {
|
|
120
120
|
var _a;
|
|
@@ -128,7 +128,7 @@ function getCapModelAndServices(projectRoot) {
|
|
|
128
128
|
else {
|
|
129
129
|
_projectRoot = projectRoot;
|
|
130
130
|
}
|
|
131
|
-
const cds = yield loadCdsModuleFromProject(_projectRoot);
|
|
131
|
+
const cds = yield loadCdsModuleFromProject(_projectRoot, true);
|
|
132
132
|
const capProjectPaths = yield getCapCustomPaths(_projectRoot);
|
|
133
133
|
const modelPaths = [
|
|
134
134
|
(0, path_1.join)(_projectRoot, capProjectPaths.app),
|
|
@@ -349,12 +349,13 @@ exports.getCapEnvironment = getCapEnvironment;
|
|
|
349
349
|
/**
|
|
350
350
|
* Load CAP CDS module. First attempt loads @sap/cds for a project based on its root.
|
|
351
351
|
* Second attempt loads @sap/cds from global installed @sap/cds-dk.
|
|
352
|
-
* Throws error if module could not be loaded.
|
|
352
|
+
* Throws error if module could not be loaded or strict mode is true and there is a version mismatch.
|
|
353
353
|
*
|
|
354
354
|
* @param capProjectPath - project root of a CAP project
|
|
355
|
+
* @param [strict] - optional, when set true an error is thrown, if global loaded cds version does not match the cds version from package.json dependency. Default is false.
|
|
355
356
|
* @returns - CAP CDS module for a CAP project
|
|
356
357
|
*/
|
|
357
|
-
function loadCdsModuleFromProject(capProjectPath) {
|
|
358
|
+
function loadCdsModuleFromProject(capProjectPath, strict = false) {
|
|
358
359
|
return __awaiter(this, void 0, void 0, function* () {
|
|
359
360
|
let module;
|
|
360
361
|
let loadProjectError;
|
|
@@ -379,6 +380,16 @@ function loadCdsModuleFromProject(capProjectPath) {
|
|
|
379
380
|
throw Error(`Could not load cds module. Attempt to load module @sap/cds from project threw error '${loadProjectError}', attempt to load module @sap/cds from @sap/cds-dk threw error '${loadError}'`);
|
|
380
381
|
}
|
|
381
382
|
const cds = 'default' in module ? module.default : module;
|
|
383
|
+
// In case strict is true and there was a fallback to global cds installation for a project that has a cds dependency, check if major versions match
|
|
384
|
+
if (strict && loadProjectError) {
|
|
385
|
+
const cdsDependencyVersion = yield getCdsVersionFromPackageJson((0, path_1.join)(capProjectPath, constants_1.FileName.Package));
|
|
386
|
+
if (typeof cdsDependencyVersion === 'string') {
|
|
387
|
+
const globalCdsVersion = cds.version;
|
|
388
|
+
if (getMajorVersion(cdsDependencyVersion) !== getMajorVersion(globalCdsVersion)) {
|
|
389
|
+
throw Error(`The @sap/cds major version (${cdsDependencyVersion}) specified in your CAP project is different to the @sap/cds version you have installed globally (${globalCdsVersion}). Please run 'npm install' on your CAP project to ensure that the correct CDS version is loaded.`);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
382
393
|
// Fix when switching cds versions dynamically
|
|
383
394
|
if (global) {
|
|
384
395
|
global.cds = cds;
|
|
@@ -503,6 +514,13 @@ function loadGlobalCdsModule() {
|
|
|
503
514
|
return (0, module_loader_1.loadModuleFromProject)(globalCdsPathCache, '@sap/cds');
|
|
504
515
|
});
|
|
505
516
|
}
|
|
517
|
+
/**
|
|
518
|
+
* Clear cache of path to global cds module.
|
|
519
|
+
*/
|
|
520
|
+
function clearGlobalCdsPathCache() {
|
|
521
|
+
globalCdsPathCache = '';
|
|
522
|
+
}
|
|
523
|
+
exports.clearGlobalCdsPathCache = clearGlobalCdsPathCache;
|
|
506
524
|
/**
|
|
507
525
|
* Get cds information, which includes versions and also the home path of cds module.
|
|
508
526
|
*
|
|
@@ -536,4 +554,36 @@ function getCdsVersionInfo(cwd) {
|
|
|
536
554
|
});
|
|
537
555
|
});
|
|
538
556
|
}
|
|
557
|
+
/**
|
|
558
|
+
* Read the version string of the @sap/cds module from the package.json file.
|
|
559
|
+
*
|
|
560
|
+
* @param packageJsonPath - path to package.json
|
|
561
|
+
* @returns - version of @sap/cds from package.json or undefined
|
|
562
|
+
*/
|
|
563
|
+
function getCdsVersionFromPackageJson(packageJsonPath) {
|
|
564
|
+
var _a;
|
|
565
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
566
|
+
let version;
|
|
567
|
+
try {
|
|
568
|
+
if (yield (0, file_1.fileExists)(packageJsonPath)) {
|
|
569
|
+
const packageJson = yield (0, file_1.readJSON)(packageJsonPath);
|
|
570
|
+
version = (_a = packageJson === null || packageJson === void 0 ? void 0 : packageJson.dependencies) === null || _a === void 0 ? void 0 : _a['@sap/cds'];
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
catch (_b) {
|
|
574
|
+
// If we can't read or parse the package.json we return undefined
|
|
575
|
+
}
|
|
576
|
+
return version;
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Get major version from version string.
|
|
581
|
+
*
|
|
582
|
+
* @param versionString - version string
|
|
583
|
+
* @returns - major version as number
|
|
584
|
+
*/
|
|
585
|
+
function getMajorVersion(versionString) {
|
|
586
|
+
var _a, _b;
|
|
587
|
+
return parseInt((_b = (_a = /\d+/.exec(versionString.split('.')[0])) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '0', 10);
|
|
588
|
+
}
|
|
539
589
|
//# sourceMappingURL=cap.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/project-access",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.7",
|
|
4
4
|
"description": "Library to access SAP Fiori tools projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"node": ">=18.x"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"fast-xml-parser": "4.2.7",
|
|
26
27
|
"findit2": "2.2.3",
|
|
27
28
|
"mem-fs": "2.1.0",
|
|
28
29
|
"mem-fs-editor": "9.4.0",
|