(params: {
filePath: string
readFile?: (filePath: string) => string | null
maxBytes: number
remainingBytes: number
})
| 235 | } |
| 236 | |
| 237 | function loadSourceWithinLimits(params: { |
| 238 | filePath: string |
| 239 | readFile?: (filePath: string) => string | null |
| 240 | maxBytes: number |
| 241 | remainingBytes: number |
| 242 | }): { code: string; bytes: number } | null { |
| 243 | const { filePath, readFile, maxBytes, remainingBytes } = params |
| 244 | |
| 245 | if (!readFile) { |
| 246 | const bytes = fs.statSync(filePath).size |
| 247 | if (bytes > maxBytes || bytes > remainingBytes) return null |
| 248 | |
| 249 | return { |
| 250 | code: fs.readFileSync(filePath, 'utf8'), |
| 251 | bytes, |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | const code = readFile(filePath) |
| 256 | if (code === null) return null |
| 257 | |
| 258 | const bytes = Buffer.byteLength(code, 'utf8') |
| 259 | if (bytes > maxBytes || bytes > remainingBytes) return null |
| 260 | |
| 261 | return { code, bytes } |
| 262 | } |
| 263 | |
| 264 | function scoreFileTokens(fullPath: string, parsed: ParsedTokens): FileCallData { |
| 265 | const scores: Record<string, number> = {} |
no outgoing calls
no test coverage detected