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

Function loadEffectiveOptions

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

* Read `filePath` and fold its `extends` chain into a single set of * effective options. Parents are applied first and the nearest config * wins — tsc replaces `paths` wholesale rather than merging it. * * `stack` holds the configs currently being resolved, so a cycle * (`a extends b extends a`

(
  filePath: string,
  stack: Set<string>,
  depth: number,
  read?: Set<string>
)

Source from the content-addressed store, hash-verified

185 * (`a extends b extends a`) stops instead of recursing forever.
186 */
187function loadEffectiveOptions(
188 filePath: string,
189 stack: Set<string>,
190 depth: number,
191 read?: Set<string>
192): EffectiveOptions | null {
193 const abs = path.resolve(filePath);
194 if (stack.has(abs) || depth > MAX_EXTENDS_DEPTH) {
195 logDebug('path-aliases: extends chain cycle or too deep', { filePath: abs, depth });
196 return null;
197 }
198 read?.add(abs);
199 const raw = readTsconfigLike(abs);
200 if (!raw) return null;
201
202 stack.add(abs);
203 const dir = path.dirname(abs);
204 const effective: EffectiveOptions = {};
205
206 const parents = typeof raw.extends === 'string' ? [raw.extends] : (raw.extends ?? []);
207 for (const spec of parents) {
208 if (typeof spec !== 'string') continue;
209 const target = resolveExtendsTarget(spec, dir);
210 if (!target) {
211 logDebug('path-aliases: unresolved extends', { from: abs, spec });
212 continue;
213 }
214 const inherited = loadEffectiveOptions(target, stack, depth + 1, read);
215 if (!inherited) continue;
216 if (inherited.baseUrl !== undefined) effective.baseUrl = inherited.baseUrl;
217 if (inherited.paths !== undefined) {
218 effective.paths = inherited.paths;
219 effective.pathsDir = inherited.pathsDir;
220 }
221 }
222 stack.delete(abs);
223
224 const co = raw.compilerOptions ?? {};
225 // Both are relative to the file that declared them, not to whichever
226 // config started the chain.
227 if (typeof co.baseUrl === 'string') effective.baseUrl = path.resolve(dir, co.baseUrl);
228 if (co.paths && typeof co.paths === 'object') {
229 effective.paths = co.paths;
230 effective.pathsDir = dir;
231 }
232 return effective;
233}
234
235function readTsconfigLike(filePath: string): RawTsconfig | null {
236 try {

Callers 1

loadProjectAliasesFunction · 0.85

Calls 7

logDebugFunction · 0.90
readTsconfigLikeFunction · 0.85
resolveExtendsTargetFunction · 0.85
hasMethod · 0.80
resolveMethod · 0.65
deleteMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected