-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathfeatureFlags.js
76 lines (62 loc) · 2.01 KB
/
featureFlags.js
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
import _ from 'lodash'
import chalk from 'chalk'
import log from './util/log'
const featureFlags = {
future: ['removeDeprecatedGapUtilities', 'purgeLayersByDefault', 'standardFontWeights'],
experimental: [
'uniformColorPalette',
'extendedSpacingScale',
'defaultLineHeights',
'extendedFontSizeScale',
'applyComplexClasses',
'darkModeVariant',
],
}
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 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) {
if (process.env.JEST_WORKER_ID !== undefined) {
return
}
if (experimentalFlagsEnabled(config).length > 0) {
const changes = experimentalFlagsEnabled(config)
.map(s => chalk.yellow(s))
.join(', ')
log.warn([
`You have enabled experimental features: ${changes}`,
'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(', ')
log.risk([
`There are upcoming breaking changes: ${changes}`,
'We highly recommend opting-in to these changes now to simplify upgrading Tailwind in the future.',
'https://tailwindcss.com/docs/upcoming-changes',
])
}
}
export default featureFlags