Skip to content

Commit 61635f4

Browse files
committed
Co-locate feature flag utilities
1 parent a7c4106 commit 61635f4

File tree

3 files changed

+74
-57
lines changed

3 files changed

+74
-57
lines changed

src/featureFlags.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import _ from 'lodash'
2+
import chalk from 'chalk'
3+
4+
const featureFlags = {
5+
future: [],
6+
experimental: ['uniformColorPalette'],
7+
}
8+
9+
export function flagEnabled(config, flag) {
10+
if (featureFlags.future.includes(flag)) {
11+
return _.get(config, ['future', flag], false)
12+
}
13+
14+
if (featureFlags.experimental.includes(flag)) {
15+
return _.get(config, ['experimental', flag], false)
16+
}
17+
18+
return false
19+
}
20+
21+
export function issueFlagNotices(config) {
22+
const log = {
23+
info(message) {
24+
console.log(chalk.bold.cyan(' info'), '-', message)
25+
},
26+
warn(message) {
27+
console.log(chalk.bold.yellow(' warn'), '-', message)
28+
},
29+
risk(message) {
30+
console.log(chalk.bold.magenta(' risk'), '-', message)
31+
},
32+
}
33+
34+
if (_.some(featureFlags.future, flag => _.get(config, ['future', flag], false))) {
35+
const changes = Object.keys(config.future)
36+
.filter(flag => featureFlags.future.includes(flag) && config.future[flag])
37+
.map(s => chalk.cyan(s))
38+
.join(', ')
39+
console.log()
40+
log.info(`You have opted-in to future-facing breaking changes: ${changes}`)
41+
log.info(
42+
'These changes are stable and will be the default behavior in the next major version of Tailwind.'
43+
)
44+
}
45+
46+
if (_.some(featureFlags.experimental, flag => _.get(config, ['experimental', flag], false))) {
47+
const changes = Object.keys(config.experimental)
48+
.filter(flag => featureFlags.experimental.includes(flag) && config.experimental[flag])
49+
.map(s => chalk.yellow(s))
50+
.join(', ')
51+
console.log()
52+
log.warn(`You have enabled experimental features: ${changes}`)
53+
log.warn(
54+
'Experimental features are not covered by semver, may introduce breaking changes, and can change at any time.'
55+
)
56+
}
57+
58+
if (Object.keys(_.get(config, 'future', {})).length < featureFlags.future.length) {
59+
const changes = featureFlags.future
60+
.filter(flag => !_.has(config, ['future', flag]))
61+
.map(s => chalk.magenta(s))
62+
.join(', ')
63+
console.log()
64+
log.risk(`There are upcoming breaking changes: ${changes}`)
65+
log.risk(
66+
'We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future.'
67+
)
68+
}
69+
}
70+
71+
export default featureFlags

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import formatCSS from './lib/formatCSS'
1111
import resolveConfig from './util/resolveConfig'
1212
import { defaultConfigFile } from './constants'
1313
import defaultConfig from '../stubs/defaultConfig.stub.js'
14+
import { flagEnabled } from './featureFlags'
1415

1516
import uniformColorPalette from './flagged/uniformColorPalette.js'
1617

1718
function getDefaultConfigs(config) {
1819
const configs = [defaultConfig]
1920

20-
if (_.get(config, ['experimental', 'uniformColorPalette'], false)) {
21+
if (flagEnabled(config, 'uniformColorPalette')) {
2122
configs.unshift(uniformColorPalette)
2223
}
2324

src/processTailwindFeatures.js

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,7 @@ import purgeUnusedStyles from './lib/purgeUnusedStyles'
1313
import corePlugins from './corePlugins'
1414
import processPlugins from './util/processPlugins'
1515
import cloneNodes from './util/cloneNodes'
16-
import chalk from 'chalk'
17-
18-
const log = {
19-
info(message) {
20-
console.log(chalk.bold.cyan(' info'), '-', message)
21-
},
22-
warn(message) {
23-
console.log(chalk.bold.yellow(' warn'), '-', message)
24-
},
25-
risk(message) {
26-
console.log(chalk.bold.magenta(' risk'), '-', message)
27-
},
28-
}
29-
30-
function issueFlagNotices(config) {
31-
const featureFlags = {
32-
future: [],
33-
experimental: ['uniformColorPalette'],
34-
}
35-
36-
if (_.some(featureFlags.future, flag => _.get(config, ['future', flag], false))) {
37-
const changes = Object.keys(config.future)
38-
.filter(flag => featureFlags.future.includes(flag) && config.future[flag])
39-
.map(s => chalk.cyan(s))
40-
.join(', ')
41-
console.log()
42-
log.info(`You have opted-in to future-facing breaking changes: ${changes}`)
43-
log.info(
44-
'These changes are stable and will be the default behavior in the next major version of Tailwind.'
45-
)
46-
}
47-
48-
if (_.some(featureFlags.experimental, flag => _.get(config, ['experimental', flag], false))) {
49-
const changes = Object.keys(config.experimental)
50-
.filter(flag => featureFlags.experimental.includes(flag) && config.experimental[flag])
51-
.map(s => chalk.yellow(s))
52-
.join(', ')
53-
console.log()
54-
log.warn(`You have enabled experimental features: ${changes}`)
55-
log.warn(
56-
'Experimental features are not covered by semver, may introduce breaking changes, and can change at any time.'
57-
)
58-
}
59-
60-
if (Object.keys(_.get(config, 'future', {})).length < featureFlags.future.length) {
61-
const changes = featureFlags.future
62-
.filter(flag => !_.has(config, ['future', flag]))
63-
.map(s => chalk.magenta(s))
64-
.join(', ')
65-
console.log()
66-
log.risk(`There are upcoming breaking changes: ${changes}`)
67-
log.risk(
68-
'We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future.'
69-
)
70-
}
71-
}
16+
import { issueFlagNotices } from './featureFlags.js'
7217

7318
export default function(getConfig) {
7419
return function(css) {

0 commit comments

Comments
 (0)