@@ -90,29 +90,16 @@ function verifyDirectoryExists(path: string, key: string) {
9090 }
9191}
9292
93- // TS 3.5 forces us to split these into 2
94- const mergeModuleNameMapperWithPreset = (
95- options : Config . InitialOptionsWithRootDir ,
96- preset : Config . InitialOptions ,
97- ) => {
98- if ( options [ 'moduleNameMapper' ] && preset [ 'moduleNameMapper' ] ) {
99- options [ 'moduleNameMapper' ] = {
100- ...options [ 'moduleNameMapper' ] ,
101- ...preset [ 'moduleNameMapper' ] ,
102- ...options [ 'moduleNameMapper' ] ,
103- } ;
104- }
105- } ;
106-
107- const mergeTransformWithPreset = (
108- options : Config . InitialOptionsWithRootDir ,
93+ const mergeOptionWithPreset = < T extends 'moduleNameMapper' | 'transform' > (
94+ options : Config . InitialOptions ,
10995 preset : Config . InitialOptions ,
96+ optionName : T ,
11097) => {
111- if ( options [ 'transform' ] && preset [ 'transform' ] ) {
112- options [ 'transform' ] = {
113- ...options [ 'transform' ] ,
114- ...preset [ 'transform' ] ,
115- ...options [ 'transform' ] ,
98+ if ( options [ optionName ] && preset [ optionName ] ) {
99+ options [ optionName ] = {
100+ ...options [ optionName ] ,
101+ ...preset [ optionName ] ,
102+ ...options [ optionName ] ,
116103 } ;
117104 }
118105} ;
@@ -206,8 +193,8 @@ const setupPreset = async (
206193 options . modulePathIgnorePatterns ,
207194 ) ;
208195 }
209- mergeModuleNameMapperWithPreset ( options , preset ) ;
210- mergeTransformWithPreset ( options , preset ) ;
196+ mergeOptionWithPreset ( options , preset , 'moduleNameMapper' ) ;
197+ mergeOptionWithPreset ( options , preset , 'transform' ) ;
211198 mergeGlobalsWithPreset ( options , preset ) ;
212199
213200 return { ...preset , ...options } ;
0 commit comments