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

Change match() to pass all webpack rule options to context. #250

Merged
merged 6 commits into from
Feb 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 2 deletions packages/babel/__tests__/babel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test('Babel options work', t => {

test('using custom match() works', t => {
const config = createConfig({}, [
match('*.js', { exclude: [] }, [
match('*.js', { exclude: null }, [
babel({
cacheDirectory: false
})
Expand All @@ -61,7 +61,7 @@ test('using custom match() works', t => {
t.deepEqual(config.module.rules, [
{
test: /^.*\.js$/,
exclude: [],
exclude: null,
use: [
{
loader: 'babel-loader',
Expand Down
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

## master
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

master -> Next version (like we used before)


- Change `match()` to passes all [webpack rule options](https://webpack.js.org/configuration/module/) to context. ([#250](https://github.com/andywer/webpack-blocks/pull/250))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passes -> pass


## 1.0.0-beta.2

- More useful error message when passing invalid blocks to `createConfig()` ([#171](https://github.com/andywer/webpack-blocks/issues/171))
Expand Down
6 changes: 3 additions & 3 deletions packages/core/lib/__tests__/match.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ test('match() supports options and extended regexps', t => {
t.plan(3)

const loaderBlock = context => config => {
t.deepEqual(Object.keys(context.match), [ 'test', 'exclude' ])
t.is(context.match.test.toString(), '/^(.*\\.js|.*\\.jsx)$/')
t.deepEqual(Object.keys(context.match), [ 'exclude', 'test' ])
t.is(context.match.test.toString(), '/^.*\\.(js|jsx)$/')
t.is(context.match.exclude, 'node_modules')
return config
}
Expand All @@ -49,7 +49,7 @@ test('match() supports options and extended regexps', t => {
// or the space will become part of the regex...

createConfig({}, [
match('{*.js,*.jsx}', { exclude: 'node_modules' }, [
match('*.{js,jsx}', { exclude: 'node_modules' }, [
loaderBlock
])
])
Expand Down
17 changes: 4 additions & 13 deletions packages/core/lib/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ module.exports = match
*
* @param {string|RegExp|Function|Array} test A glob like `*.css` or `{*.js, *.jsx}` or something else to use as `loader.test`.
* @param {object} [options] Optional advanced matching options.
* @param {string|Function|RegExp|Array|object} [options.include]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove those hints, then we definitely need to improve the documentation of the overall options parameter, since otherwise it's not clear anymore what kind of options can be passed here 😉

* @param {string|Function|RegExp|Array|object} [options.exclude]
* @param {Function[]} configSetters Array of functions as returned by webpack blocks.
* @return {Function}
*/
Expand All @@ -23,20 +21,13 @@ function match (test, options, configSetters) {

assertConfigSetters(configSetters)

const match = { test: createFileTypeMatcher(test) }
options.test = createFileTypeMatcher(test)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should print a warning if test was set in options.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if options.test was set before this line 👍


if (options.exclude) {
match.exclude = options.exclude
}
if (options.include) {
match.include = options.include
}

const groupBlock = context => config => invokeConfigSetters(configSetters, deriveContextWithMatch(context, match), config)
const groupBlock = context => config => invokeConfigSetters(configSetters, deriveContextWithMatch(context, options), config)

return Object.assign(groupBlock, {
pre: context => invokePreHooks(configSetters, deriveContextWithMatch(context, match)),
post: context => config => invokePostHooks(configSetters, deriveContextWithMatch(context, match), config)
pre: context => invokePreHooks(configSetters, deriveContextWithMatch(context, options)),
post: context => config => invokePostHooks(configSetters, deriveContextWithMatch(context, options), config)
})
}

Expand Down