Skip to content

Commit 2d090fe

Browse files
committed
Only log purge notice once per process
1 parent ef149cf commit 2d090fe

File tree

4 files changed

+35
-46
lines changed

4 files changed

+35
-46
lines changed

src/featureFlags.js

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import _ from 'lodash'
22
import chalk from 'chalk'
3+
import log from './util/log'
34

45
const featureFlags = {
56
future: ['removeDeprecatedGapUtilities'],
@@ -57,27 +58,6 @@ export function issueFlagNotices(config) {
5758
return
5859
}
5960

60-
const log = {
61-
info(messages) {
62-
console.log('')
63-
messages.forEach(message => {
64-
console.log(chalk.bold.cyan('info'), '-', message)
65-
})
66-
},
67-
warn(messages) {
68-
console.log('')
69-
messages.forEach(message => {
70-
console.log(chalk.bold.yellow('warn'), '-', message)
71-
})
72-
},
73-
risk(messages) {
74-
console.log('')
75-
messages.forEach(message => {
76-
console.log(chalk.bold.magenta('risk'), '-', message)
77-
})
78-
},
79-
}
80-
8161
if (futureFlagsEnabled(config).length > 0) {
8262
const changes = futureFlagsEnabled(config)
8363
.map(s => chalk.cyan(s))

src/lib/purgeUnusedStyles.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import _ from 'lodash'
22
import postcss from 'postcss'
33
import purgecss from '@fullhuman/postcss-purgecss'
4-
import chalk from 'chalk'
5-
import { log } from '../cli/utils'
6-
import * as emoji from '../cli/emoji'
4+
import log from '../util/log'
75

86
function removeTailwindMarkers(css) {
97
css.walkAtRules('tailwind', rule => rule.remove())
@@ -21,7 +19,7 @@ function removeTailwindMarkers(css) {
2119
})
2220
}
2321

24-
export default function purgeUnusedUtilities(config) {
22+
export default function purgeUnusedUtilities(config, configChanged) {
2523
const purgeEnabled = _.get(
2624
config,
2725
'purge.enabled',
@@ -34,21 +32,14 @@ export default function purgeUnusedUtilities(config) {
3432

3533
// Skip if `purge: []` since that's part of the default config
3634
if (Array.isArray(config.purge) && config.purge.length === 0) {
37-
log()
38-
log(
39-
emoji.warning,
40-
chalk.yellow(
41-
' Tailwind is not purging unused styles because no template paths have been provided.'
42-
)
43-
)
44-
log(
45-
chalk.white(
46-
' If you have manually configured PurgeCSS outside of Tailwind or are deliberately not\n removing unused styles, set `purge: false` in your Tailwind config file to silence\n this warning.'
47-
)
48-
)
49-
log(
50-
chalk.white('\n https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css')
51-
)
35+
if (configChanged) {
36+
log.warn([
37+
'Tailwind is not purging unused styles because no template paths have been provided.',
38+
'If you have manually configured PurgeCSS outside of Tailwind or are deliberately not removing unused styles, set `purge: false` in your Tailwind config file to silence this warning.',
39+
'https://tailwindcss.com/docs/controlling-file-size/#removing-unused-css',
40+
])
41+
}
42+
5243
return removeTailwindMarkers
5344
}
5445

src/processTailwindFeatures.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { issueFlagNotices } from './featureFlags.js'
1818

1919
import hash from 'object-hash'
2020

21-
let flagsIssued = null
2221
let previousConfig = null
2322
let processedPlugins = null
2423
let getProcessedPlugins = null
@@ -29,12 +28,9 @@ export default function(getConfig) {
2928
const configChanged = hash(previousConfig) !== hash(config)
3029
previousConfig = config
3130

32-
if (!flagsIssued || !_.isEqual(flagsIssued, _.pick(config, ['future', 'experimental']))) {
33-
flagsIssued = _.pick(config, ['future', 'experimental'])
31+
if (configChanged) {
3432
issueFlagNotices(config)
35-
}
3633

37-
if (configChanged) {
3834
processedPlugins = processPlugins([...corePlugins(config), ...config.plugins], config)
3935
getProcessedPlugins = function() {
4036
return {
@@ -55,7 +51,7 @@ export default function(getConfig) {
5551
substituteScreenAtRules(config),
5652
substituteClassApplyAtRules(config, getProcessedPlugins, configChanged),
5753
applyImportantConfiguration(config),
58-
purgeUnusedStyles(config),
54+
purgeUnusedStyles(config, configChanged),
5955
]).process(css, { from: _.get(css, 'source.input.file') })
6056
}
6157
}

src/util/log.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import chalk from 'chalk'
2+
3+
export default {
4+
info(messages) {
5+
console.log('')
6+
messages.forEach(message => {
7+
console.log(chalk.bold.cyan('info'), '-', message)
8+
})
9+
},
10+
warn(messages) {
11+
console.log('')
12+
messages.forEach(message => {
13+
console.log(chalk.bold.yellow('warn'), '-', message)
14+
})
15+
},
16+
risk(messages) {
17+
console.log('')
18+
messages.forEach(message => {
19+
console.log(chalk.bold.magenta('risk'), '-', message)
20+
})
21+
},
22+
}

0 commit comments

Comments
 (0)