/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { IFluidCompatibilityMetadata, Logger } from "@fluidframework/build-tools"; /** * Approximate month as 33 days to add some buffer and avoid over-counting months in longer spans. */ export declare const DAYS_IN_MONTH_APPROXIMATION = 33; /** * Default minimum compatibility window in months that is supported across all Fluid layers. */ export declare const DEFAULT_MINIMUM_COMPAT_WINDOW_MONTHS = 3; /** * Default directory where the generation file is located. */ export declare const DEFAULT_GENERATION_DIR = "./src"; /** * Default name of the generation file. */ export declare const DEFAULT_GENERATION_FILE_NAME = "layerGenerationState.ts"; /** * Determines if the current package version represents a patch release. * * @param pkgVersion - The semantic version of the package (e.g., "2.0.1") * @returns True if the version is a patch release, false otherwise * * @throws Error When the provided version string is not a valid semantic version * * @example * ```typescript * isCurrentPackageVersionPatch("2.0.1"); // returns true * isCurrentPackageVersionPatch("2.1.0"); // returns false * isCurrentPackageVersionPatch("3.0.0"); // returns false * ``` */ export declare function isCurrentPackageVersionPatch(pkgVersion: string): boolean; /** * Generates the complete content for a layer generation TypeScript file. * * Creates a properly formatted TypeScript file with copyright header, autogenerated warning, * and export for generation number. * * @param generation - The layer compatibility generation number * @returns The complete file content as a string ready to be written to disk * * @example * ```typescript * const content = generateLayerFileContent(5); * // Returns a complete TypeScript file with exports: * // export const generation = 5; * ``` */ export declare function generateLayerFileContent(generation: number): string; /** * Determines if a new generation should be generated based on package version changes and time since * the last release. * * This function decides whether to increment the generation number based on: * 1. Whether the package version has changed since the last update * 2. How much time has elapsed since the previous release date * 3. The minimum compatibility window constraints * * The generation increment is calculated as the number of months since the previous release, * but capped at (minimumCompatWindowMonths - 1) to maintain compatibility requirements. * * @param currentPkgVersion - The current package version to compare against the stored version * @param fluidCompatMetadata - The existing Fluid compatibility metadata, or an empty object for newly opted-in packages * @param minimumCompatWindowMonths - The minimum number of months of compatibility to maintain across layers * @param log - Optional logger instance for verbose output about the calculation process * @returns The new generation number if an update is needed, or undefined if no update is required * * @throws Error When the current date is older than the previous release date */ export declare function maybeGetNewGeneration(currentPkgVersion: string, fluidCompatMetadata: IFluidCompatibilityMetadata | Record, minimumCompatWindowMonths: number, log?: Logger): number | undefined; /** * Result of checking a package's compat layer generation status. */ export type LayerCompatCheckResult = { /** * Package does not need updates. */ needsUpdate: false; needsDeletion: false; } | { /** * Package needs updates to its layer generation metadata or files. */ needsUpdate: true; needsDeletion: false; /** * Reason why the package needs an update. */ reason: string; /** * The new generation number to write. */ newGeneration: number; } | { /** * Package is not opted in but has an orphaned generation file that should be deleted. */ needsUpdate: false; needsDeletion: true; /** * Reason why the file should be deleted. */ reason: string; /** * Path to the file that should be deleted. */ filePath: string; }; /** * Checks if a package needs compat layer generation metadata updates. * * This is a lenient check - packages without metadata or generation files are considered * as not needing updates (they are skipped). This implements an opt-in model where packages * must have `fluidCompatMetadata` in their package.json to be checked. * * Note: This check always uses the provided parameters (or defaults). Individual packages * may use different parameters when running the generate command directly, which could * cause false positives/negatives. This is an accepted limitation for the common case. * * @param pkg - The package to check * @param generationDir - Directory where the generation file is located * @param generationFileName - Name of the generation file * @param minimumCompatWindowMonths - Minimum compatibility window in months * @param log - Optional logger for verbose output * @returns Result indicating if the package needs updates and why */ export declare function checkPackageCompatLayerGeneration(pkg: { version: string; packageJson: { fluidCompatMetadata?: IFluidCompatibilityMetadata; }; directory: string; }, generationDir: string, generationFileName: string, minimumCompatWindowMonths: number, log?: Logger): Promise; /** * Result of checking multiple packages' layer compatibility generation status. */ export interface MultiPackageLayerCompatCheckResult { /** * Packages that need updates with their reasons. */ packagesNeedingUpdate: { /** * The package that needs an update. */ pkg: { name: string; version: string; packageJson: { fluidCompatMetadata?: IFluidCompatibilityMetadata; }; directory: string; }; /** * Reason why the package needs an update. */ reason: string; }[]; /** * Packages with orphaned generation files that should be deleted. */ packagesNeedingDeletion: { /** * The package with an orphaned file. */ pkg: { name: string; directory: string; }; /** * Reason why the file should be deleted. */ reason: string; /** * Path to the file that should be deleted. */ filePath: string; }[]; } /** * Checks if multiple packages need compat layer generation metadata updates. * * This implements an opt-in model where packages must have `fluidCompatMetadata` * in their package.json to be checked. Packages without metadata but with orphaned * generation files will be flagged for deletion. * * @param packages - The packages to check * @param generationDir - Directory where the generation file is located * @param generationFileName - Name of the generation file * @param minimumCompatWindowMonths - Minimum compatibility window in months * @param log - Optional logger for verbose output * @returns Result containing packages that need updates or deletion */ export declare function checkPackagesCompatLayerGeneration(packages: Iterable<{ name: string; version: string; packageJson: { fluidCompatMetadata?: IFluidCompatibilityMetadata; }; directory: string; }>, generationDir: string, generationFileName: string, minimumCompatWindowMonths: number, log?: Logger): Promise; /** * Writes the compat layer generation update for a package. * * This function performs the actual update - writing the new metadata to package.json * and the generation file. Call this after `checkPackageCompatLayerGeneration` returns * `needsUpdate: true`. * * @param pkg - The package to update * @param newGeneration - The new generation number to write * @param generationDir - Directory where the generation file is located * @param generationFileName - Name of the generation file */ export declare function writePackageCompatLayerGeneration(pkg: { version: string; directory: string; }, newGeneration: number, generationDir: string, generationFileName: string): Promise; /** * Deletes an orphaned compat layer generation file. * * Call this after `checkPackageCompatLayerGeneration` returns `needsDeletion: true`. * * @param filePath - Path to the file to delete */ export declare function deleteCompatLayerGenerationFile(filePath: string): Promise; /** * Formats an error message for packages that need compat layer generation updates. * * @param packagesNeedingUpdate - Array of packages that need updates with their reasons * @param releaseGroup - Optional release group name to include in fix command * @returns Object with formatted message and fix command */ export declare function formatCompatLayerGenerationError(packagesNeedingUpdate: { pkg: { name: string; }; reason: string; }[], releaseGroup?: string): { message: string; fixCommand: string; }; //# sourceMappingURL=compatLayerGeneration.d.ts.map