Skip to content

feat: pass feature flags down to netlify build on dev #6291

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

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 1 addition & 12 deletions src/lib/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import build from '@netlify/build'
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'toml... Remove this comment to see the full error message
import tomlify from 'tomlify-j0.4'

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

import { getBootstrapURL } from './edge-functions/bootstrap.js'
import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/consts.js'
Expand Down Expand Up @@ -93,17 +93,6 @@ export const getBuildOptions = ({
}
}

/**
* @param {*} siteInfo
* @returns {Record<string, any>}
*/
// @ts-expect-error TS(7006) FIXME: Parameter 'siteInfo' implicitly has an 'any' type.
const getFeatureFlagsFromSiteInfo = (siteInfo) => ({
...siteInfo.feature_flags,
// see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
})

Comment on lines -101 to -106
Copy link
Contributor Author

@lukasholzer lukasholzer Jan 9, 2024

Choose a reason for hiding this comment

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

just moved to the feature-flag.ts file and fixed the object destruction as feature_flags is undefined on sites that are not linked

/**
* run the build command
* @param {BuildConfig} options
Expand Down
11 changes: 11 additions & 0 deletions src/utils/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@
// @ts-expect-error TS(7006) FIXME: Parameter 'flagName' implicitly has an 'any' type.
export const isFeatureFlagEnabled = (flagName: string, siteInfo): boolean =>
Boolean(siteInfo.feature_flags && siteInfo.feature_flags[flagName] !== false)

/**
* Retrieves all Feature flags from the siteInfo
*/
export const getFeatureFlagsFromSiteInfo = (siteInfo: {
feature_flags?: Record<string, boolean | string | number>
}): Record<string, boolean | string | number> => ({
...(siteInfo.feature_flags || {}),
// see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
})
2 changes: 2 additions & 0 deletions src/utils/run-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getPathInProject } from '../lib/settings.js'
import { error } from './command-helpers.js'
import { startFrameworkServer } from './framework-server.js'
import { INTERNAL_FUNCTIONS_FOLDER } from './functions/index.js'
import { getFeatureFlagsFromSiteInfo } from './feature-flags.js'

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

Expand Down Expand Up @@ -71,6 +72,7 @@ export const runNetlifyBuild = async ({ command, env = {}, options, settings, ti
mode: 'cli',
telemetry: false,
buffer: false,
featureFlags: getFeatureFlagsFromSiteInfo(cachedConfig.siteInfo),
offline: options.offline,
packagePath: command.workspacePackage,
cwd: cachedConfig.buildDir,
Expand Down