Skip to content
Open
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
10 changes: 9 additions & 1 deletion packages/utility/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ export const isTargetFile = (
}

const dirName = normalize(path.dirname(targetFile));
return potentialPaths.some((p) => normalize(p) === dirName);
return potentialPaths.some((p) => {
const normalizedP = normalize(p);
if (normalizedP === dirName) return true;
// Support Next.js route groups: match files inside (group) subdirectories
// e.g., app/(marketing)/layout.tsx should match potentialPath 'app'
const parentDir = normalize(path.dirname(dirName));
const groupDir = path.basename(dirName);
return parentDir === normalizedP && /^\([^)]+\)$/.test(groupDir);
});
};

export const isRootLayoutFile = (
Expand Down
20 changes: 20 additions & 0 deletions packages/utility/test/path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,24 @@ describe('isTargetFile', () => {
const targetFile = 'src/components/layout.tsx';
expect(isRootLayoutFile(targetFile)).toBe(false);
});

test('returns true for layout in a Next.js route group under app/', () => {
expect(isRootLayoutFile('app/(marketing)/layout.tsx')).toBe(true);
});

test('returns true for layout in a Next.js route group under src/app/', () => {
expect(isRootLayoutFile('src/app/(dashboard)/layout.tsx')).toBe(true);
});

test('returns true for layout in route group with jsx extension', () => {
expect(isRootLayoutFile('app/(app)/layout.jsx')).toBe(true);
});

test('returns false for layout nested deeper than one route group level', () => {
expect(isRootLayoutFile('app/(app)/nested/layout.tsx')).toBe(false);
});

test('returns false for layout in directory that looks like route group but is not', () => {
expect(isRootLayoutFile('app/marketing/layout.tsx')).toBe(false);
});
});