diff --git a/src/__tests__/fetchMetals.test.ts b/src/__tests__/fetchMetals.test.ts new file mode 100644 index 0000000..6838e16 --- /dev/null +++ b/src/__tests__/fetchMetals.test.ts @@ -0,0 +1,32 @@ +import { calcServerDependency } from "../fetchMetals"; + +describe("fetchMetals", () => { + describe("calcServerDependency", () => { + function expectedDep(binaryVersion: string, serverVersion: string): string { + return `org.scalameta:metals_${binaryVersion}:${serverVersion}`; + } + it("should download from appropriate binaryVersion", () => { + expect(calcServerDependency("0.11.1")).toBe( + expectedDep("2.12", "0.11.1") + ); + expect(calcServerDependency("0.11.2")).toBe( + expectedDep("2.12", "0.11.2") + ); + expect(calcServerDependency("0.11.2-SNAPSHOT")).toBe( + expectedDep("2.12", "0.11.2-SNAPSHOT") + ); + expect(calcServerDependency("0.11.2-RC1")).toBe( + expectedDep("2.12", "0.11.2-RC1") + ); + expect(calcServerDependency("0.11.3")).toBe( + expectedDep("2.13", "0.11.3") + ); + expect(calcServerDependency("0.11.3-SNAPSHOT")).toBe( + expectedDep("2.13", "0.11.3-SNAPSHOT") + ); + expect(calcServerDependency("0.11.3-RC1")).toBe( + expectedDep("2.13", "0.11.3-RC1") + ); + }); + }); +}); diff --git a/src/fetchMetals.ts b/src/fetchMetals.ts index 193ec87..d0620fa 100644 --- a/src/fetchMetals.ts +++ b/src/fetchMetals.ts @@ -1,3 +1,4 @@ +import * as semver from "semver"; import { ChildProcessPromise, spawn } from "promisify-child-process"; import { JavaConfig } from "./getJavaConfig"; @@ -16,10 +17,7 @@ export function fetchMetals({ (p) => !p.startsWith("-agentlib") ); - const serverDependency = serverVersion.includes(":") - ? serverVersion - : `org.scalameta:metals_2.12:${serverVersion}`; - + const serverDependency = calcServerDependency(serverVersion); return spawn( javaPath, [ @@ -54,3 +52,10 @@ export function fetchMetals({ } ); } + +export function calcServerDependency(serverVersion: string): string { + const binaryVersion = semver.gt(serverVersion, "0.11.2") ? "2.13" : "2.12"; + return serverVersion.includes(":") + ? serverVersion + : `org.scalameta:metals_${binaryVersion}:${serverVersion}`; +}