MCPcopy
hub / github.com/inkeep/open-knowledge / loadConfig

Function loadConfig

packages/cli/src/config/loader.ts:103–140  ·  view source on GitHub ↗
(cwd?: string)

Source from the content-addressed store, hash-verified

101}
102
103export function loadConfig(cwd?: string): LoadConfigResult {
104 const workingDir = cwd ?? process.cwd();
105 const sources: string[] = [];
106
107 const userConfigPath = resolveConfigPath('user', workingDir);
108 const userResult = readConfigSafely({ absPath: userConfigPath });
109 let merged: Record<string, unknown> = {};
110 if (userResult.valid && userResult.source !== undefined) {
111 merged = deepMerge(merged, userResult.value as unknown as Record<string, unknown>);
112 sources.push(userConfigPath);
113 } else if (!userResult.valid) {
114 }
115
116 const projectConfigPath = resolve(workingDir, OK_DIR, CONFIG_FILENAME);
117 const projectFile = loadYamlFile(projectConfigPath);
118 if (projectFile.value !== null) {
119 const removedKeyErrors = detectRemovedKeys({
120 value: projectFile.value,
121 file: projectFile.path,
122 source: projectFile.source,
123 doc: projectFile.doc,
124 });
125 if (removedKeyErrors.length > 0) {
126 throw new Error(removedKeyErrors.map(humanFormat).join('\n\n'));
127 }
128 merged = deepMerge(merged, projectFile.value);
129 sources.push(projectConfigPath);
130 }
131
132 const result = ConfigSchema.safeParse(merged);
133 if (!result.success) {
134 const issues = annotateIssuesWithSource(result.error.issues, projectFile);
135 const error: ConfigValidationError = { code: 'SCHEMA_INVALID', issues };
136 throw new Error(humanFormat(error));
137 }
138
139 return { config: result.data, sources };
140}
141
142interface CreateProjectConfigResolverOptions {
143 startupCwd: string;

Callers 6

cli.tsFile · 0.90
init.test.tsFile · 0.90
diagnoseCommandFunction · 0.85
runSingleFileBrowserOpenFunction · 0.85
initCommandFunction · 0.85
loader.test.tsFile · 0.85

Calls 9

resolveConfigPathFunction · 0.85
readConfigSafelyFunction · 0.85
deepMergeFunction · 0.85
loadYamlFileFunction · 0.85
detectRemovedKeysFunction · 0.85
annotateIssuesWithSourceFunction · 0.85
humanFormatFunction · 0.85
mapMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected