import type { PolicyDefinition } from "../policy.js"; /** * A FluidFramework build-tools policy handler interface. * * This interface matches the `Handler` interface from `@fluidframework/build-tools`. * * @alpha */ export interface FluidHandler { /** * The name of the handler, used for filtering and display. */ name: string; /** * A regex pattern that determines which files this handler applies to. */ match: RegExp; /** * The handler function that checks a file against the policy. * * @param file - Absolute path to the file. * @param root - Path to the repo root. * @returns `undefined` if the check passes, otherwise an error message string. */ handler: (file: string, root: string) => Promise; /** * Optional resolver function that attempts to fix policy violations. * * @param file - Absolute path to the file. * @param root - Path to the repo root. * @returns An object indicating whether the fix was successful. */ resolver?: (file: string, root: string) => Promise<{ resolved: boolean; message?: string; }> | { resolved: boolean; message?: string; }; } /** * Options for converting FluidFramework handlers to repopo policies. * * @alpha */ export interface FluidAdapterOptions { /** * Optional prefix to add to policy names. Useful for namespacing Fluid policies. * * @example "Fluid:" would result in "Fluid:my-handler-name" */ namePrefix?: string; } /** * Converts FluidFramework handlers to repopo PolicyDefinitions. * * This adapter bridges the gap between FluidFramework's build-tools policy system * and repopo's policy system, allowing you to reuse existing Fluid policies in repopo. * * @remarks * * Key differences handled by this adapter: * * - **Handler signature**: Fluid uses `(file, root) => string | undefined`, * repopo uses `(args) => PolicyHandlerResult` * * - **File paths**: Fluid passes absolute paths, repopo passes repo-relative paths. * The adapter converts between the two. * * - **Return types**: Fluid returns `string | undefined` (error message or success), * repopo returns `true | PolicyFailure | PolicyFixResult` * * For a single handler, wrap it in an array: `fromFluidHandlers([handler])`. * * @example * ```typescript * import { fromFluidHandlers, makePolicy } from "repopo"; * import { copyrightFileHeaderHandlers, fluidCaseHandler } from "@fluidframework/build-tools"; * * // Convert multiple handlers with a namespace prefix * const FluidCopyrightPolicies = fromFluidHandlers(copyrightFileHeaderHandlers, { * namePrefix: "Fluid:", * }); * * // For a single handler, wrap it in an array * const [FluidCasePolicy] = fromFluidHandlers([fluidCaseHandler]); * * const config: RepopoConfig = { * policies: [ * ...FluidCopyrightPolicies.map(p => makePolicy(p)), * makePolicy(FluidCasePolicy), * ], * }; * ``` * * @param fluidHandlers - An array of FluidFramework Handler objects to convert. * @param options - Optional configuration applied to all conversions. * @returns An array of repopo PolicyDefinitions. * * @alpha */ export declare function fromFluidHandlers(fluidHandlers: FluidHandler[], options?: FluidAdapterOptions): PolicyDefinition[]; //# sourceMappingURL=fluidFramework.d.ts.map