Skip to content

Commit

Permalink
(fix): ensure Babel presets are merged (#473)
Browse files Browse the repository at this point in the history
- previously, if preset-env were not found in the user's presets,
  their presets would be overwritten by a single preset-env entry
  - now it properly merges their presets with an entry for preset-env
  • Loading branch information
agilgur5 authored Feb 2, 2020
1 parent b71431b commit 40ba936
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/babelPluginTsdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ export const babelPluginTsdx = babelPlugin.custom((babelCore: any) => ({
);

const babelOptions = config.options || {};
babelOptions.presets = babelOptions.presets || [];

const envIdx = (babelOptions.presets || []).findIndex((preset: any) =>
const envIdx = babelOptions.presets.findIndex((preset: any) =>
preset.file.request.includes('@babel/preset-env')
);

// if they use preset-env, merge their options with ours
if (envIdx !== -1) {
const preset = babelOptions.presets[envIdx];
babelOptions.presets[envIdx] = createConfigItem(
Expand All @@ -134,7 +136,8 @@ export const babelPluginTsdx = babelPlugin.custom((babelCore: any) => ({
}
);
} else {
babelOptions.presets = createConfigItems('preset', [
// if no preset-env, add it & merge with their presets
const defaultPresets = createConfigItems('preset', [
{
name: '@babel/preset-env',
targets: customOptions.targets,
Expand All @@ -143,6 +146,12 @@ export const babelPluginTsdx = babelPlugin.custom((babelCore: any) => ({
exclude: ['transform-async-to-generator', 'transform-regenerator'],
},
]);

babelOptions.presets = mergeConfigItems(
'preset',
defaultPresets,
babelOptions.presets
);
}

// Merge babelrc & our plugins together
Expand Down

0 comments on commit 40ba936

Please sign in to comment.