import type { PatternFinderOptions } from "./extractor.js"; import type { Source } from "./source.js"; import { type PatternList, type PatternCache } from "./patternList.js"; /** * Represents a set of include and exclude patterns. * These patterns are positive glob patterns. * * @see {@link ruleTest} provides the ignoring algorithm. * @see {@link ruleCompile} compiles the signed pattern. * Use this or an extractor's method to compile. * * @since 0.6.0 */ export type Rule = { /** * Provides ignored or included file and directory patterns. * * @see {@link ruleTest} provides the ignoring algorithm. * * @since 0.9.0 */ pattern: PatternList; /** * If `true`, pattern "test" will exclude file named "test". * * @see {@link ruleTest} provides the ignoring algorithm. * * @since 0.9.0 */ excludes: boolean; /** * Provides compiled ignored or included file and directory patterns. * * @see {@link ruleTest} provides the ignoring algorithm. * * @since 0.6.0 */ compiled: null | PatternCache[]; }; /** * The kind of a pattern match. * * @since 0.9.1 */ export type MatchKind = RuleMatch["kind"]; /** * @see {@link RuleMatch} * * @since 0.9.1 */ export interface RuleMatchBase { kind: K; ignored: boolean; } /** * @see {@link RuleMatch} * * @since 0.9.1 */ export interface RuleMatchBaseSource extends RuleMatchBase { source: Source; } /** * @see {@link RuleMatch} * * @since 0.9.1 */ export interface RuleMatchBasePattern extends RuleMatchBase { pattern: string; } /** * @see {@link RuleMatch} * * @since 0.11.0 */ export interface RuleMatchBaseError extends RuleMatchBase { error: Error; } /** * @see {@link RuleMatch} * * @since 0.11.0 */ export interface RuleMatchBaseInvalidSource extends RuleMatchBaseError, RuleMatchBaseSource { } /** * @see {@link RuleMatch} * * @since 0.11.0 */ export interface RuleMatchBaseInvalidPattern extends RuleMatchBasePattern, RuleMatchBaseError { } /** * @see {@link RuleMatch} * * @since 0.11.0 */ export interface RuleMatchBaseInvalidExternal extends RuleMatchBaseInvalidPattern, RuleMatchBaseSource { } /** * @see {@link RuleMatch} * * @since 0.9.1 */ export interface RuleMatchBaseExternal extends RuleMatchBasePattern, RuleMatchBaseSource { } /** * The kind of a pattern match. * * @since 0.11.0 */ export declare const enum RuleMatchKind { "none" = 0, "missingSource" = 1, "noMatch" = 2, "invalidSource" = 3, "invalidExternal" = 4, "invalidInternal" = 5, "external" = 6, "internal" = 7 } /** * @see {@link ruleTest} * * @since 0.6.0 */ export type RuleMatch = RuleMatchBase | RuleMatchBase | RuleMatchBaseSource | RuleMatchBaseInvalidSource | RuleMatchBaseInvalidExternal | RuleMatchBaseInvalidPattern | RuleMatchBaseExternal | RuleMatchBasePattern; /** * Check if a rule match is invalid. * * @since 0.11.0 */ export declare function isRuleMatchInvalid(match: RuleMatch): match is RuleMatchBaseInvalidSource | RuleMatchBaseInvalidExternal | RuleMatchBaseInvalidPattern; /** * @see {@link ruleTest} * * @since 0.6.0 */ export interface RuleTestOptions extends PatternFinderOptions { /** * Relative entry path. * * @example * "dir/subdir" * "dir/subdir/index.js" * * @since 0.6.0 */ entry: string; /** * Pre-lowercased entry path. * * @since 0.11.0 */ lowerEntry?: string; } /** * Synchronous version of {@link ruleTest}. * * @since 0.11.0 */ export declare function ruleTestSync(options: RuleTestOptions): RuleMatch; /** * Checks whether a given entry should be ignored based on internal and external patterns. * Populates unknown sources using {@link resolveSources}. * * @since 0.6.0 */ export declare function ruleTest(options: RuleTestOptions, cb: (err: Error | null, match: RuleMatch) => void): void;