Skip to content

Commit 67fc2ae

Browse files
authored
fix(ci): require a default export before treating a file as a route entry (#7028)
* fix(ci): require a default export before treating a file as a route entry Follow-up to #7026, which added `error.tsx` to the entry filenames and with it picked up `[workspaceId]/components/error/error.tsx` — named like a boundary, and not one. It exports `ErrorShell` and `ErrorState` for the thirteen real boundaries to use; Next would reject it as a boundary for having no default export. Counting it inflated the coverage number and would have recorded a shared component in the graph-weight baseline as though it were a route. The filename was never the right test. Every convention-composed entry must default-export the thing Next renders, so that is the discriminator now. Entry count goes 60 → 59, and all thirteen real `error.tsx` boundaries still walk. Also adds `template.tsx` and `default.tsx`. Neither exists under `app/workspace` today, so this changes nothing now — but the enumeration claims to cover what Next composes, and leaving two out makes that claim false the day someone adds one. Both raised in review on #7026 (Cursor and Greptile respectively); I merged before reading them, so this lands separately. * fix(ci): count every form that declares a default export `export { default } from './page'` is a valid Next entry and the regex required `as default`, so such an entry would have dropped out of the walk and skipped both the registry gate and the graph-weight ratchet — silently, which is the dangerous direction for a discriminator to fail in. Latent rather than live: the form appears once under `app/workspace`, in a barrel, not in an entry filename. Four forms now count — `export default …`, `export { default } from`, `export { default, … } from`, and `export { X as default }`. `export { default as X }` still does not: it re-exports another module's default under a name and leaves this one without one. Verified all ten variants, including that last distinction. Raised by both Cursor and Greptile on #7028.
1 parent 82b02fb commit 67fc2ae

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

scripts/check-tool-registry-boundary.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,46 @@ const ENTRY_FILENAMES = new Set([
7272
'error.tsx',
7373
'loading.tsx',
7474
'not-found.tsx',
75+
'template.tsx',
76+
'default.tsx',
7577
])
7678

79+
/**
80+
* A default export, which every convention-composed entry must have — Next
81+
* renders the default and nothing else.
82+
*
83+
* The filename alone is not enough. `[workspaceId]/components/error/error.tsx`
84+
* is named like a boundary and is not one: it exports `ErrorShell` and
85+
* `ErrorState` for the thirteen real boundaries to use, and Next would reject
86+
* it as a boundary for having no default. Counting it as an entry both inflated
87+
* the coverage number and would have recorded a shared component in the
88+
* graph-weight baseline as though it were a route.
89+
*
90+
* All four declaring forms count — `export default …`, `export { default } from`,
91+
* `export { default, … } from`, and `export { X as default }`. `export { default
92+
* as X }` does not: it re-exports someone else's default under a name and leaves
93+
* the module without one. Missing a form is the dangerous direction, since the
94+
* entry would drop out of the walk and skip both the registry gate and the
95+
* graph-weight ratchet silently.
96+
*/
97+
const DEFAULT_EXPORT_RE =
98+
/(?:^|\n)\s*export\s+default\b|(?:^|\n)\s*export\s*\{[^}]*(?:\bas\s+default\b|\bdefault\s*[,}])/
99+
100+
function hasDefaultExport(file: string): boolean {
101+
try {
102+
return DEFAULT_EXPORT_RE.test(readFileSync(file, 'utf8'))
103+
} catch {
104+
return false
105+
}
106+
}
107+
77108
function collectEntries(dir: string, found: string[] = []): string[] {
78109
for (const entry of readdirSync(dir, { withFileTypes: true })) {
79110
const full = join(dir, entry.name)
80111
if (entry.isDirectory()) collectEntries(full, found)
81-
else if (ENTRY_FILENAMES.has(entry.name)) found.push(relative(APP, full))
112+
else if (ENTRY_FILENAMES.has(entry.name) && hasDefaultExport(full)) {
113+
found.push(relative(APP, full))
114+
}
82115
}
83116
return found
84117
}

0 commit comments

Comments
 (0)