Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor getAllConfigs util function * Update eslint parser options to ES2020
- Loading branch information
Showing
1 changed file
with
8 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
import defaultConfig from '../../stubs/defaultConfig.stub.js' | ||
import { flagEnabled } from '../featureFlags' | ||
import { flatMap, get, isFunction } from 'lodash' | ||
|
||
export default function getAllConfigs(config) { | ||
const configs = flatMap([...get(config, 'presets', [defaultConfig])].reverse(), (preset) => { | ||
return getAllConfigs(isFunction(preset) ? preset() : preset) | ||
}) | ||
const configs = (config?.presets ?? [defaultConfig]) | ||
.slice() | ||
.reverse() | ||
.flatMap((preset) => getAllConfigs(preset instanceof Function ? preset() : preset)) | ||
|
||
const features = { | ||
// Add experimental configs here... | ||
} | ||
|
||
Object.keys(features).forEach((feature) => { | ||
if (flagEnabled(config, feature)) { | ||
configs.unshift(features[feature]) | ||
} | ||
}) | ||
const experimentals = Object.keys(features) | ||
.filter((feature) => flagEnabled(config, feature)) | ||
.map((feature) => features[feature]) | ||
|
||
return [config, ...configs] | ||
return [config, ...experimentals, ...configs] | ||
} |