Skip to content

Commit

Permalink
speed up verifying types deps by parallizing
Browse files Browse the repository at this point in the history
Summary: read pacakge.json files asyncronosly to speed up script execution

Reviewed By: LukeDefeo, passy

Differential Revision: D49188676

fbshipit-source-id: 55c1eeb8f62c6b3760f2a037592807c7b00af01d
  • Loading branch information
antonk52 authored and facebook-github-bot committed Sep 12, 2023
1 parent cd39292 commit cb4446d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions desktop/scripts/verify-types-dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,22 @@ type PackageJsonResult = {
unmatchedTypesPackages: UnmatchedLibType[];
};

function validatePackageJson(filepath: string): PackageJsonResult {
function isValidTypesPackageName(x: [name: string, version: string]): boolean {
return x[0].startsWith('@types/') && !IGNORED_TYPES.has(x[0]);
}

async function validatePackageJson(
filepath: string,
): Promise<PackageJsonResult> {
try {
const json = JSON.parse(fs.readFileSync(filepath).toString());
const jsonBuf = await fs.promises.readFile(filepath);
const json = JSON.parse(jsonBuf.toString());
const deps: Record<string, string> = json.dependencies || {};
const devDeps: Record<string, string> = json.devDependencies || {};
const typesPackages: Array<[string, string]> = [
...Object.entries(deps).filter(([k, v]) => k.startsWith('@types/')),
...Object.entries(devDeps).filter(([k, v]) => k.startsWith('@types/')),
].filter((x) => !IGNORED_TYPES.has(x[0]));
...Object.entries(deps).filter(isValidTypesPackageName),
...Object.entries(devDeps).filter(isValidTypesPackageName),
];

const unmatchedTypesPackages: UnmatchedLibType[] = typesPackages
.map(([rawName, rawVersion]) => {
Expand Down Expand Up @@ -106,9 +113,9 @@ async function main() {

const packageJsons = out.toString().trim().split('\n');

const unmatched = packageJsons
.map(validatePackageJson)
.filter((x) => x.unmatchedTypesPackages.length > 0);
const unmatched = await Promise.all(
packageJsons.map(validatePackageJson),
).then((x) => x.filter((x) => x.unmatchedTypesPackages.length > 0));

if (unmatched.length === 0) {
console.log('No issues found');
Expand Down

0 comments on commit cb4446d

Please sign in to comment.