Skip to content

Commit

Permalink
secure looping by checking libs existence in manifest
Browse files Browse the repository at this point in the history
simplify manifest path resolving
  • Loading branch information
tobiasso85 committed Jan 26, 2021
1 parent fd6a8e9 commit 8eeab50
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const processManifest = async (manifestResource) => {
// sap.ui5/dependencies is used for the "manifestHints/libs"
if (manifestObject["sap.ui5"]) {
const manifestDependencies = manifestObject["sap.ui5"]["dependencies"];
if (manifestDependencies) {
if (manifestDependencies && manifestDependencies.libs) {
const libs = {};
for (const [libKey, libValue] of Object.entries(manifestDependencies.libs)) {
libs[libKey] = {};
Expand Down Expand Up @@ -134,8 +134,7 @@ const isBundledWithLibrary = (embeddedBy, componentPath, libraryPathPrefix) => {
* @returns {string} manifest path, e.g. "lib/x/sub/manifest.json"
*/
const getManifestPath = (filePath, subPath) => {
const folderPathOfManifest = filePath.substr(0, filePath.length - "manifest.json".length) + subPath;
return posixPath.resolve(folderPathOfManifest + "/manifest.json");
return posixPath.resolve(posixPath.dirname(filePath), subPath, "manifest.json");
};

/**
Expand Down Expand Up @@ -189,6 +188,9 @@ class DependencyInfo {
if (!this._libsResolved) {
// early set if there is a potential cycle
this._libsResolved = Object.create(null);
if (!this.libs) {
return this._libsResolved;
}
for (const [libName, libValue] of Object.entries(this.libs)) {
const lazy = libValue.lazy;
const dependencyInfoObjectAdded = this.addResolvedLibDependency(libName, lazy);
Expand Down
47 changes: 47 additions & 0 deletions test/lib/processors/versionInfoGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,53 @@ test.serial("versionInfoGenerator simple library infos", async (t) => {
"Cannot add meta information for library 'my.lib'. The manifest.json file cannot be found");
});

test.serial("versionInfoGenerator manifest without libs", async (t) => {
const libAManifest = {
getPath: () => {
return "/resources/lib/a/manifest.json";
},
getString: async () => {
return JSON.stringify({
"sap.app": {
"id": "lib.a",
"embeds": []
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.84"
}
}
});
}
};
const libA = {name: "lib.a", version: "1.2.3", libraryManifest: libAManifest};

const options = {
rootProjectName: "myname", rootProjectVersion: "1.33.7", libraryInfos: [
libA
]};
const versionInfos = await versionInfoGenerator({options});

const resource = versionInfos[0];
const result = await resource.getString();

const oExpected = {
"name": "myname",
"version": "1.33.7",
"scmRevision": "",
"libraries": [
{
"name": "lib.a",
"version": "1.2.3",
"scmRevision": ""
}
]
};
assertVersionInfoContent(t, oExpected, result);
t.is(t.context.infoLogStub.callCount, 0);
t.is(t.context.warnLogStub.callCount, 0);
});

test.serial("versionInfoGenerator library infos with dependencies", async (t) => {
const libAManifest = {
getPath: () => {
Expand Down

0 comments on commit 8eeab50

Please sign in to comment.