MCPcopy
hub / github.com/google/gts / getBase

Function getBase

src/util.ts:59–103  ·  view source on GitHub ↗

* Recursively iterate through the dependency chain until we reach the end of * the dependency chain or encounter a circular reference * @param filePath Filepath of file currently being read * @param customReadFilep The file reading function being used * @param readFiles an array of the previousl

(
  filePath: string,
  customReadFilep: ReadFileP,
  readFiles: Set<string>,
  currentDir: string,
)

Source from the content-addressed store, hash-verified

57 * returns a ConfigFile object containing the data from all the dependencies
58 */
59async function getBase(
60 filePath: string,
61 customReadFilep: ReadFileP,
62 readFiles: Set<string>,
63 currentDir: string,
64): Promise<ConfigFile> {
65 customReadFilep = customReadFilep || readFilep;
66
67 filePath = path.resolve(currentDir, filePath);
68
69 // An error is thrown if there is a circular reference as specified by the
70 // TypeScript doc
71 if (readFiles.has(filePath)) {
72 throw new Error(`Circular reference in ${filePath}`);
73 }
74 readFiles.add(filePath);
75 try {
76 const json = await customReadFilep(filePath, 'utf8');
77 // eslint-disable-next-line @typescript-eslint/no-explicit-any
78 let contents: any;
79 try {
80 contents = JSON5.parse(json);
81 } catch (e) {
82 const err = e as Error;
83 err.message = `Unable to parse ${filePath}!\n${err.message}`;
84 throw err;
85 }
86
87 if (contents.extends) {
88 const nextFile = await getBase(
89 contents.extends,
90 customReadFilep,
91 readFiles,
92 path.dirname(filePath),
93 );
94 contents = combineTSConfig(nextFile, contents);
95 }
96
97 return contents;
98 } catch (e) {
99 const err = e as Error;
100 err.message = `Error: ${filePath}\n${err.message}`;
101 throw err;
102 }
103}
104
105/**
106 * Takes in 2 config files

Callers 1

getTSConfigFunction · 0.85

Calls 1

combineTSConfigFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…