-
Notifications
You must be signed in to change notification settings - Fork 234
Conversation
8001db3
to
a1a73be
Compare
Force push to fix build. Somehow managed to forget trailing commas. (The second force push is to fix the test order to keep rules always before oneOf, as it was in every place but that one test.) |
a1a73be
to
49a93c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi! Thank you for adding support for this!
I think the toString
handling here needs adjusting for nested rules:
Lines 83 to 88 in afdf962
}')${value.__ruleNames | |
.slice(1) | |
.map(r => `.oneOf('${r}')`) | |
.join('')}${ | |
value.__useName ? `.use('${value.__useName}')` : `` | |
} */\n`; |
Could you also add a usage of the new nested rules to the existing toString
test here?
Lines 387 to 445 in 6d3c5c3
test('toString', t => { | |
const config = new Config(); | |
config.module | |
.rule('alpha') | |
.oneOf('beta') | |
.use('babel') | |
.loader('babel-loader'); | |
const envPluginPath = require.resolve('webpack/lib/EnvironmentPlugin'); | |
const stringifiedEnvPluginPath = stringify(envPluginPath); | |
class FooPlugin {} | |
FooPlugin.__expression = `require('foo-plugin')`; | |
config | |
.plugin('env') | |
.use(envPluginPath, [{ VAR: false }]) | |
.end() | |
.plugin('gamma') | |
.use(FooPlugin) | |
.end() | |
.plugin('delta') | |
.use(class BarPlugin {}, ['bar']) | |
.end() | |
.plugin('epsilon') | |
.use(class BazPlugin {}, [{ n: 1 }, [2, 3]]); | |
config.resolve.plugin('resolver').use(FooPlugin); | |
config.optimization.minimizer('minifier').use(FooPlugin); | |
t.is( | |
config.toString().trim(), | |
` | |
{ | |
resolve: { | |
plugins: [ | |
/* config.resolve.plugin('resolver') */ | |
new (require('foo-plugin'))() | |
] | |
}, | |
module: { | |
rules: [ | |
/* config.module.rule('alpha') */ | |
{ | |
oneOf: [ | |
/* config.module.rule('alpha').oneOf('beta') */ | |
{ | |
use: [ | |
/* config.module.rule('alpha').oneOf('beta').use('babel') */ | |
{ | |
loader: 'babel-loader' | |
} | |
] | |
} | |
] | |
} | |
] | |
}, |
With those changes, this should be good to merge :-)
Well, I completely missed that. I considered a few ways of doing this, but eventually settled on just making This also fixes the hints for While working on this I realized that it should be possible to generate the paths on the fly in |
60a9c25
to
8b703e4
Compare
src/Rule.js
Outdated
this.name = name; | ||
this.names = []; | ||
|
||
let rule = this; | ||
while (rule instanceof Rule) { | ||
this.names.unshift(rule.name); | ||
this.names.unshift([rule.ruleType, rule.name]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for updating this, and good spot on the existing defaultRule
bug!
Looking at GitHub code search, it seems that there are people relying on __ruleNames
even though it's really an internal implementation details:
https://github.com/search?l=JavaScript&q=webpack-chain+__ruleNames&type=Code
As such this would unfortunately be a breaking change.
I know it wouldn't be as clean (and the toString()
in src/Config.js
would no longer be able to just use a simple .map()
on __ruleNames
), but what do what do you think about instead adding a separate types
array to go alongside names
and then a corresponding __ruleTypes
? This would be similar to what is done in Plugin
currently (aside from Plugin not needing arrays):
Lines 63 to 64 in df193ec
__pluginName: { value: this.name }, | |
__pluginType: { value: this.type }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea with the GitHub search. Keeping backwards compatibility seems to indeed be more important in this case than I expected. I'll change it to use __ruleTypes
soon.
ce3ee85
to
62327eb
Compare
Fixed the issue mentioned in the review. Pushed twice because I realized that the name I really need to get into the habit of running tests before I commit, not after. |
62327eb
to
ce3ee85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the quick update! This new approach looks great.
Just a couple of small things I spotted and we should be good to merge :-)
Published in v6.3.0 :-) |
Adds support for nested rules.
Closes #219