Skip to content

Commit

Permalink
feat: add method for an inline merge of the netlify config
Browse files Browse the repository at this point in the history
  • Loading branch information
estephinson committed Nov 7, 2023
1 parent f6bb421 commit afb2b4b
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions packages/config/src/mutations/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ import { serializeToml } from '../utils/toml.js'

import { applyMutations } from './apply.js'

// Performs a merge of the configuration changes with the existing `netlify.toml`,
// and returns the updated configuration
export const mergeConfig = async function (
configMutations,
{ configPath, headersPath, redirectsPath, context, branch, logs, featureFlags },
) {
if (configMutations.length === 0) {
return
}

const inlineConfig = applyMutations({}, configMutations)
const normalizedInlineConfig = ensureConfigPriority(inlineConfig, context, branch)
const updatedConfig = await mergeWithConfig(normalizedInlineConfig, configPath)
const configWithHeaders = await addHeaders({ config: updatedConfig, headersPath, logs, featureFlags })
const finalConfig = await addRedirects({ config: configWithHeaders, redirectsPath, logs, featureFlags })
const simplifiedConfig = simplifyConfig(finalConfig)

return simplifiedConfig
}

// Persist configuration changes to `netlify.toml`.
// If `netlify.toml` does not exist, creates it. Otherwise, merges the changes.
export const updateConfig = async function (
Expand All @@ -26,16 +46,16 @@ export const updateConfig = async function (
featureFlags,
},
) {
if (configMutations.length === 0) {
return
}

const inlineConfig = applyMutations({}, configMutations)
const normalizedInlineConfig = ensureConfigPriority(inlineConfig, context, branch)
const updatedConfig = await mergeWithConfig(normalizedInlineConfig, configPath)
const configWithHeaders = await addHeaders({ config: updatedConfig, headersPath, logs, featureFlags })
const finalConfig = await addRedirects({ config: configWithHeaders, redirectsPath, logs, featureFlags })
const simplifiedConfig = simplifyConfig(finalConfig)
const simplifiedConfig = await mergeConfig(configMutations, {
buildDir,
configPath,
headersPath,
redirectsPath,
context,
branch,
logs,
featureFlags,
})

await backupConfig({ buildDir, configPath, headersPath, redirectsPath })
await Promise.all([
Expand Down

0 comments on commit afb2b4b

Please sign in to comment.