Skip to content

Commit a342195

Browse files
committed
Simplify
1 parent 25027bc commit a342195

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

lib/src/normalizer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface NormalizedConfig {
3030
matcher: Matcher;
3131
fileFilter: (filepath: string) => boolean;
3232
customStrategies: Record<string, StrategyFn>;
33+
includeNonConflicted: boolean;
3334
}
3435

3536
/** Defaults */
@@ -100,6 +101,7 @@ export const normalizeConfig = async <T extends string = BasicMergeStrategies>(
100101
matcher,
101102
fileFilter,
102103
customStrategies: config.customStrategies ?? {},
104+
includeNonConflicted: config.includeNonConflicted ?? false,
103105
};
104106
};
105107

lib/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ export interface Config<T extends string = BasicMergeStrategies, TContext = unkn
6565

6666
/** Glob matcher: `"micromatch"`, `"picomatch"`, or custom implementation */
6767
matcher?: "micromatch" | "picomatch" | Matcher;
68+
69+
/**
70+
* Whether to include files that do not contain conflicts.
71+
* Useful for applying strategies, e.g., drop even when conflicts aren’t present.
72+
* Defaults to `false`.
73+
*/
74+
includeNonConflicted?: boolean;
6875
}
6976

7077
export type { Matcher };

lib/src/utils.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fs from "node:fs/promises";
22
import path from "node:path";
3-
import { NormalizedConfig } from "./normalizer";
43

54
/**
65
* Checks whether the given file contains Git merge conflict markers.
@@ -23,9 +22,13 @@ const hasConflict = async (filePath: string): Promise<boolean> => {
2322
export interface CollectFilesOptions {
2423
/** Root directory to start traversal (defaults to `process.cwd()`). */
2524
root?: string;
25+
26+
/** Function used to decide if a file should be considered at all. */
27+
fileFilter: (filePath: string) => boolean;
28+
2629
/**
27-
* Include files that match `fileFilter` even if they do not contain
28-
* merge conflicts. Defaults to `false`.
30+
* Whether to include files even if they don’t contain conflicts.
31+
* Defaults to `false`.
2932
*/
3033
includeNonConflicted?: boolean;
3134
}
@@ -35,17 +38,14 @@ export interface CollectFilesOptions {
3538
*
3639
* - By default, only conflicted files are returned.
3740
* - If `includeNonConflicted` is enabled, matching files are always included
38-
* (skipping conflict check).
41+
* (conflict check is skipped).
3942
*
40-
* @param config - Normalized configuration containing `fileFilter`.
41-
* @param options - Behavior flags (e.g., `includeNonConflicted`).
43+
* @param options - Collection options, including `fileFilter` and traversal root.
4244
* @returns A promise that resolves with an array of matching file paths.
4345
*/
44-
export const collectFiles = async (
45-
config: NormalizedConfig,
46-
options: CollectFilesOptions = {},
47-
): Promise<string[]> => {
48-
const { root = process.cwd(), includeNonConflicted = false } = options;
46+
export const collectFiles = async (options: CollectFilesOptions): Promise<string[]> => {
47+
const { root = process.cwd(), fileFilter, includeNonConflicted = false } = options;
48+
4949
const allFiles: string[] = [];
5050

5151
/**
@@ -62,15 +62,13 @@ export const collectFiles = async (
6262

6363
if (entry.isDirectory()) {
6464
await walk(fullPath);
65-
} else if (config.fileFilter(fullPath)) {
65+
} else if (fileFilter(fullPath)) {
6666
if (includeNonConflicted) {
6767
allFiles.push(fullPath);
68+
} else if (await hasConflict(fullPath)) {
69+
allFiles.push(fullPath);
6870
} else {
69-
if (await hasConflict(fullPath)) {
70-
allFiles.push(fullPath);
71-
} else {
72-
console.info(`Skipped (no conflicts): ${fullPath}`);
73-
}
71+
console.info(`Skipped (no conflicts): ${fullPath}`);
7472
}
7573
}
7674
}

0 commit comments

Comments
 (0)