Skip to content

Commit

Permalink
feat: pass feature flags down to netlify build on dev (#6291)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasholzer authored Jan 9, 2024
1 parent 605ba2c commit 37ac46e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
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),
})

/**
* 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

2 comments on commit 37ac46e

@github-actions
Copy link

Choose a reason for hiding this comment

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

📊 Benchmark results

  • Dependency count: 1,410
  • Package size: 422 MB
  • Number of ts-expect-error directives: 1,182

@github-actions
Copy link

Choose a reason for hiding this comment

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

📊 Benchmark results

  • Dependency count: 1,410
  • Package size: 422 MB
  • Number of ts-expect-error directives: 1,182

Please sign in to comment.