From 06d07190665fbb1e8b79577015c8b34b4ac1073f Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Thu, 30 Jan 2020 17:09:19 -0500 Subject: [PATCH] (fix): ensure Babel presets are merged - 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 --- src/babelPluginTsdx.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/babelPluginTsdx.ts b/src/babelPluginTsdx.ts index 66145ebb5..284998a01 100644 --- a/src/babelPluginTsdx.ts +++ b/src/babelPluginTsdx.ts @@ -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( @@ -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, @@ -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