* Read + JSON-parse a `codegraph.json` once and return its validated view. * Every failure mode degrades to the zero-config default — a missing file, bad * JSON, or a typo'd value never throws.
(file: string)
| 157 | * JSON, or a typo'd value never throws. |
| 158 | */ |
| 159 | function parseConfig(file: string): ParsedConfig { |
| 160 | let raw: string; |
| 161 | try { |
| 162 | raw = fs.readFileSync(file, 'utf-8'); |
| 163 | } catch { |
| 164 | return EMPTY_CONFIG; |
| 165 | } |
| 166 | |
| 167 | let parsed: unknown; |
| 168 | try { |
| 169 | parsed = JSON.parse(raw); |
| 170 | } catch (err) { |
| 171 | logWarn(`Ignoring ${PROJECT_CONFIG_FILENAME}: not valid JSON`, { |
| 172 | file, |
| 173 | error: err instanceof Error ? err.message : String(err), |
| 174 | }); |
| 175 | return EMPTY_CONFIG; |
| 176 | } |
| 177 | |
| 178 | if (!parsed || typeof parsed !== 'object') return EMPTY_CONFIG; |
| 179 | |
| 180 | const extensions = extractExtensions(parsed, file); |
| 181 | const includeIgnored = extractIncludeIgnored(parsed, file); |
| 182 | const exclude = extractExclude(parsed, file); |
| 183 | const include = extractInclude(parsed, file); |
| 184 | const deprioritize = extractPatternList(parsed, file, 'deprioritize'); |
| 185 | const webRoot = extractWebRoot(parsed, file); |
| 186 | if ( |
| 187 | extensions === EMPTY_EXTENSIONS && |
| 188 | includeIgnored.length === 0 && |
| 189 | exclude.length === 0 && |
| 190 | include.length === 0 && |
| 191 | deprioritize.length === 0 && |
| 192 | webRoot === null |
| 193 | ) { |
| 194 | return EMPTY_CONFIG; |
| 195 | } |
| 196 | return { extensions, includeIgnored, exclude, include, deprioritize, webRoot }; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Validate `webRoot`: a folder inside the project, written relative to its |
no test coverage detected