@hyperfrontend/versioning/workspace

workspace/

Workspace-level utilities for monorepo package discovery, dependency tracking, cascade versioning, and batch operations.

Overview

This module provides tools for working with multi-package workspaces (monorepos). It handles package discovery, builds dependency graphs, calculates cascade bumps when releasing, and performs batch updates across packages.

Configuration

Cascade Bumps

CascadeOptions:

Option Default Description
cascadeBumpType 'patch' Bump type for cascaded dependents
includeDevDependencies false Cascade through dev dependencies
includePeerDependencies true Cascade through peer dependencies
prereleaseId 'alpha' Prerelease identifier for prerelease bumps

Batch Updates

BatchOptions:

Option Default Description
dryRun false Preview changes without writing
updateChangelogs true Update changelog files
updateDependencyVersions true Update dependency version ranges
createGitCommit false Create git commit after updates
createGitTag false Create git tags for each updated package

Validation

ValidationOptions:

Option Description
customRules Additional validation rules
ignoreProjects Projects to skip validation
disabledRules Rules to disable

Built-in Validation Rules:

Rule Severity Description
valid-version error Version must be valid semver
valid-name error Package name required
valid-name-format error Package name must follow npm conventions
no-self-dependency error Package cannot depend on itself
no-circular-deps error No circular dependencies in workspace
version-compatibility warning Internal deps should be compatible
has-changelog warning Publishable packages should have changelog
no-prerelease-deps warning Avoid prerelease external dependencies
no-wildcard-deps warning Avoid wildcard version ranges
no-git-deps warning Avoid git URL dependencies

Usage Example

import {
  discoverPackages,
  buildDependencyGraph,
  createWorkspace,
  calculateCascadeBumps,
  applyBumps,
  validateWorkspace,
} from '@hyperfrontend/versioning'

// 1. Discover workspace
const projects = await discoverPackages('/path/to/monorepo')
const depGraph = buildDependencyGraph(projects)
const workspace = createWorkspace({
  root: '/path/to/monorepo',
  type: 'nx',
  projects,
  dependencyGraph: depGraph,
  reverseDependencyGraph: buildReverseDependencyGraph(depGraph),
})

// 2. Validate workspace
const report = validateWorkspace(workspace)
if (!report.isValid) {
  console.error(formatValidationReport(report))
  process.exit(1)
}

// 3. Calculate cascade bumps
const result = calculateCascadeBumps(workspace, [{ name: 'core', bumpType: 'minor' }])
console.log(summarizeCascadeBumps(result))
// Output: "3 package(s) affected (1 direct, 2 cascade)"

// 4. Apply bumps
const updateResult = applyBumps(workspace, result.bumps, {
  dryRun: true,
  updateChangelogs: true,
})
console.log(formatBatchResult(updateResult))

Dependencies

Uses @hyperfrontend/project-scope for file system operations and workspace detection. Uses @hyperfrontend/immutable-api-utils for immutable data structures.

See Also

API Reference

ƒ Functions

§function

createWorkspaceFromDisk(options: DiscoveryOptions): Workspace

Creates a complete workspace object by discovering packages and building the dependency graph.

Parameters

NameTypeDescription
§options
DiscoveryOptions
Discovery configuration options
(default: {})

Returns

Workspace
Complete workspace object with projects and dependency graph

Example

Create a complete workspace object from disk

import { createWorkspaceFromDisk } from '@hyperfrontend/versioning'

const workspace = createWorkspaceFromDisk()

// Access projects
for (const project of workspace.projectList) {
  console.log(`${project.name}@${project.version}`)
}

// Get dependents of a package
const dependents = workspace.dependencyGraph.get('lib-utils')
§function

findChangelogsInTree(tree: Tree, packages: unknown): Map<string, string>

Finds changelog files for a list of packages using VFS tree. Returns a map of project path to changelog absolute path.

Parameters

NameTypeDescription
§tree
Tree
VFS tree instance
§packages
unknown
List of packages to find changelogs for

Returns

Map<string, string>
Map of project path to changelog path

