@hyperfrontend/versioning/workspace/operations

operations

Workspace-wide operations: cascade bumps, batch updates, dependency-reference rewriting, and validation.

The cascade-bump family (PlannedBump, BumpReason, CascadeBumpOptions, CascadeBumpResult, DirectBumpInput) plans the propagation of a version bump through a monorepo's internal-dependency graph, so that bumping a base package automatically schedules dependent packages with the right BumpReason. The batch-update family (applyBumps, updatePackageVersionInTree, updateDependencyReferencesInTree, summarizeBatchUpdate, plus BatchUpdateResult, UpdatedPackage, FailedUpdate, BatchUpdateOptions, DEFAULT_BATCH_UPDATE_OPTIONS) carries out the planned bumps across package.json files in one transactional pass. The validation family (ValidationResult, ValidationReport, ValidationCheckResult) verifies that a planned set of changes is internally consistent before any file is written.

API Reference

ƒ Functions

§function

applyBumps(tree: Tree, workspace: Workspace, bumps: unknown, options: BatchUpdateOptions): BatchUpdateResult

Applies planned bumps to the workspace using the VFS Tree. Updates package.json version fields for all affected packages.
Changes are buffered in the tree until commitChanges() is called, enabling atomic commits and rollback on failure.

Parameters

NameTypeDescription
§tree
Tree
Virtual file system tree for buffered operations
§workspace
Workspace
Workspace containing projects to update
§bumps
unknown
Planned version bumps
§options
BatchUpdateOptions
Update options
(default: {})

Returns

BatchUpdateResult
Batch update result

Example

Apply planned bumps to workspace using VFS Tree

import { createTree, commitChanges } from '@hyperfrontend/project-scope'
import { applyBumps, calculateCascadeBumps } from '@hyperfrontend/versioning'

const tree = createTree(workspaceRoot)
const cascadeResult = calculateCascadeBumps(workspace, directBumps)
const updateResult = applyBumps(tree, workspace, cascadeResult.bumps)

if (updateResult.success) {
  commitChanges(tree) // Atomic commit of all changes
  console.log(`Updated ${updateResult.updated.length} packages`)
} else {
  console.error('Some updates failed:', updateResult.failed)
  // No commitChanges() call - changes are discarded
}
§function

calculateCascadeBumps(workspace: Workspace, directBumps: unknown, options: CascadeBumpOptions): CascadeBumpResult

Calculates cascade bumps for a workspace given direct bumps.
When packages are directly bumped (e.g., due to commits), their dependents may also need version bumps. This function calculates all affected packages.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace containing projects and dependency graph
§directBumps
unknown
Packages with direct changes
§options
CascadeBumpOptions
Configuration for cascade bump calculation
(default: {})

Returns

CascadeBumpResult
Cascade bump result

Example

Calculate cascade bumps for a workspace

import { calculateCascadeBumps } from '@hyperfrontend/versioning'

// If lib-utils is getting a minor bump
const result = calculateCascadeBumps(workspace, [
  { name: 'lib-utils', bumpType: 'minor' }
])

// result.bumps includes lib-utils and all packages that depend on it
for (const bump of result.bumps) {
  console.log(`${bump.name}: ${bump.currentVersion} -> ${bump.nextVersion}`)
}
§function

calculateCascadeBumpsFromPackage(workspace: Workspace, packageName: string, bumpType: BumpType, options: CascadeBumpOptions): CascadeBumpResult

Calculates cascade bumps starting from a single package.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace containing projects and dependency graph
§packageName
string
Package with direct changes
§bumpType
BumpType
Type of bump for the direct change
§options
CascadeBumpOptions
Configuration for cascade behavior
(default: {})

Returns

CascadeBumpResult
Cascade bump result

Example

Calculate cascade bumps from a single package

import { discoverWorkspace, calculateCascadeBumpsFromPackage } from '@hyperfrontend/versioning'

const workspace = discoverWorkspace()
const result = calculateCascadeBumpsFromPackage(workspace, '@myorg/utils', 'minor')

