import { PackageJson } from '../../_dependencies/@hyperfrontend/project-scope/project/package/index.js'; /** * A single project within a workspace. */ interface Project { /** Package name from package.json */ readonly name: string; /** Package version from package.json */ readonly version: string; /** Absolute path to project root directory */ readonly path: string; /** Absolute path to package.json */ readonly packageJsonPath: string; /** Parsed package.json content */ readonly packageJson: PackageJson; /** Absolute path to CHANGELOG.md (null if not found) */ readonly changelogPath: string | null; /** Names of workspace packages this project depends on */ readonly internalDependencies: readonly string[]; /** Names of workspace packages that depend on this project */ readonly internalDependents: readonly string[]; /** Whether this is a publishable package */ readonly publishable: boolean; /** Whether this is a private package */ readonly private: boolean; } /** * Options for creating a project. */ interface CreateProjectOptions { /** Package name */ name: string; /** Package version */ version: string; /** Absolute path to project root */ path: string; /** Absolute path to package.json */ packageJsonPath: string; /** Parsed package.json content */ packageJson: PackageJson; /** Absolute path to CHANGELOG.md */ changelogPath?: string | null; /** Names of workspace packages this project depends on */ internalDependencies?: readonly string[]; /** Names of workspace packages that depend on this project */ internalDependents?: readonly string[]; } /** * Creates a new Project object. * * @param options - Project properties * @returns A new Project object * * @example Create a new Project object * ```typescript * 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', * }) * ``` */ declare function createProject(options: CreateProjectOptions): Project; /** * Checks if a project is publishable (public and has name/version). * * @param project - The project to check * @returns True if the project can be published * * @example Check if a project is publishable * ```typescript * 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`) * } * ``` */ declare function isPublishable(project: Project): boolean; /** * Checks if a project is private. * * @param project - The project to check * @returns True if the project is marked as private * * @example Check if a project is private * ```typescript * import { discoverProject, isPrivate } from '@hyperfrontend/versioning' * * const project = discoverProject('./apps/internal-app') * if (project && isPrivate(project)) { * console.log('Skipping private package') * } * ``` */ declare function isPrivate(project: Project): boolean; /** * Checks if a project has a changelog file. * * @param project - The project to check * @returns True if changelog exists * * @example Check if a project has a changelog * ```typescript * 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) * } * ``` */ declare function hasChangelog(project: Project): boolean; /** * Checks if a project has any internal dependencies. * * @param project - The project to check * @returns True if project depends on other workspace packages * * @example Check if a project has internal dependencies * ```typescript * import { discoverProject, hasInternalDependencies } from '@hyperfrontend/versioning' * * const project = discoverProject('./libs/my-lib') * if (project && hasInternalDependencies(project)) { * console.log(`${project.name} depends on:`, project.internalDependencies) * } * ``` */ declare function hasInternalDependencies(project: Project): boolean; /** * Checks if a project has any internal dependents. * * @param project - The project to check * @returns True if other workspace packages depend on this project * * @example Check if a project has internal dependents * ```typescript * import { discoverProject, hasInternalDependents } from '@hyperfrontend/versioning' * * const project = discoverProject('./libs/utils') * if (project && hasInternalDependents(project)) { * console.log(`${project.name} is used by:`, project.internalDependents) * } * ``` */ declare function hasInternalDependents(project: Project): boolean; /** * Gets the dependency count (internal dependencies). * * @param project - Project instance to analyze * @returns Number of internal dependencies * * @example Get the dependency count for a project * ```typescript * import { discoverProject, getDependencyCount } from '@hyperfrontend/versioning' * * const project = discoverProject('./libs/my-lib') * if (project) { * console.log(`${project.name} depends on ${getDependencyCount(project)} internal packages`) * } * ``` */ declare function getDependencyCount(project: Project): number; /** * Gets the dependent count (packages that depend on this one). * * @param project - Project instance to analyze * @returns Number of internal dependents * * @example Get the dependent count for a project * ```typescript * import { discoverProject, getDependentCount } from '@hyperfrontend/versioning' * * const project = discoverProject('./libs/utils') * if (project) { * console.log(`${project.name} is used by ${getDependentCount(project)} packages`) * } * ``` */ declare function getDependentCount(project: Project): number; /** * Creates a copy of a project with updated internal dependents. * * @param project - The project to update * @param dependents - New list of internal dependents * @returns A new Project with updated dependents * * @example Create a project copy with updated dependents * ```typescript * 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) * } * ``` */ declare function withDependents(project: Project, dependents: readonly string[]): Project; /** * Creates a copy of a project with an added internal dependent. * * @param project - The project to update * @param dependent - Name of the dependent to add * @returns A new Project with the added dependent * * @example Add an internal dependent to a project * ```typescript * 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) * } * ``` */ declare function addDependent(project: Project, dependent: string): Project; /** * Workspace configuration options. */ interface WorkspaceConfig { /** Glob patterns for finding packages */ readonly patterns: readonly string[]; /** Patterns to exclude from discovery */ readonly exclude: readonly string[]; /** Whether to include changelog paths in discovery */ readonly includeChangelogs: boolean; /** Whether to track internal dependencies */ readonly trackDependencies: boolean; } /** * Workspace type indicating the package manager / tool in use. */ type WorkspaceType = 'nx' | 'turbo' | 'lerna' | 'pnpm' | 'npm' | 'yarn' | 'rush' | 'unknown'; /** * Complete workspace representation. * Contains all discovered projects and their relationships. */ interface Workspace { /** Absolute path to workspace root */ readonly root: string; /** Detected workspace type */ readonly type: WorkspaceType; /** All discovered projects indexed by name */ readonly projects: ReadonlyMap; /** Projects ordered by name */ readonly projectList: readonly Project[]; /** Configuration used for discovery */ readonly config: WorkspaceConfig; /** Dependency graph (project name -> dependents) */ readonly dependencyGraph: ReadonlyMap; /** Reverse dependency graph (project name -> dependencies) */ readonly reverseDependencyGraph: ReadonlyMap; } /** * Default workspace discovery patterns. */ declare const DEFAULT_PATTERNS: readonly string[]; /** * Default exclusion patterns. */ declare const DEFAULT_EXCLUDE: readonly string[]; /** * Default workspace configuration. */ declare const DEFAULT_WORKSPACE_CONFIG: WorkspaceConfig; /** * Creates a new workspace configuration by merging with defaults. * * @param options - Partial configuration options * @returns Complete workspace configuration * * @example Create a workspace configuration with defaults * ```typescript * import { createWorkspaceConfig } from '@hyperfrontend/versioning' * * const config = createWorkspaceConfig({ * patterns: ['packages/*', 'libs/*'], * exclude: ['node_modules', 'dist'], * }) * ``` */ declare function createWorkspaceConfig(options?: Partial): WorkspaceConfig; /** * Inputs for {@link createWorkspace}. */ interface CreateWorkspaceOptions { /** Absolute path to workspace root directory */ root: string; /** Type of workspace (nx, turbo, etc.) */ type: WorkspaceType; /** Map of project names to project objects */ projects: ReadonlyMap; /** Configuration used for workspace discovery */ config: WorkspaceConfig; /** Map of package names to their dependents */ dependencyGraph: ReadonlyMap; /** Map of package names to their dependencies */ reverseDependencyGraph: ReadonlyMap; } /** * Creates a new workspace object. * * @param options - Workspace properties * @param options.root - Absolute path to workspace root directory * @param options.type - Type of workspace (nx, turbo, etc.) * @param options.projects - Map of project names to project objects * @param options.config - Configuration used for workspace discovery * @param options.dependencyGraph - Map of package names to their dependents * @param options.reverseDependencyGraph - Map of package names to their dependencies * @returns A new Workspace object * * @example Create a new workspace object * ```typescript * 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(), * }) * ``` */ declare function createWorkspace(options: CreateWorkspaceOptions): Workspace; /** * Gets a project by name from the workspace. * * @param workspace - Workspace to search in * @param projectName - Identifier of the project to retrieve * @returns The project or undefined if not found * * @example Get a project by name from the workspace * ```typescript * import { discoverWorkspace, getProject } from '@hyperfrontend/versioning' * * const workspace = discoverWorkspace() * const project = getProject(workspace, '@myorg/utils') * if (project) { * console.log(`Version: ${project.version}`) * } * ``` */ declare function getProject(workspace: Workspace, projectName: string): Project | undefined; /** * Checks if a project exists in the workspace. * * @param workspace - Workspace to search in * @param projectName - Identifier of the project to check * @returns True if the project exists * * @example Check if a project exists in the workspace * ```typescript * import { discoverWorkspace, hasProject } from '@hyperfrontend/versioning' * * const workspace = discoverWorkspace() * if (hasProject(workspace, '@myorg/utils')) { * console.log('Package exists in workspace') * } * ``` */ declare function hasProject(workspace: Workspace, projectName: string): boolean; /** * Gets all project names in the workspace. * * @param workspace - Workspace to retrieve project names from * @returns Array of project names * * @example Get all project names in the workspace * ```typescript * import { discoverWorkspace, getProjectNames } from '@hyperfrontend/versioning' * * const workspace = discoverWorkspace() * const names = getProjectNames(workspace) * console.log(`Found ${names.length} projects:`, names) * ``` */ declare function getProjectNames(workspace: Workspace): readonly string[]; /** * Gets the count of projects in the workspace. * * @param workspace - Workspace to count projects in * @returns Number of projects * * @example Get the count of projects in the workspace * ```typescript * import { discoverWorkspace, getProjectCount } from '@hyperfrontend/versioning' * * const workspace = discoverWorkspace() * console.log(`Workspace contains ${getProjectCount(workspace)} projects`) * ``` */ declare function getProjectCount(workspace: Workspace): number; /** * Gets projects that depend on the given project. * * @param workspace - Workspace containing the dependency graph * @param projectName - Name of the dependency * @returns Array of dependent project names * * @example Get projects that depend on a given project * ```typescript * import { discoverWorkspace, getDependents } from '@hyperfrontend/versioning' * * const workspace = discoverWorkspace() * const dependents = getDependents(workspace, '@myorg/utils') * console.log(`Packages depending on @myorg/utils:`, dependents) * ``` */ declare function getDependents(workspace: Workspace, projectName: string): readonly string[]; /** * Gets projects that the given project depends on. * * @param workspace - Workspace containing the dependency graph * @param projectName - Identifier of the project to look up * @returns Array of dependency project names * * @example Get projects that the given project depends on * ```typescript * import { discoverWorkspace, getDependencies } from '@hyperfrontend/versioning' * * const workspace = discoverWorkspace() * const deps = getDependencies(workspace, '@myorg/app') * console.log(`@myorg/app depends on:`, deps) * ``` */ declare function getDependencies(workspace: Workspace, projectName: string): readonly string[]; /** * Checks if projectA depends on projectB. * * @param workspace - Workspace containing the dependency graph * @param projectA - Name of the potentially dependent project * @param projectB - Name of the potential dependency * @returns True if projectA depends on projectB * * @example Check if one project depends on another * ```typescript * 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') * } * ``` */ declare function dependsOn(workspace: Workspace, projectA: string, projectB: string): boolean; export { DEFAULT_EXCLUDE, DEFAULT_PATTERNS, DEFAULT_WORKSPACE_CONFIG, addDependent, createProject, createWorkspace, createWorkspaceConfig, dependsOn, getDependencies, getDependencyCount, getDependentCount, getDependents, getProject, getProjectCount, getProjectNames, hasChangelog, hasInternalDependencies, hasInternalDependents, hasProject, isPrivate, isPublishable, withDependents }; export type { CreateProjectOptions, Project, Workspace, WorkspaceConfig, WorkspaceType };