Example

Find changelogs using VFS tree

import { findChangelogsInTree, discoverPackages } from '@hyperfrontend/versioning'

// Inside an Nx generator
export default function myGenerator(tree: Tree) {
  const { packages } = discoverPackages()
  const changelogs = findChangelogsInTree(tree, packages)

  for (const [projectPath, changelogPath] of changelogs) {
    console.log(`Found changelog at ${changelogPath}`)
  }
}
§function

findProjectChangelogInTree(tree: Tree, projectPath: string): string

Finds the changelog file for a single project using VFS tree. Checks for common changelog names in order of priority.

Parameters

NameTypeDescription
§tree
Tree
VFS tree instance
§projectPath
string
Path to project directory

Returns

string
Absolute path to changelog or null if not found

Example

Find project changelog using VFS tree

import { findProjectChangelogInTree } from '@hyperfrontend/versioning'

// Inside an Nx generator
export default function myGenerator(tree: Tree) {
  const changelogPath = findProjectChangelogInTree(tree, 'libs/my-lib')
  if (changelogPath) {
    const content = tree.read(changelogPath, 'utf-8')
    // Process changelog content
  }
}
§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

addDependent(project: Project, dependent: string): Project

Creates a copy of a project with an added internal dependent.

Parameters

NameTypeDescription
§project
Project
The project to update
§dependent
string
Name of the dependent to add

Returns

Project
A new Project with the added dependent

Example

Add an internal dependent to a project

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

const project = discoverProject('./libs/utils')
if (project) {
  const updated = addDependent(project, '@myorg/new-app')
  console.log('Dependents now:', updated.internalDependents)
}
§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

buildDependencyGraph(projects: unknown): DependencyGraphAnalysis

Builds a complete dependency graph from a list of projects.

Parameters

NameTypeDescription
§projects
unknown
List of projects to analyze

Returns

DependencyGraphAnalysis
Dependency graph analysis result

Example

Build a complete dependency graph

import { buildDependencyGraph, discoverPackages } from '@hyperfrontend/versioning'

const { projects } = discoverPackages()
const analysis = buildDependencyGraph(projects)

// Get packages that depend on 'lib-utils'
const dependents = analysis.dependencyGraph.get('lib-utils') ?? []

// Get packages in topological order for building
const buildOrder = getTopologicalOrder(analysis)
§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

createProject(options: CreateProjectOptions): Project

Creates a new Project object.

Parameters

NameTypeDescription
§options
CreateProjectOptions
Project properties

Returns

Project
A new Project object

Example

Create a new Project object

import { createProject, readPackageJson } from '@hyperfrontend/versioning'

const packageJson = readPackageJson('./libs/my-lib/package.json')
const project = createProject({
  name: '@myorg/my-lib',
  version: '1.0.0',
  path: './libs/my-lib',
  packageJsonPath: './libs/my-lib/package.json',
  packageJson,
  changelogPath: './libs/my-lib/CHANGELOG.md',
})
§function

createWorkspace(options: CreateWorkspaceOptions): Workspace

Creates a new workspace object.

Parameters

NameTypeDescription
§options
CreateWorkspaceOptions
Workspace properties

Returns

Workspace
A new Workspace object

Example

Create a new workspace object

import { createWorkspace, createWorkspaceConfig, createProject } from '@hyperfrontend/versioning'

const projects = new Map([['@myorg/utils', createProject({ ... })]])
const workspace = createWorkspace({
  root: '/path/to/workspace',
  type: 'nx',
  projects,
  config: createWorkspaceConfig(),
  dependencyGraph: new Map(),
  reverseDependencyGraph: new Map(),
})
§function

createWorkspaceConfig(options?: Partial<WorkspaceConfig>): WorkspaceConfig

Creates a new workspace configuration by merging with defaults.

Parameters

NameTypeDescription
§options?
Partial<WorkspaceConfig>
Partial configuration options

Returns

WorkspaceConfig
Complete workspace configuration

Example

Create a workspace configuration with defaults

