From 77ef26015645dc767a1f520cf4f7772696702e5c Mon Sep 17 00:00:00 2001 From: Twentylives Date: Mon, 10 May 2021 18:22:47 +0300 Subject: [PATCH] Refactor util functions (#2616) * Refactor getAllConfigs util function * Update eslint parser options to ES2020 --- src/util/getAllConfigs.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/util/getAllConfigs.js b/src/util/getAllConfigs.js index 3e65d5db1cd2..e35f1097c236 100644 --- a/src/util/getAllConfigs.js +++ b/src/util/getAllConfigs.js @@ -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] }