Address further review feedback

- Rename hasYarnPlugin -> hasBackstageYarnPlugin for clarity
- Change SuccessCache.create to accept an options object

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2026-02-25 15:25:11 +01:00
parent 968570bbb5
commit 09eb6b5187
10 changed files with 37 additions and 26 deletions
+2 -2
View File
@@ -100,7 +100,7 @@ export class GitUtils {
}
// @public
export function hasYarnPlugin(workspaceDir?: string): Promise<boolean>;
export function hasBackstageYarnPlugin(workspaceDir?: string): Promise<boolean>;
// @public
export function isMonoRepo(): Promise<boolean>;
@@ -227,7 +227,7 @@ export function runWorkerQueueThreads<TItem, TResult, TContext>(
// @public
export class SuccessCache {
// (undocumented)
static create(name: string, basePath?: string): SuccessCache;
static create(options: { name: string; basePath?: string }): SuccessCache;
// (undocumented)
read(): Promise<Set<string>>;
static trimPaths(input: string): string;
+7 -4
View File
@@ -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<Set<string>> {
+1 -1
View File
@@ -14,4 +14,4 @@
* limitations under the License.
*/
export { hasYarnPlugin } from './yarnPlugin';
export { hasBackstageYarnPlugin } from './yarnPlugin';
+11 -11
View File
@@ -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);
});
});
+3 -1
View File
@@ -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<boolean> {
export async function hasBackstageYarnPlugin(
workspaceDir?: string,
): Promise<boolean> {
const yarnRcPath = resolvePath(
workspaceDir ?? targetPaths.rootDir,
'.yarnrc.yml',