MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / parseConfig

Function parseConfig

src/project-config.ts:144–180  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

142 * JSON, or a typo'd value never throws.
143 */
144function parseConfig(file: string): ParsedConfig {
145 let raw: string;
146 try {
147 raw = fs.readFileSync(file, 'utf-8');
148 } catch {
149 return EMPTY_CONFIG;
150 }
151
152 let parsed: unknown;
153 try {
154 parsed = JSON.parse(raw);
155 } catch (err) {
156 logWarn(`Ignoring ${PROJECT_CONFIG_FILENAME}: not valid JSON`, {
157 file,
158 error: err instanceof Error ? err.message : String(err),
159 });
160 return EMPTY_CONFIG;
161 }
162
163 if (!parsed || typeof parsed !== 'object') return EMPTY_CONFIG;
164
165 const extensions = extractExtensions(parsed, file);
166 const includeIgnored = extractIncludeIgnored(parsed, file);
167 const exclude = extractExclude(parsed, file);
168 const include = extractInclude(parsed, file);
169 const deprioritize = extractPatternList(parsed, file, 'deprioritize');
170 if (
171 extensions === EMPTY_EXTENSIONS &&
172 includeIgnored.length === 0 &&
173 exclude.length === 0 &&
174 include.length === 0 &&
175 deprioritize.length === 0
176 ) {
177 return EMPTY_CONFIG;
178 }
179 return { extensions, includeIgnored, exclude, include, deprioritize };
180}
181
182/**
183 * Validate the `extensions` map. Every failure mode degrades to "no overrides

Callers 1

loadParsedConfigFunction · 0.70

Calls 7

logWarnFunction · 0.90
extractExtensionsFunction · 0.85
extractIncludeIgnoredFunction · 0.85
extractExcludeFunction · 0.85
extractIncludeFunction · 0.85
extractPatternListFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected