diff --git a/.changeset/eighty-dots-train.md b/.changeset/eighty-dots-train.md new file mode 100644 index 000000000..169bdc7cb --- /dev/null +++ b/.changeset/eighty-dots-train.md @@ -0,0 +1,5 @@ +--- +'myst-cli': patch +--- + +effectively discard files matched by pattern if already mentioned diff --git a/packages/myst-cli/src/project/fromTOC.ts b/packages/myst-cli/src/project/fromTOC.ts index 6ad01d00d..dd5bfb75c 100644 --- a/packages/myst-cli/src/project/fromTOC.ts +++ b/packages/myst-cli/src/project/fromTOC.ts @@ -120,7 +120,8 @@ export function patternsToFileEntries( const { pattern, sort, ...leftover } = entry as PatternEntry; // Glob matches, relative to `path`, ordered naturally let matches = globSync(pattern, { cwd: path, nodir: true, ...opts }) - .filter((item) => !ignore || !ignore.includes(item)) + // ignore contains resolved entries, so we need to search for item resolved + .filter((item) => !ignore || !ignore.includes(resolve(path, item))) .sort(comparePaths); // Reverse order if descending sort is requested if (sort === 'descending') { diff --git a/packages/myst-cli/src/project/toc.pattern.spec.ts b/packages/myst-cli/src/project/toc.pattern.spec.ts index 6d6c7cd14..ecc5b25e6 100644 --- a/packages/myst-cli/src/project/toc.pattern.spec.ts +++ b/packages/myst-cli/src/project/toc.pattern.spec.ts @@ -1,4 +1,5 @@ import { describe, expect, it, beforeEach, vi } from 'vitest'; +import { resolve } from 'node:path'; import memfs from 'memfs'; import { Session } from '../session'; import { listExplicitFiles, patternsToFileEntries } from './fromTOC'; @@ -141,6 +142,21 @@ describe('patternsToFileEntries', () => { { file: 'meetings/2026-01-01.md', implicit: true }, ]); }); + it('explicitly listed files are excluded from subsequent glob patterns', () => { + memfs.vol.fromJSON({ + 'index.md': '', + 'test1.md': '', + 'test2.md': '', + }); + // Simulate ignore list built from explicit file entries (absolute paths, as listExplicitFiles returns) + const cwd = '.'; + const ignore = [resolve(cwd, 'index.md'), resolve(cwd, 'test1.md')]; + expect( + patternsToFileEntries(session, [{ pattern: '*.md' }], cwd, ignore, '/tmp/warn.txt', { + fs: memfs, + }), + ).toEqual([{ file: 'test2.md', implicit: true }]); + }); }); describe('listExplicitFiles', () => {