Skip to content

Commit

Permalink
Update to 4.0, deprecate 2.8 (#287)
Browse files Browse the repository at this point in the history
* Update to 4.0, deprecate 2.8

Also switch from definitelytyped-header-parser to
@definitelytyped/header-parser,
@definitelytyped/typescript-versions,
@definitelytyped/utils.

This brings a couple of updates, principally a new way of tracking which
TS versions have shipped under the "latest" tag vs shipped under the
"next" tag. dtslint tests *only* versions that have shipped under
"latest", plus whatever is *currently* shipping under "next". It doesn't
test any betas or RCs.

Note that the new dependencies are currently closed source. We're
waiting on the MS open source legal office to OK the new repos.

* make range handle latest correctly

* reindent tsconfig
  • Loading branch information
sandersn committed Nov 29, 2021
1 parent 7f25731 commit f9c442f
Show file tree
Hide file tree
Showing 10 changed files with 879 additions and 129 deletions.
835 changes: 832 additions & 3 deletions packages/dtslint/package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/dtslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"prepublishOnly": "npm run build && npm run test && npm run lint"
},
"dependencies": {
"definitelytyped-header-parser": "3.9.0",
"@definitelytyped/header-parser": "0.0.29",
"@definitelytyped/typescript-versions": "0.0.29",
"@definitelytyped/utils": "0.0.29",
"dts-critic": "^3.0.2",
"fs-extra": "^6.0.1",
"json-stable-stringify": "^1.0.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/dtslint/src/checks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert = require("assert");
import { makeTypesVersionsForPackageJson, TypeScriptVersion } from "definitelytyped-header-parser";
import { makeTypesVersionsForPackageJson } from "@definitelytyped/header-parser";
import { TypeScriptVersion } from "@definitelytyped/typescript-versions";
import { pathExists } from "fs-extra";
import { join as joinPaths } from "path";

Expand Down
22 changes: 9 additions & 13 deletions packages/dtslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!/usr/bin/env node

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

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

Expand All @@ -36,8 +32,8 @@ async function main(): Promise<void> {
case "--installAll":
console.log("Cleaning old installs and installing for all TypeScript versions...");
console.log("Working...");
await cleanInstalls();
await installAll();
await cleanTypeScriptInstalls();
await installAllTypeScriptVersions();
return;
case "--localTs":
lookingForTsLocal = true;
Expand Down Expand Up @@ -79,14 +75,14 @@ async function main(): Promise<void> {
listen(dirPath, tsLocal);
// Do this *after* to ensure messages sent during installation aren't dropped.
if (!tsLocal) {
await installAll();
await installAllTypeScriptVersions();
}
} else {
if (!tsLocal) {
if (onlyTestTsNext) {
await installNext();
await installTypeScriptNext();
} else {
await installAll();
await installAllTypeScriptVersions();
}
}
await runTests(dirPath, onlyTestTsNext, expectOnly, tsLocal);
Expand Down Expand Up @@ -140,7 +136,7 @@ async function runTests(
const version = withoutPrefix(name, "ts");
if (version === undefined || !(await stat(joinPaths(dirPath, name))).isDirectory()) { return undefined; }

if (!isTypeScriptVersion(version)) {
if (!TypeScriptVersion.isTypeScriptVersion(version)) {
throw new Error(`There is an entry named ${name}, but ${version} is not a valid TypeScript version.`);
}
if (!TypeScriptVersion.isRedirectable(version)) {
Expand Down
84 changes: 0 additions & 84 deletions packages/dtslint/src/installer.ts

This file was deleted.

19 changes: 12 additions & 7 deletions packages/dtslint/src/lint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert = require("assert");
import { TypeScriptVersion } from "definitelytyped-header-parser";
import { TypeScriptVersion } from "@definitelytyped/typescript-versions";
import { typeScriptPath } from "@definitelytyped/utils";
import { pathExists } from "fs-extra";
import { join as joinPaths, normalize } from "path";
import { Configuration, ILinterOptions, Linter } from "tslint";
Expand All @@ -9,7 +10,6 @@ type IConfigurationFile = Configuration.IConfigurationFile;

import { getProgram, Options as ExpectOptions } from "./rules/expectRule";

import { typeScriptPath } from "./installer";
import { readJson, withoutPrefix } from "./util";

export async function lint(
Expand Down Expand Up @@ -186,15 +186,20 @@ function range(minVersion: TsVersion, maxVersion: TsVersion): ReadonlyArray<TsVe
assert(maxVersion === "local");
return ["local"];
}
if (minVersion === TypeScriptVersion.latest) {
assert(maxVersion === TypeScriptVersion.latest);
return [TypeScriptVersion.latest];
}
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 minIdx = TypeScriptVersion.supported.indexOf(minVersion);
const minIdx = TypeScriptVersion.shipped.indexOf(minVersion);
assert(minIdx >= 0);
const maxIdx = TypeScriptVersion.supported.indexOf(maxVersion as TypeScriptVersion);
if (maxVersion === TypeScriptVersion.latest) {
return [...TypeScriptVersion.shipped.slice(minIdx), TypeScriptVersion.latest];
}
const maxIdx = TypeScriptVersion.shipped.indexOf(maxVersion as TypeScriptVersion);
assert(maxIdx >= minIdx);
return TypeScriptVersion.supported.slice(minIdx, maxIdx + 1);
return TypeScriptVersion.shipped.slice(minIdx, maxIdx + 1);
}

export type TsVersion = TypeScriptVersion | "local";
2 changes: 1 addition & 1 deletion packages/dtslint/src/rules/dtHeaderRule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderExpected, validate } from "definitelytyped-header-parser";
import { renderExpected, validate } from "@definitelytyped/header-parser";
import * as Lint from "tslint";
import * as ts from "typescript";
import { failure, isMainFile } from "../util";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Type definitions for dt-header 1.0
// Project: https://github.com/bobby-headers/dt-header
// Definitions by: Jane Doe <https://github.com/jane doe>
~ [Error parsing header. Expected: /\<https\:\/\/github\.com\/([a-zA-Z\d\-]+)\>/. See: https://github.com/Microsoft/dtslint/blob/master/docs/dt-header.md]
~ [Error parsing header. Expected: /\<https\:\/\/github\.com\/([a-zA-Z\d\-]+)\/?\>/. See: https://github.com/Microsoft/dtslint/blob/master/docs/dt-header.md]
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Type definitions for dt-header 1.0
// Project: https://github.com/bobby-headers/dt-header
// Definitions by: Jane Doe <https://github.org/janedoe>
~ [Error parsing header. Expected: /\<https\:\/\/github\.com\/([a-zA-Z\d\-]+)\>/. See: https://github.com/Microsoft/dtslint/blob/master/docs/dt-header.md]
~ [Error parsing header. Expected: /\<https\:\/\/github\.com\/([a-zA-Z\d\-]+)\/?\>/. See: https://github.com/Microsoft/dtslint/blob/master/docs/dt-header.md]
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
35 changes: 18 additions & 17 deletions packages/dtslint/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es2017"],
"outDir": "bin",
"sourceMap": true,
"newLine": "lf",
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es2017"],
"outDir": "bin",
"sourceMap": true,
"newLine": "lf",

"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true
},
"include": ["src"]
}
"noFallthroughCasesInSwitch": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"esModuleInterop": true
},
"include": ["src"]
}

0 comments on commit f9c442f

Please sign in to comment.