Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add method for an inline merge of the netlify config #5369

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 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 (
Comment on lines +13 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Performs a merge of the configuration changes with the existing `netlify.toml`,
// and returns the updated configuration
export const mergeConfig = async function (
/**
* Performs a merge of the configuration changes with the existing `netlify.toml`,
* and returns the updated configuration
*/
export const mergeConfig = async function (

Use JSDoc for function annotations as they can be picked up by the intellisense

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,15 @@ 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, {
configPath,
headersPath,
redirectsPath,
context,
branch,
logs,
featureFlags,
})

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