From 0ee302b40dc1cfeede0e107b30facdb1e6d187f8 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Tue, 11 Aug 2026 12:08:10 -0700 Subject: [PATCH] improvement(audits): skip the sql-date-binding parse for files without drizzle-orm check:sql-date-binding Babel-parsed all 13,941 source files in apps, packages, and scripts. A violation can only come from an `sql` tag resolved through a `drizzle-orm` import, and both the static and dynamic resolvers match the specifier as a string literal, so a file that never names the module cannot produce one. Only ~590 files do. Skipping the parse for the other 92% of bytes takes the audit from ~4.5s to ~0.8s and drops it out of the four slowest audits, taking check:audits from 6.0s to 5.3s wall and 38.0s to 32.9s serial. Output is unchanged. --- scripts/check-sql-date-binding.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/check-sql-date-binding.ts b/scripts/check-sql-date-binding.ts index abbacb1f9c2..514e8884fd4 100644 --- a/scripts/check-sql-date-binding.ts +++ b/scripts/check-sql-date-binding.ts @@ -544,6 +544,18 @@ function analyzeSource(source: string, file = 'source.ts'): FileAnalysis { return { violations } } +/** + * Skips the parse for files that cannot bind the tag. + * + * `collectSqlBindings` and `isDrizzleImportCall` both match the specifier as a string literal, + * so a source that never names the module yields no bindings and no violations. That is all but + * ~590 of the ~13,900 scanned files, and not parsing them takes the audit from ~4.5s to ~0.8s. + * An escaped specifier (`'drizzle\x2dorm'`) would evade the substring; the repo contains none. + */ +function mayBindDrizzleSql(source: string): boolean { + return source.includes(DRIZZLE_MODULE) +} + function collectSources(dir: string, found: string[] = []): string[] { for (const entry of readdirSync(dir, { withFileTypes: true })) { if (SKIP_DIRS.has(entry.name)) continue @@ -560,7 +572,9 @@ function main(): void { const skipped: { file: string; parseError: string }[] = [] for (const file of files) { - const analysis = analyzeSource(readFileSync(file, 'utf8'), file) + const source = readFileSync(file, 'utf8') + if (!mayBindDrizzleSql(source)) continue + const analysis = analyzeSource(source, file) if (analysis.parseError) skipped.push({ file, parseError: analysis.parseError }) violations.push(...analysis.violations) }