Skip to content

Commit

Permalink
[INTERNAL] Adapt to new Specification#getSpecVersion implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Nov 28, 2022
1 parent 0554b3f commit 421c418
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 40 deletions.
6 changes: 3 additions & 3 deletions lib/framework/add.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()}"`
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/framework/remove.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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()}"`
);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/framework/use.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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()}"`
);
}

Expand Down
7 changes: 0 additions & 7 deletions lib/framework/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
7 changes: 6 additions & 1 deletion test/lib/framework/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion test/lib/framework/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion test/lib/framework/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 0 additions & 21 deletions test/lib/framework/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
});

0 comments on commit 421c418

Please sign in to comment.