diff --git a/packages/gatsby/src/bootstrap/load-config/index.ts b/packages/gatsby/src/bootstrap/load-config/index.ts index 585dfe8bc4a1f..44282be0f2580 100644 --- a/packages/gatsby/src/bootstrap/load-config/index.ts +++ b/packages/gatsby/src/bootstrap/load-config/index.ts @@ -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`) } }