( defaults: Record<string, any>, overrides: Record<string, any>, rootPath: string, )
| 1402 | } |
| 1403 | |
| 1404 | function 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) |
no test coverage detected