console.log(`${result.totalAffected} packages will be bumped`)
for (const bump of result.bumps) {
  console.log(`${bump.name}: ${bump.currentVersion} -> ${bump.nextVersion}`)
}
§function

summarizeBatchUpdate(result: BatchUpdateResult): string

Creates a summary of the batch update result.

Parameters

NameTypeDescription
§result
BatchUpdateResult
Result object from batch update operation

Returns

string
Human-readable summary

Example

Create a summary of the batch update result

import { batchUpdateVersions, summarizeBatchUpdate } from '@hyperfrontend/versioning'

const result = batchUpdateVersions(workspace, updates)
console.log(summarizeBatchUpdate(result))
// Output:
// Successfully updated 3 package(s)
//
// Updated packages:
//   @myorg/utils: 1.0.0 -> 1.1.0
//   @myorg/core: 2.0.0 -> 2.1.0
§function

summarizeCascadeBumps(result: CascadeBumpResult): string

Gets a summary of the cascade bump calculation.

Parameters

NameTypeDescription
§result
CascadeBumpResult
Result object from cascade bump calculation

Returns

string
Human-readable summary

Example

Get a summary of cascade bump results

import { calculateCascadeBumps, summarizeCascadeBumps } from '@hyperfrontend/versioning'

const result = calculateCascadeBumps(workspace, [{ name: '@myorg/utils', bumpType: 'patch' }])
console.log(summarizeCascadeBumps(result))
// Output:
// 3 package(s) affected:
//   - 1 direct bump(s)
//   - 2 cascade bump(s)
§function

summarizeValidation(report: ValidationReport): string

Creates a summary of the validation report.

Parameters

NameTypeDescription
§report
ValidationReport
Report object from workspace validation

Returns

string
Human-readable summary

Example

Create a summary of the validation report

import { validateWorkspace, summarizeValidation } from '@hyperfrontend/versioning'

const report = validateWorkspace(workspace)
console.log(summarizeValidation(report))
// Output:
// Workspace validation passed
//   2 warning(s)
§function

updateDependencyReferencesInTree(tree: Tree, packageJsonPath: string, versionUpdates: Map<string, string>): void

Updates dependency version references in a package.json file using a VFS Tree.
Uses the changeFile() pattern for cleaner transformation. Silently skips if the file doesn't exist.

Parameters

NameTypeDescription
§tree
Tree
Virtual file system tree
§packageJsonPath
string
Relative path to package.json
§versionUpdates
Map<string, string>
Map of package name to new version

Example

Update dependency version references using VFS Tree

import { updateDependencyReferencesInTree } from '@hyperfrontend/versioning'

// Inside an Nx generator
export default function syncDeps(tree: Tree) {
  const updates = new Map([
    ['@myorg/utils', '2.0.0'],
    ['@myorg/core', '3.1.0'],
  ])

  updateDependencyReferencesInTree(tree, 'apps/my-app/package.json', updates)
}
§function

updatePackageVersionInTree(tree: Tree, packageJsonPath: string, newVersion: string): void

Updates a package.json file using a VFS Tree.

Parameters

NameTypeDescription
§tree
Tree
Virtual file system tree
§packageJsonPath
string
Relative path to package.json
§newVersion
string
New version string

Example

Update a package.json version using VFS Tree

import { updatePackageVersionInTree } from '@hyperfrontend/versioning'

// Inside an Nx generator
export default function bumpVersion(tree: Tree) {
  updatePackageVersionInTree(tree, 'libs/my-lib/package.json', '2.0.0')
}
§function

validateProject(project: Project): ValidationResult

Validates a single project.

Parameters

NameTypeDescription
§project
Project
The project to validate

Returns

ValidationResult
Validation result

Example

Validate a single project

import { discoverProject, validateProject } from '@hyperfrontend/versioning'

const project = discoverProject('./libs/my-lib')
if (project) {
  const result = validateProject(project)
  if (!result.valid) {
    console.error('Validation failed:', result.error)
  }
}
§function