import { createWorkspaceConfig } from '@hyperfrontend/versioning'

const config = createWorkspaceConfig({
  patterns: ['packages/*', 'libs/*'],
  exclude: ['node_modules', 'dist'],
})
§function

dependsOn(workspace: Workspace, projectA: string, projectB: string): boolean

Checks if projectA depends on projectB.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace containing the dependency graph
§projectA
string
Name of the potentially dependent project
§projectB
string
Name of the potential dependency

Returns

boolean
True if projectA depends on projectB

Example

Check if one project depends on another

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

const workspace = discoverWorkspace()
if (dependsOn(workspace, '@myorg/app', '@myorg/utils')) {
  console.log('@myorg/app directly depends on @myorg/utils')
}
§function

discoverAllChangelogs(workspaceRoot: string, patterns: unknown): unknown

Discovers all changelog files within a workspace.

Parameters

NameTypeDescription
§workspaceRoot
string
Workspace root path
§patterns
unknown
Glob patterns for finding changelogs (default: all CHANGELOGs)
(default: ...)

Returns

unknown
Array of discovered changelog information

Example

Discover all changelog files within a workspace

import { discoverAllChangelogs } from '@hyperfrontend/versioning'

const changelogs = discoverAllChangelogs('/path/to/workspace')
for (const changelog of changelogs) {
  console.log(`${changelog.projectPath} -> ${changelog.path}`)
}
§function

discoverPackages(options: DiscoveryOptions): DiscoveryResult

Discovers all packages within a workspace. Finds package.json files, parses them, and optionally discovers changelogs and internal dependencies.

Parameters

NameTypeDescription
§options
DiscoveryOptions
Discovery options
(default: {})

Returns

DiscoveryResult
Discovery result with all found packages

Example

Discover all packages within a workspace

import { discoverPackages } from '@hyperfrontend/versioning'

// Discover all packages in current workspace
const result = discoverPackages()

// Discover with custom patterns
const result = discoverPackages({
  patterns: ['packages/*/package.json'],
  includeChangelogs: true
})

// Access discovered projects
for (const project of result.projects) {
  console.log(`${project.name}@${project.version}`)
}
§function

discoverProject(projectPath: string): Project

Discovers a single project by path.

Parameters

NameTypeDescription
§projectPath
string
Path to project directory or package.json

Returns

Project
The discovered project or null if not found

Example

Discover a single project by path

import { discoverProject } from '@hyperfrontend/versioning'

const project = discoverProject('./libs/utils')
if (project) {
  console.log(`Found ${project.name}@${project.version}`)
}

// Also accepts direct package.json path
const project2 = discoverProject('./libs/utils/package.json')
§function

discoverProjectByName(projectName: string, options: DiscoveryOptions): Project

Discovers a project by name within a workspace.

Parameters

NameTypeDescription
§projectName
string
Name of the project to find
§options
DiscoveryOptions
Discovery options
(default: {})

Returns

Project
The project or null if not found

Example

Discover a project by name within a workspace

import { discoverProjectByName } from '@hyperfrontend/versioning'

const project = discoverProjectByName('@myorg/utils')
if (project) {
  console.log(`Found at ${project.path}`)
}

// With custom workspace root
const project2 = discoverProjectByName('@myorg/core', { workspaceRoot: '/custom/path' })
§function

findChangelogs(workspaceRoot: string, packages: unknown): Map<string, string>

Finds changelog files for a list of packages. Returns a map of project path to changelog absolute path.

Parameters

NameTypeDescription
§workspaceRoot
string
Workspace root path
§packages
unknown
List of packages to find changelogs for

Returns

Map<string, string>
Map of project path to changelog path

Example

Find changelog files for all packages

import { findChangelogs, discoverPackages } from '@hyperfrontend/versioning'

const { packages } = discoverPackages()
const changelogs = findChangelogs('/workspace', packages)

for (const [projectPath, changelogPath] of changelogs) {
  console.log(`${projectPath} -> ${changelogPath}`)
}
§function

findInternalDependencies(packageJson: PackageJson, workspacePackageNames: Set<string>): string[]

