Skip to content

Commit

Permalink
refactor: use base resolver to resolve config (#1858)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv authored Oct 3, 2020
1 parent d7c6930 commit ef14a7c
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class WebpackCLI extends GroupHelper {
constructor() {
super();
this.groupMap = new Map();
this.args = {};
this.compilation = new Compiler();
this.compilerConfiguration = {};
this.outputConfiguration = {};
Expand Down Expand Up @@ -60,21 +59,9 @@ class WebpackCLI extends GroupHelper {
coreCliHelper.processArguments(coreCliArgs, this.compilerConfiguration, coreConfig);
}

/**
* Responsible for resolving config
* @private\
* @param {Object} processed args
* @returns {void}
*/
async _handleConfig(parsedArgs) {
const resolvedConfig = await handleConfigResolution(parsedArgs);
this._mergeOptionsToConfiguration(resolvedConfig.options);
this._mergeOptionsToOutputConfiguration(resolvedConfig.outputOptions);
}

async _baseResolver(cb, parsedArgs, configOptions) {
const resolvedConfig = cb(parsedArgs, configOptions);
this._mergeOptionsToConfiguration(resolvedConfig.options);
async _baseResolver(cb, parsedArgs, strategy) {
const resolvedConfig = await cb(parsedArgs, this.compilerConfiguration);
this._mergeOptionsToConfiguration(resolvedConfig.options, strategy);
this._mergeOptionsToOutputConfiguration(resolvedConfig.outputOptions);
}

Expand Down Expand Up @@ -226,9 +213,9 @@ class WebpackCLI extends GroupHelper {
async runOptionGroups(parsedArgs) {
await Promise.resolve()
.then(() => this._handleDefaultEntry())
.then(() => this._handleConfig(parsedArgs))
.then(() => this._baseResolver(resolveMode, parsedArgs, this.compilerConfiguration))
.then(() => this._baseResolver(resolveOutput, parsedArgs, {}, outputStrategy))
.then(() => this._baseResolver(handleConfigResolution, parsedArgs))
.then(() => this._baseResolver(resolveMode, parsedArgs))
.then(() => this._baseResolver(resolveOutput, parsedArgs, outputStrategy))
.then(() => this._handleCoreFlags())
.then(() => this._baseResolver(basicResolver, parsedArgs))
.then(() => this._handleGroupHelper(this.advancedGroup))
Expand Down

0 comments on commit ef14a7c

Please sign in to comment.