Avoid using SemVer instances

Use strings instead. They are easier to serialize and deserialize.
This commit is contained in:
Andrew Eisenberg
2021-06-04 13:34:55 -07:00
parent 9b5753ab00
commit 06687e95c8
10 changed files with 26 additions and 26 deletions

View File

@@ -3,7 +3,7 @@ import * as path from "path";
import test from "ava";
import * as yaml from "js-yaml";
import { parse } from "semver";
import { clean } from "semver";
import sinon from "sinon";
import { runQueries } from "./analyze";
@@ -39,13 +39,13 @@ test("status report fields and search path setting", async (t) => {
[Language.cpp]: [
{
packName: "a/b",
version: parse("1.0.0"),
version: clean("1.0.0"),
},
],
[Language.java]: [
{
packName: "c/d",
version: parse("2.0.0"),
version: clean("2.0.0"),
},
],
} as Packs;

View File

@@ -318,7 +318,7 @@ function packWithVersionToQuerySuiteEntry(
): string {
let text = `- qlpack: ${pack.packName}`;
if (pack.version) {
text += `${"\n"} version: ${pack.version.format()}`;
text += `${"\n"} version: ${pack.version}`;
}
return text;
}

View File

@@ -3,7 +3,7 @@ import * as path from "path";
import * as github from "@actions/github";
import test, { ExecutionContext } from "ava";
import { parse } from "semver";
import { clean } from "semver";
import sinon from "sinon";
import * as api from "./api-client";
@@ -1027,7 +1027,7 @@ test("Config specifies packages", async (t) => {
[Language.javascript]: [
{
packName: "a/b",
version: parse("1.2.3"),
version: clean("1.2.3"),
},
],
});
@@ -1084,13 +1084,13 @@ test("Config specifies packages for multiple languages", async (t) => {
[Language.javascript]: [
{
packName: "a/b",
version: parse("1.2.3"),
version: clean("1.2.3"),
},
],
[Language.python]: [
{
packName: "c/d",
version: parse("1.2.3"),
version: clean("1.2.3"),
},
],
});
@@ -1366,7 +1366,7 @@ test("no packs", parsePacksMacro, undefined, [], {});
test("two packs", parsePacksMacro, ["a/b", "c/d@1.2.3"], [Language.cpp], {
[Language.cpp]: [
{ packName: "a/b", version: undefined },
{ packName: "c/d", version: parse("1.2.3") },
{ packName: "c/d", version: clean("1.2.3") },
],
});
test(
@@ -1380,11 +1380,11 @@ test(
{
[Language.cpp]: [
{ packName: "a/b", version: undefined },
{ packName: "c/d", version: parse("1.2.3") },
{ packName: "c/d", version: clean("1.2.3") },
],
[Language.java]: [
{ packName: "d/e", version: undefined },
{ packName: "f/g", version: parse("1.2.3") },
{ packName: "f/g", version: clean("1.2.3") },
],
}
);

View File

@@ -133,7 +133,7 @@ export interface PackWithVersion {
/** qualified name of a package reference */
packName: string;
/** version of the package, or undefined, which means latest version */
version?: semver.SemVer;
version?: string;
}
/**
@@ -1072,14 +1072,14 @@ function toPackWithVersion(packStr, configFile: string): PackWithVersion {
throw new Error(getPacksStrInvalid(packStr, configFile));
}
const nameWithVersion = packStr.split("@");
let version: semver.SemVer | undefined;
let version: string | undefined;
if (
nameWithVersion.length > 2 ||
!PACK_IDENTIFIER_PATTERN.test(nameWithVersion[0])
) {
throw new Error(getPacksStrInvalid(packStr, configFile));
} else if (nameWithVersion.length === 2) {
version = semver.parse(nameWithVersion[1]) || undefined;
version = semver.clean(nameWithVersion[1]) || undefined;
if (!version) {
throw new Error(getPacksStrInvalid(packStr, configFile));
}