feat: add .nanocoderignore file support - #881
Conversation
There was a problem hiding this comment.
Pull request overview
Adds workspace-level support for an optional .nanocoderignore file, extending the existing ignore-pattern loader so Nanocoder can exclude tracked-but-unwanted files from AI context without changing Git ignore rules.
Changes:
- Extend
loadGitignore()to also read and merge patterns from.nanocoderignore(additive with defaults and.gitignore). - Add AVA tests covering
.nanocoderignore-only, merged.gitignore+.nanocoderignore, and missing-file scenarios. - Document
.nanocoderignorebehavior in the file explorer docs and add a changeset entry.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| source/utils/gitignore-loader.ts | Loads .nanocoderignore in addition to .gitignore and default ignore directories. |
| source/utils/gitignore-loader.spec.ts | Adds tests for .nanocoderignore loading and merging behavior. |
| docs/features/file-explorer.md | Documents .nanocoderignore support and intended use cases. |
| .changeset/clear-boats-rhyme.md | Changelog entry for the new .nanocoderignore feature. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| * @param cwd - The current working directory to load .gitignore / .nanocoderignore from | ||
| * @returns An ignore instance configured with patterns | ||
| */ | ||
| export function loadGitignore(cwd: string): ReturnType<typeof ignore> { | ||
| const ig = ignore(); | ||
| const gitignorePath = join(cwd, '.gitignore'); | ||
| const nanocoderignorePath = join(cwd, '.nanocoderignore'); |
| test.serial('loadGitignore works without .nanocoderignore file', async t => { | ||
| const testDir = join(process.cwd(), 'test-no-nanocoderignore-temp'); | ||
|
|
||
| try { | ||
| mkdirSync(testDir, {recursive: true}); | ||
| // No .nanocoderignore file | ||
|
|
||
| const ig = loadGitignore(testDir); | ||
|
|
||
| // Should still have default ignores and not throw | ||
| t.true(ig.ignores('node_modules/file.js')); | ||
| t.false(ig.ignores('src/file.ts')); | ||
| } finally { | ||
| rmSync(testDir, {recursive: true, force: true}); | ||
| } | ||
| }); |
|
|
akramcodez
left a comment
There was a problem hiding this comment.
Hey @A-S-Manoj, this looks good overall! I checked the implementation, tests, docs, and the existing call sites, and the overall approach is clean and nicely scoped.
There are just two small gaps I'd like you to address before we merge:
-
Read-error test: Please add a test for the
.nanocoderignoreread-error path. For example, you can make.nanocoderignorea directory soreadFileSyncthrows, then verify thatloadGitignore()still returns a working ignore instance. Since the implementation intentionally fails silently here, it'd be good to have a regression test for that behavior. -
Minor naming cleanup: Since the parameter represents the workspace root rather than an arbitrary current working directory, please consider renaming
cwdtoworkspaceRootinloadGitignore()and its JSDoc. This isn't a correctness issue, just a small readability improvement.
Other than these minor gaps, everything looks good to me. Nice work!
Closes #755
Description
Adds support for an optional
.nanocoderignorefile at the workspace root. Patterns in it are merged into the sameignoreinstance used for.gitignore, additively — nothing already ignored stops being ignored, and this doesn't replace.gitignorehandling.This lets you keep files tracked in git (e.g.
package-lock.json, generated fixtures,.env) while still excluding them from what the AI reads, saving tokens and avoiding context bloat, without touching your actual git ignore rules.loadGitignore()insource/utils/gitignore-loader.tswas extended to also look for.nanocoderignoreincwdand add its contents on top of the existing.gitignore+ default ignores. Function name and return type are unchanged, so all 5 existing call sites work with no changes. Read failures on.nanocoderignorefail silently, matching existing.gitignoreerror handling.Type of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Added 3 new test cases to
gitignore-loader.spec.ts:.nanocoderignorealone,.gitignore+.nanocoderignoretogether, and neither file present (no-op, no throw).Manual Testing
Not applicable — this change is isolated to file-ignore pattern matching and doesn't touch provider/model code paths.
Checklist