Skip to content

Commit 5bf19d8

Browse files
committed
Fix .rooignore not working for .next folders in nested projects
Fixes #4647 The issue was that the listFiles function was using a blanket '.*' pattern to exclude all hidden directories (directories starting with a dot) at the ripgrep level, before the RooIgnoreController could process them. This meant that .next folders were being filtered out during file discovery, preventing the .rooignore patterns from working correctly for these directories. Changes: - Replaced the generic '.*' pattern in DIRS_TO_IGNORE with specific patterns for common hidden directories (.git, .svn, .hg, .bzr, .vscode, .idea) - Removed special handling for the '.*' pattern in directory filtering logic - Added test case to verify .next folders can now be properly controlled via .rooignore This allows users to specify patterns like 'example-nextjs/.next/' in their .rooignore file and have them work as expected, while still filtering out common hidden directories that should typically be ignored.
1 parent ca0338a commit 5bf19d8

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/core/ignore/__tests__/RooIgnoreController.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,33 @@ describe("RooIgnoreController", () => {
215215
expect(emptyController.validateAccess("secrets/api-keys.json")).toBe(true)
216216
expect(emptyController.validateAccess(".git/HEAD")).toBe(true)
217217
})
218+
219+
/**
220+
* Tests the specific scenario from GitHub issue #4647
221+
* where .next folders should be properly ignored when specified in .rooignore
222+
*/
223+
it("should correctly ignore .next folders in nested projects (GitHub issue #4647)", async () => {
224+
// Setup .rooignore content that matches the GitHub issue scenario
225+
mockFileExists.mockResolvedValue(true)
226+
mockReadFile.mockResolvedValue("example-nextjs/.next/")
227+
await controller.initialize()
228+
229+
// Test files that should be ignored (in example-nextjs/.next/)
230+
expect(controller.validateAccess("example-nextjs/.next/static/chunks/main.js")).toBe(false)
231+
expect(controller.validateAccess("example-nextjs/.next/build-manifest.json")).toBe(false)
232+
expect(controller.validateAccess("example-nextjs/.next/server/pages/index.js")).toBe(false)
233+
234+
// Test files that should be allowed
235+
expect(controller.validateAccess("example-nextjs/src/app.js")).toBe(true)
236+
expect(controller.validateAccess("example-nextjs/package.json")).toBe(true)
237+
expect(controller.validateAccess("other-project/.next/file.js")).toBe(true)
238+
expect(controller.validateAccess(".next/standalone-file.js")).toBe(true)
239+
240+
// Test that .git and .vscode are still handled by explicit ignore in listFiles
241+
// (these should be allowed by RooIgnoreController since they're not in this .rooignore)
242+
expect(controller.validateAccess(".git/config")).toBe(true)
243+
expect(controller.validateAccess(".vscode/settings.json")).toBe(true)
244+
})
218245
})
219246

220247
describe("validateCommand", () => {

src/services/glob/list-files.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ const DIRS_TO_IGNORE = [
2626
"deps",
2727
"pkg",
2828
"Pods",
29-
".*",
29+
".git",
30+
".svn",
31+
".hg",
32+
".bzr",
33+
".vscode",
34+
".idea",
3035
]
3136

3237
/**
@@ -156,14 +161,9 @@ function buildNonRecursiveArgs(): string[] {
156161

157162
// Apply directory exclusions for non-recursive searches
158163
for (const dir of DIRS_TO_IGNORE) {
159-
if (dir === ".*") {
160-
// For hidden files/dirs in non-recursive mode
161-
args.push("-g", "!.*")
162-
} else {
163-
// Direct children only
164-
args.push("-g", `!${dir}`)
165-
args.push("-g", `!${dir}/**`)
166-
}
164+
// Direct children only
165+
args.push("-g", `!${dir}`)
166+
args.push("-g", `!${dir}/**`)
167167
}
168168

169169
return args
@@ -237,11 +237,6 @@ async function listFilteredDirectories(
237237
* Determine if a directory should be included in results based on filters
238238
*/
239239
function shouldIncludeDirectory(dirName: string, recursive: boolean, gitignorePatterns: string[]): boolean {
240-
// Skip hidden directories if configured to ignore them
241-
if (dirName.startsWith(".") && DIRS_TO_IGNORE.includes(".*")) {
242-
return false
243-
}
244-
245240
// Check against explicit ignore patterns
246241
if (isDirectoryExplicitlyIgnored(dirName)) {
247242
return false

0 commit comments

Comments
 (0)