Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch npm info concurrently
Browse files Browse the repository at this point in the history
jablko committed Jun 2, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 73170c0 commit 9fb23ec
Showing 1 changed file with 44 additions and 41 deletions.
85 changes: 44 additions & 41 deletions packages/publisher/src/calculate-versions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import { defaultLocalOptions } from "./lib/common";
import { ChangedPackages, ChangedPackagesJson, ChangedTypingJson, versionsFilename } from "./lib/versions";
import { getDefinitelyTyped, AllPackages, NotNeededPackage, writeDataFile } from "@definitelytyped/definitions-parser";
import {
mapDefinedAsync,
logUncaughtErrors,
loggerWithErrors,
FS,
LoggerWithErrors,
defaultCacheDir,
} from "@definitelytyped/utils";
import { logUncaughtErrors, loggerWithErrors, FS, LoggerWithErrors, defaultCacheDir } from "@definitelytyped/utils";
import { fetchTypesPackageVersionInfo } from "@definitelytyped/retag";
import * as pacote from "pacote";

@@ -41,40 +34,50 @@ async function computeAndSaveChangedPackages(

async function computeChangedPackages(allPackages: AllPackages, log: LoggerWithErrors): Promise<ChangedPackages> {
log.info("# Computing changed packages...");
const changedTypings = await mapDefinedAsync(allPackages.allTypings(), async (pkg) => {
const { version, needsPublish } = await fetchTypesPackageVersionInfo(pkg, /*publish*/ true, log);
if (needsPublish) {
log.info(`Need to publish: ${pkg.desc}@${version}`);
for (const { name } of pkg.packageJsonDependencies) {
await pacote.manifest(name, { cache: defaultCacheDir }).catch((reason) => {
throw reason.code === "E404"
? new Error(
`'${pkg.name}' depends on '${name}' which does not exist on npm. All dependencies must exist.`,
{ cause: reason }
)
: reason;
});
}
const latestVersion = pkg.isLatest
? undefined
: (await fetchTypesPackageVersionInfo(allPackages.getLatest(pkg), /*publish*/ true)).version;
return { pkg, version, latestVersion };
}
return undefined;
});
const changedTypings = (
await Promise.all(
allPackages.allTypings().map(async (pkg) => {
const { version, needsPublish } = await fetchTypesPackageVersionInfo(pkg, /*publish*/ true, log);
if (needsPublish) {
log.info(`Need to publish: ${pkg.desc}@${version}`);
for (const { name } of pkg.packageJsonDependencies) {
await pacote.manifest(name, { cache: defaultCacheDir }).catch((reason) => {
throw reason.code === "E404"
? new Error(
`'${pkg.name}' depends on '${name}' which does not exist on npm. All dependencies must exist.`,
{ cause: reason }
)
: reason;
});
}
const latestVersion = pkg.isLatest
? undefined
: (await fetchTypesPackageVersionInfo(allPackages.getLatest(pkg), /*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 mapDefinedAsync(allPackages.allNotNeeded(), async (pkg) => {
if (!(await isAlreadyDeprecated(pkg, log))) {
await pacote.manifest(pkg.libraryName, { cache: defaultCacheDir }).catch((reason) => {
throw reason.code === "E404"
? new Error(`To deprecate '@types/${pkg.name}', '${pkg.libraryName}' must exist on npm.`, { cause: reason })
: reason;
});
log.info(`To be deprecated: ${pkg.name}`);
return pkg;
}
return undefined;
});
const changedNotNeededPackages = (
await Promise.all(
allPackages.allNotNeeded().map(async (pkg) => {
if (!(await isAlreadyDeprecated(pkg, log))) {
await pacote.manifest(pkg.libraryName, { cache: defaultCacheDir }).catch((reason) => {
throw reason.code === "E404"
? new Error(`To deprecate '@types/${pkg.name}', '${pkg.libraryName}' must exist on npm.`, {
cause: reason,
})
: reason;
});
log.info(`To be deprecated: ${pkg.name}`);
return pkg;
}
return undefined;
})
)
).filter((value): value is NonNullable<typeof value> => value as never);
return { changedTypings, changedNotNeededPackages };
}

0 comments on commit 9fb23ec

Please sign in to comment.