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

Commit

Permalink
Use TypeScriptVersion.latest instead of "next" (#279)
Browse files Browse the repository at this point in the history
* Convert latest TS version to "next" on DT

dtslint installs the latest version of typescript as "next" because
that's the npm name.

Probably a better fix is to install typescript@next into a directory
with the same name as the rest, stripping off the .0-dev.20200323 part.

* Just install typescript@next into 3.9 folder

This removes the need to change the name when testing dependencies. I'm
not sure yet about when testing the main package.

* Remove "next" from TsVersion type

Instead, just use TYpeScriptVersion.latest everywhere except when
installing from npm.

* Update TS and fix new compile error
  • Loading branch information
sandersn authored Mar 23, 2020
1 parent 02bf509 commit 1bd4ce5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
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

0 comments on commit 1bd4ce5

Please sign in to comment.