`readFile` through the LRU content cache (null = read failed, also cached).
(filePath: string)
| 936 | |
| 937 | /** `readFile` through the LRU content cache (null = read failed, also cached). */ |
| 938 | private readFileCached(filePath: string): string | null { |
| 939 | if (this.fileCache.has(filePath)) { |
| 940 | return this.fileCache.get(filePath)!; |
| 941 | } |
| 942 | const fullPath = path.join(this.projectRoot, filePath); |
| 943 | try { |
| 944 | // Import resolvers may follow package metadata to an archive (`file:*.har`, |
| 945 | // for example). Reject anything extraction would not accept before UTF-8 |
| 946 | // decoding can multiply a large binary blob into gigabytes of V8 heap. |
| 947 | // Read for names, never for a megabyte of hex (see withoutLongRuns). |
| 948 | const source = readSourceText(fullPath); |
| 949 | const content = source === null ? null : withoutLongRuns(source); |
| 950 | this.fileCache.set(filePath, content); |
| 951 | return content; |
| 952 | } catch (error) { |
| 953 | logDebug('Failed to read file for resolution', { filePath, error: String(error) }); |
| 954 | this.fileCache.set(filePath, null); |
| 955 | return null; |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | /** |
| 960 | * `readFileCached(filePath)?.includes(needle)` for an ASCII needle, searched |
no test coverage detected