Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
typescript-bot committed Apr 21, 2022
1 parent a63b04e commit 8665394
Show file tree
Hide file tree
Showing 115 changed files with 722 additions and 734 deletions.
14 changes: 7 additions & 7 deletions packages/definitions-parser/src/check-parse-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Semver,
UncachedNpmInfoClient,
NpmInfoRawVersions,
NpmInfoVersion
NpmInfoVersion,
} from "@definitelytyped/utils";

export async function checkParseResults(
Expand Down Expand Up @@ -56,11 +56,11 @@ export 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...",
flavor: pkg => pkg.desc
flavor: (pkg) => pkg.desc,
}
: undefined
);
Expand All @@ -82,7 +82,7 @@ function checkTypeScriptVersions(allPackages: AllPackages): void {
export function checkPathMappings(allPackages: AllPackages): void {
for (const pkg of allPackages.allTypings()) {
const unusedPathMappings = new Set(
Object.keys(pkg.pathMappings).filter(m => m !== pkg.name && m !== pkg.unescapedName)
Object.keys(pkg.pathMappings).filter((m) => m !== pkg.name && m !== pkg.unescapedName)
);

// If A depends on B, and B has path mappings, A must have the same mappings.
Expand Down Expand Up @@ -110,7 +110,7 @@ export function checkPathMappings(allPackages: AllPackages): void {
throw new Error(`${pkg.desc} has unused path mappings for [${Array.from(unusedPathMappings).join(", ")}].
If these mappings are actually used, they could be missing in a dependency's tsconfig.json instead.
Check the path mappings for [${Array.from(allPackages.allDependencyTypings(pkg))
.map(d => d.name)
.map((d) => d.name)
.join(", ")}].`);
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ async function checkNpm(
`Typings already defined for ${name} (${libraryName}) as of ${firstTypedVersion.versionString} (our version: ${ourVersion})`
);
const contributorUrls = contributors
.map(c => {
.map((c) => {
const gh = "https://github.com/";
return c.url.startsWith(gh) ? `@${c.url.slice(gh.length)}` : `${c.name} (${c.url})`;
})
Expand Down Expand Up @@ -222,5 +222,5 @@ const notNeededExceptions: ReadonlySet<string> = new Set([
"raspi-serial",
"raspi-soft-pwm",
// Declare "typings" but don't actually have them yet (https://github.com/stampit-org/stampit/issues/245)
"stampit"
"stampit",
]);
12 changes: 6 additions & 6 deletions packages/definitions-parser/src/get-affected-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PackageId,
PackageBase,
getMangledNameForScopedPackage,
formatDependencyVersion
formatDependencyVersion,
} from "./packages";

export interface Affected {
Expand All @@ -16,26 +16,26 @@ export interface Affected {

/** Gets all packages that have changed on this branch, plus all packages affected by the change. */
export function getAffectedPackages(allPackages: AllPackages, changedPackageIds: PackageId[]): Affected {
const resolved = changedPackageIds.map(id => allPackages.tryResolve(id));
const resolved = changedPackageIds.map((id) => allPackages.tryResolve(id));
// If a package doesn't exist, that's because it was deleted.
const changed = mapDefined(resolved, id => allPackages.tryGetTypingsData(id));
const dependent = mapIterable(collectDependers(resolved, getReverseDependencies(allPackages, resolved)), p =>
const changed = mapDefined(resolved, (id) => allPackages.tryGetTypingsData(id));
const dependent = mapIterable(collectDependers(resolved, getReverseDependencies(allPackages, resolved)), (p) =>
allPackages.getTypingsData(p)
);
return { changedPackages: changed, dependentPackages: sortPackages(dependent), allPackages };
}

/** Every package name in the original list, plus their dependencies (incl. dependencies' dependencies). */
export function allDependencies(allPackages: AllPackages, packages: Iterable<TypingsData>): TypingsData[] {
return sortPackages(transitiveClosure(packages, pkg => allPackages.allDependencyTypings(pkg)));
return sortPackages(transitiveClosure(packages, (pkg) => allPackages.allDependencyTypings(pkg)));
}

/** Collect all packages that depend on changed packages, and all that depend on those, etc. */
function collectDependers(
changedPackages: PackageId[],
reverseDependencies: Map<PackageId, Set<PackageId>>
): Set<PackageId> {
const dependers = transitiveClosure(changedPackages, pkg => reverseDependencies.get(pkg) || []);
const dependers = transitiveClosure(changedPackages, (pkg) => reverseDependencies.get(pkg) || []);
// Don't include the original changed packages, just their dependers
for (const original of changedPackages) {
dependers.delete(original);
Expand Down
22 changes: 11 additions & 11 deletions packages/definitions-parser/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
formatDependencyVersion,
getDependencyFromFile,
AllPackages,
NotNeededPackage
NotNeededPackage,
} from "./packages";
import {
Logger,
Expand All @@ -19,7 +19,7 @@ import {
assertDefined,
Semver,
UncachedNpmInfoClient,
NpmInfo
NpmInfo,
} from "@definitelytyped/utils";
import { getAffectedPackages } from "./get-affected-packages";

Expand Down Expand Up @@ -54,7 +54,7 @@ export async function gitDiff(log: Logger, definitelyTypedPath: string): Promise
// We are probably already on master, so compare to the last commit.
diff = (await run(`git diff ${sourceBranch}~1 --name-status`)).trim();
}
return diff.split("\n").map(line => {
return diff.split("\n").map((line) => {
const [status, file] = line.split(/\s+/, 2);
return { status: status.trim(), file: file.trim() } as GitDiff;
});
Expand Down Expand Up @@ -95,7 +95,7 @@ export async function getAffectedPackagesFromDiff(
) {
const allPackages = await AllPackages.read(dt);
const diffs = await gitDiff(consoleLogger.info, definitelyTypedPath);
if (diffs.find(d => d.file === "notNeededPackages.json")) {
if (diffs.find((d) => d.file === "notNeededPackages.json")) {
const uncached = new UncachedNpmInfoClient();
for (const deleted of getNotNeededPackages(allPackages, diffs)) {
const source = await uncached.fetchNpmInfo(deleted.libraryName); // eg @babel/parser
Expand All @@ -110,19 +110,19 @@ export async function getAffectedPackagesFromDiff(
: selection === "affected"
? getAffectedPackages(allPackages, gitChanges(diffs))
: {
changedPackages: allPackages.allTypings().filter(t => selection.test(t.name)),
changedPackages: allPackages.allTypings().filter((t) => selection.test(t.name)),
dependentPackages: [],
allPackages
allPackages,
};

console.log(
`Testing ${affected.changedPackages.length} changed packages: ${affected.changedPackages
.map(t => t.desc)
.map((t) => t.desc)
.toString()}`
);
console.log(
`Testing ${affected.dependentPackages.length} dependent packages: ${affected.dependentPackages
.map(t => t.desc)
.map((t) => t.desc)
.toString()}`
);
return affected;
Expand Down Expand Up @@ -169,17 +169,17 @@ it is supposed to replace, ${latestTypings.versionString} of ${unneeded.fullNpmN
export function getNotNeededPackages(allPackages: AllPackages, diffs: GitDiff[]) {
const deletedPackages = new Set(
diffs
.filter(d => d.status === "D")
.filter((d) => d.status === "D")
.map(
d =>
(d) =>
assertDefined(
getDependencyFromFile(d.file),
`Unexpected file deleted: ${d.file}
When removing packages, you should only delete files that are a part of removed packages.`
).name
)
);
return mapDefined(deletedPackages, p => {
return mapDefined(deletedPackages, (p) => {
const hasTyping = allPackages.hasTypingFor({ name: p, version: "*" });
const notNeeded = allPackages.getNotNeededPackage(p);
if (hasTyping) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getTypingInfo } from "./definition-parser";
export const definitionParserWorkerFilename = __filename;

if (!module.parent) {
process.on("message", message => {
process.on("message", (message) => {
assert(process.argv.length === 3);
const typesPath = process.argv[2];
// tslint:disable-next-line no-async-without-await
Expand Down
53 changes: 28 additions & 25 deletions packages/definitions-parser/src/lib/definition-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PackageJsonDependency,
TypingsDataRaw,
TypingsVersionsRaw,
DirectoryParsedTypingVersion
DirectoryParsedTypingVersion,
} from "../packages";
import { getAllowedPackageJsonDependencies } from "./settings";
import {
Expand All @@ -26,7 +26,7 @@ import {
unmangleScopedPackage,
removeVersionFromPackageName,
hasVersionNumberInMapping,
mangleScopedPackage
mangleScopedPackage,
} from "@definitelytyped/utils";
import { TypeScriptVersion } from "@definitelytyped/typescript-versions";

Expand Down Expand Up @@ -58,7 +58,7 @@ export async function getTypingInfo(packageName: string, fs: FS): Promise<Typing
}
const [rootDirectoryLs, olderVersionDirectories] = split<string, OlderVersionDir>(
fs.readdir(),
fileOrDirectoryName => {
(fileOrDirectoryName) => {
const version = parseVersionFromDirectoryName(fileOrDirectoryName);
return version === undefined ? undefined : { directoryName: fileOrDirectoryName, version };
}
Expand All @@ -68,7 +68,7 @@ export async function getTypingInfo(packageName: string, fs: FS): Promise<Typing

const latestData: TypingsDataRaw = {
libraryVersionDirectoryName: undefined,
...(await combineDataForAllTypesVersions(packageName, rootDirectoryLs, fs, undefined))
...(await combineDataForAllTypesVersions(packageName, rootDirectoryLs, fs, undefined)),
};

const older = await Promise.all(
Expand All @@ -87,7 +87,7 @@ export async function getTypingInfo(packageName: string, fs: FS): Promise<Typing
const ls = fs.readdir(directoryName);
const data: TypingsDataRaw = {
libraryVersionDirectoryName: formatTypingVersion(directoryVersion),
...(await combineDataForAllTypesVersions(packageName, ls, fs.subDir(directoryName), directoryVersion))
...(await combineDataForAllTypesVersions(packageName, ls, fs.subDir(directoryName), directoryVersion)),
};

if (!matchesVersion(data, directoryVersion, considerLibraryMinorVersion)) {
Expand Down Expand Up @@ -122,8 +122,8 @@ interface LsMinusTypesVersionsAndPackageJson {
readonly hasPackageJson: boolean;
}
function getTypesVersionsAndPackageJson(ls: readonly string[]): LsMinusTypesVersionsAndPackageJson {
const withoutPackageJson = ls.filter(name => name !== packageJsonName);
const [remainingLs, typesVersions] = split(withoutPackageJson, fileOrDirectoryName => {
const withoutPackageJson = ls.filter((name) => name !== packageJsonName);
const [remainingLs, typesVersions] = split(withoutPackageJson, (fileOrDirectoryName) => {
const match = /^ts(\d+\.\d+)$/.exec(fileOrDirectoryName);
if (match === null) {
return undefined;
Expand Down Expand Up @@ -159,7 +159,7 @@ export function parseVersionFromDirectoryName(
}
return {
major: Number(match[1]),
minor: match[3] !== undefined ? Number(match[3]) : undefined // tslint:disable-line strict-type-predicates (false positive)
minor: match[3] !== undefined ? Number(match[3]) : undefined, // tslint:disable-line strict-type-predicates (false positive)
};
}

Expand All @@ -174,7 +174,7 @@ export function tryParsePackageVersion(versionString: string | undefined): Depen
}
return {
major: Number(match[1]),
minor: match[3] !== undefined ? Number(match[3]) : undefined // tslint:disable-line strict-type-predicates (false positive)
minor: match[3] !== undefined ? Number(match[3]) : undefined, // tslint:disable-line strict-type-predicates (false positive)
};
}

Expand Down Expand Up @@ -204,7 +204,7 @@ async function combineDataForAllTypesVersions(
libraryMinorVersion,
typeScriptVersion: minTsVersion,
libraryName,
projects
projects,
} = parseHeaderOrFail(readFileAndThrowOnBOM("index.d.ts", fs));

const dataForRoot = getTypingDataForSingleTypesVersion(
Expand All @@ -215,7 +215,7 @@ async function combineDataForAllTypesVersions(
fs,
directoryVersion
);
const dataForOtherTypesVersions = typesVersions.map(tsVersion => {
const dataForOtherTypesVersions = typesVersions.map((tsVersion) => {
const subFs = fs.subDir(`ts${tsVersion}`);
return getTypingDataForSingleTypesVersion(
tsVersion,
Expand All @@ -242,7 +242,7 @@ async function combineDataForAllTypesVersions(

const files = Array.from(
flatMap(allTypesVersions, ({ typescriptVersion, declFiles }) =>
declFiles.map(file => (typescriptVersion === undefined ? file : `ts${typescriptVersion}/${file}`))
declFiles.map((file) => (typescriptVersion === undefined ? file : `ts${typescriptVersion}/${file}`))
)
);

Expand All @@ -258,25 +258,25 @@ async function combineDataForAllTypesVersions(
typesVersions,
files,
license,
dependencies: Object.assign({}, ...allTypesVersions.map(v => v.dependencies)),
dependencies: Object.assign({}, ...allTypesVersions.map((v) => v.dependencies)),
testDependencies: getAllUniqueValues<"testDependencies", string>(allTypesVersions, "testDependencies"),
pathMappings: Object.assign({}, ...allTypesVersions.map(v => v.pathMappings)),
pathMappings: Object.assign({}, ...allTypesVersions.map((v) => v.pathMappings)),
packageJsonDependencies,
contentHash: hash(
hasPackageJson ? [...files, packageJsonName] : files,
mapDefined(allTypesVersions, a => a.tsconfigPathsForHash),
mapDefined(allTypesVersions, (a) => a.tsconfigPathsForHash),
fs
),
globals: getAllUniqueValues<"globals", string>(allTypesVersions, "globals"),
declaredModules: getAllUniqueValues<"declaredModules", string>(allTypesVersions, "declaredModules"),
imports: checkPackageJsonImports(packageJson.imports, packageJsonName),
exports: checkPackageJsonExportsAndAddPJsonEntry(packageJson.exports, packageJsonName),
type: checkPackageJsonType(packageJson.type, packageJsonName)
type: checkPackageJsonType(packageJson.type, packageJsonName),
};
}

function getAllUniqueValues<K extends string, T>(records: readonly Record<K, readonly T[]>[], key: K): readonly T[] {
return unique(flatMap(records, x => x[key]));
return unique(flatMap(records, (x) => x[key]));
}

interface TypingDataFromIndividualTypeScriptVersion {
Expand Down Expand Up @@ -332,19 +332,22 @@ function getTypingDataForSingleTypesVersion(
checkAllFilesUsed(ls, usedFiles, otherFiles, packageName, fs);
for (const untestedTypeFile of filter(
otherFiles,
name => name.endsWith(".d.ts") || name.endsWith(".d.mts") || name.endsWith(".d.cts")
(name) => name.endsWith(".d.ts") || name.endsWith(".d.mts") || name.endsWith(".d.cts")
)) {
// add d.ts files from OTHER_FILES.txt in order get their dependencies
// tslint:disable-next-line:non-literal-fs-path -- Not a reference to the fs package
types.set(untestedTypeFile, createSourceFile(untestedTypeFile, fs.readFile(untestedTypeFile)));
}

const { dependencies: dependenciesWithDeclaredModules, globals, declaredModules } = getModuleInfo(packageName, types);
const declaredRootModules = new Set(declaredModules.map(m => rootName(m, types, packageName)));
const declaredRootModules = new Set(declaredModules.map((m) => rootName(m, types, packageName)));
// Don't count an import of "x" as a dependency if we saw `declare module "x"` somewhere.
const dependenciesSet = new Set(filter(dependenciesWithDeclaredModules, m => !declaredRootModules.has(m)));
const dependenciesSet = new Set(filter(dependenciesWithDeclaredModules, (m) => !declaredRootModules.has(m)));
const testDependencies = Array.from(
filter(getTestDependencies(packageName, types, tests.keys(), dependenciesSet, fs), m => !declaredRootModules.has(m))
filter(
getTestDependencies(packageName, types, tests.keys(), dependenciesSet, fs),
(m) => !declaredRootModules.has(m)
)
);

const { paths } = tsconfig.compilerOptions;
Expand Down Expand Up @@ -373,7 +376,7 @@ function getTypingDataForSingleTypesVersion(
globals,
declaredModules,
declFiles: sort(types.keys()),
tsconfigPathsForHash
tsconfigPathsForHash,
};
}

Expand Down Expand Up @@ -494,7 +497,7 @@ Other d.ts files must either be referenced through index.d.ts, tests, or added t
}

function isRelativePath(path: string) {
return path.split(/\//).every(part => part.length > 0 && !part.match(/^\.+$|[\\\n\r]/));
return path.split(/\//).every((part) => part.length > 0 && !part.match(/^\.+$|[\\\n\r]/));
}

interface TsConfig {
Expand Down Expand Up @@ -633,7 +636,7 @@ const nodeBuiltins: ReadonlySet<string> = new Set([
"util",
"v8",
"vm",
"zlib"
"zlib",
]);

function parseDependencyVersionFromPath(
Expand All @@ -657,7 +660,7 @@ function withoutEnd(s: string, end: string): string | undefined {
}

function hash(files: readonly string[], tsconfigPathsForHash: readonly string[], fs: FS): string {
const fileContents = files.map(f => `${f}**${readFileAndThrowOnBOM(f, fs)}`);
const fileContents = files.map((f) => `${f}**${readFileAndThrowOnBOM(f, fs)}`);
let allContent = fileContents.join("||");
for (const path of tsconfigPathsForHash) {
allContent += path;
Expand Down
Loading

0 comments on commit 8665394

Please sign in to comment.