Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve createConfig() error message #182

Merged
merged 2 commits into from
Aug 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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