From 966399c3d82252bce748ade000cb9adeeab14b9c Mon Sep 17 00:00:00 2001 From: Ge Date: Mon, 9 Mar 2026 11:38:14 +0200 Subject: [PATCH] fix: preserve negation prefix when resolving config patterns --- src/config/tolgeerc.ts | 9 ++++++--- .../validTolgeeRc/withNegationPattern.json | 6 ++++++ test/unit/config.test.ts | 13 +++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 test/__fixtures__/validTolgeeRc/withNegationPattern.json diff --git a/src/config/tolgeerc.ts b/src/config/tolgeerc.ts index 2bfa2c8..d9402cf 100644 --- a/src/config/tolgeerc.ts +++ b/src/config/tolgeerc.ts @@ -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 diff --git a/test/__fixtures__/validTolgeeRc/withNegationPattern.json b/test/__fixtures__/validTolgeeRc/withNegationPattern.json new file mode 100644 index 0000000..b99a57c --- /dev/null +++ b/test/__fixtures__/validTolgeeRc/withNegationPattern.json @@ -0,0 +1,6 @@ +{ + "$schema": "../../../schema.json", + "apiUrl": "https://app.tolgee.io", + "projectId": 1337, + "patterns": ["./src/**/*.tsx", "!./src/excluded.tsx"] +} diff --git a/test/unit/config.test.ts b/test/unit/config.test.ts index 9d382cf..de13e9e 100644 --- a/test/unit/config.test.ts +++ b/test/unit/config.test.ts @@ -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)