Move plugin pass initialization logic a bit.

This commit is contained in:
Logan Smyth 2017-11-24 16:56:05 -08:00
parent 1d0a3d6772
commit b5cb78d33a

View File

@ -46,36 +46,29 @@ class OptionManager {
* - `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(config: MergeOptions, pass: Array<Plugin>, envName: string) {
mergeOptions(config: MergeOptions, pass?: Array<Plugin>, envName: string) {
const result = loadConfig(config); const result = loadConfig(config);
const plugins = result.plugins.map(descriptor => const plugins = result.plugins.map(descriptor =>
loadPluginDescriptor(descriptor, envName), loadPluginDescriptor(descriptor, envName),
); );
const presets = result.presets.map(descriptor => const presets = result.presets.map(descriptor => ({
loadPresetDescriptor(descriptor, envName), pass: config.options.passPerPreset ? [] : pass,
); preset: loadPresetDescriptor(descriptor, envName),
}));
const passPerPreset = config.options.passPerPreset;
pass = pass || this.passes[0];
// resolve presets // resolve presets
if (presets.length > 0) { if (presets.length > 0) {
let presetPasses = null;
if (passPerPreset) {
presetPasses = presets.map(() => []);
// The passes are created in the same order as the preset list, but are inserted before any // The passes are created in the same order as the preset list, but are inserted before any
// existing additional passes. // existing additional passes.
this.passes.splice(1, 0, ...presetPasses); this.passes.splice(
} 1,
0,
presets.forEach((presetConfig, i) => { ...presets.map(o => o.pass).filter(p => p !== pass),
this.mergeOptions(
presetConfig,
presetPasses ? presetPasses[i] : pass,
envName,
); );
presets.forEach(({ preset, pass }) => {
this.mergeOptions(preset, pass, envName);
}); });
} }
@ -112,7 +105,7 @@ class OptionManager {
try { try {
for (const config of configChain) { for (const config of configChain) {
this.mergeOptions(config, undefined, envName); this.mergeOptions(config, this.passes[0], envName);
} }
} catch (e) { } catch (e) {
// There are a few case where thrown errors will try to annotate themselves multiple times, so // There are a few case where thrown errors will try to annotate themselves multiple times, so