From 3240ed9a284205172e7096bcd8d65286770b7513 Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Mon, 24 Jun 2024 12:32:36 +0200 Subject: [PATCH 1/3] fix: preserve cached config while mutating config --- packages/build/src/core/config.js | 7 ++++--- packages/build/src/steps/update_config.js | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/build/src/core/config.js b/packages/build/src/core/config.js index 42e4fadc9c..3d8bc2614d 100644 --- a/packages/build/src/core/config.js +++ b/packages/build/src/core/config.js @@ -1,4 +1,4 @@ -import { resolveConfig, updateConfig, restoreConfig } from '@netlify/config' +import { resolveConfig, mergeConfigs, updateConfig, restoreConfig } from '@netlify/config' import mapObj from 'map-obj' import { getChildEnv } from '../env/main.js' @@ -138,9 +138,10 @@ const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, con // change would create debug logs which would be too verbose. // Errors are propagated and assigned to the specific plugin or core step // which changed the configuration. -export const resolveUpdatedConfig = async function (configOpts, configMutations) { +export const resolveUpdatedConfig = async function (configOpts, configMutations, netlifyConfig) { try { - return await resolveConfig({ ...configOpts, configMutations, debug: false }) + const resolved = await resolveConfig({ ...configOpts, configMutations, debug: false }) + return mergeConfigs([resolved, { config: netlifyConfig }], { concatenateArrays: true }) } catch (error) { changeErrorType(error, 'resolveConfig', 'pluginValidation') throw error diff --git a/packages/build/src/steps/update_config.js b/packages/build/src/steps/update_config.js index a6be72f1ef..f0374c5c9b 100644 --- a/packages/build/src/steps/update_config.js +++ b/packages/build/src/steps/update_config.js @@ -42,18 +42,18 @@ export const updateNetlifyConfig = async function ({ systemLogConfigMutations(systemLog, newConfigMutations) } - const configMutationsA = [...configMutations, ...newConfigMutations] + const mergedConfigMutations = [...configMutations, ...newConfigMutations] const { config: netlifyConfigA, headersPath: headersPathA, redirectsPath: redirectsPathA, - } = await resolveUpdatedConfig(configOpts, configMutationsA) + } = await resolveUpdatedConfig(configOpts, mergedConfigMutations, netlifyConfig) logConfigOnUpdate({ logs, netlifyConfig: netlifyConfigA, debug }) errorParams.netlifyConfig = netlifyConfigA return { netlifyConfig: netlifyConfigA, - configMutations: configMutationsA, + configMutations: mergedConfigMutations, headersPath: headersPathA, redirectsPath: redirectsPathA, } From 9347e7500371e15774633f4044ed4fdcdbebcdd7 Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Wed, 26 Jun 2024 17:49:25 +0200 Subject: [PATCH 2/3] chore: updates --- package.json | 3 ++- packages/build/src/core/build.ts | 7 +++++++ packages/build/src/core/config.js | 10 +++++++--- packages/build/src/steps/core_step.ts | 3 +++ packages/build/src/steps/plugin.js | 2 ++ packages/build/src/steps/run_core_steps.ts | 3 +++ packages/build/src/steps/run_step.ts | 5 +++++ packages/build/src/steps/run_steps.js | 2 ++ packages/build/src/steps/update_config.js | 3 ++- 9 files changed, 33 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index d8a8edb26a..6549dbe8d9 100644 --- a/package.json +++ b/package.json @@ -67,5 +67,6 @@ "lint-staged": { "!(packages/*/tests/**/fixtures/**/*)*.+(j|t)s": "eslint --ignore-path .gitignore --cache --fix", "*": "prettier --write --ignore-unknown" - } + }, + "packageManager": "yarn@1.22.22+sha256.c17d3797fb9a9115bf375e31bfd30058cac6bc9c3b8807a3d8cb2094794b51ca" } diff --git a/packages/build/src/core/build.ts b/packages/build/src/core/build.ts index 359475a903..22f474da23 100644 --- a/packages/build/src/core/build.ts +++ b/packages/build/src/core/build.ts @@ -180,6 +180,7 @@ const tExecBuild = async function ({ } = await runAndReportBuild({ pluginsOptions, netlifyConfig, + cachedConfig, configOpts, siteInfo, configPath, @@ -240,6 +241,7 @@ export const execBuild = measureDuration(tExecBuild, 'total', { parentTag: 'buil export const runAndReportBuild = async function ({ pluginsOptions, netlifyConfig, + cachedConfig, configOpts, siteInfo, configPath, @@ -295,6 +297,7 @@ export const runAndReportBuild = async function ({ } = await initAndRunBuild({ pluginsOptions, netlifyConfig, + cachedConfig, configOpts, siteInfo, configPath, @@ -400,6 +403,7 @@ export const runAndReportBuild = async function ({ const initAndRunBuild = async function ({ pluginsOptions, netlifyConfig, + cachedConfig, configOpts, siteInfo, configPath, @@ -508,6 +512,7 @@ const initAndRunBuild = async function ({ childProcesses, pluginsOptions: pluginsOptionsA, netlifyConfig, + cachedConfig, configOpts, packageJson, configPath, @@ -583,6 +588,7 @@ const runBuild = async function ({ childProcesses, pluginsOptions, netlifyConfig, + cachedConfig, configOpts, packageJson, configPath, @@ -671,6 +677,7 @@ const runBuild = async function ({ deployId, errorParams, netlifyConfig, + cachedConfig, configOpts, logs, debug, diff --git a/packages/build/src/core/config.js b/packages/build/src/core/config.js index 3d8bc2614d..3937154eec 100644 --- a/packages/build/src/core/config.js +++ b/packages/build/src/core/config.js @@ -138,10 +138,14 @@ const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, con // change would create debug logs which would be too verbose. // Errors are propagated and assigned to the specific plugin or core step // which changed the configuration. -export const resolveUpdatedConfig = async function (configOpts, configMutations, netlifyConfig) { +export const resolveUpdatedConfig = async function (configOpts, configMutations, cachedConfig) { try { - const resolved = await resolveConfig({ ...configOpts, configMutations, debug: false }) - return mergeConfigs([resolved, { config: netlifyConfig }], { concatenateArrays: true }) + return await resolveConfig({ + ...configOpts, + configMutations, + cachedConfig, + debug: false, + }) } catch (error) { changeErrorType(error, 'resolveConfig', 'pluginValidation') throw error diff --git a/packages/build/src/steps/core_step.ts b/packages/build/src/steps/core_step.ts index f72d132ed9..dd8f3c9c88 100644 --- a/packages/build/src/steps/core_step.ts +++ b/packages/build/src/steps/core_step.ts @@ -27,6 +27,7 @@ export const fireCoreStep = async function ({ errorParams, configOpts, netlifyConfig, + cachedConfig, configMutations, headersPath, redirectsPath, @@ -65,6 +66,7 @@ export const fireCoreStep = async function ({ branch, childEnv: childEnvA, netlifyConfig, + cachedConfig, nodePath, configMutations, headersPath, @@ -86,6 +88,7 @@ export const fireCoreStep = async function ({ } = await updateNetlifyConfig({ configOpts, netlifyConfig, + cachedConfig, headersPath, redirectsPath, configMutations, diff --git a/packages/build/src/steps/plugin.js b/packages/build/src/steps/plugin.js index 9a49f50de6..b4550d634b 100644 --- a/packages/build/src/steps/plugin.js +++ b/packages/build/src/steps/plugin.js @@ -26,6 +26,7 @@ export const firePluginStep = async function ({ errorParams, configOpts, netlifyConfig, + cachedConfig, configMutations, headersPath, redirectsPath, @@ -76,6 +77,7 @@ export const firePluginStep = async function ({ } = await updateNetlifyConfig({ configOpts, netlifyConfig, + cachedConfig, headersPath, packagePath, redirectsPath, diff --git a/packages/build/src/steps/run_core_steps.ts b/packages/build/src/steps/run_core_steps.ts index b7e5ff0bf0..7da5ee43ed 100644 --- a/packages/build/src/steps/run_core_steps.ts +++ b/packages/build/src/steps/run_core_steps.ts @@ -108,6 +108,7 @@ const executeBuildStep = async function ({ try { const { netlifyConfig: netlifyConfigA, configMutations } = await runBuildStep({ + cachedConfig, netlifyConfig, buildDir, nodePath, @@ -148,6 +149,7 @@ const executeBuildStep = async function ({ } const runBuildStep = async function ({ + cachedConfig, netlifyConfig, buildDir, nodePath, @@ -170,6 +172,7 @@ const runBuildStep = async function ({ nodePath, constants, netlifyConfig, + cachedConfig, logs, debug, timers: [], diff --git a/packages/build/src/steps/run_step.ts b/packages/build/src/steps/run_step.ts index 5a7540f00a..c8cc2df040 100644 --- a/packages/build/src/steps/run_step.ts +++ b/packages/build/src/steps/run_step.ts @@ -53,6 +53,7 @@ export const runStep = async function ({ failedPlugins, configOpts, netlifyConfig, + cachedConfig, configMutations, headersPath, redirectsPath, @@ -143,6 +144,7 @@ export const runStep = async function ({ durationNs, metrics, } = await fireStep({ + cachedConfig, event, childProcess, packageName, @@ -304,6 +306,7 @@ const getFireStep = function (packageName: string, coreStepId?: string, event?: } const tFireStep = function ({ + cachedConfig, event, childProcess, packageName, @@ -371,6 +374,7 @@ const tFireStep = function ({ errorParams, configOpts, netlifyConfig, + cachedConfig, configMutations, headersPath, redirectsPath, @@ -398,6 +402,7 @@ const tFireStep = function ({ errorParams, configOpts, netlifyConfig, + cachedConfig, configMutations, headersPath, redirectsPath, diff --git a/packages/build/src/steps/run_steps.js b/packages/build/src/steps/run_steps.js index 80d81c9a38..4f24831b37 100644 --- a/packages/build/src/steps/run_steps.js +++ b/packages/build/src/steps/run_steps.js @@ -11,6 +11,7 @@ import { runStep } from './run_step.js' // If an error arises, runs `onError` events. // Runs `onEnd` events at the end, whether an error was thrown or not. export const runSteps = async function ({ + cachedConfig, steps, buildbotServerSocket, events, @@ -134,6 +135,7 @@ export const runSteps = async function ({ error, failedPlugins, configOpts, + cachedConfig, netlifyConfig: netlifyConfigA, configMutations, headersPath: headersPathA, diff --git a/packages/build/src/steps/update_config.js b/packages/build/src/steps/update_config.js index f0374c5c9b..449736712a 100644 --- a/packages/build/src/steps/update_config.js +++ b/packages/build/src/steps/update_config.js @@ -13,6 +13,7 @@ import { logConfigMutations, systemLogConfigMutations } from '../log/messages/mu export const updateNetlifyConfig = async function ({ configOpts, netlifyConfig, + cachedConfig, headersPath, redirectsPath, configMutations, @@ -47,7 +48,7 @@ export const updateNetlifyConfig = async function ({ config: netlifyConfigA, headersPath: headersPathA, redirectsPath: redirectsPathA, - } = await resolveUpdatedConfig(configOpts, mergedConfigMutations, netlifyConfig) + } = await resolveUpdatedConfig(configOpts, mergedConfigMutations, cachedConfig) logConfigOnUpdate({ logs, netlifyConfig: netlifyConfigA, debug }) errorParams.netlifyConfig = netlifyConfigA From 58a94dbe559d46dad1c2be899d6ebd7a6a812b3f Mon Sep 17 00:00:00 2001 From: Lukas Holzer Date: Wed, 26 Jun 2024 17:54:35 +0200 Subject: [PATCH 3/3] chore: cleanup --- package.json | 3 +-- packages/build/src/core/config.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 6549dbe8d9..d8a8edb26a 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,5 @@ "lint-staged": { "!(packages/*/tests/**/fixtures/**/*)*.+(j|t)s": "eslint --ignore-path .gitignore --cache --fix", "*": "prettier --write --ignore-unknown" - }, - "packageManager": "yarn@1.22.22+sha256.c17d3797fb9a9115bf375e31bfd30058cac6bc9c3b8807a3d8cb2094794b51ca" + } } diff --git a/packages/build/src/core/config.js b/packages/build/src/core/config.js index 3937154eec..b2e0450d08 100644 --- a/packages/build/src/core/config.js +++ b/packages/build/src/core/config.js @@ -1,10 +1,10 @@ -import { resolveConfig, mergeConfigs, updateConfig, restoreConfig } from '@netlify/config' +import { resolveConfig, restoreConfig, updateConfig } from '@netlify/config' import mapObj from 'map-obj' import { getChildEnv } from '../env/main.js' import { addApiErrorHandlers } from '../error/api.js' import { changeErrorType } from '../error/info.js' -import { logBuildDir, logConfigPath, logConfig, logContext } from '../log/messages/config.js' +import { logBuildDir, logConfig, logConfigPath, logContext } from '../log/messages/config.js' import { logConfigOnUpload, logHeadersOnUpload, logRedirectsOnUpload } from '../log/messages/mutations.js' import { measureDuration } from '../time/main.js' import { getPackageJson } from '../utils/package.js'