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

Function parseConfig

src/project-config.ts:160–198  ·  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

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

Callers 1

loadParsedConfigFunction · 0.70

Calls 9

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

Tested by

no test coverage detected