Skip to content
Open
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
9 changes: 6 additions & 3 deletions src/config/tolgeerc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ function parseConfig(input: Schema, configDir: string) {

// convert relative paths in config to absolute
if (rc.patterns !== undefined) {
rc.patterns = rc.patterns.map((pattern: string) =>
resolve(configDir, pattern).replace(/\\/g, '/')
);
rc.patterns = rc.patterns.map((pattern: string) => {
const isNegated = pattern.startsWith('!');
const raw = isNegated ? pattern.slice(1) : pattern;
const resolved = resolve(configDir, raw).replace(/\\/g, '/');
return isNegated ? `!${resolved}` : resolved;
});
}

// convert relative paths in config to absolute
Expand Down
6 changes: 6 additions & 0 deletions test/__fixtures__/validTolgeeRc/withNegationPattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "../../../schema.json",
"apiUrl": "https://app.tolgee.io",
"projectId": 1337,
"patterns": ["./src/**/*.tsx", "!./src/excluded.tsx"]
}
13 changes: 13 additions & 0 deletions test/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ describe('.tolgeerc', () => {
}
});

it('preserves negation prefix when resolving patterns', async () => {
const path = fileURLToPath(
new URL('./validTolgeeRc/withNegationPattern.json', FIXTURES_PATH)
);

const cfg = (await loadTolgeeRc(path))!;

expect(cfg.patterns!.some((p) => p.startsWith('!'))).toBe(true);
for (const pattern of cfg.patterns!) {
expect(pattern.lastIndexOf('!')).toBeLessThanOrEqual(0);
}
});

it('converts projectId to number', async () => {
const path = fileURLToPath(
new URL('./validTolgeeRc/withProjectIdString.json', FIXTURES_PATH)
Expand Down