Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ Here's an explanation of the configuration options:

Example configuration:

```json
```json5
{
"output": {
"filePath": "repomix-output.xml",
Expand All @@ -389,6 +389,7 @@ Example configuration:
"ignore": {
"useGitignore": true,
"useDefaultPatterns": true,
// Patterns can also be specified in .repomixignore
"customPatterns": ["additional-folder", "**/*.log"]
},
"security": {
Expand Down
5 changes: 5 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@
"trailingCommas": "all",
"semicolons": "always"
}
},
"json": {
"parser": {
"allowComments": true
}
}
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"p-map": "^7.0.3",
"picocolors": "^1.1.1",
"strip-comments": "^2.0.1",
"strip-json-comments": "^5.0.1",
"tiktoken": "^1.0.18",
"zod": "^3.24.1"
},
Expand Down
1 change: 1 addition & 0 deletions repomix.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"ignore": {
"useGitignore": true,
"useDefaultPatterns": true,
// ignore is specified in .repomixignore
"customPatterns": []
},
"security": {
Expand Down
3 changes: 2 additions & 1 deletion src/config/configLoad.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'node:fs/promises';
import path from 'node:path';
import stripJsonComments from 'strip-json-comments';
import { z } from 'zod';
import { RepomixError, rethrowValidationErrorIfZodError } from '../shared/errorHandle.js';
import { logger } from '../shared/logger.js';
Expand Down Expand Up @@ -67,7 +68,7 @@ export const loadFileConfig = async (rootDir: string, argConfigPath: string | nu
const loadAndValidateConfig = async (filePath: string): Promise<RepomixConfigFile> => {
try {
const fileContent = await fs.readFile(filePath, 'utf-8');
const config = JSON.parse(fileContent);
const config = JSON.parse(stripJsonComments(fileContent));
Comment thread
yamadashy marked this conversation as resolved.
return repomixConfigFileSchema.parse(config);
} catch (error) {
rethrowValidationErrorIfZodError(error, 'Invalid config schema');
Expand Down
22 changes: 22 additions & 0 deletions tests/config/configLoad.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ describe('configLoad', () => {

await expect(loadFileConfig(process.cwd(), 'test-config.json')).rejects.toThrow('Invalid JSON');
});

test('should parse config file with comments', async () => {
const configWithComments = `{
// Output configuration
"output": {
"filePath": "test-output.txt"
},
/* Ignore configuration */
"ignore": {
"useGitignore": true // Use .gitignore file
}
}`;

vi.mocked(fs.readFile).mockResolvedValue(configWithComments);
vi.mocked(fs.stat).mockResolvedValue({ isFile: () => true } as Stats);

const result = await loadFileConfig(process.cwd(), 'test-config.json');
expect(result).toEqual({
output: { filePath: 'test-output.txt' },
ignore: { useGitignore: true },
});
});
});

describe('mergeConfigs', () => {
Expand Down