cli: switch repo lint --cache option to --successCache and --successCacheDir

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-10-07 16:37:03 +02:00
parent beaa723f1e
commit 50cc7351cf
8 changed files with 21 additions and 15 deletions
+2 -1
View File
@@ -446,7 +446,8 @@ Usage: backstage-cli repo lint [options]
Options:
--format <format>
--since <ref>
--cache [path]
--successCache
--successCacheDir <path>
--fix
-h, --help
```
+6 -2
View File
@@ -62,8 +62,12 @@ export function registerRepoCommand(program: Command) {
'Only lint packages that changed since the specified ref',
)
.option(
'--cache [path]',
'Enable caching, storing it in node_modules/.cache/backstage-cli by default, or at the provided directory',
'--successCache',
'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run',
)
.option(
'--successCacheDir <path>',
'Set the success cache location, (default: node_modules/.cache/backstage-cli)',
)
.option('--fix', 'Attempt to automatically fix violations')
.action(lazy(() => import('./repo/lint').then(m => m.command)));
+6 -7
View File
@@ -63,11 +63,10 @@ async function writeCache(dir: string, cache: Cache) {
export async function command(opts: OptionValues, cmd: Command): Promise<void> {
let packages = await PackageGraph.listTargetPackages();
const cacheDir =
opts.cache === true
? paths.resolveTargetRoot('node_modules/.cache/backstage-cli')
: opts.cache;
const cacheContext = cacheDir
const cacheDir = resolvePath(
opts.successCacheDir ?? 'node_modules/.cache/backstage-cli',
);
const cacheContext = opts.successCache
? {
cache: await readCache(cacheDir),
lockfile: await Lockfile.load(paths.resolveTargetRoot('yarn.lock')),
@@ -136,7 +135,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
workerData: {
fix: Boolean(opts.fix),
format: opts.format as string | undefined,
shouldCache: Boolean(cacheDir),
shouldCache: Boolean(cacheContext),
successCache: cacheContext?.cache,
},
workerFactory: async ({ fix, format, shouldCache, successCache }) => {
@@ -252,7 +251,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
}
}
if (cacheDir) {
if (cacheContext) {
await writeCache(cacheDir, outputSuccessCache);
}