Skip to content

Commit

Permalink
feat: pass default config for resolveUpdatedConfig instead of cached …
Browse files Browse the repository at this point in the history
…config
  • Loading branch information
lukasholzer committed Jul 10, 2024
1 parent 6e08464 commit 669c426
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 29 deletions.
15 changes: 8 additions & 7 deletions packages/build/src/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const tExecBuild = async function ({
} = await loadConfig({
configOpts,
cachedConfig,
defaultConfig,
cachedConfigPath,
envOpt,
debug,
Expand Down Expand Up @@ -180,7 +181,7 @@ const tExecBuild = async function ({
} = await runAndReportBuild({
pluginsOptions,
netlifyConfig,
cachedConfig,
defaultConfig,
configOpts,
siteInfo,
configPath,
Expand Down Expand Up @@ -241,7 +242,7 @@ export const execBuild = measureDuration(tExecBuild, 'total', { parentTag: 'buil
export const runAndReportBuild = async function ({
pluginsOptions,
netlifyConfig,
cachedConfig,
defaultConfig,
configOpts,
siteInfo,
configPath,
Expand Down Expand Up @@ -297,7 +298,7 @@ export const runAndReportBuild = async function ({
} = await initAndRunBuild({
pluginsOptions,
netlifyConfig,
cachedConfig,
defaultConfig,
configOpts,
siteInfo,
configPath,
Expand Down Expand Up @@ -403,7 +404,7 @@ export const runAndReportBuild = async function ({
const initAndRunBuild = async function ({
pluginsOptions,
netlifyConfig,
cachedConfig,
defaultConfig,
configOpts,
siteInfo,
configPath,
Expand Down Expand Up @@ -512,7 +513,7 @@ const initAndRunBuild = async function ({
childProcesses,
pluginsOptions: pluginsOptionsA,
netlifyConfig,
cachedConfig,
defaultConfig,
configOpts,
packageJson,
configPath,
Expand Down Expand Up @@ -588,7 +589,7 @@ const runBuild = async function ({
childProcesses,
pluginsOptions,
netlifyConfig,
cachedConfig,
defaultConfig,
configOpts,
packageJson,
configPath,
Expand Down Expand Up @@ -677,7 +678,7 @@ const runBuild = async function ({
deployId,
errorParams,
netlifyConfig,
cachedConfig,
defaultConfig,
configOpts,
logs,
debug,
Expand Down
9 changes: 4 additions & 5 deletions packages/build/src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,15 @@ const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, con
// Errors are propagated and assigned to the specific plugin or core step
// which changed the configuration.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const resolveUpdatedConfig = async function (configOpts, configMutations, cachedConfig) {
export const resolveUpdatedConfig = async function (configOpts, configMutations, defaultConfig) {
try {
return await resolveConfig({
const resolved = await resolveConfig({
...configOpts,
configMutations,
// TODO: remove cached Config here again as this causes tests to fail in the CLI
// Currently investigating the root cause.
// cachedConfig,
defaultConfig,
debug: false,
})
return resolved
} catch (error) {
changeErrorType(error, 'resolveConfig', 'pluginValidation')
throw error
Expand Down
6 changes: 3 additions & 3 deletions packages/build/src/steps/core_step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const fireCoreStep = async function ({
errorParams,
configOpts,
netlifyConfig,
cachedConfig,
defaultConfig,
configMutations,
headersPath,
redirectsPath,
Expand Down Expand Up @@ -66,7 +66,7 @@ export const fireCoreStep = async function ({
branch,
childEnv: childEnvA,
netlifyConfig,
cachedConfig,
defaultConfig,
nodePath,
configMutations,
headersPath,
Expand All @@ -88,7 +88,7 @@ export const fireCoreStep = async function ({
} = await updateNetlifyConfig({
configOpts,
netlifyConfig,
cachedConfig,
defaultConfig,
headersPath,
redirectsPath,
configMutations,
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/steps/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const firePluginStep = async function ({
errorParams,
configOpts,
netlifyConfig,
cachedConfig,
defaultConfig,
configMutations,
headersPath,
redirectsPath,
Expand Down Expand Up @@ -77,7 +77,7 @@ export const firePluginStep = async function ({
} = await updateNetlifyConfig({
configOpts,
netlifyConfig,
cachedConfig,
defaultConfig,
headersPath,
packagePath,
redirectsPath,
Expand Down
6 changes: 3 additions & 3 deletions packages/build/src/steps/run_core_steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const executeBuildStep = async function ({

try {
const { netlifyConfig: netlifyConfigA, configMutations } = await runBuildStep({
cachedConfig,
defaultConfig,
netlifyConfig,
buildDir,
nodePath,
Expand Down Expand Up @@ -149,7 +149,7 @@ const executeBuildStep = async function ({
}

const runBuildStep = async function ({
cachedConfig,
defaultConfig,
netlifyConfig,
buildDir,
nodePath,
Expand All @@ -172,7 +172,7 @@ const runBuildStep = async function ({
nodePath,
constants,
netlifyConfig,
cachedConfig,
defaultConfig,
logs,
debug,
timers: [],
Expand Down
10 changes: 5 additions & 5 deletions packages/build/src/steps/run_step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const runStep = async function ({
failedPlugins,
configOpts,
netlifyConfig,
cachedConfig,
defaultConfig,
configMutations,
headersPath,
redirectsPath,
Expand Down Expand Up @@ -144,7 +144,7 @@ export const runStep = async function ({
durationNs,
metrics,
} = await fireStep({
cachedConfig,
defaultConfig,
event,
childProcess,
packageName,
Expand Down Expand Up @@ -306,7 +306,7 @@ const getFireStep = function (packageName: string, coreStepId?: string, event?:
}

const tFireStep = function ({
cachedConfig,
defaultConfig,
event,
childProcess,
packageName,
Expand Down Expand Up @@ -374,7 +374,7 @@ const tFireStep = function ({
errorParams,
configOpts,
netlifyConfig,
cachedConfig,
defaultConfig,
configMutations,
headersPath,
redirectsPath,
Expand Down Expand Up @@ -402,7 +402,7 @@ const tFireStep = function ({
errorParams,
configOpts,
netlifyConfig,
cachedConfig,
defaultConfig,
configMutations,
headersPath,
redirectsPath,
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/steps/run_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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,
defaultConfig,
steps,
buildbotServerSocket,
events,
Expand Down Expand Up @@ -135,7 +135,7 @@ export const runSteps = async function ({
error,
failedPlugins,
configOpts,
cachedConfig,
defaultConfig,
netlifyConfig: netlifyConfigA,
configMutations,
headersPath: headersPathA,
Expand Down
4 changes: 2 additions & 2 deletions packages/build/src/steps/update_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { logConfigMutations, systemLogConfigMutations } from '../log/messages/mu
export const updateNetlifyConfig = async function ({
configOpts,
netlifyConfig,
cachedConfig,
defaultConfig,
headersPath,
redirectsPath,
configMutations,
Expand Down Expand Up @@ -48,7 +48,7 @@ export const updateNetlifyConfig = async function ({
config: netlifyConfigA,
headersPath: headersPathA,
redirectsPath: redirectsPathA,
} = await resolveUpdatedConfig(configOpts, mergedConfigMutations, cachedConfig)
} = await resolveUpdatedConfig(configOpts, mergedConfigMutations, defaultConfig)
logConfigOnUpdate({ logs, netlifyConfig: netlifyConfigA, debug })

errorParams.netlifyConfig = netlifyConfigA
Expand Down
27 changes: 27 additions & 0 deletions packages/config/tests/mutate/tests.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { existsSync } from 'fs'
import { copyFile, rm } from 'fs/promises'
import { join } from 'path'
import { fileURLToPath } from 'url'

import { Fixture, normalizeOutput } from '@netlify/testing'
import test from 'ava'

import { updateConfig } from '../../lib/index.js'
import { resolveConfig } from '../../lib/main.js'

const FIXTURES_DIR = fileURLToPath(new URL('fixtures', import.meta.url))

Expand Down Expand Up @@ -140,3 +142,28 @@ test('updateConfig() does not delete _headers if headersPath not provided', asyn
t.is(typeof headersPath, 'string')
t.true(existsSync(headersPath))
})

test('Programmatic resolveConfig with configMutations', async (t) => {
const { config } = await resolveConfig({
mode: 'cli',
context: 'production',
configMutations: [{ keys: ['functions', 'directory'], value: 'new_functions', event: 'onPreBuild' }],
})
t.is(config.functionsDirectory, join(process.cwd(), 'new_functions'))
t.is(config.build.functions, join(process.cwd(), 'new_functions'))
})

test('Programmatic resolveConfig with configMutations and defaultConfig', async (t) => {
const { config } = await resolveConfig({
mode: 'cli',
context: 'production',
defaultConfig: {
functionsDirectory: 'functions',
build: { functions: 'functions' },
},
configMutations: [{ keys: ['functions', 'directory'], value: 'new_functions', event: 'onPreBuild' }],
})

t.is(config.functionsDirectory, join(process.cwd(), 'new_functions'))
t.is(config.build.functions, join(process.cwd(), 'new_functions'))
})

0 comments on commit 669c426

Please sign in to comment.