You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
4 months ago
|
const merge = require('deepmerge');
|
||
|
const ChainedMap = require('./ChainedMap');
|
||
|
const Orderable = require('./Orderable');
|
||
|
|
||
|
module.exports = Orderable(
|
||
|
class extends ChainedMap {
|
||
|
constructor(parent, name) {
|
||
|
super(parent);
|
||
|
this.name = name;
|
||
|
this.extend(['loader', 'options']);
|
||
|
}
|
||
|
|
||
|
tap(f) {
|
||
|
this.options(f(this.get('options')));
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
merge(obj, omit = []) {
|
||
|
if (!omit.includes('loader') && 'loader' in obj) {
|
||
|
this.loader(obj.loader);
|
||
|
}
|
||
|
|
||
|
if (!omit.includes('options') && 'options' in obj) {
|
||
|
this.options(merge(this.store.get('options') || {}, obj.options));
|
||
|
}
|
||
|
|
||
|
return super.merge(obj, [...omit, 'loader', 'options']);
|
||
|
}
|
||
|
|
||
|
toConfig() {
|
||
|
const config = this.clean(this.entries() || {});
|
||
|
|
||
|
Object.defineProperties(config, {
|
||
|
__useName: { value: this.name },
|
||
|
__ruleNames: { value: this.parent && this.parent.names },
|
||
|
__ruleTypes: { value: this.parent && this.parent.ruleTypes },
|
||
|
});
|
||
|
|
||
|
return config;
|
||
|
}
|
||
|
},
|
||
|
);
|