tailwindcss/src/processTailwindFeatures.js

102 lines
3.6 KiB
JavaScript
Raw Normal View History

import _ from 'lodash'
import postcss from 'postcss'
import substituteTailwindAtRules from './lib/substituteTailwindAtRules'
import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
import substituteVariantsAtRules from './lib/substituteVariantsAtRules'
import substituteResponsiveAtRules from './lib/substituteResponsiveAtRules'
import convertLayerAtRulesToControlComments from './lib/convertLayerAtRulesToControlComments'
import substituteScreenAtRules from './lib/substituteScreenAtRules'
import substituteClassApplyAtRules from './lib/substituteClassApplyAtRules'
import purgeUnusedStyles from './lib/purgeUnusedStyles'
2018-07-11 11:45:45 -04:00
2019-01-31 19:23:18 -05:00
import corePlugins from './corePlugins'
2018-06-22 20:57:40 -04:00
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.'
)
}
}
2019-01-09 11:48:04 -05:00
2018-07-16 08:37:23 -04:00
export default function(getConfig) {
return function(css) {
2018-07-16 08:37:23 -04:00
const config = getConfig()
issueFlagNotices(config)
2019-01-31 19:23:18 -05:00
const processedPlugins = processPlugins([...corePlugins(config), ...config.plugins], config)
const getProcessedPlugins = function() {
return {
...processedPlugins,
base: cloneNodes(processedPlugins.base),
components: cloneNodes(processedPlugins.components),
utilities: cloneNodes(processedPlugins.utilities),
}
}
return postcss([
substituteTailwindAtRules(config, getProcessedPlugins()),
evaluateTailwindFunctions(config),
substituteVariantsAtRules(config, getProcessedPlugins()),
substituteResponsiveAtRules(config),
convertLayerAtRulesToControlComments(config),
substituteScreenAtRules(config),
substituteClassApplyAtRules(config, getProcessedPlugins().utilities),
purgeUnusedStyles(config),
]).process(css, { from: _.get(css, 'source.input.file') })
}
}