Finds internal dependencies in a package.json. Returns names of workspace packages that this package depends on.

Parameters

NameTypeDescription
§packageJson
PackageJson
Parsed package.json content
§workspacePackageNames
Set<string>
Set of all package names in the workspace

Returns

string[]
Array of internal dependency names

Example

Find internal dependencies in a package

const internalDeps = findInternalDependencies(packageJson, allPackageNames)
// ['@scope/lib-a', '@scope/lib-b']
§function

findInternalDependenciesWithTypes(packageName: string, packageJson: PackageJson, workspacePackageNames: Set<string>): DependencyEdge[]

Finds internal dependencies with type information.

Parameters

NameTypeDescription
§packageName
string
Name of the package being analyzed
§packageJson
PackageJson
Parsed package.json content
§workspacePackageNames
Set<string>
Set of all package names in the workspace

Returns

DependencyEdge[]
Array of dependency edges with type information

Example

Find internal dependencies with type information

import { findInternalDependenciesWithTypes, readPackageJson } from '@hyperfrontend/versioning'

const packageJson = readPackageJson('./libs/my-lib/package.json')
const workspacePackages = new Set(['@myorg/utils', '@myorg/core'])

const edges = findInternalDependenciesWithTypes('@myorg/my-lib', packageJson, workspacePackages)
for (const edge of edges) {
  console.log(`${edge.from} -> ${edge.to} (${edge.type})`)
}
§function

findProjectChangelog(projectPath: string): string

Finds the changelog file for a single project. Checks for common changelog names in order of priority.

Parameters

NameTypeDescription
§projectPath
string
Path to project directory

Returns

string
Absolute path to changelog or null if not found

Example

Find the changelog for a single project

import { findProjectChangelog } from '@hyperfrontend/versioning'

const changelogPath = findProjectChangelog('./libs/my-lib')
if (changelogPath) {
  console.log('Found changelog:', changelogPath)
}
§function

getDependencies(workspace: Workspace, projectName: string): unknown

Gets projects that the given project depends on.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace containing the dependency graph
§projectName
string
Identifier of the project to look up

Returns

unknown
Array of dependency project names

Example

Get projects that the given project depends on

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

const workspace = discoverWorkspace()
const deps = getDependencies(workspace, '@myorg/app')
console.log(`@myorg/app depends on:`, deps)
§function

getDependencyCount(project: Project): number

Gets the dependency count (internal dependencies).

Parameters

NameTypeDescription
§project
Project
Project instance to analyze

Returns

number
Number of internal dependencies

Example

Get the dependency count for a project

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

const project = discoverProject('./libs/my-lib')
if (project) {
  console.log(`${project.name} depends on ${getDependencyCount(project)} internal packages`)
}
§function

getDependentCount(project: Project): number

Gets the dependent count (packages that depend on this one).

Parameters

NameTypeDescription
§project
Project
Project instance to analyze

Returns

number
Number of internal dependents

Example

Get the dependent count for a project

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

const project = discoverProject('./libs/utils')
if (project) {
  console.log(`${project.name} is used by ${getDependentCount(project)} packages`)
}
§function

getDependents(workspace: Workspace, projectName: string): unknown

Gets projects that depend on the given project.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace containing the dependency graph
§projectName
string
Name of the dependency

Returns

unknown
Array of dependent project names

Example

Get projects that depend on a given project

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

const workspace = discoverWorkspace()
const dependents = getDependents(workspace, '@myorg/utils')
console.log(`Packages depending on @myorg/utils:`, dependents)
§function

getExpectedChangelogPath(projectPath: string, fileName: string): string

Gets the expected changelog path for a project. Returns the standard CHANGELOG.md path regardless of whether it exists.

Parameters

NameTypeDescription
§projectPath
string
Directory containing the project files
§fileName
string
Changelog filename to use (default: 'CHANGELOG.md')
(default: DEFAULT_CHANGELOG_FILENAME)

Returns

string
Absolute path to changelog file in the project directory

Example

