MCPcopy
hub / github.com/vitejs/vite / mergeConfigRecursively

Function mergeConfigRecursively

packages/vite/src/node/utils.ts:1404–1507  ·  view source on GitHub ↗
(
  defaults: Record<string, any>,
  overrides: Record<string, any>,
  rootPath: string,
)

Source from the content-addressed store, hash-verified

1402}
1403
1404function mergeConfigRecursively(
1405 defaults: Record<string, any>,
1406 overrides: Record<string, any>,
1407 rootPath: string,
1408) {
1409 const merged: Record<string, any> = { ...defaults }
1410 if (rollupOptionsRootPaths.has(rootPath)) {
1411 setupRollupOptionCompat(merged, rootPath)
1412 }
1413 if (rootPath === 'server') {
1414 setupHmrWsOptionCompat(merged)
1415 }
1416 if (rootPath === 'server.hmr') {
1417 for (const key of wsOptionKeys) {
1418 Object.defineProperty(
1419 merged,
1420 key,
1421 Object.getOwnPropertyDescriptor(defaults, key)!,
1422 )
1423 }
1424 }
1425
1426 for (const key in overrides) {
1427 const value = overrides[key]
1428 if (value == null) {
1429 continue
1430 }
1431
1432 let existing = merged[key]
1433 if (key === 'rollupOptions' && rollupOptionsRootPaths.has(rootPath)) {
1434 // if both rollupOptions and rolldownOptions are present,
1435 // ignore rollupOptions and use rolldownOptions
1436 if (overrides.rolldownOptions) continue
1437 existing = merged.rolldownOptions
1438 }
1439
1440 if (existing == null) {
1441 if (rootPath === '' && key === 'environments' && isObject(value)) {
1442 // Clone to avoid mutating the original override object
1443 const environments = { ...value }
1444 for (const envName in environments) {
1445 environments[envName] = setupRollupOptionCompatForEnvironment(
1446 environments[envName],
1447 )
1448 }
1449 merged[key] = environments
1450 } else if (rootPath === 'environments') {
1451 // `environments` exists, but a new environment is added
1452 merged[key] = setupRollupOptionCompatForEnvironment(value)
1453 } else {
1454 merged[key] = value
1455 }
1456 continue
1457 }
1458
1459 // fields that require special handling
1460 if (key === 'alias' && (rootPath === 'resolve' || rootPath === '')) {
1461 merged[key] = mergeAlias(existing, value)

Callers 1

mergeConfigFunction · 0.85

Calls 8

setupRollupOptionCompatFunction · 0.85
setupHmrWsOptionCompatFunction · 0.85
isObjectFunction · 0.85
mergeAliasFunction · 0.85
arraifyFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected