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

Function extractWebRoot

src/project-config.ts:208–227  ·  view source on GitHub ↗

* Validate `webRoot`: a folder inside the project, written relative to its * root (`"public"`, `"./web/"`, `"site\\htdocs"`, `"."`). Returned with `/` * separators and no `./` or trailing `/`; the project root is ''. A non-string, * an empty string, an absolute path (the server's own path, like

(parsed: object, file: string)

Source from the content-addressed store, hash-verified

206 * throws.
207 */
208function extractWebRoot(parsed: object, file: string): string | null {
209 const raw = (parsed as ProjectConfig).webRoot;
210 if (raw === undefined) return null;
211 const hint = 'must be a folder relative to the project root, like "public", or "." for the root itself';
212 if (typeof raw !== 'string' || !raw.trim()) {
213 logWarn(`Ignoring "webRoot" in ${PROJECT_CONFIG_FILENAME}: it ${hint}`, { file });
214 return null;
215 }
216 const slashed = raw.trim().replace(/\\/g, '/');
217 if (slashed.startsWith('/') || /^[A-Za-z]:/.test(slashed)) {
218 logWarn(`Ignoring "webRoot" in ${PROJECT_CONFIG_FILENAME}: "${raw}" is an absolute path; it ${hint}`, { file });
219 return null;
220 }
221 const normalized = path.posix.normalize(slashed).replace(/\/+$/, '');
222 if (normalized === '..' || normalized.startsWith('../')) {
223 logWarn(`Ignoring "webRoot" in ${PROJECT_CONFIG_FILENAME}: "${raw}" is outside the project; it ${hint}`, { file });
224 return null;
225 }
226 return normalized === '.' ? '' : normalized;
227}
228
229/**
230 * Validate the `extensions` map. Every failure mode degrades to "no overrides

Callers 1

parseConfigFunction · 0.85

Calls 2

logWarnFunction · 0.90
normalizeMethod · 0.80

Tested by

no test coverage detected