Skip to content

Commit

Permalink
Better error handling for removed experimental features
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed Oct 4, 2020
1 parent f3a4f22 commit 629737f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 28 additions & 1 deletion src/featureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import log from './util/log'
const featureFlags = {
future: ['removeDeprecatedGapUtilities', 'purgeLayersByDefault'],
experimental: [
'uniformColorPalette',
'extendedSpacingScale',
'defaultLineHeights',
'extendedFontSizeScale',
Expand All @@ -15,6 +14,15 @@ const featureFlags = {
'additionalBreakpoint',
'redesignedColorPalette',
],
removed: {
uniformColorPalette: [
`The ${chalk.red(
'uniformColorPalette'
)} experiment has been removed in favor of a different color palette.`,
'If you would like to continue using this palette, you can copy it manually from here:',
'https://github.com/tailwindlabs/tailwindcss/blob/753925f72c61980fa6d7ba398b7e2a1ba0e4b438/src/flagged/uniformColorPalette.js',
],
},
}

export function flagEnabled(config, flag) {
Expand Down Expand Up @@ -47,7 +55,26 @@ function futureFlagsAvailable(config) {
return featureFlags.future.filter(flag => !_.has(config, ['future', flag]))
}

function removedFlagsEnabled(config) {
if (config.experimental === 'all') {
return false
}

return Object.keys(_.get(config, 'experimental', {})).filter(
flag => Object.keys(featureFlags.removed).includes(flag) && config.experimental[flag]
)
}

export function issueFlagNotices(config) {
if (removedFlagsEnabled(config).length > 0) {
removedFlagsEnabled(config).forEach(flag => {
log.error(featureFlags.removed[flag])
})

console.warn('')
throw new Error('Enabled experimental features have been removed.')
}

if (process.env.JEST_WORKER_ID !== undefined) {
return
}
Expand Down
2 changes: 0 additions & 2 deletions src/util/getAllConfigs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import defaultConfig from '../../stubs/defaultConfig.stub.js'
import { flagEnabled } from '../featureFlags'
import uniformColorPalette from '../flagged/uniformColorPalette.js'
import extendedSpacingScale from '../flagged/extendedSpacingScale.js'
import defaultLineHeights from '../flagged/defaultLineHeights.js'
import extendedFontSizeScale from '../flagged/extendedFontSizeScale.js'
Expand All @@ -12,7 +11,6 @@ import redesignedColorPalette from '../flagged/redesignedColorPalette'
export default function getAllConfigs(config) {
const configs = [defaultConfig]
const features = {
uniformColorPalette,
extendedSpacingScale,
defaultLineHeights,
extendedFontSizeScale,
Expand Down

0 comments on commit 629737f

Please sign in to comment.