Get expected changelog path for a project

import { getExpectedChangelogPath } from '@hyperfrontend/versioning'

const changelogPath = getExpectedChangelogPath('./libs/my-lib')
// => '/workspace/libs/my-lib/CHANGELOG.md'

const customPath = getExpectedChangelogPath('./libs/my-lib', 'HISTORY.md')
// => '/workspace/libs/my-lib/HISTORY.md'
§function

getProject(workspace: Workspace, projectName: string): Project

Gets a project by name from the workspace.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace to search in
§projectName
string
Identifier of the project to retrieve

Returns

Project
The project or undefined if not found

Example

Get a project by name from the workspace

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

const workspace = discoverWorkspace()
const project = getProject(workspace, '@myorg/utils')
if (project) {
  console.log(`Version: ${project.version}`)
}
§function

getProjectCount(workspace: Workspace): number

Gets the count of projects in the workspace.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace to count projects in

Returns

number
Number of projects

Example

Get the count of projects in the workspace

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

const workspace = discoverWorkspace()
console.log(`Workspace contains ${getProjectCount(workspace)} projects`)
§function

getProjectNames(workspace: Workspace): unknown

Gets all project names in the workspace.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace to retrieve project names from

Returns

unknown
Array of project names

Example

Get all project names in the workspace

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

const workspace = discoverWorkspace()
const names = getProjectNames(workspace)
console.log(`Found ${names.length} projects:`, names)
§function

getTopologicalOrder(analysis: DependencyGraphAnalysis): unknown

Gets a topological ordering of packages for building. Packages with no dependencies come first.

Parameters

NameTypeDescription
§analysis
DependencyGraphAnalysis
Dependency graph analysis result

Returns

unknown
Array of package names in build order

Example

Get packages in topological order for building

const buildOrder = getTopologicalOrder(analysis)
for (const pkg of buildOrder) {
  await build(pkg)
}
§function

getTransitiveDependencies(workspace: Workspace, packageName: string): Set<string>

Gets all transitive dependencies of a package (direct and indirect).

Parameters

NameTypeDescription
§workspace
Workspace
The workspace containing projects
§packageName
string
Name of the package to analyze

Returns

Set<string>
Set of all packages this package depends on

Example

Get all transitive dependencies of a package

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

const workspace = discoverWorkspace()
const allDeps = getTransitiveDependencies(workspace, '@myorg/app')

console.log(`@myorg/app transitively depends on ${allDeps.size} packages`)
for (const dep of allDeps) {
  console.log(`  - ${dep}`)
}
§function

getTransitiveDependents(workspace: Workspace, packageName: string): Set<string>

Gets all transitive dependents of a package (direct and indirect).

Parameters

NameTypeDescription
§workspace
Workspace
The workspace containing projects
§packageName
string
Name of the package to analyze

Returns

Set<string>
Set of all packages that depend on this package

Example

Get all transitive dependents of a package

// If lib-a depends on lib-utils and app-main depends on lib-a
// Then getTransitiveDependents('lib-utils') returns ['lib-a', 'app-main']
§function

hasChangelog(projectPath: string): boolean

Checks if a project has a changelog file.

Parameters

NameTypeDescription
§projectPath
string
Directory containing the project to check

Returns

boolean
True if changelog exists

Example

Check if a project has a changelog

import { hasChangelog } from '@hyperfrontend/versioning'

if (hasChangelog('./libs/my-lib')) {
  console.log('Project has a changelog')
}
§function

hasInternalDependencies(project: Project): boolean

Checks if a project has any internal dependencies.

Parameters

NameTypeDescription
§project
Project
The project to check

Returns

boolean
True if project depends on other workspace packages

Example

Check if a project has internal dependencies

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

const project = discoverProject('./libs/my-lib')
if (project && hasInternalDependencies(project)) {
  console.log(`${project.name} depends on:`, project.internalDependencies)
}
§function

hasInternalDependents(project: Project): boolean

Checks if a project has any internal dependents.

Parameters

NameTypeDescription
§project
Project
The project to check

