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
5 changes: 5 additions & 0 deletions .changeset/eighty-dots-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

effectively discard files matched by pattern if already mentioned
3 changes: 2 additions & 1 deletion packages/myst-cli/src/project/fromTOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
16 changes: 16 additions & 0 deletions packages/myst-cli/src/project/toc.pattern.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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', () => {
Expand Down