Skip to content

Commit

Permalink
refactor: code
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Nov 3, 2020
1 parent 04d2997 commit 746fcb4
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/webpack-cli/lib/groups/resolveConfig.js
Expand Up @@ -156,9 +156,9 @@ const finalize = async (moduleObj, args) => {
const isMultiCompilerMode = Array.isArray(config);
const rawConfigs = isMultiCompilerMode ? config : [config];

let isFunctionalConfig = false;
let configs = [];

let configs = await Promise.all(
await Promise.all(
rawConfigs.map(async (rawConfig) => {
const isPromise = typeof rawConfig.then === 'function';

Expand All @@ -168,20 +168,26 @@ const finalize = async (moduleObj, args) => {

// `Promise` may return `Function`
if (typeof rawConfig === 'function') {
isFunctionalConfig = true;
// when config is a function, pass the env from args to the config function
rawConfig = await rawConfig(env, args);
}

return rawConfig;
}),
);
).then((allConfigs) => {
allConfigs.map((singleConfig) => {
if (Array.isArray(singleConfig)) {
singleConfig.map((conf) => configs.push(conf));
} else {
configs.push(singleConfig);
}
});
});

if (configName) {
const foundConfigNames = [];
const configsToFilter = Array.isArray[configs[0]] ? configs[0] : configs;

configs = configsToFilter.filter((options) => {
configs = configs.filter((options) => {
const found = configName.includes(options.name);

if (found) {
Expand All @@ -208,7 +214,7 @@ const finalize = async (moduleObj, args) => {
process.exit(2);
}

newOptionsObject['options'] = isMultiCompilerMode || isFunctionalConfig ? configs : configs[0];
newOptionsObject['options'] = isMultiCompilerMode || Array.isArray(configs) ? configs : configs[0];

return newOptionsObject;
};
Expand Down

0 comments on commit 746fcb4

Please sign in to comment.