* Index a single file with pre-read content and stats. * Used by the parallel batch reader to avoid redundant file I/O.
(
relativePath: string,
content: string,
stats: fs.Stats
)
| 3275 | * Used by the parallel batch reader to avoid redundant file I/O. |
| 3276 | */ |
| 3277 | async indexFileWithContent( |
| 3278 | relativePath: string, |
| 3279 | content: string, |
| 3280 | stats: fs.Stats |
| 3281 | ): Promise<ExtractionResult> { |
| 3282 | // Prevent `../` traversal; follow in-root symlinks like the directory walk (#935). |
| 3283 | const fullPath = validatePathWithinRoot(this.rootDir, relativePath, { allowSymlinkEscape: true }); |
| 3284 | if (!fullPath) { |
| 3285 | logWarn('Path traversal blocked in indexFileWithContent', { relativePath }); |
| 3286 | return { |
| 3287 | nodes: [], |
| 3288 | edges: [], |
| 3289 | unresolvedReferences: [], |
| 3290 | errors: [{ message: 'Path traversal blocked', filePath: relativePath, severity: 'error', code: 'path_traversal' }], |
| 3291 | durationMs: 0, |
| 3292 | }; |
| 3293 | } |
| 3294 | |
| 3295 | const language = detectLanguage(relativePath, content, loadExtensionOverrides(this.rootDir), this.rootDir); |
| 3296 | |
| 3297 | // Check file size |
| 3298 | if (stats.size > MAX_SOURCE_FILE_SIZE_BYTES) { |
| 3299 | const result: ExtractionResult = { |
| 3300 | nodes: [], |
| 3301 | edges: [], |
| 3302 | unresolvedReferences: [], |
| 3303 | errors: [ |
| 3304 | { |
| 3305 | message: `File exceeds max size (${stats.size} > ${MAX_SOURCE_FILE_SIZE_BYTES})`, |
| 3306 | filePath: relativePath, |
| 3307 | severity: 'warning', |
| 3308 | code: 'size_exceeded', |
| 3309 | }, |
| 3310 | ], |
| 3311 | durationMs: 0, |
| 3312 | }; |
| 3313 | await this.storeExtractionResult(relativePath, content, language, stats, result, createYielder()); |
| 3314 | return result; |
| 3315 | } |
| 3316 | |
| 3317 | // Detect language (honoring the project's codegraph.json extension overrides) |
| 3318 | if (!isLanguageSupported(language)) { |
| 3319 | return { |
| 3320 | nodes: [], |
| 3321 | edges: [], |
| 3322 | unresolvedReferences: [], |
| 3323 | errors: [], |
| 3324 | durationMs: 0, |
| 3325 | }; |
| 3326 | } |
| 3327 | |
| 3328 | // Extract from source. Use cached framework names if indexAll has run, |
| 3329 | // otherwise detect on the spot so single-file re-index paths still emit |
| 3330 | // route nodes / middleware / etc. |
| 3331 | const frameworkNames = this.frameworksForFile(relativePath, this.ensureDetectedFrameworks()); |
| 3332 | const result = extractFromSource(relativePath, content, language, frameworkNames); |
| 3333 | |
| 3334 | // Store in database |
no test coverage detected