Review comments - swap prefix to pattern
Signed-off-by: Zackery Griesinger <zack.griesinger@c2fo.com>
This commit is contained in:
committed by
Zack Griesinger
parent
bec82b0b2f
commit
b471662e8a
@@ -1,5 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': minor
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Add --prefix option to override matching glob patterns for backstage versioning
|
||||
|
||||
@@ -22,11 +22,11 @@ yarn backstage-cli versions:bump
|
||||
The reason for bumping all `@backstage` packages at once is to maintain the
|
||||
dependencies that they have between each other.
|
||||
|
||||
If you are using other plugins you can pass in the `--prefix` option to update
|
||||
If you are using other plugins you can pass in the `--pattern` option to update
|
||||
more than just the `@backstage/*` dependencies.
|
||||
|
||||
```bash
|
||||
yarn backstage-cli versions:bump --prefix '@{backstage,roadiehq}/*'
|
||||
yarn backstage-cli versions:bump --pattern '@{backstage,roadiehq}/*'
|
||||
```
|
||||
|
||||
## Following create-app template changes
|
||||
|
||||
@@ -594,7 +594,7 @@ Usage: backstage-cli versions:bump [options]
|
||||
|
||||
Options:
|
||||
-h, --help display help for command
|
||||
-p, --prefix Override glob for matching packages to upgrade
|
||||
-p, --pattern Override glob for matching packages to upgrade
|
||||
```
|
||||
|
||||
## versions:check
|
||||
|
||||
@@ -214,7 +214,10 @@ export function registerCommands(program: CommanderStatic) {
|
||||
|
||||
program
|
||||
.command('versions:bump')
|
||||
.option('--prefix <glob>', 'Override glob for matching packages to upgrade')
|
||||
.option(
|
||||
'--pattern <glob>',
|
||||
'Override glob for matching packages to upgrade',
|
||||
)
|
||||
.description('Bump Backstage packages to the latest versions')
|
||||
.action(lazy(() => import('./versions/bump').then(m => m.default)));
|
||||
|
||||
|
||||
@@ -126,10 +126,10 @@ describe('bump', () => {
|
||||
jest.spyOn(runObj, 'run').mockResolvedValue(undefined);
|
||||
|
||||
const { log: logs } = await withLogCollector(['log'], async () => {
|
||||
await bump({ prefix: null } as Command);
|
||||
await bump({ pattern: null } as Command);
|
||||
});
|
||||
expect(logs.filter(Boolean)).toEqual([
|
||||
'Using default prefix glob @backstage/*',
|
||||
'Using default pattern glob @backstage/*',
|
||||
'Checking for updates of @backstage/theme',
|
||||
'Checking for updates of @backstage/core',
|
||||
'Checking for updates of @backstage/core-api',
|
||||
@@ -182,7 +182,7 @@ describe('bump', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should bump backstage dependencies and dependencies matching prefix glob', async () => {
|
||||
it('should bump backstage dependencies and dependencies matching pattern glob', async () => {
|
||||
// Make sure all modules involved in package discovery are in the module cache before we mock fs
|
||||
await mapDependencies(paths.targetDir, '@backstage/*');
|
||||
const customLockfileMock = `${lockfileMock}
|
||||
@@ -252,10 +252,10 @@ describe('bump', () => {
|
||||
jest.spyOn(runObj, 'run').mockResolvedValue(undefined);
|
||||
|
||||
const { log: logs } = await withLogCollector(['log'], async () => {
|
||||
await bump({ prefix: '@{backstage,backstage-extra}/*' } as any);
|
||||
await bump({ pattern: '@{backstage,backstage-extra}/*' } as any);
|
||||
});
|
||||
expect(logs.filter(Boolean)).toEqual([
|
||||
'Using custom prefix glob @{backstage,backstage-extra}/*',
|
||||
'Using custom pattern glob @{backstage,backstage-extra}/*',
|
||||
'Checking for updates of @backstage/theme',
|
||||
'Checking for updates of @backstage-extra/custom-two',
|
||||
'Checking for updates of @backstage-extra/custom',
|
||||
@@ -349,10 +349,10 @@ describe('bump', () => {
|
||||
jest.spyOn(runObj, 'run').mockResolvedValue(undefined);
|
||||
|
||||
const { log: logs } = await withLogCollector(['log'], async () => {
|
||||
await bump({ prefix: null } as any);
|
||||
await bump({ pattern: null } as any);
|
||||
});
|
||||
expect(logs.filter(Boolean)).toEqual([
|
||||
'Using default prefix glob @backstage/*',
|
||||
'Using default pattern glob @backstage/*',
|
||||
'Checking for updates of @backstage/theme',
|
||||
'Checking for updates of @backstage/core',
|
||||
'Package info not found, ignoring package @backstage/theme',
|
||||
|
||||
@@ -38,7 +38,7 @@ const DEP_TYPES = [
|
||||
'optionalDependencies',
|
||||
];
|
||||
|
||||
const DEFAULT_PREFIX_GLOB = '@backstage/*';
|
||||
const DEFAULT_PATTERN_GLOB = '@backstage/*';
|
||||
|
||||
type PkgVersionInfo = {
|
||||
range: string;
|
||||
@@ -50,19 +50,19 @@ type PkgVersionInfo = {
|
||||
export default async (cmd: Command) => {
|
||||
const lockfilePath = paths.resolveTargetRoot('yarn.lock');
|
||||
const lockfile = await Lockfile.load(lockfilePath);
|
||||
let prefix = cmd.prefix;
|
||||
let pattern = cmd.pattern;
|
||||
|
||||
if (!prefix) {
|
||||
console.log(`Using default prefix glob ${DEFAULT_PREFIX_GLOB}`);
|
||||
prefix = DEFAULT_PREFIX_GLOB;
|
||||
if (!pattern) {
|
||||
console.log(`Using default pattern glob ${DEFAULT_PATTERN_GLOB}`);
|
||||
pattern = DEFAULT_PATTERN_GLOB;
|
||||
} else {
|
||||
console.log(`Using custom prefix glob ${prefix}`);
|
||||
console.log(`Using custom pattern glob ${pattern}`);
|
||||
}
|
||||
|
||||
const findTargetVersion = createVersionFinder();
|
||||
|
||||
// First we discover all Backstage dependencies within our own repo
|
||||
const dependencyMap = await mapDependencies(paths.targetDir, prefix);
|
||||
const dependencyMap = await mapDependencies(paths.targetDir, pattern);
|
||||
|
||||
// Next check with the package registry to see which dependency ranges we need to bump
|
||||
const versionBumps = new Map<string, PkgVersionInfo[]>();
|
||||
@@ -100,7 +100,7 @@ export default async (cmd: Command) => {
|
||||
}
|
||||
});
|
||||
|
||||
const filter = (name: string) => minimatch(name, prefix);
|
||||
const filter = (name: string) => minimatch(name, pattern);
|
||||
|
||||
// Check for updates of transitive backstage dependencies
|
||||
await workerThreads(16, lockfile.keys(), async name => {
|
||||
|
||||
@@ -64,7 +64,7 @@ export async function fetchPackageInfo(
|
||||
/** Map all dependencies in the repo as dependency => dependents */
|
||||
export async function mapDependencies(
|
||||
targetDir: string,
|
||||
prefixGlob: string,
|
||||
pattern: string,
|
||||
): Promise<Map<string, PkgVersionInfo[]>> {
|
||||
const { Project } = require('@lerna/project');
|
||||
const project = new Project(targetDir);
|
||||
@@ -77,7 +77,7 @@ export async function mapDependencies(
|
||||
);
|
||||
|
||||
for (const [name, range] of deps) {
|
||||
if (minimatch(name, prefixGlob)) {
|
||||
if (minimatch(name, pattern)) {
|
||||
dependencyMap.set(
|
||||
name,
|
||||
(dependencyMap.get(name) ?? []).concat({
|
||||
|
||||
@@ -7840,6 +7840,11 @@
|
||||
resolved "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
|
||||
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==
|
||||
|
||||
"@types/minimatch@^3.0.5":
|
||||
version "3.0.5"
|
||||
resolved "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz#1001cc5e6a3704b83c236027e77f2f58ea010f40"
|
||||
integrity sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==
|
||||
|
||||
"@types/minimist@^1.2.0":
|
||||
version "1.2.2"
|
||||
resolved "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c"
|
||||
|
||||
Reference in New Issue
Block a user