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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: microsoft/dtslint
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 285e5a9a168800e72382101b2e416baf129e8fc4
Choose a base ref
...
head repository: microsoft/dtslint
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9c555b9209246654d6f752da6565fd15bcc55672
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Sep 1, 2020

  1. update package-lock

    sandersn committed Sep 1, 2020
    Copy the full SHA
    0b61b96 View commit details
  2. Flip typesVersions (#306)

    * Flip typesVersions
    
    1. Update @DefinitelyTyped dependencies
    2. Simplify+invert runTests
    
    * account for Minimum TS version in ts* directories
    
    * ❤️ lint
    
    * maxVersion: narrow type to removed undefined from first param
    
    * go back to latest of @DefinitelyTyped packages
    sandersn authored Sep 1, 2020
    Copy the full SHA
    90a45fc View commit details
  3. 4.0.0 - flip order of typesVersions

    Order typesVersions old-to-new, not new-to-old. Also put newest version
    in the root, with older versions in ts* subdirectories.
    sandersn committed Sep 1, 2020
    Copy the full SHA
    9c555b9 View commit details
Showing with 89 additions and 60 deletions.
  1. +39 −17 package-lock.json
  2. +1 −1 package.json
  3. +47 −40 src/index.ts
  4. +2 −2 src/lint.ts
56 changes: 39 additions & 17 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dtslint",
"version": "3.7.0",
"version": "4.0.0",
"description": "Runs tests on TypeScript definition files",
"files": [
"bin",
87 changes: 47 additions & 40 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -2,13 +2,14 @@

import { parseTypeScriptVersionLine } from "@definitelytyped/header-parser";
import { AllTypeScriptVersion, TypeScriptVersion } from "@definitelytyped/typescript-versions";
import assert = require("assert");
import { readdir, readFile, stat } from "fs-extra";
import { basename, dirname, join as joinPaths, resolve } from "path";

import { cleanTypeScriptInstalls, installAllTypeScriptVersions, installTypeScriptNext } from "@definitelytyped/utils";
import { checkPackageJson, checkTsconfig } from "./checks";
import { checkTslintJson, lint, TsVersion } from "./lint";
import { assertDefined, last, mapDefinedAsync, withoutPrefix } from "./util";
import { mapDefinedAsync, withoutPrefix } from "./util";

async function main(): Promise<void> {
const args = process.argv.slice(2);
@@ -151,61 +152,67 @@ async function runTests(
await checkPackageJson(dirPath, typesVersions);
}

const minVersion = maxVersion(
getMinimumTypeScriptVersionFromComment(indexText),
TypeScriptVersion.lowest) as TypeScriptVersion;
if (onlyTestTsNext || tsLocal) {
const tsVersion = tsLocal ? "local" : TypeScriptVersion.latest;
if (typesVersions.length === 0) {
await testTypesVersion(dirPath, tsVersion, tsVersion, isOlderVersion, dt, indexText, expectOnly, tsLocal);
} else {
const latestTypesVersion = last(typesVersions);
const versionPath = joinPaths(dirPath, `ts${latestTypesVersion}`);
const versionIndexText = await readFile(joinPaths(versionPath, "index.d.ts"), "utf-8");
await testTypesVersion(
versionPath, tsVersion, tsVersion,
isOlderVersion, dt, versionIndexText, expectOnly, tsLocal, /*inTypesVersionDirectory*/ true);
}
await testTypesVersion(dirPath, tsVersion, tsVersion, isOlderVersion, dt, expectOnly, tsLocal, /*isLatest*/ true);
} else {
await testTypesVersion(dirPath, undefined, getTsVersion(0), isOlderVersion, dt, indexText, expectOnly, undefined);
for (let i = 0; i < typesVersions.length; i++) {
const version = typesVersions[i];
const versionPath = joinPaths(dirPath, `ts${version}`);
const versionIndexText = await readFile(joinPaths(versionPath, "index.d.ts"), "utf-8");
await testTypesVersion(
versionPath, version, getTsVersion(i + 1), isOlderVersion, dt, versionIndexText,
expectOnly, undefined, /*inTypesVersionDirectory*/ true);
}

function getTsVersion(i: number): TsVersion {
return i === typesVersions.length
? TypeScriptVersion.latest
: assertDefined(TypeScriptVersion.previous(typesVersions[i]));
// For example, typesVersions of [3.2, 3.5, 3.6] will have
// associated ts3.2, ts3.5, ts3.6 directories, for
// <=3.2, <=3.5, <=3.6 respectively; the root level is for 3.7 and above.
// so this code needs to generate ranges [lowest-3.2, 3.3-3.5, 3.6-3.6, 3.7-latest]
const lows = [TypeScriptVersion.lowest, ...typesVersions.map(next)];
const his = [...typesVersions, TypeScriptVersion.latest];
assert.strictEqual(lows.length, his.length);
for (let i = 0; i < lows.length; i++) {
const low = maxVersion(minVersion, lows[i]);
const hi = his[i];
assert(
parseFloat(hi) >= parseFloat(low),
`'// Minimum TypeScript Version: ${minVersion}' in header skips ts${hi} folder.`);
const isLatest = hi === TypeScriptVersion.latest;
const versionPath = isLatest ? dirPath : joinPaths(dirPath, `ts${hi}`);
if (lows.length > 1) {
console.log("testing from", low, "to", hi, "in", versionPath);
}
await testTypesVersion(versionPath, low, hi, isOlderVersion, dt, expectOnly, undefined, isLatest);
}
}
}

function maxVersion(v1: TypeScriptVersion | undefined, v2: TypeScriptVersion): TypeScriptVersion;
function maxVersion(v1: AllTypeScriptVersion | undefined, v2: AllTypeScriptVersion): AllTypeScriptVersion;
function maxVersion(v1: AllTypeScriptVersion | undefined, v2: AllTypeScriptVersion) {
if (!v1) return v2;
if (!v2) return v1;
if (parseFloat(v1) >= parseFloat(v2)) return v1;
return v2;
}

function next(v: TypeScriptVersion): TypeScriptVersion {
const index = TypeScriptVersion.supported.indexOf(v);
assert.notStrictEqual(index, -1);
assert(index < TypeScriptVersion.supported.length);
return TypeScriptVersion.supported[index + 1];
}

async function testTypesVersion(
dirPath: string,
lowVersion: TsVersion | undefined,
maxVersion: TsVersion,
lowVersion: TsVersion,
hiVersion: TsVersion,
isOlderVersion: boolean,
dt: boolean,
indexText: string,
expectOnly: boolean,
tsLocal: string | undefined,
inTypesVersionDirectory?: boolean,
isLatest: boolean,
): Promise<void> {
const minVersionFromComment = getTypeScriptVersionFromComment(indexText);
if (minVersionFromComment !== undefined && inTypesVersionDirectory) {
throw new Error(`Already in the \`ts${lowVersion}\` directory, don't need \`// Minimum TypeScript Version\`.`);
}
const minVersion = lowVersion
|| minVersionFromComment && TypeScriptVersion.isSupported(minVersionFromComment) && minVersionFromComment
|| TypeScriptVersion.lowest;

await checkTslintJson(dirPath, dt);
await checkTsconfig(dirPath, dt
? { relativeBaseUrl: ".." + (isOlderVersion ? "/.." : "") + (inTypesVersionDirectory ? "/.." : "") + "/" }
? { relativeBaseUrl: ".." + (isOlderVersion ? "/.." : "") + (isLatest ? "" : "/..") + "/" }
: undefined);
const err = await lint(dirPath, minVersion, maxVersion, !!inTypesVersionDirectory, expectOnly, tsLocal);
const err = await lint(dirPath, lowVersion, hiVersion, isLatest, expectOnly, tsLocal);
if (err) {
throw new Error(err);
}
@@ -237,7 +244,7 @@ function assertPathIsNotBanned(dirPath: string) {
}
}

function getTypeScriptVersionFromComment(text: string): AllTypeScriptVersion | undefined {
function getMinimumTypeScriptVersionFromComment(text: string): AllTypeScriptVersion | undefined {
const match = text.match(/\/\/ (?:Minimum )?TypeScript Version: /);
if (!match) {
return undefined;
4 changes: 2 additions & 2 deletions src/lint.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ export async function lint(
dirPath: string,
minVersion: TsVersion,
maxVersion: TsVersion,
inTypesVersionDirectory: boolean,
isLatest: boolean,
expectOnly: boolean,
tsLocal: string | undefined): Promise<string | undefined> {
const tsconfigPath = joinPaths(dirPath, "tsconfig.json");
@@ -49,7 +49,7 @@ export async function lint(
// External dependencies should have been handled by `testDependencies`;
// typesVersions should be handled in a separate lint
if (!isExternalDependency(file, dirPath, lintProgram) &&
(inTypesVersionDirectory || !isTypesVersionPath(fileName, dirPath))) {
(!isLatest || !isTypesVersionPath(fileName, dirPath))) {
linter.lint(fileName, text, config);
}
}