Skip to content

Commit 37ac46e

Browse files
author
Lukas Holzer
authored
feat: pass feature flags down to netlify build on dev (#6291)
1 parent 605ba2c commit 37ac46e

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/lib/build.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import build from '@netlify/build'
55
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'toml... Remove this comment to see the full error message
66
import tomlify from 'tomlify-j0.4'
77

8-
import { isFeatureFlagEnabled } from '../utils/feature-flags.js'
8+
import { getFeatureFlagsFromSiteInfo } from '../utils/feature-flags.js'
99

1010
import { getBootstrapURL } from './edge-functions/bootstrap.js'
1111
import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/consts.js'
@@ -93,17 +93,6 @@ export const getBuildOptions = ({
9393
}
9494
}
9595

96-
/**
97-
* @param {*} siteInfo
98-
* @returns {Record<string, any>}
99-
*/
100-
// @ts-expect-error TS(7006) FIXME: Parameter 'siteInfo' implicitly has an 'any' type.
101-
const getFeatureFlagsFromSiteInfo = (siteInfo) => ({
102-
...siteInfo.feature_flags,
103-
// see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
104-
zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
105-
})
106-
10796
/**
10897
* run the build command
10998
* @param {BuildConfig} options

src/utils/feature-flags.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@
1313
// @ts-expect-error TS(7006) FIXME: Parameter 'flagName' implicitly has an 'any' type.
1414
export const isFeatureFlagEnabled = (flagName: string, siteInfo): boolean =>
1515
Boolean(siteInfo.feature_flags && siteInfo.feature_flags[flagName] !== false)
16+
17+
/**
18+
* Retrieves all Feature flags from the siteInfo
19+
*/
20+
export const getFeatureFlagsFromSiteInfo = (siteInfo: {
21+
feature_flags?: Record<string, boolean | string | number>
22+
}): Record<string, boolean | string | number> => ({
23+
...(siteInfo.feature_flags || {}),
24+
// see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
25+
zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
26+
})

src/utils/run-build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getPathInProject } from '../lib/settings.js'
88
import { error } from './command-helpers.js'
99
import { startFrameworkServer } from './framework-server.js'
1010
import { INTERNAL_FUNCTIONS_FOLDER } from './functions/index.js'
11+
import { getFeatureFlagsFromSiteInfo } from './feature-flags.js'
1112

1213
const netlifyBuildPromise = import('@netlify/build')
1314

@@ -71,6 +72,7 @@ export const runNetlifyBuild = async ({ command, env = {}, options, settings, ti
7172
mode: 'cli',
7273
telemetry: false,
7374
buffer: false,
75+
featureFlags: getFeatureFlagsFromSiteInfo(cachedConfig.siteInfo),
7476
offline: options.offline,
7577
packagePath: command.workspacePackage,
7678
cwd: cachedConfig.buildDir,

0 commit comments

Comments
 (0)