-
Notifications
You must be signed in to change notification settings - Fork 4k
/
featureFlags.js
49 lines (39 loc) · 1.23 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
import _ from 'lodash'
import chalk from 'chalk'
import log from './util/log'
const featureFlags = {
future: [],
experimental: [],
}
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]
)
}
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.',
])
}
}
export default featureFlags