Skip to content

Commit 793d37d

Browse files
committed
fix(tools): traverse require() edges in the boundary guard
Review flagged `require()` as an untraversed edge form, and it is not hypothetical here — this codebase uses lazy `require('@/…')` to break import cycles, including from a client-reachable file (`tools/params.ts` reaches `@/blocks` that way). Those edges are as real as static imports; a `require` of the registry would have walked straight past the guard. The audit now covers every form a module can be reached by, each verified rather than assumed: CAUGHT plain named import { tools } from '@/tools/registry' CAUGHT side-effect import '@/tools/registry' CAUGHT extensionful import { tools } from '@/tools/registry.ts' CAUGHT ns re-export export * as ns from '@/tools/registry' CAUGHT dynamic import('@/tools/registry') CAUGHT require require('@/tools/registry') clean tree passes No new violations surfaced — the 35 guarded page/layout graphs stay clean with require edges followed.
1 parent 12cb234 commit 793d37d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

scripts/check-tool-registry-boundary.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs']
7070
* still puts 4,300 tools' worth of executable config on a client path, so it
7171
* counts as reaching it — and the settings route's registry edge hid behind
7272
* exactly such an import.
73+
*
74+
* `REQUIRE_RE` matters for the same reason: this codebase uses lazy
75+
* `require('@/…')` to break import cycles (`tools/params.ts` reaches `@/blocks`
76+
* that way), and those edges are as real as static ones.
7377
*/
7478
const IMPORT_RE = /(?:^|\n)\s*import\s+(?!type\b)(?:[\s\S]*?from\s*)?['"]([^'"]+)['"]/g
7579
const REEXPORT_RE =
7680
/(?:^|\n)\s*export\s+(?!type\b)(?:\*(?:\s+as\s+[\w$]+)?|\{[\s\S]*?\})\s*from\s*['"]([^'"]+)['"]/g
7781
const DYNAMIC_IMPORT_RE = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g
82+
const REQUIRE_RE = /\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)/g
7883

7984
/** Resolves `@/` and relative specifiers. Bare package specifiers are ignored. */
8085
function resolveSpecifier(specifier: string, importer: string): string | null {
@@ -119,7 +124,7 @@ function walk(entry: string): Walk {
119124
} catch {
120125
continue
121126
}
122-
for (const pattern of [IMPORT_RE, REEXPORT_RE, DYNAMIC_IMPORT_RE]) {
127+
for (const pattern of [IMPORT_RE, REEXPORT_RE, DYNAMIC_IMPORT_RE, REQUIRE_RE]) {
123128
pattern.lastIndex = 0
124129
let match = pattern.exec(source)
125130
while (match !== null) {

0 commit comments

Comments
 (0)