(projectRoot: string)
| 41 | * A file it cannot read declares no package, so the qualifier does not match. |
| 42 | */ |
| 43 | export function goPackageReader(projectRoot: string): GoPackageOf { |
| 44 | const cache = new Map<string, string | null>(); |
| 45 | return (filePath) => { |
| 46 | const hit = cache.get(filePath); |
| 47 | if (hit !== undefined) return hit; |
| 48 | let pkg: string | null = null; |
| 49 | const absPath = validatePathWithinRoot(projectRoot, filePath); |
| 50 | if (absPath) { |
| 51 | try { |
| 52 | const fd = openSync(absPath, 'r'); |
| 53 | try { |
| 54 | const buf = Buffer.alloc(HEAD_BYTES); |
| 55 | const n = readSync(fd, buf, 0, HEAD_BYTES, 0); |
| 56 | pkg = goPackageClause(buf.toString('utf8', 0, n)); |
| 57 | } finally { |
| 58 | closeSync(fd); |
| 59 | } |
| 60 | } catch { |
| 61 | pkg = null; |
| 62 | } |
| 63 | } |
| 64 | cache.set(filePath, pkg); |
| 65 | return pkg; |
| 66 | }; |
| 67 | } |
no test coverage detected