diff --git a/packages/cli-node/src/monorepo/Lockfile.ts b/packages/cli-node/src/monorepo/Lockfile.ts index efdf1e48d2..8a481c77ad 100644 --- a/packages/cli-node/src/monorepo/Lockfile.ts +++ b/packages/cli-node/src/monorepo/Lockfile.ts @@ -19,6 +19,7 @@ import fs from 'fs-extra'; const ENTRY_PATTERN = /^((?:@[^/]+\/)?[^@/]+)@(.+)$/; +/** @internal */ type LockfileData = { [entry: string]: { version: string; @@ -30,18 +31,29 @@ type LockfileData = { }; }; +/** @internal */ type LockfileQueryEntry = { range: string; version: string; dataKey: string; }; -type LockfileDiffEntry = { +/** + * An entry for a single difference between two {@link Lockfile}s. + * + * @public + */ +export type LockfileDiffEntry = { name: string; range: string; }; -type LockfileDiff = { +/** + * Represents the difference between two {@link Lockfile}s. + * + * @public + */ +export type LockfileDiff = { added: LockfileDiffEntry[]; changed: LockfileDiffEntry[]; removed: LockfileDiffEntry[]; @@ -60,13 +72,26 @@ const SPECIAL_OBJECT_KEYS = [ `binaries`, ]; +/** + * Represents a package manager lockfile. + * + * @public + */ export class Lockfile { - static async load(path: string) { + /** + * Load a {@link Lockfile} from a file path. + */ + static async load(path: string): Promise { const lockfileContents = await fs.readFile(path, 'utf8'); return Lockfile.parse(lockfileContents); } - static parse(content: string) { + /** + * Parse lockfile contents into a {@link Lockfile}. + * + * @public + */ + static parse(content: string): Lockfile { let data: LockfileData; try { data = parseSyml(content); @@ -108,6 +133,11 @@ export class Lockfile { private readonly data: LockfileData, ) {} + /** + * 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 + * across all versions. + */ createSimplifiedDependencyGraph(): Map> { const graph = new Map>(); diff --git a/packages/cli-node/src/monorepo/index.ts b/packages/cli-node/src/monorepo/index.ts index 8a3eae3508..5071849116 100644 --- a/packages/cli-node/src/monorepo/index.ts +++ b/packages/cli-node/src/monorepo/index.ts @@ -14,9 +14,14 @@ * limitations under the License. */ -export { PackageGraph } from './PackageGraph'; -export type { - PackageGraphNode, - BackstagePackage, - BackstagePackageJson, +export { + PackageGraph, + type PackageGraphNode, + type BackstagePackage, + type BackstagePackageJson, } from './PackageGraph'; +export { + Lockfile, + type LockfileDiff, + type LockfileDiffEntry, +} from './Lockfile';