diff --git a/lib/framework/add.js b/lib/framework/add.js index 68f51d5c..033e8609 100644 --- a/lib/framework/add.js +++ b/lib/framework/add.js @@ -1,4 +1,4 @@ -import {getRootProjectConfiguration, getFrameworkResolver, isValidSpecVersion} from "./utils.js"; +import {getRootProjectConfiguration, getFrameworkResolver} from "./utils.js"; /** * Adds the given set of libraries to the framework libraries section in the ui5.yaml @@ -10,10 +10,10 @@ import {getRootProjectConfiguration, getFrameworkResolver, isValidSpecVersion} f export default async function({projectGraphOptions, libraries}) { const project = await getRootProjectConfiguration(projectGraphOptions); - if (!isValidSpecVersion(project.getSpecVersion())) { + if (project.getSpecVersion().lt("2.0")) { throw new Error( `ui5 add command requires specVersion "2.0" or higher. ` + - `Project ${project.getName()} uses specVersion "${project.getSpecVersion()}"` + `Project ${project.getName()} uses specVersion "${project.getSpecVersion().toString()}"` ); } diff --git a/lib/framework/remove.js b/lib/framework/remove.js index 27c8d916..bb5f9370 100644 --- a/lib/framework/remove.js +++ b/lib/framework/remove.js @@ -1,4 +1,4 @@ -import {getRootProjectConfiguration, isValidSpecVersion} from "./utils.js"; +import {getRootProjectConfiguration} from "./utils.js"; import logger from "@ui5/logger"; const log = logger.getLogger("cli:framework:remove"); @@ -13,10 +13,10 @@ const log = logger.getLogger("cli:framework:remove"); export default async function({projectGraphOptions, libraries}) { const project = await getRootProjectConfiguration(projectGraphOptions); - if (!isValidSpecVersion(project.getSpecVersion())) { + if (project.getSpecVersion().lt("2.0")) { throw new Error( `ui5 remove command requires specVersion "2.0" or higher. ` + - `Project ${project.getName()} uses specVersion "${project.getSpecVersion()}"` + `Project ${project.getName()} uses specVersion "${project.getSpecVersion().toString()}"` ); } diff --git a/lib/framework/use.js b/lib/framework/use.js index 1cccb0cf..168c2ef1 100644 --- a/lib/framework/use.js +++ b/lib/framework/use.js @@ -1,4 +1,4 @@ -import {getRootProjectConfiguration, getFrameworkResolver, isValidSpecVersion} from "./utils.js"; +import {getRootProjectConfiguration, getFrameworkResolver} from "./utils.js"; async function resolveVersion({frameworkName, frameworkVersion}, resolverOptions) { return await getFrameworkResolver(frameworkName).resolveVersion(frameworkVersion, resolverOptions); @@ -25,10 +25,10 @@ function getEffectiveFrameworkName({project, frameworkOptions}) { export default async function({projectGraphOptions, frameworkOptions}) { const project = await getRootProjectConfiguration(projectGraphOptions); - if (!isValidSpecVersion(project.getSpecVersion())) { + if (project.getSpecVersion().lt("2.0")) { throw new Error( `ui5 use command requires specVersion "2.0" or higher. ` + - `Project ${project.getName()} uses specVersion "${project.getSpecVersion()}"` + `Project ${project.getName()} uses specVersion "${project.getSpecVersion().toString()}"` ); } diff --git a/lib/framework/utils.js b/lib/framework/utils.js index 80d40bfe..675b33b5 100644 --- a/lib/framework/utils.js +++ b/lib/framework/utils.js @@ -28,10 +28,3 @@ export function getFrameworkResolver(frameworkName) { throw new Error("Invalid framework.name: " + frameworkName); } } - -export function isValidSpecVersion(specVersion) { - // Only checks for a string and versions that are not supported - // The CLI relies on the @ui5/project to correctly verify the version - return typeof specVersion === "string" && specVersion !== "" && - specVersion !== "0.1" && specVersion !== "1.0" && specVersion !== "1.1"; -} diff --git a/test/lib/framework/add.js b/test/lib/framework/add.js index 84d5d76a..1fa6aaee 100644 --- a/test/lib/framework/add.js +++ b/test/lib/framework/add.js @@ -5,7 +5,12 @@ import esmock from "esmock"; function createMockProject(attr) { return { getName: () => attr.name, - getSpecVersion: () => attr.specVersion, + getSpecVersion: () => { + return { + toString: () => attr.specVersion, + lt: () => attr.specVersion === "1.0", + }; + }, getPath: () => attr.path, getFrameworkName: () => attr.frameworkName, getFrameworkVersion: () => attr.frameworkVersion, diff --git a/test/lib/framework/remove.js b/test/lib/framework/remove.js index e25a5f0d..20dcd9eb 100644 --- a/test/lib/framework/remove.js +++ b/test/lib/framework/remove.js @@ -5,7 +5,12 @@ import esmock from "esmock"; function createMockProject(attr) { return { getName: () => attr.name, - getSpecVersion: () => attr.specVersion, + getSpecVersion: () => { + return { + toString: () => attr.specVersion, + lt: () => attr.specVersion === "1.0", + }; + }, getPath: () => attr.path, getFrameworkName: () => attr.frameworkName, getFrameworkVersion: () => attr.frameworkVersion, diff --git a/test/lib/framework/use.js b/test/lib/framework/use.js index 8b51c583..c356ef2f 100644 --- a/test/lib/framework/use.js +++ b/test/lib/framework/use.js @@ -5,7 +5,12 @@ import esmock from "esmock"; function createMockProject(attr) { return { getName: () => attr.name, - getSpecVersion: () => attr.specVersion, + getSpecVersion: () => { + return { + toString: () => attr.specVersion, + lt: () => attr.specVersion === "1.0", + }; + }, getPath: () => attr.path, getFrameworkName: () => attr.frameworkName, getFrameworkVersion: () => attr.frameworkVersion, diff --git a/test/lib/framework/utils.js b/test/lib/framework/utils.js index 6fb630d3..90dd537b 100644 --- a/test/lib/framework/utils.js +++ b/test/lib/framework/utils.js @@ -93,24 +93,3 @@ test.serial("getFrameworkResolver: Invalid framework.name", (t) => { message: "Invalid framework.name: UI5" }); }); - -test.serial("isValidSpecVersion", (t) => { - const {isValidSpecVersion} = t.context.utils; - - t.true(isValidSpecVersion("2.0")); - t.true(isValidSpecVersion("2.1")); - t.true(isValidSpecVersion("3.0")); - t.true(isValidSpecVersion("123456789")); - t.true(isValidSpecVersion("123456789.0.0.0")); - - t.false(isValidSpecVersion()); - t.false(isValidSpecVersion(undefined)); - t.false(isValidSpecVersion(null)); - t.false(isValidSpecVersion(true)); - t.false(isValidSpecVersion({})); - t.false(isValidSpecVersion(function() {})); - t.false(isValidSpecVersion("")); - t.false(isValidSpecVersion("0.1")); - t.false(isValidSpecVersion("1.0")); - t.false(isValidSpecVersion("1.1")); -});