Returns

boolean
True if other workspace packages depend on this project

Example

Check if a project has internal dependents

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

const project = discoverProject('./libs/utils')
if (project && hasInternalDependents(project)) {
  console.log(`${project.name} is used by:`, project.internalDependents)
}
§function

hasProject(workspace: Workspace, projectName: string): boolean

Checks if a project exists in the workspace.

Parameters

NameTypeDescription
§workspace
Workspace
Workspace to search in
§projectName
string
Identifier of the project to check

Returns

boolean
True if the project exists

Example

Check if a project exists in the workspace

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

const workspace = discoverWorkspace()
if (hasProject(workspace, '@myorg/utils')) {
  console.log('Package exists in workspace')
}
§function

hasProjectChangelog(project: Project): boolean

Checks if a project has a changelog file.

Parameters

NameTypeDescription
§project
Project
The project to check

Returns

boolean
True if changelog exists

Example

Check if a project has a changelog

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

const project = discoverProject('./libs/my-lib')
if (project && !hasChangelog(project)) {
  console.log('Warning: No changelog found for', project.name)
}
§function

isPrivate(project: Project): boolean

Checks if a project is private.

Parameters

NameTypeDescription
§project
Project
The project to check

Returns

boolean
True if the project is marked as private

Example

Check if a project is private

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

const project = discoverProject('./apps/internal-app')
if (project && isPrivate(project)) {
  console.log('Skipping private package')
}
§function

isPublishable(project: Project): boolean

Checks if a project is publishable (public and has name/version).

Parameters

NameTypeDescription
§project
Project
The project to check

Returns

boolean
True if the project can be published

Example

Check if a project is publishable

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

const project = discoverProject('./libs/my-lib')
if (project && isPublishable(project)) {
  console.log(`${project.name} can be published to npm`)
}
§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

transitivelyDependsOn(workspace: Workspace, packageA: string, packageB: string): boolean

Checks if package A transitively depends on package B.

Parameters

NameTypeDescription
§workspace
Workspace
The workspace containing projects
§packageA
string
Name of the potentially dependent package
§packageB
string
Name of the potential dependency

Returns

boolean
True if packageA transitively depends on packageB

Example

Check if one package transitively depends on another

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

const workspace = discoverWorkspace()

