* Locate an `extends` target the way tsc does: `./x`-style values are * relative to the referencing config, anything else is a node_modules * package specifier resolved by walking up from that config. A missing * `.json` extension is implied, and a bare package name means its * `tsconfig.json`.
(spec: string, fromDir: string)
| 148 | * `tsconfig.json`. |
| 149 | */ |
| 150 | function resolveExtendsTarget(spec: string, fromDir: string): string | null { |
| 151 | const isFile = (p: string): boolean => { |
| 152 | try { |
| 153 | return fs.statSync(p).isFile(); |
| 154 | } catch { |
| 155 | return false; |
| 156 | } |
| 157 | }; |
| 158 | |
| 159 | if (spec.startsWith('./') || spec.startsWith('../') || path.isAbsolute(spec)) { |
| 160 | const base = path.resolve(fromDir, spec); |
| 161 | for (const cand of [base, `${base}.json`, path.join(base, 'tsconfig.json')]) { |
| 162 | if (isFile(cand)) return cand; |
| 163 | } |
| 164 | return null; |
| 165 | } |
| 166 | |
| 167 | let dir = fromDir; |
| 168 | for (;;) { |
| 169 | const base = path.join(dir, 'node_modules', spec); |
| 170 | for (const cand of [base, `${base}.json`, path.join(base, 'tsconfig.json')]) { |
| 171 | if (isFile(cand)) return cand; |
| 172 | } |
| 173 | const parent = path.dirname(dir); |
| 174 | if (parent === dir) return null; |
| 175 | dir = parent; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Read `filePath` and fold its `extends` chain into a single set of |
no test coverage detected