Skip to content

Commit df062c3

Browse files
committed
docs(changeset): Fix logger
1 parent 40362dc commit df062c3

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

.changeset/hip-lions-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"git-json-resolver": patch
3+
---
4+
5+
Fix logger

lib/src/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const createLogger = async (config: LoggerConfig = {}) => {
7070
const lines = entries.map(
7171
e => `[${e.timestamp}] [${e.level.toUpperCase()}] ${e.message}`,
7272
);
73+
await fsPromises.mkdir(path.dirname(filePath), { recursive: true });
7374
await fsPromises.appendFile(filePath, lines.join("\n") + "\n");
7475
} catch (error) {
7576
/* v8 ignore next 2 -- logs only */

lib/src/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface FileEntry {
99

1010
/** Sentinel used to explicitly drop a value. */
1111
export const DROP = Symbol("MERGE_DROP");
12+
export const DEFAULT_BACKUP_DIR = ".merge-backups";
1213

1314
/**
1415
* Checks whether the given file contains Git merge conflict markers.
@@ -44,13 +45,15 @@ export const listMatchingFiles = async ({
4445
matcher,
4546
includeNonConflicted,
4647
debug,
47-
backupDir,
48+
backupDir = DEFAULT_BACKUP_DIR,
4849
}: CollectFilesOptions): Promise<FileEntry[]> => {
4950
for (const p of [...include, ...exclude]) {
5051
if (p.startsWith("!")) throw new Error(`Negation not allowed in include/exclude: ${p}`);
5152
if (p.includes("\\")) console.warn(`Use '/' as path separator: ${p}`);
5253
}
5354

55+
exclude.push(backupDir);
56+
5457
const fileMatcher = (filepath: string) => {
5558
const posixPath = filepath.replace(/\\/g, "/");
5659
return matcher.isMatch(posixPath, include) && !matcher.isMatch(posixPath, exclude);
@@ -149,7 +152,7 @@ export const createSkipDirectoryMatcher = (
149152
};
150153
};
151154

152-
export const backupFile = async (filePath: string, backupDir = ".merge-backups") => {
155+
export const backupFile = async (filePath: string, backupDir: string) => {
153156
const relPath = path.relative(process.cwd(), filePath);
154157
const backupPath = path.join(backupDir, relPath);
155158

0 commit comments

Comments
 (0)