Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
typescript-bot committed Feb 8, 2024
1 parent 31de5d3 commit c51c367
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 23 deletions.
4 changes: 3 additions & 1 deletion packages/definitions-parser/src/get-affected-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 23 additions & 9 deletions packages/definitions-parser/src/git.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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[];
},
};
}

Expand All @@ -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<string, PackageId> = new Map();
const additions: Map<string, PackageId> = new Map();
let attwChanges: PackageId[] = [];
Expand All @@ -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`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 8 additions & 8 deletions packages/definitions-parser/test/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,22 @@ 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: [
{ typesDirectoryName: "lodash", version: "*" },
{ 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
});
Expand Down
15 changes: 11 additions & 4 deletions packages/dtslint/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function main(): Promise<void> {
if (lookingForTsLocal) {
throw new Error("Path for --localTs was not provided.");
}

const npmChecks = onlyNpmChecks ? "only" : expectOnly ? false : !skipNpmChecks;

if (shouldListen) {
Expand All @@ -109,22 +109,29 @@ async function main(): Promise<void> {
}

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");
}

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;
Expand Down

0 comments on commit c51c367

Please sign in to comment.