Skip to content

Commit

Permalink
[FEATURE] Support for spec version 2.0 (#277)
Browse files Browse the repository at this point in the history
[FEATURE] Support for spec version 2.0
Support for spec version 2.0 in
ui5Framework translator and projectPreprocessor.
  • Loading branch information
svbender authored Mar 20, 2020
1 parent 6fde55a commit 770a56f
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 18 deletions.
6 changes: 4 additions & 2 deletions lib/projectPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ class ProjectPreprocessor {
return false; // ignore this project
}

if (project.specVersion !== "0.1" && project.specVersion !== "1.0" && project.specVersion !== "1.1") {
if (project.specVersion !== "0.1" && project.specVersion !== "1.0" &&
project.specVersion !== "1.1" && project.specVersion !== "2.0") {
throw new Error(
`Unsupported specification version ${project.specVersion} defined for project ` +
`${project.id}. Your UI5 CLI installation might be outdated. ` +
Expand Down Expand Up @@ -353,7 +354,8 @@ class ProjectPreprocessor {
throw new Error(`No specification version defined for extension ${extension.metadata.name}`);
} else if (extension.specVersion !== "0.1" &&
extension.specVersion !== "1.0" &&
extension.specVersion !== "1.1") {
extension.specVersion !== "1.1" &&
extension.specVersion !== "2.0") {
throw new Error(
`Unsupported specification version ${extension.specVersion} defined for extension ` +
`${extension.metadata.name}. Your UI5 CLI installation might be outdated. ` +
Expand Down
25 changes: 16 additions & 9 deletions lib/translators/ui5Framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,23 @@ const utils = {
// Ignoring UI5 Framework libraries in dependencies
return ui5Dependencies;
}
if (project.framework && project.framework.libraries) {
project.framework.libraries.forEach((dependency) => {
if (!ui5Dependencies.includes(dependency.name) && utils.shouldIncludeDependency(dependency, root)) {
ui5Dependencies.push(dependency.name);
}
});

if (project.specVersion === "2.0") {
if (project.framework && project.framework.libraries) {
project.framework.libraries.forEach((dependency) => {
if (!ui5Dependencies.includes(dependency.name) && utils.shouldIncludeDependency(dependency, root)) {
ui5Dependencies.push(dependency.name);
}
});
} else {
log.verbose(`Project ${project.metadata.name} defines no framework.libraries configuration`);
// Possible future enhancement: Fallback to detect OpenUI5 framework dependencies in package.json
}
} else {
log.verbose(`Project ${project.metadata.name} defines no framework.libraries configuration`);
// Possible future enhancement: Fallback to detect OpenUI5 framework dependencies in package.json
log.verbose(`Project ${project.metadata.name} defines invalid ` +
`specification version ${project.specVersion} for framework.libraries configuration`);
}

project.dependencies.map((depProject) => {
utils.getFrameworkLibrariesFromTree(depProject, ui5Dependencies, false);
});
Expand Down Expand Up @@ -209,7 +216,7 @@ module.exports = {
});
queue.push(...project.dependencies);

if (project.framework && project.framework.libraries) {
if (project.specVersion === "2.0" && project.framework && project.framework.libraries) {
const frameworkDeps = project.framework.libraries.map((dependency) => {
if (!frameworkLibs[dependency.name]) {
throw new Error(`Missing framework library ${dependency.name} ` +
Expand Down
20 changes: 20 additions & 0 deletions test/lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,23 @@ test("specVersion: Extension with valid version 1.1", async (t) => {
await preprocessor.applyExtension(extension);
t.deepEqual(handleShimStub.getCall(0).args[0].specVersion, "1.1", "Correct spec version");
});

test("specVersion: Extension with valid version 2.0", async (t) => {
const extension = {
id: "extension.a",
path: applicationAPath,
dependencies: [],
version: "1.0.0",
specVersion: "2.0",
kind: "extension",
type: "project-shim",
metadata: {
name: "shims.a"
},
shims: {}
};
const preprocessor = new Preprocessor({});
const handleShimStub = sinon.stub(preprocessor, "handleShim");
await preprocessor.applyExtension(extension);
t.deepEqual(handleShimStub.getCall(0).args[0].specVersion, "2.0", "Correct spec version");
});
16 changes: 16 additions & 0 deletions test/lib/projectPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,22 @@ test("specVersion: Project with valid version 1.1", async (t) => {
t.deepEqual(res.specVersion, "1.1", "Correct spec version");
});

test("specVersion: Project with valid version 2.0", async (t) => {
const tree = {
id: "application.a",
path: applicationAPath,
dependencies: [],
version: "1.0.0",
specVersion: "2.0",
type: "application",
metadata: {
name: "xy"
}
};
const res = await projectPreprocessor.processTree(tree);
t.deepEqual(res.specVersion, "2.0", "Correct spec version");
});

test("isBeingProcessed: Is not being processed", (t) => {
const preprocessor = new projectPreprocessor._ProjectPreprocessor({});

Expand Down
49 changes: 42 additions & 7 deletions test/lib/translators/ui5Framework.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ function defineTest(testName, {
}
};

function project({name, version, type, framework, _level, dependencies = []}) {
function project({name, version, type, specVersion = "2.0", framework, _level, dependencies = []}) {
const proj = {
_level,
id: name + "-id",
version,
path: path.join(fakeBaseDir, "project-" + name),
specVersion: "1.1",
specVersion,
kind: "project",
type,
metadata: {
Expand Down Expand Up @@ -156,6 +156,12 @@ function defineTest(testName, {
version: "7.8.9",
path: path.join(fakeBaseDir, "project-test-dependency-no-framework"),
dependencies: []
},
{
id: "test-dependency-framework-old-spec-version-id",
version: "10.11.12",
path: path.join(fakeBaseDir, "project-test-dependency-framework-old-spec-version"),
dependencies: []
}
]
};
Expand All @@ -168,7 +174,7 @@ function defineTest(testName, {
})
.withArgs(path.join(fakeBaseDir, "project-test-application", "ui5.yaml"))
.resolves([{
specVersion: "1.1",
specVersion: "2.0",
type: "application",
metadata: {
name: "test-application"
Expand All @@ -189,7 +195,7 @@ function defineTest(testName, {
}])
.withArgs(path.join(fakeBaseDir, "project-test-dependency", "ui5.yaml"))
.resolves([{
specVersion: "1.1",
specVersion: "2.0",
type: "library",
metadata: {
name: "test-dependency"
Expand All @@ -208,12 +214,27 @@ function defineTest(testName, {
}])
.withArgs(path.join(fakeBaseDir, "project-test-dependency-no-framework", "ui5.yaml"))
.resolves([{
specVersion: "1.1",
specVersion: "2.0",
type: "library",
metadata: {
name: "test-dependency-no-framework"
}
}])
.withArgs(path.join(fakeBaseDir, "project-test-dependency-framework-old-spec-version", "ui5.yaml"))
.resolves([{
specVersion: "1.1",
type: "library",
metadata: {
name: "test-dependency-framework-old-spec-version"
},
framework: {
libraries: [
{
name: "sap.ui.lib5"
}
]
}
}])
.withArgs(path.join(ui5PackagesBaseDir, npmScope, "sap.ui.lib1",
frameworkName === "SAPUI5" ? "1.75.1" : "1.75.0", "ui5.yaml"
))
Expand Down Expand Up @@ -381,6 +402,20 @@ function defineTest(testName, {
version: "7.8.9",
type: "library"
}),
project({
_level: 1,
name: "test-dependency-framework-old-spec-version",
specVersion: "1.1",
version: "10.11.12",
type: "library",
framework: {
libraries: [
{
name: "sap.ui.lib5"
}
]
},
}),
frameworkProject({
_level: 1,
name: "sap.ui.lib1",
Expand Down Expand Up @@ -441,7 +476,7 @@ function defineErrorTest(testName, {
})
.withArgs(path.join(fakeBaseDir, "application-project", "ui5.yaml"))
.resolves([{
specVersion: "1.1",
specVersion: "2.0",
type: "application",
metadata: {
name: "test-project"
Expand Down Expand Up @@ -749,7 +784,7 @@ test.serial("SAPUI5: ui5Framework translator should throw error when using a lib
dependencies: []
};
const projectPreprocessorTree = Object.assign({}, translatorTree, {
specVersion: "1.1",
specVersion: "2.0",
type: "application",
metadata: {
name: "test-project"
Expand Down
13 changes: 13 additions & 0 deletions test/lib/translators/ui5Framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project without dependencies",
test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dependency with libraries", (t) => {
const tree = {
id: "test1",
specVersion: "2.0",
metadata: {
name: "test1"
},
Expand All @@ -249,6 +250,7 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep
dependencies: [
{
id: "test2",
specVersion: "2.0",
metadata: {
name: "test2"
},
Expand All @@ -266,6 +268,7 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep
dependencies: [
{
id: "test3",
specVersion: "2.0",
metadata: {
name: "test3"
},
Expand All @@ -286,6 +289,7 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep
},
{
id: "@sapui5/lib8",
specVersion: "2.0",
metadata: {
name: "lib8"
},
Expand All @@ -300,16 +304,25 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep
},
{
id: "@openui5/lib9",
specVersion: "1.1",
metadata: {
name: "lib9"
},
dependencies: []
},
{
id: "@foo/library",
specVersion: "1.1",
metadata: {
name: "foo.library"
},
framework: {
libraries: [
{
name: "should.also.be.ignored"
}
]
},
dependencies: []
}
]
Expand Down

0 comments on commit 770a56f

Please sign in to comment.