Skip to content

Commit

Permalink
Improve createConfig() error message (#182)
Browse files Browse the repository at this point in the history
In case you passed an invalid setter.
  • Loading branch information
andywer authored Aug 5, 2017
1 parent 8259981 commit 49f7fb4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @webpack-blocks/core - Changelog

## Next version

- More useful error message when passing invalid blocks to `createConfig()` ([#171](https://github.com/andywer/webpack-blocks/issues/171))

## 1.0.0-beta

- Added `match()`
Expand Down
11 changes: 9 additions & 2 deletions packages/core/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ const isFunction = value => typeof value === 'function'
* @param {Function[]} configSetters Array of functions as returned by webpack blocks.
*/
function assertConfigSetters (configSetters) {
if (!Array.isArray(configSetters) || !configSetters.every(isFunction)) {
throw new Error('Expected parameter \'configSetters\' to be an array of functions.')
if (!Array.isArray(configSetters)) {
throw new Error(`Expected parameter 'configSetters' to be an array of functions. Instead got ${configSetters}.`)
}
if (!configSetters.every(isFunction)) {
const invalidElementIndex = configSetters.findIndex(setter => !isFunction(setter))
throw new Error(
`Expected parameter 'configSetters' to be an array of functions. ` +
`Element at index ${invalidElementIndex} is invalid: ${configSetters[invalidElementIndex]}.`
)
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/webpack/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Next version

- Make resolve() prepend custom extensions ([#177](https://github.com/andywer/webpack-blocks/issues/177))
- Let core `createConfig()` validate the passed setters ([#171](https://github.com/andywer/webpack-blocks/issues/171))


## 1.0.0-beta.2

Expand Down
2 changes: 0 additions & 2 deletions packages/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @see https://webpack.github.io/docs/configuration.html
*/

const assert = require('assert-plus')
const core = require('@webpack-blocks/core')
const webpack = require('webpack')
const webpackMerge = require('webpack-merge')
Expand Down Expand Up @@ -43,7 +42,6 @@ exports.sourceMaps = sourceMaps
* @return {object} Webpack config object.
*/
function createConfig (configSetters) {
assert.arrayOfFunc(configSetters, '1st param passed to createConfig.vanilla() must be an array of functions.')
return core.createConfig({ webpack, webpackVersion }, [ createEmptyConfig ].concat(configSetters))
}

Expand Down
1 change: 0 additions & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"bugs": "https://github.com/andywer/webpack-blocks/issues",
"dependencies": {
"@webpack-blocks/core": "^1.0.0-beta",
"assert-plus": "^1.0.0",
"webpack-merge": "^4.1.0"
},
"devDependencies": {
Expand Down

0 comments on commit 49f7fb4

Please sign in to comment.