Skip to content

Commit

Permalink
Fetch npm info concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed May 10, 2022
1 parent e0032dd commit 5931bb1
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions packages/publisher/src/calculate-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { ChangedPackages, ChangedPackagesJson, ChangedTypingJson, versionsFilena
import { getDefinitelyTyped, AllPackages, NotNeededPackage, writeDataFile } from "@definitelytyped/definitions-parser";
import {
assertDefined,
mapDefinedAsync,
logUncaughtErrors,
loggerWithErrors,
FS,
LoggerWithErrors,
UncachedNpmInfoClient,
withNpmCache,
CachedNpmInfoClient,
nAtATime,
} from "@definitelytyped/utils";
import { fetchTypesPackageVersionInfo } from "@definitelytyped/retag";
import { cacheDirPath } from "./lib/settings";
Expand Down Expand Up @@ -66,35 +66,39 @@ async function computeChangedPackages(
client: CachedNpmInfoClient
): Promise<ChangedPackages> {
log.info("# Computing changed packages...");
const changedTypings = await mapDefinedAsync(allPackages.allTypings(), async (pkg) => {
const { version, needsPublish } = await fetchTypesPackageVersionInfo(pkg, client, /*publish*/ true, log);
if (needsPublish) {
log.info(`Need to publish: ${pkg.desc}@${version}`);
for (const { name } of pkg.packageJsonDependencies) {
const changedTypings = (
await nAtATime(10, allPackages.allTypings(), async (pkg) => {
const { version, needsPublish } = await fetchTypesPackageVersionInfo(pkg, client, /*publish*/ true, log);
if (needsPublish) {
log.info(`Need to publish: ${pkg.desc}@${version}`);
for (const { name } of pkg.packageJsonDependencies) {
assertDefined(
await client.fetchAndCacheNpmInfo(name),
`'${pkg.name}' depends on '${name}' which does not exist on npm. All dependencies must exist.`
);
}
const latestVersion = pkg.isLatest
? undefined
: (await fetchTypesPackageVersionInfo(allPackages.getLatest(pkg), client, /*publish*/ true)).version;
return { pkg, version, latestVersion };
}
return undefined;
})
).filter((value): value is NonNullable<typeof value> => value as never);
log.info("# Computing deprecated packages...");
const changedNotNeededPackages = (
await nAtATime(10, allPackages.allNotNeeded(), async (pkg) => {
if (!(await isAlreadyDeprecated(pkg, client, log))) {
assertDefined(
await client.fetchAndCacheNpmInfo(name),
`'${pkg.name}' depends on '${name}' which does not exist on npm. All dependencies must exist.`
await client.fetchAndCacheNpmInfo(pkg.libraryName),
`To deprecate '@types/${pkg.name}', '${pkg.libraryName}' must exist on npm.`
);
log.info(`To be deprecated: ${pkg.name}`);
return pkg;
}
const latestVersion = pkg.isLatest
? undefined
: (await fetchTypesPackageVersionInfo(allPackages.getLatest(pkg), client, /*publish*/ true)).version;
return { pkg, version, latestVersion };
}
return undefined;
});
log.info("# Computing deprecated packages...");
const changedNotNeededPackages = await mapDefinedAsync(allPackages.allNotNeeded(), async (pkg) => {
if (!(await isAlreadyDeprecated(pkg, client, log))) {
assertDefined(
await client.fetchAndCacheNpmInfo(pkg.libraryName),
`To deprecate '@types/${pkg.name}', '${pkg.libraryName}' must exist on npm.`
);
log.info(`To be deprecated: ${pkg.name}`);
return pkg;
}
return undefined;
});
return undefined;
})
).filter((value): value is NonNullable<typeof value> => value as never);
return { changedTypings, changedNotNeededPackages };
}

Expand Down

0 comments on commit 5931bb1

Please sign in to comment.