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

Function extractWebRoot

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

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