Pass releaseManifest to versionFinder

Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
Johan Haals
2022-01-21 14:17:50 +01:00
parent c2930c3b2c
commit 061393a964
4 changed files with 45 additions and 122 deletions
+4 -1
View File
@@ -344,7 +344,10 @@ export function registerCommands(program: CommanderStatic) {
.option(
'--release-line <main|next>',
'Bump to the latest version of a specific release line',
'main',
)
.option(
'--backstage-release <version>',
'Bump to a specific Backstage release',
)
.description('Bump Backstage packages to the latest versions')
.action(lazy(() => import('./versions/bump').then(m => m.default)));
+40 -6
View File
@@ -27,10 +27,16 @@ import {
mapDependencies,
fetchPackageInfo,
Lockfile,
YarnInfoInspectData,
} from '../../lib/versioning';
import { forbiddenDuplicatesFilter } from './lint';
import { BACKSTAGE_JSON } from '@backstage/cli-common';
import { runParallelWorkers } from '../../lib/parallel';
import {
getByReleaseLine,
getByVersion,
ReleaseManifest,
} from '@backstage/release-manifest';
const DEP_TYPES = [
'dependencies',
@@ -60,7 +66,22 @@ export default async (cmd: Command) => {
console.log(`Using custom pattern glob ${pattern}`);
}
const findTargetVersion = createVersionFinder(cmd.releaseLine);
if (cmd.releaseLine && cmd.backstageRelease) {
throw new Error(
'Cannot specify both --release-line and --backstage-release',
);
}
let releaseManifest;
if (cmd.backstageRelease) {
releaseManifest = await getByVersion({ version: cmd.backstageRelease });
} else if (cmd.releaseLine) {
releaseManifest = await getByReleaseLine({ releaseLine: cmd.releaseLine });
}
const findTargetVersion = createVersionFinder({
releaseLine: cmd.releaseLine,
releaseManifest,
});
// First we discover all Backstage dependencies within our own repo
const dependencyMap = await mapDependencies(paths.targetDir, pattern);
@@ -284,14 +305,22 @@ export default async (cmd: Command) => {
}
};
export function createVersionFinder(
releaseLine = 'latest',
packageInfoFetcher = fetchPackageInfo,
) {
export function createVersionFinder(options: {
releaseLine?: string;
packageInfoFetcher?: () => Promise<YarnInfoInspectData>;
releaseManifest?: ReleaseManifest;
}) {
const {
releaseLine = 'latest',
packageInfoFetcher = fetchPackageInfo,
releaseManifest,
} = options;
// The main release line is just an alias for latest
const distTag = releaseLine === 'main' ? 'latest' : releaseLine;
const found = new Map<string, string>();
const releasePackages = new Map(
releaseManifest?.packages.map(p => [p.name, p.version]),
);
return async function findTargetVersion(name: string) {
const existing = found.get(name);
if (existing) {
@@ -299,6 +328,11 @@ export function createVersionFinder(
}
console.log(`Checking for updates of ${name}`);
const manifestVersion = releasePackages.get(name);
if (manifestVersion) {
return manifestVersion;
}
const info = await packageInfoFetcher(name);
const latestVersion = info['dist-tags'].latest;
if (!latestVersion) {