Skip to content

Commit

Permalink
[INTERNAL] ui5Framework: Fix handling of optional dependencies on roo…
Browse files Browse the repository at this point in the history
…t project
  • Loading branch information
RandomByte committed Mar 24, 2020
1 parent 69fcb17 commit 6b717fd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/translators/ui5Framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,12 @@ module.exports = {
if (project.specVersion === "2.0" && project.framework && project.framework.libraries) {
const frameworkDeps = project.framework.libraries
.filter((dependency) => {
// Filter out development and unresolved optional dependencies
if (dependency.development) {
return false;
if (dependency.optional && frameworkLibs[dependency.name]) {
// Resolved optional dependencies shall be used
return true;
}
if (!frameworkLibs[dependency.name] && dependency.optional) {
return false;
}
return true;
// Filter out development and unresolved optional dependencies for non-root projects
return utils.shouldIncludeDependency(dependency, project._level === 0);
})
.map((dependency) => {
if (!frameworkLibs[dependency.name]) {
Expand Down
47 changes: 47 additions & 0 deletions test/lib/translators/ui5Framework.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ function defineTest(testName, {
"sap.ui.lib1"
],
optionalDependencies: []
},
"sap.ui.lib8": {
npmPackageName: "@sapui5/sap.ui.lib8",
version: "1.75.8",
dependencies: [],
optionalDependencies: []
}
}
};
Expand Down Expand Up @@ -189,6 +195,10 @@ function defineTest(testName, {
{
name: "sap.ui.lib4",
optional: true
},
{
name: "sap.ui.lib8",
development: true
}
]
}
Expand Down Expand Up @@ -216,6 +226,10 @@ function defineTest(testName, {
{
name: "sap.ui.lib6",
development: true
},
{
name: "sap.ui.lib8",
optional: true // optional dependency gets resolved by dev-dependency of root project
}
]
}
Expand Down Expand Up @@ -286,6 +300,17 @@ function defineTest(testName, {
name: "sap.ui.lib4"
},
framework: {libraries: []}
}])
.withArgs(path.join(ui5PackagesBaseDir, npmScope, "sap.ui.lib8",
frameworkName === "SAPUI5" ? "1.75.8" : "1.75.0", "ui5.yaml"
))
.resolves([{
specVersion: "1.0",
type: "library",
metadata: {
name: "sap.ui.lib8"
},
framework: {libraries: []}
}]);

// Prevent applying types as this would require a lot of mocking
Expand Down Expand Up @@ -327,6 +352,12 @@ function defineTest(testName, {
dependencies: {
"@openui5/sap.ui.lib1": "1.75.0"
}
})
.withArgs("@openui5/sap.ui.lib8@1.75.0")
.resolves({
name: "@openui5/sap.ui.lib8",
version: "1.75.0",
dependencies: {}
});
} else if (frameworkName === "SAPUI5") {
sinon.stub(Installer.prototype, "readJson")
Expand Down Expand Up @@ -355,6 +386,10 @@ function defineTest(testName, {
{
name: "sap.ui.lib4",
optional: true
},
{
name: "sap.ui.lib8",
development: true
}
]
},
Expand All @@ -380,6 +415,10 @@ function defineTest(testName, {
{
name: "sap.ui.lib6",
development: true
},
{
name: "sap.ui.lib8",
optional: true
}
]
},
Expand Down Expand Up @@ -409,6 +448,10 @@ function defineTest(testName, {
]
})
]
}),
frameworkProject({
_level: 1,
name: "sap.ui.lib8",
})
]
}),
Expand Down Expand Up @@ -445,6 +488,10 @@ function defineTest(testName, {
name: "sap.ui.lib1"
})
]
}),
frameworkProject({
_level: 1,
name: "sap.ui.lib8",
})
]
});
Expand Down

0 comments on commit 6b717fd

Please sign in to comment.