Pass per preset: merge nested preset sub-options into preset
This commit is contained in:
parent
3f1353d01f
commit
e7187faea6
@ -66,7 +66,7 @@ export default class File extends Store {
|
|||||||
|
|
||||||
// If we are in the "pass per preset" mode, build
|
// If we are in the "pass per preset" mode, build
|
||||||
// also plugins for each preset.
|
// also plugins for each preset.
|
||||||
if (this.opts.passPerPresset) {
|
if (this.opts.passPerPreset) {
|
||||||
// All the "per preset" options are inherited from the main options.
|
// All the "per preset" options are inherited from the main options.
|
||||||
this.perPresetOpts = [];
|
this.perPresetOpts = [];
|
||||||
this.opts.presets.forEach(presetOpts => {
|
this.opts.presets.forEach(presetOpts => {
|
||||||
|
|||||||
@ -185,9 +185,10 @@ module.exports = {
|
|||||||
type: "string"
|
type: "string"
|
||||||
},
|
},
|
||||||
|
|
||||||
passPerPresset: {
|
passPerPreset: {
|
||||||
description: "Whether to spawn a traversal pass per a preset. By default all presets are merged.",
|
description: "Whether to spawn a traversal pass per a preset. By default all presets are merged.",
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
default: false
|
default: false,
|
||||||
|
hidden: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -157,22 +157,23 @@ export default class OptionManager {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mergeOptions(opts, loc, null, path.dirname(loc));
|
this.mergeOptions(opts, this.options, loc, null, path.dirname(loc));
|
||||||
this.resolvedConfigs.push(loc);
|
this.resolvedConfigs.push(loc);
|
||||||
|
|
||||||
return !!opts;
|
return !!opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is called when we want to merge the input `opts` into our
|
* This is called when we want to merge the input `opts` into the
|
||||||
* base options.
|
* base options (passed as the `extendingOpts`: at top-level it's the
|
||||||
|
* main options, at presets level it's presets options).
|
||||||
*
|
*
|
||||||
* - `alias` is used to output pretty traces back to the original source.
|
* - `alias` is used to output pretty traces back to the original source.
|
||||||
* - `loc` is used to point to the original config.
|
* - `loc` is used to point to the original config.
|
||||||
* - `dirname` is used to resolve plugins relative to it.
|
* - `dirname` is used to resolve plugins relative to it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mergeOptions(rawOpts?: Object, alias: string = "foreign", loc?: string, dirname?: string) {
|
mergeOptions(rawOpts?: Object, extendingOpts?: Object, alias: string = "foreign", loc?: string, dirname?: string) {
|
||||||
if (!rawOpts) return;
|
if (!rawOpts) return;
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -223,11 +224,9 @@ export default class OptionManager {
|
|||||||
if (opts.presets) {
|
if (opts.presets) {
|
||||||
// If we're in the "pass per preset" mode, we resolve the presets
|
// If we're in the "pass per preset" mode, we resolve the presets
|
||||||
// and keep them for further execution to calculate the options.
|
// and keep them for further execution to calculate the options.
|
||||||
if (opts.passPerPresset) {
|
if (opts.passPerPreset) {
|
||||||
opts.presets = this.resolvePresets(opts.presets, dirname, (preset, presetLoc) => {
|
opts.presets = this.resolvePresets(opts.presets, dirname, (preset, presetLoc) => {
|
||||||
if (preset.plugins) {
|
this.mergeOptions(preset, preset, presetLoc, presetLoc, dirname);
|
||||||
preset.plugins = OptionManager.normalisePlugins(presetLoc, dirname, preset.plugins);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, just merge presets options into the main options.
|
// Otherwise, just merge presets options into the main options.
|
||||||
@ -244,11 +243,17 @@ export default class OptionManager {
|
|||||||
delete opts.env;
|
delete opts.env;
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge them into this current files options
|
// Merge them into current extending options in case of top-level
|
||||||
merge(this.options, opts);
|
// options. In case of presets, just re-assign options which are got
|
||||||
|
// normalized during the `mergeOptions`.
|
||||||
|
if (rawOpts !== extendingOpts) {
|
||||||
|
merge(extendingOpts, opts);
|
||||||
|
} else {
|
||||||
|
Object.assign(extendingOpts, opts);
|
||||||
|
}
|
||||||
|
|
||||||
// merge in env options
|
// merge in env options
|
||||||
this.mergeOptions(envOpts, `${alias}.env.${envKey}`, null, dirname);
|
this.mergeOptions(envOpts, extendingOpts, `${alias}.env.${envKey}`, null, dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -259,6 +264,7 @@ export default class OptionManager {
|
|||||||
this.resolvePresets(presets, dirname, (presetOpts, presetLoc) => {
|
this.resolvePresets(presets, dirname, (presetOpts, presetLoc) => {
|
||||||
this.mergeOptions(
|
this.mergeOptions(
|
||||||
presetOpts,
|
presetOpts,
|
||||||
|
this.options,
|
||||||
presetLoc,
|
presetLoc,
|
||||||
presetLoc,
|
presetLoc,
|
||||||
path.dirname(presetLoc)
|
path.dirname(presetLoc)
|
||||||
@ -298,7 +304,7 @@ export default class OptionManager {
|
|||||||
.map((line) => line.replace(/#(.*?)$/, "").trim())
|
.map((line) => line.replace(/#(.*?)$/, "").trim())
|
||||||
.filter((line) => !!line);
|
.filter((line) => !!line);
|
||||||
|
|
||||||
this.mergeOptions({ ignore: lines }, loc);
|
this.mergeOptions({ ignore: lines }, this.options, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
findConfigs(loc) {
|
findConfigs(loc) {
|
||||||
@ -365,7 +371,7 @@ export default class OptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// merge in base options
|
// merge in base options
|
||||||
this.mergeOptions(opts, "base", null, filename && path.dirname(filename));
|
this.mergeOptions(opts, this.options, "base", null, filename && path.dirname(filename));
|
||||||
|
|
||||||
// normalise
|
// normalise
|
||||||
this.normaliseOptions(opts);
|
this.normaliseOptions(opts);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user