From 31ddac8c9acf350a313e0b7f1c298dacbaf91068 Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Thu, 19 Mar 2020 12:11:43 +0100 Subject: [PATCH 1/4] [BREAKING] Support for spec version 2.0 BREAKING CHANGE: Support for spec version 2.0 in ui5Framework translator and projectPreprocessor. --- lib/projectPreprocessor.js | 6 ++- lib/translators/ui5Framework.js | 4 +- .../translators/ui5Framework.integration.js | 45 ++++++++++++++++--- test/lib/translators/ui5Framework.js | 13 ++++++ 4 files changed, 59 insertions(+), 9 deletions(-) diff --git a/lib/projectPreprocessor.js b/lib/projectPreprocessor.js index 14642924e..4f404e3ba 100644 --- a/lib/projectPreprocessor.js +++ b/lib/projectPreprocessor.js @@ -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. ` + @@ -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. ` + diff --git a/lib/translators/ui5Framework.js b/lib/translators/ui5Framework.js index 1b58a10d3..6df77766f 100644 --- a/lib/translators/ui5Framework.js +++ b/lib/translators/ui5Framework.js @@ -71,7 +71,7 @@ const utils = { // Ignoring UI5 Framework libraries in dependencies return ui5Dependencies; } - if (project.framework && project.framework.libraries) { + if (project.specVersion === "2.0" && project.framework && project.framework.libraries) { project.framework.libraries.forEach((dependency) => { if (!ui5Dependencies.includes(dependency.name) && utils.shouldIncludeDependency(dependency, root)) { ui5Dependencies.push(dependency.name); @@ -209,7 +209,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} ` + diff --git a/test/lib/translators/ui5Framework.integration.js b/test/lib/translators/ui5Framework.integration.js index 9a59742eb..c2e2417ac 100644 --- a/test/lib/translators/ui5Framework.integration.js +++ b/test/lib/translators/ui5Framework.integration.js @@ -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: { @@ -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: [] } ] }; @@ -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" @@ -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" @@ -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" )) @@ -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", diff --git a/test/lib/translators/ui5Framework.js b/test/lib/translators/ui5Framework.js index 831bbc5ec..7ac9a6400 100644 --- a/test/lib/translators/ui5Framework.js +++ b/test/lib/translators/ui5Framework.js @@ -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" }, @@ -249,6 +250,7 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep dependencies: [ { id: "test2", + specVersion: "2.0", metadata: { name: "test2" }, @@ -266,6 +268,7 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep dependencies: [ { id: "test3", + specVersion: "2.0", metadata: { name: "test3" }, @@ -286,6 +289,7 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep }, { id: "@sapui5/lib8", + specVersion: "2.0", metadata: { name: "lib8" }, @@ -300,6 +304,7 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep }, { id: "@openui5/lib9", + specVersion: "1.1", metadata: { name: "lib9" }, @@ -307,9 +312,17 @@ test.serial("utils.getFrameworkLibrariesFromTree: Project with libraries and dep }, { id: "@foo/library", + specVersion: "1.1", metadata: { name: "foo.library" }, + framework: { + libraries: [ + { + name: "should.also.be.ignored" + } + ] + }, dependencies: [] } ] From 95a767f8fce18e88d4aeec2110aac1a5ed697310 Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Thu, 19 Mar 2020 12:25:17 +0100 Subject: [PATCH 2/4] Fix spec version in new integration tests --- test/lib/translators/ui5Framework.integration.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/translators/ui5Framework.integration.js b/test/lib/translators/ui5Framework.integration.js index c2e2417ac..a7e66d0fb 100644 --- a/test/lib/translators/ui5Framework.integration.js +++ b/test/lib/translators/ui5Framework.integration.js @@ -476,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" @@ -784,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" From 33c00c3463799759ca5b154ba4e7f9d595fd513e Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Fri, 20 Mar 2020 10:58:13 +0100 Subject: [PATCH 3/4] Add missing unit tests for spec version --- test/lib/extensions.js | 20 ++++++++++++++++++++ test/lib/projectPreprocessor.js | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/test/lib/extensions.js b/test/lib/extensions.js index a1c283505..a490e7e1f 100644 --- a/test/lib/extensions.js +++ b/test/lib/extensions.js @@ -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"); +}); diff --git a/test/lib/projectPreprocessor.js b/test/lib/projectPreprocessor.js index c55ec6e71..8d764c2af 100644 --- a/test/lib/projectPreprocessor.js +++ b/test/lib/projectPreprocessor.js @@ -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({}); From 3486fa7682ce55ab7dfdbd6a98d21ccba9717920 Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Fri, 20 Mar 2020 12:17:38 +0100 Subject: [PATCH 4/4] Add verbose log for invalid specVersion --- lib/translators/ui5Framework.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/translators/ui5Framework.js b/lib/translators/ui5Framework.js index 6df77766f..eef2ea5c1 100644 --- a/lib/translators/ui5Framework.js +++ b/lib/translators/ui5Framework.js @@ -71,16 +71,23 @@ const utils = { // Ignoring UI5 Framework libraries in dependencies return ui5Dependencies; } - if (project.specVersion === "2.0" && 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); });