validateWorkspace(workspace: Workspace): ValidationReport

Validates a workspace for common issues.

Parameters

NameTypeDescription
§workspace
Workspace
The workspace to validate

Returns

ValidationReport
Validation report

Example

Validate a workspace for common issues

import { validateWorkspace } from '@hyperfrontend/versioning'

const report = validateWorkspace(workspace)

if (!report.valid) {
  console.error(`${report.errorCount} error(s) found`)
  for (const result of report.results) {
    if (!result.result.valid) {
      console.error(`  ${result.checkName}: ${result.result.error}`)
    }
  }
}

Interfaces

§interface

BatchUpdateOptions

Options for batch update operations.

Properties

§updateDependencyReferences?:boolean
Whether to update dependency references in other packages
§interface

BatchUpdateResult

Result of a batch update operation.

Properties

§readonly failed:unknown
Packages that failed to update
§readonly success:boolean
Whether all updates succeeded
§readonly total:number
Total number of packages processed
§readonly updated:unknown
Packages successfully updated
§interface

CascadeBumpOptions

Options for cascade bump calculation.

Properties

§cascadeBumpType?:BumpType
Bump type for cascaded dependents. Default is 'patch' - dependents get a patch bump when their dependencies change.
§includeDevDependencies?:boolean
Whether to include dev dependencies in cascade. Default is false - only production dependencies trigger cascades.
§includePeerDependencies?:boolean
Whether to include peer dependencies in cascade. Default is true - peer dependency updates should cascade.
§prereleaseId?:string
Custom prerelease identifier for prerelease bumps.
§interface

CascadeBumpResult

Result of cascade bump calculation.

Properties

§readonly bumps:unknown
All planned bumps, in topological order
§readonly cascadeBumps:unknown
Packages bumped due to cascading
§readonly directBumps:unknown
Packages explicitly bumped (direct changes)
§readonly totalAffected:number
Total number of packages affected
§interface

DirectBumpInput

Input for calculating cascade bumps.

Properties

§bumpType:BumpType
Type of bump
§name:string
Package name
§interface

FailedUpdate

Information about a failed update.

Properties

§readonly error:string
Error message
§readonly name:string
Package name
§readonly packageJsonPath:string
Path to package.json
§interface

PlannedBump

A planned version bump for a package.

Properties

§readonly bumpType:BumpType
Type of bump
§readonly currentVersion:string
Current version
§readonly name:string
Package name
§readonly nextVersion:string
Next version after bump
§readonly reason:BumpReason
Reason for the bump
§readonly triggeredBy:unknown
Packages that triggered this bump (for cascade bumps)
§interface

UpdatedPackage

Information about a successfully updated package.

Properties

§readonly name:string
Package name
§readonly newVersion:string
New version
§readonly packageJsonPath:string
Path to package.json
§readonly previousVersion:string
Previous version
§interface

ValidationCheckResult

Result of a specific validation check.

Properties

§readonly checkId:string
Check identifier
§readonly checkName:string
Human-readable check name
§readonly packageName:string
Package being checked (null for workspace-level checks)
§readonly result:ValidationResult
Check result
§interface

ValidationReport

Aggregated validation report.

Properties

§readonly errorCount:number
Total number of errors
§readonly invalidPackages:unknown
Packages with validation errors
§readonly results:unknown
All validation results
§readonly valid:boolean
Whether all checks passed
§readonly warningCount:number
Total number of warnings
§interface

WorkspaceValidationResult

Validation result for a single check.

Properties

§readonly error?:string
Error message if invalid
§readonly valid:boolean
Whether the check passed
§readonly warning?:string
Warning message (valid but potentially problematic)

Types

§type

BumpReason

Reason for a version bump.
type BumpReason = "direct" | "cascade" | "sync"

Variables

§type

DEFAULT_BATCH_UPDATE_OPTIONS

Default batch update options.
§type

DEFAULT_CASCADE_OPTIONS

Default cascade bump options.