json-conflict-resolver
Version:
A rules-based JSON conflict resolver that parses Git conflict markers, reconstructs ours/theirs, and merges with deterministic strategies — beyond line-based merges.
45 lines (44 loc) • 2.07 kB
TypeScript
import { NormalizedConfig } from "./normalizer";
export interface FileEntry {
filePath: string;
content: string;
}
/** Sentinel used to explicitly drop a value. */
export declare const DROP: unique symbol;
export declare const DEFAULT_BACKUP_DIR = ".merge-backups";
/**
* Status codes returned by strategy functions.
* Using individual constants for optimal bundle size.
*/
export declare const StrategyStatus_OK: 0;
export declare const StrategyStatus_CONTINUE: 1;
export declare const StrategyStatus_FAIL: 2;
export declare const StrategyStatus_SKIP: 3;
/**
* Checks whether the given file contains Git merge conflict markers.
*
* @param content - File content to check.
* @returns `true` if conflict markers exist, otherwise `false`.
*/
export declare const hasConflict: (content: string) => boolean;
export type CollectFilesOptions = Pick<NormalizedConfig, "include" | "exclude" | "matcher" | "includeNonConflicted" | "debug" | "backupDir"> & {
/** Root directory to start traversal (defaults to `process.cwd()`). */
root?: string;
};
/**
* Recursively collects files that match the provided `fileFilter`.
*
* - By default, only conflicted files are returned.
* - If `includeNonConflicted` is enabled, matching files are always included.
*
* @param options - Collection options, including `fileFilter` and traversal root.
* @returns A promise that resolves with an array of `{ filePath, content }`.
*/
export declare const listMatchingFiles: ({ root, include, exclude, matcher, includeNonConflicted, debug, backupDir, }: CollectFilesOptions) => Promise<FileEntry[]>;
/**
* Derive directory pruning patterns from include/exclude rules.
* These patterns are used to avoid walking unnecessary directories.
*/
export declare const createSkipDirectoryMatcher: (include: string[], exclude: string[], matcher: NormalizedConfig["matcher"]) => (dirPath: string) => boolean;
export declare const backupFile: (filePath: string, backupDir?: string) => Promise<string>;
export declare const restoreBackups: (backupDir?: string) => Promise<void>;