2018-07-16 08:35:58 -04:00
|
|
|
import _ from 'lodash'
|
2018-06-22 20:52:59 -04:00
|
|
|
import postcss from 'postcss'
|
|
|
|
|
|
|
|
|
|
import substituteTailwindAtRules from './lib/substituteTailwindAtRules'
|
|
|
|
|
import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
|
|
|
|
|
import substituteVariantsAtRules from './lib/substituteVariantsAtRules'
|
|
|
|
|
import substituteResponsiveAtRules from './lib/substituteResponsiveAtRules'
|
2020-07-15 09:41:19 -04:00
|
|
|
import convertLayerAtRulesToControlComments from './lib/convertLayerAtRulesToControlComments'
|
2018-06-22 20:52:59 -04:00
|
|
|
import substituteScreenAtRules from './lib/substituteScreenAtRules'
|
|
|
|
|
import substituteClassApplyAtRules from './lib/substituteClassApplyAtRules'
|
2020-04-28 09:51:27 -04:00
|
|
|
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'
|
2020-07-21 10:21:57 -04:00
|
|
|
import cloneNodes from './util/cloneNodes'
|
2020-08-05 13:59:59 -04:00
|
|
|
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) {
|
2018-07-16 08:30:57 -04:00
|
|
|
return function(css) {
|
2018-07-16 08:37:23 -04:00
|
|
|
const config = getConfig()
|
2020-08-05 13:59:59 -04:00
|
|
|
|
|
|
|
|
issueFlagNotices(config)
|
|
|
|
|
|
2019-01-31 19:23:18 -05:00
|
|
|
const processedPlugins = processPlugins([...corePlugins(config), ...config.plugins], config)
|
2018-06-22 20:52:59 -04:00
|
|
|
|
2020-07-21 10:21:57 -04:00
|
|
|
const getProcessedPlugins = function() {
|
|
|
|
|
return {
|
|
|
|
|
...processedPlugins,
|
|
|
|
|
base: cloneNodes(processedPlugins.base),
|
|
|
|
|
components: cloneNodes(processedPlugins.components),
|
|
|
|
|
utilities: cloneNodes(processedPlugins.utilities),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-16 08:30:57 -04:00
|
|
|
return postcss([
|
2020-07-21 10:21:57 -04:00
|
|
|
substituteTailwindAtRules(config, getProcessedPlugins()),
|
2019-01-22 11:47:48 -05:00
|
|
|
evaluateTailwindFunctions(config),
|
2020-07-21 10:21:57 -04:00
|
|
|
substituteVariantsAtRules(config, getProcessedPlugins()),
|
2018-07-16 08:30:57 -04:00
|
|
|
substituteResponsiveAtRules(config),
|
2020-07-15 09:41:19 -04:00
|
|
|
convertLayerAtRulesToControlComments(config),
|
2018-07-16 08:30:57 -04:00
|
|
|
substituteScreenAtRules(config),
|
2020-07-21 10:21:57 -04:00
|
|
|
substituteClassApplyAtRules(config, getProcessedPlugins().utilities),
|
2020-04-28 09:51:27 -04:00
|
|
|
purgeUnusedStyles(config),
|
2018-07-16 08:35:58 -04:00
|
|
|
]).process(css, { from: _.get(css, 'source.input.file') })
|
2018-07-16 08:30:57 -04:00
|
|
|
}
|
2018-06-22 20:52:59 -04:00
|
|
|
}
|