MCPcopy
hub / github.com/jonaskello/tsconfig-paths / loadTsconfigFromExtends

Function loadTsconfigFromExtends

src/tsconfig-loader.ts:171–212  ·  view source on GitHub ↗

* Intended to be called only from loadTsconfig. * Parameters don't have defaults because they should use the same as loadTsconfig.

(
  configFilePath: string,
  extendedConfigValue: string,
  // eslint-disable-next-line no-shadow
  existsSync: (path: string) => boolean,
  readFileSync: (filename: string) => string
)

Source from the content-addressed store, hash-verified

169 * Parameters don't have defaults because they should use the same as loadTsconfig.
170 */
171function loadTsconfigFromExtends(
172 configFilePath: string,
173 extendedConfigValue: string,
174 // eslint-disable-next-line no-shadow
175 existsSync: (path: string) => boolean,
176 readFileSync: (filename: string) => string
177): Tsconfig {
178 if (
179 typeof extendedConfigValue === "string" &&
180 extendedConfigValue.indexOf(".json") === -1
181 ) {
182 extendedConfigValue += ".json";
183 }
184 const currentDir = path.dirname(configFilePath);
185 let extendedConfigPath = path.join(currentDir, extendedConfigValue);
186 if (
187 extendedConfigValue.indexOf("/") !== -1 &&
188 extendedConfigValue.indexOf(".") !== -1 &&
189 !existsSync(extendedConfigPath)
190 ) {
191 extendedConfigPath = path.join(
192 currentDir,
193 "node_modules",
194 extendedConfigValue
195 );
196 }
197
198 const config =
199 loadTsconfig(extendedConfigPath, existsSync, readFileSync) || {};
200
201 // baseUrl should be interpreted as relative to extendedConfigPath,
202 // but we need to update it so it is relative to the original tsconfig being loaded
203 if (config.compilerOptions?.baseUrl) {
204 const extendsDir = path.dirname(extendedConfigValue);
205 config.compilerOptions.baseUrl = path.join(
206 extendsDir,
207 config.compilerOptions.baseUrl
208 );
209 }
210
211 return config;
212}
213
214function mergeTsconfigs(
215 base: Tsconfig | undefined,

Callers 1

loadTsconfigFunction · 0.85

Calls 1

loadTsconfigFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…