speed up verifying types deps by parallizing
Summary: read pacakge.json files asyncronosly to speed up script execution Reviewed By: LukeDefeo, passy Differential Revision: D49188676 fbshipit-source-id: 55c1eeb8f62c6b3760f2a037592807c7b00af01d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cd392929e0
commit
cb4446d76c
@@ -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]) => {
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user