(
configFilePath: string,
// eslint-disable-next-line no-shadow
existsSync: (path: string) => boolean = fs.existsSync,
readFileSync: (filename: string) => string = (filename: string) =>
fs.readFileSync(filename, "utf8")
)
| 113 | } |
| 114 | |
| 115 | export function loadTsconfig( |
| 116 | configFilePath: string, |
| 117 | // eslint-disable-next-line no-shadow |
| 118 | existsSync: (path: string) => boolean = fs.existsSync, |
| 119 | readFileSync: (filename: string) => string = (filename: string) => |
| 120 | fs.readFileSync(filename, "utf8") |
| 121 | ): Tsconfig | undefined { |
| 122 | if (!existsSync(configFilePath)) { |
| 123 | return undefined; |
| 124 | } |
| 125 | |
| 126 | const configString = readFileSync(configFilePath); |
| 127 | const cleanedJson = StripBom(configString); |
| 128 | let config: Tsconfig; |
| 129 | try { |
| 130 | config = JSON5.parse(cleanedJson); |
| 131 | } catch (e) { |
| 132 | throw new Error(`${configFilePath} is malformed ${e.message}`); |
| 133 | } |
| 134 | |
| 135 | let extendedConfig = config.extends; |
| 136 | if (extendedConfig) { |
| 137 | let base: Tsconfig; |
| 138 | |
| 139 | if (Array.isArray(extendedConfig)) { |
| 140 | base = extendedConfig.reduce( |
| 141 | (currBase, extendedConfigElement) => |
| 142 | mergeTsconfigs( |
| 143 | currBase, |
| 144 | loadTsconfigFromExtends( |
| 145 | configFilePath, |
| 146 | extendedConfigElement, |
| 147 | existsSync, |
| 148 | readFileSync |
| 149 | ) |
| 150 | ), |
| 151 | {} |
| 152 | ); |
| 153 | } else { |
| 154 | base = loadTsconfigFromExtends( |
| 155 | configFilePath, |
| 156 | extendedConfig, |
| 157 | existsSync, |
| 158 | readFileSync |
| 159 | ); |
| 160 | } |
| 161 | |
| 162 | return mergeTsconfigs(base, config); |
| 163 | } |
| 164 | return config; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Intended to be called only from loadTsconfig. |
no test coverage detected
searching dependent graphs…