mergeConfigRecursively() — astro Function Reference
Architecture documentation for the mergeConfigRecursively() function in merge.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 3e40db17_0001_3ecb_3f8e_3ef4971790f6["mergeConfigRecursively()"] 59d6cf60_ff4d_d499_5395_b2c915d5ed58["merge.ts"] 3e40db17_0001_3ecb_3f8e_3ef4971790f6 -->|defined in| 59d6cf60_ff4d_d499_5395_b2c915d5ed58 4c00ca19_2bc9_05c7_bd27_7e949188bd23["mergeConfig()"] 4c00ca19_2bc9_05c7_bd27_7e949188bd23 -->|calls| 3e40db17_0001_3ecb_3f8e_3ef4971790f6 style 3e40db17_0001_3ecb_3f8e_3ef4971790f6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/config/merge.ts lines 6–64
function mergeConfigRecursively(
defaults: Record<string, any>,
overrides: Record<string, any>,
rootPath: string,
) {
const merged: Record<string, any> = { ...defaults };
for (const key in overrides) {
const value = overrides[key];
if (value == null) {
continue;
}
const existing = merged[key];
if (existing == null) {
merged[key] = value;
continue;
}
// fields that require special handling:
if (key === 'vite' && rootPath === '') {
merged[key] = mergeViteConfig(existing, value);
continue;
}
if (key === 'server' && rootPath === '') {
// server config can be a function or an object, if one of the two values is a function,
// create a new wrapper function that merges them
if (typeof existing === 'function' || typeof value === 'function') {
merged[key] = (...args: any[]) => {
const existingConfig = typeof existing === 'function' ? existing(...args) : existing;
const valueConfig = typeof value === 'function' ? value(...args) : value;
return mergeConfigRecursively(existingConfig, valueConfig, key);
};
continue;
}
}
// for server.allowedHosts, if the value is a boolean
if (key === 'allowedHosts' && rootPath === 'server' && typeof existing === 'boolean') {
continue;
}
if (Array.isArray(existing) || Array.isArray(value)) {
merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
continue;
}
if (isURL(existing) && isURL(value)) {
merged[key] = value;
continue;
}
if (isObject(existing) && isObject(value)) {
merged[key] = mergeConfigRecursively(existing, value, rootPath ? `${rootPath}.${key}` : key);
continue;
}
merged[key] = value;
}
return merged;
}
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does mergeConfigRecursively() do?
mergeConfigRecursively() is a function in the astro codebase, defined in packages/astro/src/core/config/merge.ts.
Where is mergeConfigRecursively() defined?
mergeConfigRecursively() is defined in packages/astro/src/core/config/merge.ts at line 6.
What calls mergeConfigRecursively()?
mergeConfigRecursively() is called by 1 function(s): mergeConfig.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free