Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @definitelytyped/dtslint-runner #6

Merged
merged 14 commits into from
May 4, 2020
Merged
5,287 changes: 461 additions & 4,826 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "definitelytyped-tools",
"private": true,
"scripts": {
"prepare": "lerna bootstrap",
"prepare": "lerna bootstrap --no-ci",
"pretest": "npm run build",
"lint": "eslint . --ext .ts",
"format": "prettier --write 'packages/**/*.ts'",
Expand All @@ -12,6 +12,7 @@
"devDependencies": {
"@types/jest": "^25.1.3",
"@types/node": "^12.12.29",
"@types/yargs": "^15.0.4",
"@typescript-eslint/eslint-plugin": "^2.22.0",
"@typescript-eslint/parser": "^2.22.0",
"eslint": "^6.8.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { defaultLocalOptions } from "./lib/common";
import {
getDefinitelyTyped,
AllPackages,
formatTypingVersion,
TypingsData,
TypingVersion,
ParseDefinitionsOptions
} from "@definitelytyped/definitions-parser";
import { ParseDefinitionsOptions } from "./get-definitely-typed";
import { TypingsData, AllPackages, TypingVersion, formatTypingVersion } from "./packages";
import {
assertDefined,
best,
logUncaughtErrors,
mapDefined,
nAtATime,
loggerWithErrors,
FS,
logger,
writeLog,
Expand All @@ -24,23 +15,22 @@ import {
NpmInfoVersion
} from "@definitelytyped/utils";

if (!module.parent) {
const log = loggerWithErrors()[0];
logUncaughtErrors(async () =>
checkParseResults(
true,
await getDefinitelyTyped(defaultLocalOptions, log),
defaultLocalOptions,
new UncachedNpmInfoClient()
)
);
}

export default async function checkParseResults(
includeNpmChecks: boolean,
export async function checkParseResults(
includeNpmChecks: false,
dt: FS,
options: ParseDefinitionsOptions
): Promise<void>;
export async function checkParseResults(
includeNpmChecks: true,
dt: FS,
options: ParseDefinitionsOptions,
client: UncachedNpmInfoClient
): Promise<void>;
export async function checkParseResults(
includeNpmChecks: boolean,
dt: FS,
options: ParseDefinitionsOptions,
client?: UncachedNpmInfoClient
): Promise<void> {
const allPackages = await AllPackages.read(dt);
const [log, logResult] = logger();
Expand All @@ -66,7 +56,7 @@ export default async function checkParseResults(
await nAtATime(
10,
allPackages.allTypings(),
pkg => checkNpm(pkg, log, dependedOn, client),
pkg => checkNpm(pkg, log, dependedOn, client!),
options.progress
? {
name: "Checking for typed packages...",
Expand Down
2 changes: 1 addition & 1 deletion packages/definitions-parser/src/get-definitely-typed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function getDefinitelyTyped(options: ParseDefinitionsOptions, log:
if (stdout) {
throw new Error(`'git diff' should be empty. Following files changed:\n${stdout}`);
}
log.info(`Using local Definitely Typed at ${options.definitelyTypedPath}.`);
log.info(`Using local DefinitelyTyped at ${options.definitelyTypedPath}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with this typography

return new DiskFS(`${options.definitelyTypedPath}/`);
}

Expand Down
1 change: 1 addition & 0 deletions packages/definitions-parser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./check-parse-results";
export * from "./clean";
export * from "./data-file";
export * from "./get-affected-packages";
Expand Down
2 changes: 1 addition & 1 deletion packages/definitions-parser/src/parse-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function parseDefinitions(
const typings: { [name: string]: TypingsVersionsRaw } = {};

const start = Date.now();
if (parallel) {
if (parallel && parallel.nProcesses > 1) {
log.info("Parsing in parallel...");
await runWithChildProcesses({
inputs: packageNames,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AllPackages, NotNeededPackage, TypesDataFile, getAffectedPackages } from "@definitelytyped/definitions-parser";
import { createTypingsVersionRaw, testo } from "../utils";
import { getAffectedPackages } from "../src/get-affected-packages";
import { NotNeededPackage, TypesDataFile, AllPackages } from "../src/packages";
import { testo, createTypingsVersionRaw } from "./utils";

const typesData: TypesDataFile = {
jquery: createTypingsVersionRaw("jquery", [], []),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import {
AllPackages,
NotNeededPackage,
TypesDataFile,
GitDiff,
getNotNeededPackages,
checkNotNeededPackage
} from "@definitelytyped/definitions-parser";
import { createTypingsVersionRaw, testo } from "../utils";
import { NpmInfo } from "@definitelytyped/utils";
import { createTypingsVersionRaw, testo } from "./utils";
import { GitDiff, getNotNeededPackages, checkNotNeededPackage } from "../src/git";
import { NotNeededPackage, TypesDataFile, AllPackages } from "../src/packages";

const typesData: TypesDataFile = {
jquery: createTypingsVersionRaw("jquery", [], []),
Expand Down
30 changes: 30 additions & 0 deletions packages/definitions-parser/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
import { TypingsVersionsRaw, License, PackageId } from "../src/packages";

export function testo(o: { [s: string]: () => void }) {
for (const k of Object.keys(o)) {
test(k, o[k], 100_000);
}
}

export function createTypingsVersionRaw(
name: string,
dependencies: PackageId[],
testDependencies: string[]
): TypingsVersionsRaw {
return {
"1.0.0": {
libraryName: name,
typingsPackageName: name,
dependencies,
testDependencies,
files: ["index.d.ts"],
libraryMajorVersion: 1,
libraryMinorVersion: 0,
pathMappings: [],
contributors: [{ name: "Bender", url: "futurama.com", githubUsername: "bender" }],
minTsVersion: "2.3",
typesVersions: [],
license: License.MIT,
packageJsonDependencies: [],
contentHash: "11111111111111",
projectName: "zombo.com",
globals: [],
declaredModules: []
}
};
}
7 changes: 7 additions & 0 deletions packages/dtslint-runner/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
src
test
logs
.DS_Store
.vscode
*.tsbuildinfo
tsconfig.json
3 changes: 3 additions & 0 deletions packages/dtslint-runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @definitelytyped/dtslint-runner

A unification of [dtslint-runner](https://github.com/DefinitelyTyped/dtslint-runner) and [the CI part of types-publisher](https://github.com/microsoft/types-publisher/blob/master/src/tester/test-runner.ts).
4 changes: 4 additions & 0 deletions packages/dtslint-runner/expectedFailures.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
electron-localshortcut
electron-prompt
electron-window-state
electron-spellchecker
34 changes: 34 additions & 0 deletions packages/dtslint-runner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@definitelytyped/dtslint-runner",
"version": "0.0.30-next.1",
"description": "Run dtslint on DefinitelyTyped packages",
"homepage": "https://github.com/microsoft/DefinitelyTyped-tools#readme",
"license": "MIT",
"main": "dist/index.js",
"bin": "dist/index.js",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/microsoft/DefinitelyTyped-tools.git"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
},
"bugs": {
"url": "https://github.com/microsoft/DefinitelyTyped-tools/issues"
},
"dependencies": {
"@definitelytyped/definitions-parser": "0.0.30-next.1",
"@definitelytyped/utils": "0.0.30-next.0",
"dtslint": "^3.4.1",
"fs-extra": "^9.0.0",
"stats-lite": "^2.2.0",
"yargs": "^15.3.1"
},
"devDependencies": {
"@types/fs-extra": "^8.1.0",
"@types/stats-lite": "^2.2.0"
}
}
101 changes: 101 additions & 0 deletions packages/dtslint-runner/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import os from "os";
import yargs from "yargs";
import { RunDTSLintOptions } from "./types";
import { runDTSLint } from "./main";
import { assertDefined, logUncaughtErrors } from "@definitelytyped/utils";

export { runDTSLint, RunDTSLintOptions };

if (!module.parent) {
const args = yargs
.options({
clone: {
group: "DefinitelyTyped acquisition",
description: "Clone DefinitelyTyped before running. Can be used as a boolean flag or set to the SHA to clone.",
conflicts: "path"
},
path: {
group: "DefinitelyTyped acquisition",
description: "Path to local DefinitelyTyped clone.",
conflicts: "clone",
type: "string",
default: "../DefinitelyTyped"
},
selection: {
group: "Package selection",
description: "Which packages to test.",
type: "string",
choices: ["all", "affected"],
default: "affected"
},
nProcesses: {
group: "Parallelism",
description: "How many processes to distribute parallelizable tasks over.",
type: "number",
default: os.cpus().length
},
shardId: {
group: "Parallelism",
description: "The machine index when sharding a run over multiple machines.",
type: "number",
implies: "shardCount"
},
shardCount: {
group: "Parallelism",
description: "The total number of machines when sharding a run over multiple machines.",
type: "number",
implies: "shardId"
},
localTypeScriptPath: {
group: "dtslint options",
description:
"Path to local TypeScript installation to be used by dtslint instead of all supported TypeScript versions.",
type: "string",
conflicts: "onlyTestTsNext"
},
onlyTestTsNext: {
group: "dtslint options",
description: "Run dtslint only with typescript@next instead of all supported TypeScript versions.",
type: "boolean",
conflicts: "localTypeScriptPath",
default: false
},
expectOnly: {
group: "dtslint options",
description: "Run only the ExpectType lint rule.",
type: "boolean",
default: false
},
// Not sure why you’d use this, so I’m hiding it
noInstall: {
hidden: true,
type: "boolean",
default: false
}
})
.wrap(Math.min(yargs.terminalWidth(), 120)).argv;

const options: RunDTSLintOptions = {
definitelyTypedAcquisition: args.clone
? {
kind: "clone",
sha: typeof args.clone === "string" ? args.clone : undefined
}
: {
kind: "local",
path: args.path
},
onlyRunAffectedPackages: args.selection === "affected",
nProcesses: args.nProcesses,
shard: args.shardCount ? { id: assertDefined(args.shardId), count: args.shardCount } : undefined,
localTypeScriptPath: args.localTypeScriptPath,
onlyTestTsNext: args.onlyTestTsNext,
expectOnly: args.expectOnly,
noInstall: args.noInstall
};

logUncaughtErrors(async () => {
const failures = await runDTSLint(options);
process.exit(failures);
});
}
Loading