cli: fix watch options for array config #892
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.

What kind of change does this PR introduce?
bugfix
Did you add tests for your changes?
nope! I didn't see any existing tests for
processOptions.If relevant, did you update the documentation?
I did not, but this should make the current docs on the watch options true for Webpack configs that are arrays.
Summary
webpack/webpack#4594 points out that watch options aren't being honored when the
Webpack config is an Array. In cases when it's an array, there may not
be a firstOptions.watchOptions, but there will be an options.watchOptions.
In the current implementation, when the Webpack compiler watch method is
called with watchOptions and the Webpack config is an array, watchOptions
will be
trueand not an object.I should also note that I don't have a ton of context into the intentions behind using the
watch(which is a boolean) in the case that the other options are absent, and an object ifwatchis false on both options and firstOptions, so at the very least my goal with this PR is to give someone who has better context the information I found so that they can make a good decision on what's best to do here.webpack/webpack#4594 (not open, but still broken)
Does this PR introduce a breaking change?
It does not, this should be a seamless fallback in the case when the Webpack config is an array instead of an object that does the right thing when the CLI has watch-* flags.
Testing/Repro
console.logforwatchOptionsabove the call tocompiler.watchin webpack-cliwebpack-watch-poll-cfgfrom the example repo to verify thewatchOptionsfrom a webpack.config.js works as expected and received the following:webpack-watch-poll-clifrom the example repo to verify thewatchOptionsfrom a CLI flag (--watch-poll) was incorrect (with an Array config):yarn installwebpack-watch-poll-clifrom the example repo to verify thewatchOptionsfrom a CLI flag (--watch-poll) works as expected with an Array config and received the following: