* 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, )
| 57 | * returns a ConfigFile object containing the data from all the dependencies |
| 58 | */ |
| 59 | async 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 |
no test coverage detected
searching dependent graphs…