forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatureFlags.js
More file actions
105 lines (87 loc) · 2.75 KB
/
featureFlags.js
File metadata and controls
105 lines (87 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import _ from 'lodash'
import chalk from 'chalk'
const featureFlags = {
future: ['removeDeprecatedGapUtilities'],
experimental: [
'uniformColorPalette',
'extendedSpacingScale',
'defaultLineHeights',
'extendedFontSizeScale',
],
}
export function flagEnabled(config, flag) {
if (featureFlags.future.includes(flag)) {
return config.future === 'all' || _.get(config, ['future', flag], false)
}
if (featureFlags.experimental.includes(flag)) {
return config.experimental === 'all' || _.get(config, ['experimental', flag], false)
}
return false
}
function futureFlagsEnabled(config) {
if (config.future === 'all') {
return featureFlags.future
}
return Object.keys(_.get(config, 'future', {})).filter(
flag => featureFlags.future.includes(flag) && config.future[flag]
)
}
function experimentalFlagsEnabled(config) {
if (config.experimental === 'all') {
return featureFlags.experimental
}
return Object.keys(_.get(config, 'experimental', {})).filter(
flag => featureFlags.experimental.includes(flag) && config.experimental[flag]
)
}
function futureFlagsAvailable(config) {
if (config.future === 'all') {
return []
}
return featureFlags.future.filter(flag => !_.has(config, ['future', flag]))
}
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 (futureFlagsEnabled(config).length > 0) {
const changes = futureFlagsEnabled(config)
.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 (experimentalFlagsEnabled(config).length > 0) {
const changes = experimentalFlagsEnabled(config)
.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 (futureFlagsAvailable(config).length > 0) {
const changes = futureFlagsAvailable(config)
.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.'
)
log.risk('https://tailwindcss.com/docs/upcoming-changes')
}
}
export default featureFlags