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

Function loadEffectiveOptions

src/resolution/path-aliases.ts:175–219  ·  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
)

Source from the content-addressed store, hash-verified

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

Callers 1

loadProjectAliasesFunction · 0.85

Calls 7

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

Tested by

no test coverage detected