Skip to content

Commit 64ae9c0

Browse files
author
Arnav
committed
fix(scripts): normalize Windows path separators in validation scripts
1 parent 6154482 commit 64ae9c0

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

‎scripts/check-api-validation-contracts.ts‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { readdir, readFile } from 'node:fs/promises'
33
import path from 'node:path'
44

55
const ROOT = path.resolve(import.meta.dir, '..')
6-
const API_DIR = path.join(ROOT, 'apps/sim/app/api')
7-
const CONTRACTS_DIR = path.join(ROOT, 'apps/sim/lib/api/contracts')
8-
const QUERY_HOOKS_DIR = path.join(ROOT, 'apps/sim/hooks/queries')
9-
const SELECTOR_HOOKS_DIR = path.join(ROOT, 'apps/sim/hooks/selectors')
6+
const toPosix = (p: string) => p.replace(/\\/g, '/')
7+
const API_DIR = toPosix(path.join(ROOT, 'apps/sim/app/api'))
8+
const CONTRACTS_DIR = toPosix(path.join(ROOT, 'apps/sim/lib/api/contracts'))
9+
const QUERY_HOOKS_DIR = toPosix(path.join(ROOT, 'apps/sim/hooks/queries'))
10+
const SELECTOR_HOOKS_DIR = toPosix(path.join(ROOT, 'apps/sim/hooks/selectors'))
1011

1112
/**
1213
* `totalRoutes` is reported, never gated.
@@ -477,7 +478,7 @@ function findRawFetchFindings(
477478
exemptions: number
478479
missingReasons: AnnotationMissingReasonFinding[]
479480
} {
480-
const relativePath = path.relative(ROOT, filePath)
481+
const relativePath = toPosix(path.relative(ROOT, filePath))
481482
const lines = content.split('\n')
482483
const findings: RawFetchFinding[] = []
483484
const missingReasons: AnnotationMissingReasonFinding[] = []
@@ -515,7 +516,7 @@ function findDoubleCastFindings(
515516
exemptions: number
516517
missingReasons: AnnotationMissingReasonFinding[]
517518
} {
518-
const relativePath = path.relative(ROOT, filePath)
519+
const relativePath = toPosix(path.relative(ROOT, filePath))
519520
const lines = content.split('\n')
520521
const findings: DoubleCastFinding[] = []
521522
const missingReasons: AnnotationMissingReasonFinding[] = []
@@ -562,7 +563,7 @@ function findRawJsonFindings(
562563
exemptions: number
563564
missingReasons: AnnotationMissingReasonFinding[]
564565
} {
565-
const relativePath = path.relative(ROOT, filePath)
566+
const relativePath = toPosix(path.relative(ROOT, filePath))
566567
const lines = content.split('\n')
567568
const findings: RawJsonFinding[] = []
568569
const missingReasons: AnnotationMissingReasonFinding[] = []
@@ -613,7 +614,7 @@ function findUntypedResponseFindings(
613614
exemptions: number
614615
missingReasons: AnnotationMissingReasonFinding[]
615616
} {
616-
const relativePath = path.relative(ROOT, filePath)
617+
const relativePath = toPosix(path.relative(ROOT, filePath))
617618
const lines = content.split('\n')
618619
const findings: UntypedResponseFinding[] = []
619620
const missingReasons: AnnotationMissingReasonFinding[] = []
@@ -683,7 +684,7 @@ function findSameOriginApiFetchFindings(
683684
exemptions: number
684685
missingReasons: AnnotationMissingReasonFinding[]
685686
} {
686-
const relativePath = path.relative(ROOT, filePath)
687+
const relativePath = toPosix(path.relative(ROOT, filePath))
687688
const lines = content.split('\n')
688689
const findings: SameOriginApiFetchFinding[] = []
689690
const missingReasons: AnnotationMissingReasonFinding[] = []
@@ -713,7 +714,7 @@ function findSameOriginApiFetchFindings(
713714
}
714715

715716
function routeFamily(routePath: string): string {
716-
const relative = routePath.replace(/^apps\/sim\/app\/api\//, '')
717+
const relative = toPosix(routePath).replace(/^apps\/sim\/app\/api\//, '')
717718
const [first, second] = relative.split('/')
718719

719720
if (first === 'tools') return `tools/${second ?? 'unknown'}`
@@ -767,7 +768,7 @@ function hasZodUsage(relativePath: string, content: string): boolean {
767768
}
768769

769770
function auditRoute(filePath: string, content: string): RouteAudit {
770-
const relativePath = path.relative(ROOT, filePath)
771+
const relativePath = toPosix(path.relative(ROOT, filePath))
771772
const schemaConstructorCount = [...content.matchAll(ZOD_SCHEMA_CONSTRUCTOR_PATTERN)].length
772773

773774
return {
@@ -785,7 +786,7 @@ function auditRoute(filePath: string, content: string): RouteAudit {
785786

786787
function findAdHocWireTypes(filePath: string, content: string): WireTypeFinding[] {
787788
const findings: WireTypeFinding[] = []
788-
const relativePath = path.relative(ROOT, filePath)
789+
const relativePath = toPosix(path.relative(ROOT, filePath))
789790

790791
for (const match of content.matchAll(WIRE_TYPE_DECLARATION_PATTERN)) {
791792
const kind = match[1]
@@ -814,7 +815,7 @@ function findAdHocWireTypes(filePath: string, content: string): WireTypeFinding[
814815
}
815816

816817
function auditQueryHook(filePath: string, content: string): QueryHookAudit {
817-
const relativePath = path.relative(ROOT, filePath)
818+
const relativePath = toPosix(path.relative(ROOT, filePath))
818819
const schemaConstructorCount = [...content.matchAll(ZOD_SCHEMA_CONSTRUCTOR_PATTERN)].length
819820

820821
return {
@@ -1281,13 +1282,13 @@ async function main() {
12811282
let sameOriginApiFetchExemptions = 0
12821283
let doubleCastExemptions = 0
12831284

1284-
const appsSimRoot = path.join(ROOT, 'apps/sim')
1285-
const contractsRoot = path.join(CONTRACTS_DIR, path.sep)
1285+
const appsSimRoot = toPosix(path.join(ROOT, 'apps/sim'))
1286+
const contractsRoot = `${toPosix(CONTRACTS_DIR)}/`
12861287

12871288
for (const filePath of sourceFiles) {
12881289
const content = sourceCache.get(filePath) ?? (await readFile(filePath, 'utf8'))
1289-
if (filePath.startsWith(contractsRoot)) sourceCache.set(filePath, content)
1290-
const normalized = filePath.replace(/\\/g, '/')
1290+
const normalized = toPosix(filePath)
1291+
if (normalized.startsWith(contractsRoot)) sourceCache.set(filePath, content)
12911292

12921293
if (isClientHookFile(filePath) && content.includes('fetch')) {
12931294
const rawFetch = findRawFetchFindings(filePath, content)

‎scripts/check-tool-registry-boundary.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function collectEntries(
169169
for (const entry of readdirSync(dir, { withFileTypes: true })) {
170170
const full = join(dir, entry.name)
171171
if (entry.isDirectory()) collectEntries(full, matches, found)
172-
else if (matches(entry.name, full)) found.push(relative(APP, full))
172+
else if (matches(entry.name, full)) found.push(relative(APP, full).replaceAll('\\', '/'))
173173
}
174174
return found
175175
}

0 commit comments

Comments
 (0)