Skip to content

Commit b9da72d

Browse files
committed
improve jsdoc and reuse types
add tests for versionInfoGenerator with new parameters * libraryManifest * embeddedManifests
1 parent 666b3cb commit b9da72d

File tree

3 files changed

+275
-25
lines changed

3 files changed

+275
-25
lines changed

lib/processors/versionInfoGenerator.js

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function getTimestamp() {
1919
/**
2020
* Manifest libraries as defined in the manifest.json file
2121
*
22-
* @typedef {object<string, object>} ManifestLibraries
22+
* @typedef {object<string, {lazy: boolean}>} ManifestLibraries
2323
*
2424
* sample:
2525
* <pre>
@@ -37,10 +37,10 @@ function getTimestamp() {
3737
*
3838
* @typedef {object} ManifestInfo
3939
*
40-
* @property {string} id The library name
41-
* @property {string} embeddedBy the library this component is embedded in
42-
* @property {string[]} embeds the embedded component names
43-
* @property {ManifestLibraries} libs the dependencies
40+
* @property {string} id The library name, e.g. "lib.x"
41+
* @property {string} embeddedBy the library this component is embedded in, e.g. "lib.x"
42+
* @property {string[]} embeds the embedded component names, e.g. ["lib.x.sub"]
43+
* @property {ManifestLibraries} libs the dependencies, e.g. {"sap.chart":{"lazy": true}, "sap.f":{}}
4444
*/
4545

4646

@@ -85,6 +85,7 @@ const processManifest = async (manifestResource) => {
8585
};
8686

8787
/**
88+
* Checks if a component (componentPath) is bundled with the library (embeddedBy)
8889
*
8990
* @param {string} embeddedBy e.g. "../"
9091
* @param {string} componentPath e.g. "lib/x/sub"
@@ -126,7 +127,7 @@ const isBundledWithLibrary = (embeddedBy, componentPath, libraryPathPrefix) => {
126127
};
127128

128129
/**
129-
* Retrieves the manifest path
130+
* Retrieves the manifest path of a subcomponent
130131
*
131132
* @param {string} filePath path to the manifest, e.g. "lib/x/manifest.json"
132133
* @param {string} subPath relative sub path, e.g. "sub"
@@ -137,31 +138,37 @@ const getManifestPath = (filePath, subPath) => {
137138
return posixPath.resolve(folderPathOfManifest + "/manifest.json");
138139
};
139140

140-
141+
/**
142+
* Represents dependency information for a library.
143+
* Dependencies can be resolved recursively using <code>#resolve</code>
144+
* and are stored then in <code>libsResolved</code>
145+
*/
141146
class DependencyInfo {
142147
/**
143148
*
144-
* @param {object} libs
145-
* @param {string} name
149+
* @param {ManifestLibraries} libs
150+
* @param {string} name library name, e.g. "lib.x"
146151
*/
147152
constructor(libs, name) {
148153
this.libs = libs;
149154
this.name = name;
150155

151156
/**
152-
* contains as key the lirbary name and as value the lazy property
157+
* contains as key the library name and as value an object with an optional lazy property
153158
*
154-
* @type {object}
159+
* @type {ManifestLibraries}
155160
*/
156161
this.libsResolved = Object.create(null);
157162
this.wasResolved = false;
158163
}
159164

160165
/**
166+
* Add library to libsResolved and if already present
167+
* merge lazy property
161168
*
162-
* @param {string} libName
169+
* @param {string} libName library name, e.g. "lib.x"
163170
* @param {boolean} lazy
164-
* @returns {{lazy: boolean}}
171+
* @returns {{lazy: boolean}} the added library
165172
*/
166173
addResolvedLibDependency(libName, lazy) {
167174
let alreadyResolved = this.libsResolved[libName];
@@ -219,7 +226,7 @@ class DependencyInfo {
219226
* Sorts the keys of a given object
220227
*
221228
* @param {object} obj the object
222-
* @returns {{}}
229+
* @returns {{}} the object with sorted keys
223230
*/
224231
const sortObjectKeys = (obj) => {
225232
const sortedObject = {};
@@ -232,9 +239,10 @@ const sortObjectKeys = (obj) => {
232239
};
233240

234241
/**
242+
* Builds the manifestHints object from the dependencyInfo
235243
*
236244
* @param {DependencyInfo} dependencyInfo
237-
* @returns {object} manifestHints
245+
* @returns {{dependencies: {libs: ManifestLibraries}}} manifestHints
238246
*/
239247
const getManifestHints = (dependencyInfo) => {
240248
if (dependencyInfo && Object.keys(dependencyInfo.libsResolved).length) {
@@ -307,6 +315,13 @@ class ArtifactInfo {
307315
}
308316
}
309317

318+
/**
319+
* Processes the manifest and creates a ManifestInfo and an ArtifactInfo.
320+
*
321+
* @param {module:@ui5/fs.Resource} libraryManifest
322+
* @param {string} [name] library name, if not provided using the ManifestInfo's id
323+
* @returns {Promise<{manifestInfo: ManifestInfo, libraryArtifactInfo: ArtifactInfo}>}
324+
*/
310325
async function processManifestAndGetArtifactInfo(libraryManifest, name) {
311326
const manifestInfo = await processManifest(libraryManifest);
312327
name = name || manifestInfo.id;
@@ -340,21 +355,23 @@ const processLibraryInfo = async (libraryInfo) => {
340355
return getManifestPath(libraryInfo.libraryManifest.getPath(), embed);
341356
});
342357
// e.g. manifest resource with lib/x/sub/manifest.json
343-
const relevantManifests = libraryInfo.manifestResources.filter((manifestResource) => {
358+
let embeddedManifests = libraryInfo.embeddedManifests || [];
359+
embeddedManifests = embeddedManifests.filter((manifestResource) => {
344360
return embeddedPaths.includes(manifestResource.getPath());
345361
});
346362

347363
// get all embedded manifests
348-
const embeddedManifestPromises = relevantManifests.map(async (relevantManifest) => {
364+
const embeddedManifestPromises = embeddedManifests.map(async (embeddedManifest) => {
349365
const {manifestInfo: embeddedManifestInfo, libraryArtifactInfo: embeddedArtifactInfo} =
350-
await processManifestAndGetArtifactInfo(relevantManifest);
366+
await processManifestAndGetArtifactInfo(embeddedManifest);
351367

352368
const componentName = embeddedManifestInfo.id;
353369

354-
const fullManifestPath = posixPath.dirname(relevantManifest.getPath());
355-
const libraryPathPrefix = posixPath.dirname(libraryInfo.libraryManifest.getPath());
370+
const embeddedManifestDirName = posixPath.dirname(embeddedManifest.getPath());
371+
const libraryManifestDirName = posixPath.dirname(libraryInfo.libraryManifest.getPath());
356372

357-
if (isBundledWithLibrary(embeddedManifestInfo.embeddedBy, fullManifestPath, libraryPathPrefix + "/")) {
373+
if (isBundledWithLibrary(embeddedManifestInfo.embeddedBy, embeddedManifestDirName,
374+
libraryManifestDirName + "/")) {
358375
bundledComponents.add(componentName);
359376
}
360377
return embeddedArtifactInfo;
@@ -376,7 +393,7 @@ const processLibraryInfo = async (libraryInfo) => {
376393
* @property {string} version The library version, e.g. "1.0.0"
377394
* @property {module:@ui5/fs.Resource} libraryManifest library manifest resource,
378395
* e.g. resource with path "lib/x/manifest.json"
379-
* @property {module:@ui5/fs.Resource[]} manifestResources list of embedded manifest resources,
396+
* @property {module:@ui5/fs.Resource[]} embeddedManifests list of embedded manifest resources,
380397
* e.g. resource with path "lib/x/sub/manifest.json"
381398
*/
382399

@@ -395,7 +412,7 @@ const processLibraryInfo = async (libraryInfo) => {
395412
* name: "lib.x",
396413
* version: "1.0.0",
397414
* libraryManifest: module:@ui5/fs.Resource,
398-
* manifestResources: module:@ui5/fs.Resource[]
415+
* embeddedManifests: module:@ui5/fs.Resource[]
399416
* }
400417
* </pre>
401418
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with an array containing the versionInfo resource
@@ -416,7 +433,7 @@ module.exports = async function({options}) {
416433
const dependencyInfoMap = new Map();
417434

418435

419-
// gather all manifestHints
436+
// process library infos
420437
const librariesPromises = options.libraryInfos.map((libraryInfo) => {
421438
return processLibraryInfo(libraryInfo);
422439
});

lib/tasks/generateVersionInfo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = async ({workspace, dependencies, options: {rootProject, pattern
3030
manifestResources.filter((manifestResource) => manifestResource !== libraryManifest);
3131
return {
3232
libraryManifest,
33-
manifestResources: embeddedManifests,
33+
embeddedManifests,
3434
name: dotLibResource._project.metadata.name,
3535
version: dotLibResource._project.version
3636
};

0 commit comments

Comments
 (0)