diff --git a/.changeset/icy-sides-appear.md b/.changeset/icy-sides-appear.md new file mode 100644 index 0000000000..74f6729a83 --- /dev/null +++ b/.changeset/icy-sides-appear.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli-node': patch +--- + +Add `get` and `keys` methods to `Lockfile` class diff --git a/packages/cli-node/report.api.md b/packages/cli-node/report.api.md index 0c13469866..71f2b69ca8 100644 --- a/packages/cli-node/report.api.md +++ b/packages/cli-node/report.api.md @@ -98,7 +98,9 @@ export function isMonoRepo(): Promise; export class Lockfile { createSimplifiedDependencyGraph(): Map>; diff(otherLockfile: Lockfile): LockfileDiff; + get(name: string): LockfileQueryEntry[] | undefined; getDependencyTreeHash(startName: string): string; + keys(): IterableIterator; static load(path: string): Promise; static parse(content: string): Lockfile; } @@ -116,6 +118,13 @@ export type LockfileDiffEntry = { range: string; }; +// @public +export type LockfileQueryEntry = { + range: string; + version: string; + dataKey: string; +}; + // @public export const packageFeatureType: readonly [ '@backstage/BackendFeature', diff --git a/packages/cli-node/src/monorepo/Lockfile.ts b/packages/cli-node/src/monorepo/Lockfile.ts index 7c4dc04f33..d7a6f5f0b6 100644 --- a/packages/cli-node/src/monorepo/Lockfile.ts +++ b/packages/cli-node/src/monorepo/Lockfile.ts @@ -32,8 +32,12 @@ type LockfileData = { }; }; -/** @internal */ -type LockfileQueryEntry = { +/** + * A single entry in a {@link Lockfile}. + * + * @public + */ +export type LockfileQueryEntry = { range: string; version: string; dataKey: string; @@ -134,6 +138,16 @@ export class Lockfile { private readonly data: LockfileData, ) {} + /** Returns the name of all packages available in the lockfile */ + get(name: string): LockfileQueryEntry[] | undefined { + return this.packages.get(name); + } + + /** Get the entries for a single package in the lockfile */ + keys(): IterableIterator { + return this.packages.keys(); + } + /** * Creates a simplified dependency graph from the lockfile data, where each * key is a package, and the value is a set of all packages that it depends on diff --git a/packages/cli-node/src/monorepo/index.ts b/packages/cli-node/src/monorepo/index.ts index 14630356b9..20f0253806 100644 --- a/packages/cli-node/src/monorepo/index.ts +++ b/packages/cli-node/src/monorepo/index.ts @@ -27,4 +27,5 @@ export { Lockfile, type LockfileDiff, type LockfileDiffEntry, + type LockfileQueryEntry, } from './Lockfile';