diff --git a/packages/rstack/src/fmt/ignore.ts b/packages/rstack/src/fmt/ignore.ts index bc814a5..1405de2 100644 --- a/packages/rstack/src/fmt/ignore.ts +++ b/packages/rstack/src/fmt/ignore.ts @@ -9,7 +9,7 @@ import type { ResolvedFmtConfig } from './types.ts'; * Prettier already skips other generated lock files when it cannot infer a parser, so this list * contains only the additional defaults owned by `rs fmt`. */ -const defaultIgnorePatterns = ['package-lock.json', 'pnpm-lock.yaml']; +const defaultIgnoreNames = ['package-lock.json', 'pnpm-lock.yaml']; type IgnoreMatcher = (filePath: string, isDirectory?: boolean) => boolean; @@ -20,6 +20,12 @@ interface CreateIgnoreMatcherOptions { ignorePaths?: string[]; } +const createDefaultIgnoreMatcher = (): IgnoreMatcher => { + const suffixes = defaultIgnoreNames.map((name) => `${path.sep}${name}`); + + return (filePath) => suffixes.some((suffix) => filePath.endsWith(suffix)); +}; + const createPatternMatcher = (rootPath: string, patterns: string): IgnoreMatcher => { const matcher = createIgnore({ allowRelativePaths: true }).add(patterns); const rootPrefix = rootPath.endsWith(path.sep) ? rootPath : `${rootPath}${path.sep}`; @@ -58,10 +64,12 @@ const createIgnoreMatcher = async ({ cwd, ignorePaths = [], }: CreateIgnoreMatcherOptions): Promise => { - const configMatcher = createPatternMatcher( - config.rootPath, - [...defaultIgnorePatterns, ...config.ignorePatterns].join('\n'), - ); + const configMatcher = config.ignorePatterns.length + ? createPatternMatcher( + config.rootPath, + [...defaultIgnoreNames, ...config.ignorePatterns].join('\n'), + ) + : createDefaultIgnoreMatcher(); if (ignorePaths.length === 0) { return configMatcher; } diff --git a/packages/rstack/tests/fmt/ignore.test.ts b/packages/rstack/tests/fmt/ignore.test.ts index 5826767..1d03361 100644 --- a/packages/rstack/tests/fmt/ignore.test.ts +++ b/packages/rstack/tests/fmt/ignore.test.ts @@ -64,6 +64,9 @@ test('ignores common lock files by default and allows explicit negation', async expect(isIgnored(path.join(rootPath, 'package-lock.json'))).toBe(true); expect(isIgnored(path.join(rootPath, 'packages/app/pnpm-lock.yaml'))).toBe(true); + expect(isIgnored(path.join(rootPath, 'packages/app/PNPM-LOCK.YAML'))).toBe(false); + expect(isIgnored(path.join(rootPath, '../shared/pnpm-lock.yaml'))).toBe(true); + expect(isIgnored(path.join(rootPath, 'pnpm-lock.yaml.backup'))).toBe(false); expect(isIgnoredAfterReinclude(path.join(rootPath, 'pnpm-lock.yaml'))).toBe(false); });