Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Use TypeScriptVersion.latest instead of "next" #279

Merged
merged 4 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async function runTests(
}

if (onlyTestTsNext || tsLocal) {
const tsVersion = tsLocal ? "local" : "next";
const tsVersion = tsLocal ? "local" : TypeScriptVersion.latest;
if (typesVersions.length === 0) {
await testTypesVersion(dirPath, tsVersion, tsVersion, isOlderVersion, dt, indexText, expectOnly, tsLocal);
} else {
Expand All @@ -177,7 +177,7 @@ async function runTests(
}

function getTsVersion(i: number): TsVersion {
return i === typesVersions.length ? "next" : assertDefined(TypeScriptVersion.previous(typesVersions[i]));
return i === typesVersions.length ? TypeScriptVersion.latest : assertDefined(TypeScriptVersion.previous(typesVersions[i]));
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function installNext() {
await install("next");
}

async function install(version: TsVersion): Promise<void> {
async function install(version: TsVersion | "next"): Promise<void> {
if (version === "local") {
return;
}
Expand All @@ -47,8 +47,11 @@ export function typeScriptPath(version: TsVersion, tsLocal: string | undefined):
return path.join(installDir(version), "node_modules", "typescript");
}

function installDir(version: TsVersion): string {
function installDir(version: TsVersion | "next"): string {
assert(version !== "local");
if (version === "next") {
version = TypeScriptVersion.latest;
}
return path.join(installsDir, version);
}

Expand All @@ -69,7 +72,7 @@ async function execAndThrowErrors(cmd: string, cwd?: string): Promise<void> {
});
}

function packageJson(version: TsVersion): {} {
function packageJson(version: TsVersion | "next"): {} {
return {
description: `Installs typescript@${version}`,
repository: "N/A",
Expand Down
15 changes: 5 additions & 10 deletions src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,19 @@ async function getLintConfig(
}

function range(minVersion: TsVersion, maxVersion: TsVersion): ReadonlyArray<TsVersion> {
if (minVersion === "next") {
assert(maxVersion === "next");
return ["next"];
}
if (minVersion === "local") {
assert(maxVersion === "local");
return ["local"];
}
assert(maxVersion !== "local");

// The last item of TypeScriptVersion is the unreleased version of Typescript,
// which is called 'next' on npm, so replace it with 'next'.
const allReleased: TsVersion[] = [...TypeScriptVersion.supported];
allReleased[allReleased.length - 1] = "next";
const minIdx = allReleased.indexOf(minVersion);
const minIdx = TypeScriptVersion.supported.indexOf(minVersion);
assert(minIdx >= 0);
const maxIdx = allReleased.indexOf(maxVersion);
const maxIdx = TypeScriptVersion.supported.indexOf(maxVersion as TypeScriptVersion);
assert(maxIdx >= minIdx);
return allReleased.slice(minIdx, maxIdx + 1);
return TypeScriptVersion.supported.slice(minIdx, maxIdx + 1);
}

export type TsVersion = TypeScriptVersion | "next" | "local";
export type TsVersion = TypeScriptVersion | "local";
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function assertDefined<T>(a: T | undefined): T {
return a;
}

export async function mapDefinedAsync<T, U>(arr: Iterable<T>, mapper: (t: T) => Promise<U | undefined>): Promise<U[]> {
export async function mapDefinedAsync<T, U>(arr: Iterable<T>, mapper: (t: T) => Promise<U | undefined>): Promise<(awaited U)[]> {
const out = [];
for (const a of arr) {
const res = await mapper(a);
Expand Down