From c51c367b5c0838690808a262f2aea066a2ab36fa Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Thu, 8 Feb 2024 23:48:27 +0000 Subject: [PATCH] Format --- .../src/get-affected-packages.ts | 4 ++- packages/definitions-parser/src/git.ts | 32 +++++++++++++------ .../test/get-affected-packages.test.ts | 9 +++++- packages/definitions-parser/test/git.test.ts | 16 +++++----- packages/dtslint/src/index.ts | 15 ++++++--- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/packages/definitions-parser/src/get-affected-packages.ts b/packages/definitions-parser/src/get-affected-packages.ts index 38780d7388..701c66bc7a 100644 --- a/packages/definitions-parser/src/get-affected-packages.ts +++ b/packages/definitions-parser/src/get-affected-packages.ts @@ -89,7 +89,9 @@ export async function getAffectedPackagesWorker( ); const attwChanges = new Set( ( - await Promise.all(attwChangedPackages.map(async (id) => (await allPackages.tryGetTypingsData(id))?.subDirectoryPath)) + await Promise.all( + attwChangedPackages.map(async (id) => (await allPackages.tryGetTypingsData(id))?.subDirectoryPath), + ) ).filter((d): d is string => !!d && !packageNames.has(d) && !dependents.has(d)), ); return { diff --git a/packages/definitions-parser/src/git.ts b/packages/definitions-parser/src/git.ts index e703e22064..4fa5eaaaeb 100644 --- a/packages/definitions-parser/src/git.ts +++ b/packages/definitions-parser/src/git.ts @@ -1,4 +1,12 @@ -import { Logger, assertDefined, cacheDir, consoleLogger, execAndThrowErrors, joinPaths, symmetricDifference } from "@definitelytyped/utils"; +import { + Logger, + assertDefined, + cacheDir, + consoleLogger, + execAndThrowErrors, + joinPaths, + symmetricDifference, +} from "@definitelytyped/utils"; import * as pacote from "pacote"; import * as semver from "semver"; import { inspect } from "util"; @@ -55,8 +63,12 @@ export async function gitDiff(log: Logger, definitelyTypedPath: string, diffBase async function getAttwJson(definitelyTypedPath: string, diffBase: string) { return { - base: JSON.parse(await execAndThrowErrors("git", ["show", `${diffBase}:attw.json`], definitelyTypedPath)) as { failingPackages: string[] }, - head: JSON.parse(await readFile(joinPaths(definitelyTypedPath, "attw.json"), "utf8")) as { failingPackages: string[] }, + base: JSON.parse(await execAndThrowErrors("git", ["show", `${diffBase}:attw.json`], definitelyTypedPath)) as { + failingPackages: string[]; + }, + head: JSON.parse(await readFile(joinPaths(definitelyTypedPath, "attw.json"), "utf8")) as { + failingPackages: string[]; + }, }; } @@ -67,7 +79,7 @@ async function getAttwJson(definitelyTypedPath: string, diffBase: string) { export async function gitChanges( diffs: GitDiff[], getAttwJson: () => Promise<{ base: { failingPackages: string[] }; head: { failingPackages: string[] } }>, -): Promise<{ errors: string[]; } | { deletions: PackageId[]; additions: PackageId[]; attwChanges: PackageId[]; }> { +): Promise<{ errors: string[] } | { deletions: PackageId[]; additions: PackageId[]; attwChanges: PackageId[] }> { const deletions: Map = new Map(); const additions: Map = new Map(); let attwChanges: PackageId[] = []; @@ -76,11 +88,13 @@ export async function gitChanges( if (diff.file === "attw.json") { try { const { base, head } = await getAttwJson(); - attwChanges = Array.from(symmetricDifference(new Set(base.failingPackages), new Set(head.failingPackages))).map(p => { - const [typesDirectoryName, versionDirectory] = p.split("/", 2); - const version = parseVersionFromDirectoryName(versionDirectory) ?? "*"; - return { typesDirectoryName, version }; - }) + attwChanges = Array.from(symmetricDifference(new Set(base.failingPackages), new Set(head.failingPackages))).map( + (p) => { + const [typesDirectoryName, versionDirectory] = p.split("/", 2); + const version = parseVersionFromDirectoryName(versionDirectory) ?? "*"; + return { typesDirectoryName, version }; + }, + ); } catch { errors.push(`Error reading attw.json`); } diff --git a/packages/definitions-parser/test/get-affected-packages.test.ts b/packages/definitions-parser/test/get-affected-packages.test.ts index 631b27435c..61ce2fcca3 100644 --- a/packages/definitions-parser/test/get-affected-packages.test.ts +++ b/packages/definitions-parser/test/get-affected-packages.test.ts @@ -59,7 +59,14 @@ testo({ `/dt/types/has-older-test-dependency /dt/types/known`, ]; - const { packageNames } = await getAffectedPackagesWorker(allPackages, packageOutput, [], [], dependentOutput, "/dt"); + const { packageNames } = await getAffectedPackagesWorker( + allPackages, + packageOutput, + [], + [], + dependentOutput, + "/dt", + ); expect(packageNames).toEqual(new Set(["jquery"])); }, async newPackage() { diff --git a/packages/definitions-parser/test/git.test.ts b/packages/definitions-parser/test/git.test.ts index e624d86d75..881b29a6bc 100644 --- a/packages/definitions-parser/test/git.test.ts +++ b/packages/definitions-parser/test/git.test.ts @@ -128,12 +128,12 @@ testo({ ).toEqual([new NotNeededPackage("ember__object", "@ember/object", "1.0.0")]); }, async attwChanges() { - expect(await gitChanges([ - { status: "M", file: "attw.json" }, - ], createGetAttwJson( - ["lodash", "jquery/v1", "react"], - ["jquery/v2", "react", "new-package"] - ))).toEqual({ + expect( + await gitChanges( + [{ status: "M", file: "attw.json" }], + createGetAttwJson(["lodash", "jquery/v1", "react"], ["jquery/v2", "react", "new-package"]), + ), + ).toEqual({ additions: [], deletions: [], attwChanges: [ @@ -141,9 +141,9 @@ testo({ { typesDirectoryName: "jquery", version: { major: 1, minor: undefined } }, { typesDirectoryName: "jquery", version: { major: 2, minor: undefined } }, { typesDirectoryName: "new-package", version: "*" }, - ] + ], }); - } + }, // TODO: Test npm info (and with scoped names) // TODO: Test with dependents, etc etc }); diff --git a/packages/dtslint/src/index.ts b/packages/dtslint/src/index.ts index 76f8ffae3a..8b567890e8 100644 --- a/packages/dtslint/src/index.ts +++ b/packages/dtslint/src/index.ts @@ -94,7 +94,7 @@ async function main(): Promise { if (lookingForTsLocal) { throw new Error("Path for --localTs was not provided."); } - + const npmChecks = onlyNpmChecks ? "only" : expectOnly ? false : !skipNpmChecks; if (shouldListen) { @@ -109,14 +109,16 @@ async function main(): Promise { } function usage(): void { - console.error("Usage: dtslint [--version] [--onlyTestTsNext] [--expectOnly] [--localTs path] [--skipNpmChecks] [--onlyNpmChecks]"); + console.error( + "Usage: dtslint [--version] [--onlyTestTsNext] [--expectOnly] [--localTs path] [--skipNpmChecks] [--onlyNpmChecks]", + ); console.error("Args:"); console.error(" --version Print version and exit."); console.error(" --expectOnly Run only the ExpectType lint rule."); console.error(" --onlyTestTsNext Only run with `typescript@next`, not with the minimum version."); console.error(" --localTs path Run with *path* as the latest version of TS."); console.error(" --skipNpmChecks Don't query npm - skips name/version checks and @arethetypeswrong/cli."); - console.error(" --onlyNpmChecks Only run the npm checks (name/version checks and @arethetypeswrong/cli).") + console.error(" --onlyNpmChecks Only run the npm checks (name/version checks and @arethetypeswrong/cli)."); console.error(""); console.error("onlyTestTsNext and localTs are (1) mutually exclusive and (2) test a single version of TS"); } @@ -124,7 +126,12 @@ function usage(): void { function listen(dirPath: string, tsLocal: string | undefined): void { // Don't await this here to ensure that messages sent during installation aren't dropped. process.on("message", async (message: unknown) => { - const { path, onlyTestTsNext, expectOnly, npmChecks = true } = message as { + const { + path, + onlyTestTsNext, + expectOnly, + npmChecks = true, + } = message as { path: string; onlyTestTsNext: boolean; expectOnly?: boolean;