Skip to content

Commit

Permalink
Fix presets ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 7, 2020
1 parent a65b757 commit 3285782
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
24 changes: 19 additions & 5 deletions packages/babel-core/src/config/full.js
Expand Up @@ -103,10 +103,20 @@ export default gensync<[any], ResolvedConfig | null>(function* loadFullConfig(
const descriptor = rawPresets[i];
if (descriptor.options !== false) {
try {
presets.push({
preset: yield* loadPresetDescriptor(descriptor, context),
pass: descriptor.ownPass ? [] : pluginDescriptorsPass,
});
// Presets normally run in reverse order, but if they
// have their own pass they run after the presets
// in the previous pass.
if (descriptor.ownPass) {
presets.push({
preset: yield* loadPresetDescriptor(descriptor, context),
pass: [],
});
} else {
presets.unshift({
preset: yield* loadPresetDescriptor(descriptor, context),
pass: pluginDescriptorsPass,
});
}
} catch (e) {
if (e.code === "BABEL_UNKNOWN_OPTION") {
checkNoUnwrappedItemOptionPairs(rawPresets, i, "preset", e);
Expand All @@ -129,7 +139,7 @@ export default gensync<[any], ResolvedConfig | null>(function* loadFullConfig(
for (const { preset, pass } of presets) {
if (!preset) return true;

pass.unshift(...preset.plugins);
pass.push(...preset.plugins);

const ignored = yield* recursePresetDescriptors(preset.presets, pass);
if (ignored) return true;
Expand Down Expand Up @@ -178,6 +188,10 @@ export default gensync<[any], ResolvedConfig | null>(function* loadFullConfig(
.map(plugins => ({ plugins }));
opts.passPerPreset = opts.presets.length > 0;

if (context.filename?.includes("RuntimeErrorContaine")) {
console.log(initialPluginsDescriptors.map(p => p.key));
}

return {
options: opts,
passes: passes,
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-core/test/api.js
Expand Up @@ -423,6 +423,8 @@ describe("api", function () {
"argone;",
"five;",
"six;",
"twentyone;",
"twentytwo;",
"three;",
"four;",
"nineteen;",
Expand Down
Expand Up @@ -14,6 +14,12 @@
"./five",
"./six",
],
presets: [{
plugins: [
"./twentyone",
"./twentytwo",
]
}]
}, {
passPerPreset: true,
presets: [{
Expand Down
@@ -0,0 +1 @@
module.exports = require("./plugin")("twentyone");
@@ -0,0 +1 @@
module.exports = require("./plugin")("twentytwo");

0 comments on commit 3285782

Please sign in to comment.