Skip to content

Commit

Permalink
fix: setup base flags when config file doesn't exist (#37714)
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh authored Mar 1, 2023
1 parent 21e798b commit 44cbfb5
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions packages/gatsby/src/bootstrap/load-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,43 @@ export async function loadConfig({
})
}

if (config && processFlags) {
if (processFlags) {
// Setup flags
if (config) {
// Get flags
const {
enabledConfigFlags,
unknownFlagMessage,
unfitFlagMessage,
message,
} = handleFlags(availableFlags, config.flags)
const {
enabledConfigFlags,
unknownFlagMessage,
unfitFlagMessage,
message,
} = handleFlags(availableFlags, config?.flags ?? {})

if (unknownFlagMessage !== ``) {
reporter.warn(unknownFlagMessage)
}
if (unfitFlagMessage !== ``) {
reporter.warn(unfitFlagMessage)
}
// set process.env for each flag
enabledConfigFlags.forEach(flag => {
process.env[flag.env] = `true`
})

// Print out message.
if (message !== ``) {
reporter.info(message)
}
if (unknownFlagMessage !== ``) {
reporter.warn(unknownFlagMessage)
}
if (unfitFlagMessage !== ``) {
reporter.warn(unfitFlagMessage)
}
// set process.env for each flag
enabledConfigFlags.forEach(flag => {
process.env[flag.env] = `true`
})

process.env.GATSBY_SLICES = `true`
// Print out message.
if (message !== ``) {
reporter.info(message)
}

// track usage of feature
enabledConfigFlags.forEach(flag => {
if (flag.telemetryId) {
telemetry.trackFeatureIsUsed(flag.telemetryId)
}
})
process.env.GATSBY_SLICES = `true`

// Track the usage of config.flags
if (config.flags) {
telemetry.trackFeatureIsUsed(`ConfigFlags`)
// track usage of feature
enabledConfigFlags.forEach(flag => {
if (flag.telemetryId) {
telemetry.trackFeatureIsUsed(flag.telemetryId)
}
})

// Track the usage of config.flags
if (config?.flags) {
telemetry.trackFeatureIsUsed(`ConfigFlags`)
}
}

Expand Down

0 comments on commit 44cbfb5

Please sign in to comment.