cli-node: add get and keys methods to Lockfile class

There are a few of these classes floating around
the codebase - my hope by adding these methods
here is that we can start unifying around this
shared implementation.

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2025-08-08 17:49:05 +01:00
parent 1abbf97a38
commit d9a78351b4
4 changed files with 31 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli-node': patch
---
Add `get` and `keys` methods to `Lockfile` class
+9
View File
@@ -98,7 +98,9 @@ export function isMonoRepo(): Promise<boolean>;
export class Lockfile {
createSimplifiedDependencyGraph(): Map<string, Set<string>>;
diff(otherLockfile: Lockfile): LockfileDiff;
get(name: string): LockfileQueryEntry[] | undefined;
getDependencyTreeHash(startName: string): string;
keys(): IterableIterator<string>;
static load(path: string): Promise<Lockfile>;
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',
+16 -2
View File
@@ -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<string> {
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
+1
View File
@@ -27,4 +27,5 @@ export {
Lockfile,
type LockfileDiff,
type LockfileDiffEntry,
type LockfileQueryEntry,
} from './Lockfile';