diff --git a/src/featureFlags.js b/src/featureFlags.js new file mode 100644 index 000000000..ee45ad939 --- /dev/null +++ b/src/featureFlags.js @@ -0,0 +1,71 @@ +import _ from 'lodash' +import chalk from 'chalk' + +const featureFlags = { + future: [], + experimental: ['uniformColorPalette'], +} + +export function flagEnabled(config, flag) { + if (featureFlags.future.includes(flag)) { + return _.get(config, ['future', flag], false) + } + + if (featureFlags.experimental.includes(flag)) { + return _.get(config, ['experimental', flag], false) + } + + return false +} + +export function issueFlagNotices(config) { + const log = { + info(message) { + console.log(chalk.bold.cyan(' info'), '-', message) + }, + warn(message) { + console.log(chalk.bold.yellow(' warn'), '-', message) + }, + risk(message) { + console.log(chalk.bold.magenta(' risk'), '-', message) + }, + } + + if (_.some(featureFlags.future, flag => _.get(config, ['future', flag], false))) { + const changes = Object.keys(config.future) + .filter(flag => featureFlags.future.includes(flag) && config.future[flag]) + .map(s => chalk.cyan(s)) + .join(', ') + console.log() + log.info(`You have opted-in to future-facing breaking changes: ${changes}`) + log.info( + 'These changes are stable and will be the default behavior in the next major version of Tailwind.' + ) + } + + if (_.some(featureFlags.experimental, flag => _.get(config, ['experimental', flag], false))) { + const changes = Object.keys(config.experimental) + .filter(flag => featureFlags.experimental.includes(flag) && config.experimental[flag]) + .map(s => chalk.yellow(s)) + .join(', ') + console.log() + log.warn(`You have enabled experimental features: ${changes}`) + log.warn( + 'Experimental features are not covered by semver, may introduce breaking changes, and can change at any time.' + ) + } + + if (Object.keys(_.get(config, 'future', {})).length < featureFlags.future.length) { + const changes = featureFlags.future + .filter(flag => !_.has(config, ['future', flag])) + .map(s => chalk.magenta(s)) + .join(', ') + console.log() + log.risk(`There are upcoming breaking changes: ${changes}`) + log.risk( + 'We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future.' + ) + } +} + +export default featureFlags diff --git a/src/index.js b/src/index.js index 900813338..9f507f55b 100644 --- a/src/index.js +++ b/src/index.js @@ -11,13 +11,14 @@ import formatCSS from './lib/formatCSS' import resolveConfig from './util/resolveConfig' import { defaultConfigFile } from './constants' import defaultConfig from '../stubs/defaultConfig.stub.js' +import { flagEnabled } from './featureFlags' import uniformColorPalette from './flagged/uniformColorPalette.js' function getDefaultConfigs(config) { const configs = [defaultConfig] - if (_.get(config, ['experimental', 'uniformColorPalette'], false)) { + if (flagEnabled(config, 'uniformColorPalette')) { configs.unshift(uniformColorPalette) } diff --git a/src/processTailwindFeatures.js b/src/processTailwindFeatures.js index 494dd0178..7899dee7e 100644 --- a/src/processTailwindFeatures.js +++ b/src/processTailwindFeatures.js @@ -13,62 +13,7 @@ import purgeUnusedStyles from './lib/purgeUnusedStyles' import corePlugins from './corePlugins' import processPlugins from './util/processPlugins' import cloneNodes from './util/cloneNodes' -import chalk from 'chalk' - -const log = { - info(message) { - console.log(chalk.bold.cyan(' info'), '-', message) - }, - warn(message) { - console.log(chalk.bold.yellow(' warn'), '-', message) - }, - risk(message) { - console.log(chalk.bold.magenta(' risk'), '-', message) - }, -} - -function issueFlagNotices(config) { - const featureFlags = { - future: [], - experimental: ['uniformColorPalette'], - } - - if (_.some(featureFlags.future, flag => _.get(config, ['future', flag], false))) { - const changes = Object.keys(config.future) - .filter(flag => featureFlags.future.includes(flag) && config.future[flag]) - .map(s => chalk.cyan(s)) - .join(', ') - console.log() - log.info(`You have opted-in to future-facing breaking changes: ${changes}`) - log.info( - 'These changes are stable and will be the default behavior in the next major version of Tailwind.' - ) - } - - if (_.some(featureFlags.experimental, flag => _.get(config, ['experimental', flag], false))) { - const changes = Object.keys(config.experimental) - .filter(flag => featureFlags.experimental.includes(flag) && config.experimental[flag]) - .map(s => chalk.yellow(s)) - .join(', ') - console.log() - log.warn(`You have enabled experimental features: ${changes}`) - log.warn( - 'Experimental features are not covered by semver, may introduce breaking changes, and can change at any time.' - ) - } - - if (Object.keys(_.get(config, 'future', {})).length < featureFlags.future.length) { - const changes = featureFlags.future - .filter(flag => !_.has(config, ['future', flag])) - .map(s => chalk.magenta(s)) - .join(', ') - console.log() - log.risk(`There are upcoming breaking changes: ${changes}`) - log.risk( - 'We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future.' - ) - } -} +import { issueFlagNotices } from './featureFlags.js' export default function(getConfig) { return function(css) {