diff --git a/.changeset/move-utils-to-cli-node.md b/.changeset/move-utils-to-cli-node.md index 7c14536ccf..f708dde666 100644 --- a/.changeset/move-utils-to-cli-node.md +++ b/.changeset/move-utils-to-cli-node.md @@ -2,4 +2,4 @@ '@backstage/cli-node': patch --- -Added `hasYarnPlugin` and `SuccessCache` exports, moved from `@backstage/cli`. +Added `hasBackstageYarnPlugin` and `SuccessCache` exports, moved from `@backstage/cli`. diff --git a/packages/cli-node/report.api.md b/packages/cli-node/report.api.md index 187f56640c..9d4887ca59 100644 --- a/packages/cli-node/report.api.md +++ b/packages/cli-node/report.api.md @@ -100,7 +100,7 @@ export class GitUtils { } // @public -export function hasYarnPlugin(workspaceDir?: string): Promise; +export function hasBackstageYarnPlugin(workspaceDir?: string): Promise; // @public export function isMonoRepo(): Promise; @@ -227,7 +227,7 @@ export function runWorkerQueueThreads( // @public export class SuccessCache { // (undocumented) - static create(name: string, basePath?: string): SuccessCache; + static create(options: { name: string; basePath?: string }): SuccessCache; // (undocumented) read(): Promise>; static trimPaths(input: string): string; diff --git a/packages/cli-node/src/cache/SuccessCache.ts b/packages/cli-node/src/cache/SuccessCache.ts index 62bef34137..78913ed0b6 100644 --- a/packages/cli-node/src/cache/SuccessCache.ts +++ b/packages/cli-node/src/cache/SuccessCache.ts @@ -40,12 +40,15 @@ export class SuccessCache { return input.replaceAll(targetPaths.rootDir, ''); } - static create(name: string, basePath?: string): SuccessCache { - return new SuccessCache(name, basePath); + static create(options: { name: string; basePath?: string }): SuccessCache { + return new SuccessCache(options); } - private constructor(name: string, basePath?: string) { - this.#path = resolvePath(basePath ?? DEFAULT_CACHE_BASE_PATH, name); + private constructor(options: { name: string; basePath?: string }) { + this.#path = resolvePath( + options.basePath ?? DEFAULT_CACHE_BASE_PATH, + options.name, + ); } async read(): Promise> { diff --git a/packages/cli-node/src/yarn/index.ts b/packages/cli-node/src/yarn/index.ts index ce4eb4231c..871aa14ca8 100644 --- a/packages/cli-node/src/yarn/index.ts +++ b/packages/cli-node/src/yarn/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export { hasYarnPlugin } from './yarnPlugin'; +export { hasBackstageYarnPlugin } from './yarnPlugin'; diff --git a/packages/cli-node/src/yarn/yarnPlugin.test.ts b/packages/cli-node/src/yarn/yarnPlugin.test.ts index aba1dda579..ecbff45ba7 100644 --- a/packages/cli-node/src/yarn/yarnPlugin.test.ts +++ b/packages/cli-node/src/yarn/yarnPlugin.test.ts @@ -16,12 +16,12 @@ import { createMockDirectory } from '@backstage/backend-test-utils'; import { overrideTargetPaths } from '@backstage/cli-common/testUtils'; -import { hasYarnPlugin } from './yarnPlugin'; +import { hasBackstageYarnPlugin } from './yarnPlugin'; const mockDir = createMockDirectory(); overrideTargetPaths(mockDir.path); -describe('hasYarnPlugin', () => { +describe('hasBackstageYarnPlugin', () => { beforeEach(() => { mockDir.clear(); }); @@ -29,7 +29,7 @@ describe('hasYarnPlugin', () => { it('should return false when .yarnrc.yml does not exist', async () => { mockDir.setContent({}); - const result = await hasYarnPlugin(); + const result = await hasBackstageYarnPlugin(); expect(result).toBe(false); }); @@ -38,7 +38,7 @@ describe('hasYarnPlugin', () => { '.yarnrc.yml': '', }); - const result = await hasYarnPlugin(); + const result = await hasBackstageYarnPlugin(); expect(result).toBe(false); }); @@ -47,7 +47,7 @@ describe('hasYarnPlugin', () => { '.yarnrc.yml': 'plugins: []', }); - const result = await hasYarnPlugin(); + const result = await hasBackstageYarnPlugin(); expect(result).toBe(false); }); @@ -60,7 +60,7 @@ plugins: `, }); - const result = await hasYarnPlugin(); + const result = await hasBackstageYarnPlugin(); expect(result).toBe(false); }); @@ -74,7 +74,7 @@ plugins: `, }); - const result = await hasYarnPlugin(); + const result = await hasBackstageYarnPlugin(); expect(result).toBe(true); }); @@ -86,7 +86,7 @@ plugins: `, }); - const result = await hasYarnPlugin(); + const result = await hasBackstageYarnPlugin(); expect(result).toBe(true); }); @@ -95,7 +95,7 @@ plugins: '.yarnrc.yml': 'invalid: yaml: content: [', }); - await expect(hasYarnPlugin()).rejects.toThrow(); + await expect(hasBackstageYarnPlugin()).rejects.toThrow(); }); it('should throw error when .yarnrc.yml has unexpected structure', async () => { @@ -105,7 +105,7 @@ plugins: "not an array" `, }); - await expect(hasYarnPlugin()).rejects.toThrow( + await expect(hasBackstageYarnPlugin()).rejects.toThrow( 'Unexpected content in .yarnrc.yml', ); }); @@ -120,7 +120,7 @@ plugins: }, }); - const result = await hasYarnPlugin(mockDir.resolve('custom-dir')); + const result = await hasBackstageYarnPlugin(mockDir.resolve('custom-dir')); expect(result).toBe(true); }); }); diff --git a/packages/cli-node/src/yarn/yarnPlugin.ts b/packages/cli-node/src/yarn/yarnPlugin.ts index 87a3b98973..65383edd0c 100644 --- a/packages/cli-node/src/yarn/yarnPlugin.ts +++ b/packages/cli-node/src/yarn/yarnPlugin.ts @@ -37,7 +37,9 @@ const yarnRcSchema = z.object({ * @returns Promise resolving to true if the plugin is installed, false otherwise * @public */ -export async function hasYarnPlugin(workspaceDir?: string): Promise { +export async function hasBackstageYarnPlugin( + workspaceDir?: string, +): Promise { const yarnRcPath = resolvePath( workspaceDir ?? targetPaths.rootDir, '.yarnrc.yml', diff --git a/packages/cli/src/modules/lint/commands/repo/lint.ts b/packages/cli/src/modules/lint/commands/repo/lint.ts index 4351725d57..a3ae69302c 100644 --- a/packages/cli/src/modules/lint/commands/repo/lint.ts +++ b/packages/cli/src/modules/lint/commands/repo/lint.ts @@ -41,7 +41,10 @@ function depCount(pkg: BackstagePackageJson) { export async function command(opts: OptionValues, cmd: Command): Promise { let packages = await PackageGraph.listTargetPackages(); - const cache = SuccessCache.create('lint', opts.successCacheDir); + const cache = SuccessCache.create({ + name: 'lint', + basePath: opts.successCacheDir, + }); const cacheContext = opts.successCache ? { entries: await cache.read(), diff --git a/packages/cli/src/modules/migrate/commands/versions/bump.ts b/packages/cli/src/modules/migrate/commands/versions/bump.ts index 4b15da4676..8fe7013ac8 100644 --- a/packages/cli/src/modules/migrate/commands/versions/bump.ts +++ b/packages/cli/src/modules/migrate/commands/versions/bump.ts @@ -31,7 +31,7 @@ import { isError, NotFoundError } from '@backstage/errors'; import { resolve as resolvePath } from 'node:path'; import { - hasYarnPlugin, + hasBackstageYarnPlugin, Lockfile, runConcurrentTasks, } from '@backstage/cli-node'; @@ -76,7 +76,7 @@ function extendsDefaultPattern(pattern: string): boolean { export default async (opts: OptionValues) => { const lockfilePath = targetPaths.resolveRoot('yarn.lock'); const lockfile = await Lockfile.load(lockfilePath); - const yarnPluginEnabled = await hasYarnPlugin(); + const yarnPluginEnabled = await hasBackstageYarnPlugin(); let pattern = opts.pattern; diff --git a/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts b/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts index 2c94e3639d..42285259b3 100644 --- a/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts +++ b/packages/cli/src/modules/new/lib/execution/PortableTemplater.ts @@ -28,7 +28,7 @@ import { Lockfile } from '@backstage/cli-node'; import { targetPaths } from '@backstage/cli-common'; import { createPackageVersionProvider } from '../../../../lib/version'; -import { hasYarnPlugin } from '@backstage/cli-node'; +import { hasBackstageYarnPlugin } from '@backstage/cli-node'; const builtInHelpers = { camelCase, @@ -55,7 +55,7 @@ export class PortableTemplater { /* ignored */ } - const yarnPluginEnabled = await hasYarnPlugin(); + const yarnPluginEnabled = await hasBackstageYarnPlugin(); const versionProvider = createPackageVersionProvider(lockfile, { preferBackstageProtocol: yarnPluginEnabled, }); diff --git a/packages/cli/src/modules/test/commands/repo/test.ts b/packages/cli/src/modules/test/commands/repo/test.ts index 0ccac5c9b5..53f86fd635 100644 --- a/packages/cli/src/modules/test/commands/repo/test.ts +++ b/packages/cli/src/modules/test/commands/repo/test.ts @@ -332,7 +332,10 @@ export async function command(opts: OptionValues, cmd: Command): Promise { ); } - const cache = SuccessCache.create('test', opts.successCacheDir); + const cache = SuccessCache.create({ + name: 'test', + basePath: opts.successCacheDir, + }); const graph = await getPackageGraph(); // Shared state for the bridge