MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolveExtendsTarget

Function resolveExtendsTarget

src/resolution/path-aliases.ts:150–177  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

148 * `tsconfig.json`.
149 */
150function 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

Callers 1

loadEffectiveOptionsFunction · 0.85

Calls 3

isFileFunction · 0.85
resolveMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected