From 8f2072c5febf18f326abf282328aaab334a745d5 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Wed, 9 Jan 2019 21:30:41 +0100 Subject: [PATCH] [FEATURE] Add specification version 1.0 --- docs/Configuration.md | 19 ++++-- lib/projectPreprocessor.js | 14 +++-- test/fixtures/application.a/ui5.yaml | 2 +- test/lib/extensions.js | 86 ++++++++++++++++++++++++++++ test/lib/projectPreprocessor.js | 80 +++++++++++++++++++++++--- 5 files changed, 183 insertions(+), 18 deletions(-) diff --git a/docs/Configuration.md b/docs/Configuration.md index 4f2d85ccd..c7cc73eea 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -1,7 +1,7 @@ # Configuration This document describes the configuration of UI5 Build and Development Tooling based projects and extensions. -The content represents the **[Specification Version](#specification-versions) `0.1`**. +The content represents the **[Specification Version](#specification-versions) `1.0`**. ## Contents - [Project Configuration](#project-configuration) @@ -282,8 +282,19 @@ shims: ## Specification Versions The specification version as configured in the `specVersion` property, defines the version a configuration is based on. -**List of all available specification versions:** +### Compatibility Matrix -Version | Description +Version | [UI5 CLI](https://github.com/SAP/ui5-cli) Release --- | --- -**0.1** | Initial version +**0.1** | v0.0.1+ +**1.0** | v1.0.0+ + +### Specification Version 0.1 +Initial version. + +Version 0.1 projects are compatible with [UI5 CLI](https://github.com/SAP/ui5-cli) v0.0.1 and above. + +### Specification Version 1.0 +First stable release. + +Version 1.0 projects are supported by [UI5 CLI](https://github.com/SAP/ui5-cli) v1.0.0 and above. diff --git a/lib/projectPreprocessor.js b/lib/projectPreprocessor.js index 7ceca20ec..bce6df697 100644 --- a/lib/projectPreprocessor.js +++ b/lib/projectPreprocessor.js @@ -267,10 +267,10 @@ class ProjectPreprocessor { return false; // ignore this project } - if (project.specVersion !== "0.1") { + if (project.specVersion !== "0.1" && project.specVersion !== "1.0") { throw new Error( `Invalid specification version defined for project ${project.id}: ${project.specVersion}. ` + - "The currently only allowed version is \"0.1\""); + "See https://github.com/SAP/ui5-project/blob/master/docs/Configuration.md#specification-versions"); } if (!project.type) { @@ -324,10 +324,11 @@ class ProjectPreprocessor { if (!extension.specVersion) { throw new Error(`No specification version defined for extension ${extension.metadata.name}`); - } else if (extension.specVersion !== "0.1") { + } else if (extension.specVersion !== "0.1" && extension.specVersion !== "1.0") { throw new Error( - `Invalid specification version defined for extension ${extension.metadata.name}: ` + - `${extension.specVersion}. The currently only allowed version is "0.1"`); + `Invalid specification version defined for extension ` + + `${extension.metadata.name}: ${extension.specVersion}. ` + + `See https://github.com/SAP/ui5-project/blob/master/docs/Configuration.md#specification-versions`); } else if (this.appliedExtensions[extension.metadata.name]) { log.verbose(`Extension with the name ${extension.metadata.name} has already been applied. ` + "This might have been done during dependency lookahead."); @@ -510,5 +511,6 @@ module.exports = { */ processTree: function(tree) { return new ProjectPreprocessor().processTree(tree); - } + }, + ProjectPreprocessor }; diff --git a/test/fixtures/application.a/ui5.yaml b/test/fixtures/application.a/ui5.yaml index 7e28c5d7c..898f4e816 100644 --- a/test/fixtures/application.a/ui5.yaml +++ b/test/fixtures/application.a/ui5.yaml @@ -1,5 +1,5 @@ --- -specVersion: "0.1" +specVersion: "1.0" type: application metadata: name: application.a diff --git a/test/lib/extensions.js b/test/lib/extensions.js index c3226c352..cd2c4e91f 100644 --- a/test/lib/extensions.js +++ b/test/lib/extensions.js @@ -1,6 +1,8 @@ const {test} = require("ava"); const path = require("path"); +const sinon = require("sinon"); const projectPreprocessor = require("../..").projectPreprocessor; +const Preprocessor = require("../..").projectPreprocessor.ProjectPreprocessor; const applicationAPath = path.join(__dirname, "..", "fixtures", "application.a"); const legacyLibraryAPath = path.join(__dirname, "..", "fixtures", "legacy.library.a"); const legacyLibraryBPath = path.join(__dirname, "..", "fixtures", "legacy.library.b"); @@ -10,6 +12,10 @@ const legacyCollectionLibraryX = path.join(__dirname, "..", "fixtures", "legacy. const legacyCollectionLibraryY = path.join(__dirname, "..", "fixtures", "legacy.collection.a", "src", "legacy.library.y"); +test.afterEach.always((t) => { + sinon.restore(); +}); + test("Project with project-shim extension with dependency configuration", (t) => { const tree = { id: "application.a", @@ -570,3 +576,83 @@ test("Project with task extension dependency - task module not found", async (t) const error = await t.throws(projectPreprocessor.processTree(tree)); t.regex(error.message, /^Cannot find module.*/, "Rejected with error"); }); + +test("specVersion: Missing version", async (t) => { + const extension = { + id: "extension.a", + path: applicationAPath, + dependencies: [], + version: "1.0.0", + kind: "extension", + type: "project-shim", + metadata: { + name: "shims.a" + }, + shims: {} + }; + const preprocessor = new Preprocessor(); + await t.throws(preprocessor.applyExtension(extension), + "No specification version defined for extension shims.a", + "Rejected with error"); +}); + +test("specVersion: Extension with invalid version", async (t) => { + const extension = { + id: "extension.a", + path: applicationAPath, + dependencies: [], + version: "1.0.0", + specVersion: "0.9", + kind: "extension", + type: "project-shim", + metadata: { + name: "shims.a" + }, + shims: {} + }; + const preprocessor = new Preprocessor(); + await t.throws(preprocessor.applyExtension(extension), + "Invalid specification version defined for extension shims.a: 0.9. " + + "See https://github.com/SAP/ui5-project/blob/master/docs/Configuration.md#specification-versions", + "Rejected with error"); +}); + +test("specVersion: Extension with valid version 0.1", async (t) => { + const extension = { + id: "extension.a", + path: applicationAPath, + dependencies: [], + version: "1.0.0", + specVersion: "0.1", + 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, "0.1", "Correct spec version"); +}); + +test("specVersion: Extension with valid version 1.0", async (t) => { + const extension = { + id: "extension.a", + path: applicationAPath, + dependencies: [], + version: "1.0.0", + specVersion: "1.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, "1.0", "Correct spec version"); +}); diff --git a/test/lib/projectPreprocessor.js b/test/lib/projectPreprocessor.js index 2c473cb6d..91a3a7640 100644 --- a/test/lib/projectPreprocessor.js +++ b/test/lib/projectPreprocessor.js @@ -16,7 +16,7 @@ test("Project with inline configuration", (t) => { path: applicationAPath, dependencies: [], version: "1.0.0", - specVersion: "0.1", + specVersion: "1.0", type: "application", metadata: { name: "xy" @@ -43,7 +43,7 @@ test("Project with inline configuration", (t) => { id: "application.a", kind: "project", version: "1.0.0", - specVersion: "0.1", + specVersion: "1.0", path: applicationAPath }, "Parsed correctly"); }); @@ -113,7 +113,7 @@ test("Project with ui5.yaml at default location", (t) => { id: "application.a", kind: "project", version: "1.0.0", - specVersion: "0.1", + specVersion: "1.0", path: applicationAPath }, "Parsed correctly"); }); @@ -332,7 +332,7 @@ test("Ignores additional application-projects", (t) => { id: "application.a", kind: "project", version: "1.0.0", - specVersion: "0.1", + specVersion: "1.0", path: applicationAPath }, "Parsed correctly"); }); @@ -540,7 +540,7 @@ test("Project tree B with inline configs", (t) => { const treeAWithInlineConfigs = { id: "application.a", version: "1.0.0", - specVersion: "0.1", + specVersion: "1.0", path: applicationAPath, type: "application", metadata: { @@ -654,7 +654,7 @@ const expectedTreeAWithInlineConfigs = { "id": "application.a", "kind": "project", "version": "1.0.0", - "specVersion": "0.1", + "specVersion": "1.0", "path": applicationAPath, "_level": 0, "type": "application", @@ -760,7 +760,7 @@ const expectedTreeAWithConfigPaths = { "id": "application.a", "kind": "project", "version": "1.0.0", - "specVersion": "0.1", + "specVersion": "1.0", "path": applicationAPath, "configPath": path.join(applicationAPath, "ui5.yaml"), "_level": 0, @@ -1370,3 +1370,69 @@ test("Library version in package.json data is missing", (t) => { t.is(error.message, "\"version\" is missing for project " + tree.id); }); }); + +test("specVersion: Missing version", (t) => { + const tree = { + id: "application.a", + path: "non-existent", + dependencies: [], + version: "1.0.0", + type: "application", + metadata: { + name: "xy" + } + }; + return t.throws(projectPreprocessor.processTree(tree), + "No specification version defined for root project application.a", + "Rejected with error"); +}); + +test("specVersion: Project with invalid version", async (t) => { + const tree = { + id: "application.a", + path: applicationAPath, + dependencies: [], + version: "1.0.0", + specVersion: "0.9", + type: "application", + metadata: { + name: "xy" + } + }; + await t.throws(projectPreprocessor.processTree(tree), + "Invalid specification version defined for project application.a: 0.9. " + + "See https://github.com/SAP/ui5-project/blob/master/docs/Configuration.md#specification-versions", + "Rejected with error"); +}); + +test("specVersion: Project with valid version 0.1", async (t) => { + const tree = { + id: "application.a", + path: applicationAPath, + dependencies: [], + version: "1.0.0", + specVersion: "0.1", + type: "application", + metadata: { + name: "xy" + } + }; + const res = await projectPreprocessor.processTree(tree); + t.deepEqual(res.specVersion, "0.1", "Correct spec version"); +}); + +test("specVersion: Project with valid version 1.0", async (t) => { + const tree = { + id: "application.a", + path: applicationAPath, + dependencies: [], + version: "1.0.0", + specVersion: "1.0", + type: "application", + metadata: { + name: "xy" + } + }; + const res = await projectPreprocessor.processTree(tree); + t.deepEqual(res.specVersion, "1.0", "Correct spec version"); +});