if (transitivelyDependsOn(workspace, '@myorg/app', '@myorg/utils')) {
  console.log('Bumping @myorg/utils will affect @myorg/app')
}
§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}`)
    }
  }
}
§function

withDependents(project: Project, dependents: unknown): Project

Creates a copy of a project with updated internal dependents.

Parameters

NameTypeDescription
§project
Project
The project to update
§dependents
unknown
New list of internal dependents

Returns

Project
A new Project with updated dependents

Example

Create a project copy with updated dependents

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

const project = discoverProject('./libs/utils')
if (project) {
  const updated = withDependents(project, ['@myorg/app', '@myorg/web'])
  console.log('Updated dependents:', updated.internalDependents)
}

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

CreateProjectOptions

Options for creating a project.

Properties

§changelogPath?:string
Absolute path to CHANGELOG.md
§internalDependencies?:unknown
Names of workspace packages this project depends on
§internalDependents?:unknown
Names of workspace packages that depend on this project
§name:string
Package name
§packageJson:PackageJson
Parsed package.json content
§packageJsonPath:string
Absolute path to package.json
§path:string
Absolute path to project root
§version:string
Package version
§interface

DependencyEdge

A single dependency edge in the graph.

Properties

§readonly from:string
Package that has the dependency
§readonly to:string
Package being depended on
§readonly type:DependencyType
Type of dependency relationship
§readonly versionRange:string
Version range specified
§interface

DependencyGraphAnalysis

Result of dependency graph analysis.

Properties

§readonly circularDependencies:unknown
Detected circular dependency chains
§readonly dependencyGraph:DependencyGraph
Forward graph: package -> dependents
§readonly edges:unknown
All dependency edges
§readonly hasCircularDependencies:boolean
Whether the graph has circular dependencies
§readonly leafPackages:unknown
Packages with no dependents (leaf nodes)
§readonly reverseDependencyGraph:DependencyGraph
Reverse graph: package -> dependencies
§readonly rootPackages:unknown
Packages with no dependencies (root nodes)
§interface

DirectBumpInput

Input for calculating cascade bumps.

Properties

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

DiscoveredChangelog

Represents a discovered changelog file.

Properties

§readonly filename:string
Name of the changelog file
§readonly path:string
Absolute path to the changelog file
§readonly projectPath:string
Path to the project containing this changelog
§readonly relativePath:string
Relative path from project root
§interface

DiscoveryOptions

Options for package discovery.

Properties

§exclude?:unknown
Patterns to exclude
§includeChangelogs?:boolean
Include changelogs in discovery
§patterns?:unknown
Glob patterns for finding package.json files
§trackDependencies?:boolean
Track internal dependencies
§tree?:Tree
Optional VFS tree for VFS-aware discovery
§workspaceRoot?:string
Workspace root (auto-detected if not provided)
§interface

DiscoveryResult

Result of package discovery.

Properties

§readonly config:WorkspaceConfig
Configuration used for discovery
§readonly packageNames:ReadonlySet<string>
All discovered package names
§readonly projectMap:ReadonlyMap<string, Project>
Projects indexed by name
§readonly projects:unknown
All discovered projects
§readonly workspaceRoot:string
Workspace root path
§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

Project

A single project within a workspace.

Properties

§readonly changelogPath:string
Absolute path to CHANGELOG.md (null if not found)
§readonly internalDependencies:unknown
Names of workspace packages this project depends on
§readonly internalDependents:unknown
Names of workspace packages that depend on this project
§readonly name:string
Package name from package.json
§readonly packageJson:PackageJson
Parsed package.json content
§readonly packageJsonPath:string
Absolute path to package.json
§readonly path:string
Absolute path to project root directory
§readonly private:boolean
Whether this is a private package
§readonly publishable:boolean
Whether this is a publishable package
§readonly version:string
Package version from package.json
§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)
§interface

Workspace

Complete workspace representation. Contains all discovered projects and their relationships.

Properties

§readonly config:WorkspaceConfig
Configuration used for discovery
§readonly dependencyGraph:ReadonlyMap<string, unknown>
Dependency graph (project name -> dependents)
§readonly projectList:unknown
Projects ordered by name
§readonly projects:ReadonlyMap<string, Project>
All discovered projects indexed by name
§readonly reverseDependencyGraph:ReadonlyMap<string, unknown>
Reverse dependency graph (project name -> dependencies)
§readonly root:string
Absolute path to workspace root
§readonly type:WorkspaceType
Detected workspace type
§interface

WorkspaceConfig

Workspace configuration options.

Properties

§readonly exclude:unknown
Patterns to exclude from discovery
§readonly includeChangelogs:boolean
Whether to include changelog paths in discovery
§readonly patterns:unknown
Glob patterns for finding packages
§readonly trackDependencies:boolean
Whether to track internal dependencies

Types

§type

BumpReason

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

DependencyGraph

Dependency graph structure. Maps package name to list of packages that depend on it.
type DependencyGraph = ReadonlyMap<string, unknown>
§type

DependencyType

Dependency relation type.
type DependencyType = "dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies"
§type

WorkspaceType

Workspace type indicating the package manager / tool in use.
type WorkspaceType = "nx" | "turbo" | "lerna" | "pnpm" | "npm" | "yarn" | "rush" | "unknown"

Variables

§type

CHANGELOG_NAMES

Common changelog file names in priority order.
§type

DEFAULT_BATCH_UPDATE_OPTIONS

Default batch update options.
§type

DEFAULT_CASCADE_OPTIONS

Default cascade bump options.
§type

DEFAULT_EXCLUDE

Default exclusion patterns.
§type

DEFAULT_PATTERNS

Default workspace discovery patterns.
§type

DEFAULT_WORKSPACE_CONFIG

Default workspace configuration.