@@ -3,10 +3,11 @@ import * as fs from 'fs';
33import * as fsExtra from 'fs-extra' ;
44import * as path from 'path' ;
55import * as tsc from 'typescript' ;
6- import { JestConfig , TsJestConfig } from './jest-types' ;
6+ import { ConfigGlobals , JestConfig , TsJestConfig } from './jest-types' ;
77import { logOnce } from './logger' ;
8+ import * as _ from 'lodash' ;
89
9- export function getTSJestConfig ( globals : any ) : TsJestConfig {
10+ export function getTSJestConfig ( globals : ConfigGlobals ) : TsJestConfig {
1011 return globals && globals [ 'ts-jest' ] ? globals [ 'ts-jest' ] : { } ;
1112}
1213
@@ -94,8 +95,7 @@ function getPathToClosestTSConfig(
9495 return getPathToClosestTSConfig ( path . join ( startDir , '..' ) , startDir ) ;
9596}
9697
97- // TODO: This can take something more specific than globals
98- function getTSConfigPathFromConfig ( globals : any ) : string {
98+ function getTSConfigPathFromConfig ( globals : ConfigGlobals ) : string {
9999 const defaultTSConfigFile = getPathToClosestTSConfig ( ) ;
100100 if ( ! globals ) {
101101 return defaultTSConfigFile ;
@@ -115,29 +115,18 @@ export function mockGlobalTSConfigSchema(globals: any) {
115115 return { 'ts-jest' : { tsConfigFile : configPath } } ;
116116}
117117
118- const tsConfigCache : { [ key : string ] : any } = { } ;
119- // TODO: Perhaps rename collectCoverage to here, as it seems to be the official jest name now:
120- // https://github.com/facebook/jest/issues/3524
121- export function getTSConfig (
122- globals ,
123- rootDir : string = '' ,
124- collectCoverage : boolean = false ,
125- ) {
126- const configPath = getTSConfigPathFromConfig ( globals ) ;
127- logOnce ( `Reading tsconfig file from path ${ configPath } ` ) ;
128- const skipBabel = getTSJestConfig ( globals ) . skipBabel ;
129-
118+ export const getTSConfig = _ . memoize ( getTSConfig_local , ( globals , rootDir ) => {
130119 // check cache before resolving configuration
131120 // NB: We use JSON.stringify() to create a consistent, unique signature. Although it lacks a uniform
132121 // shape, this is simpler and faster than using the crypto package to generate a hash signature.
133- const tsConfigCacheKey = JSON . stringify ( [
134- skipBabel ,
135- collectCoverage ,
136- configPath ,
137- ] ) ;
138- if ( tsConfigCacheKey in tsConfigCache ) {
139- return tsConfigCache [ tsConfigCacheKey ] ;
140- }
122+ return JSON . stringify ( globals , rootDir ) ;
123+ } ) ;
124+
125+ // Non-memoized version of TSConfig
126+ function getTSConfig_local ( globals , rootDir : string = '' ) {
127+ const configPath = getTSConfigPathFromConfig ( globals ) ;
128+ logOnce ( `Reading tsconfig file from path ${ configPath } ` ) ;
129+ const skipBabel = getTSJestConfig ( globals ) . skipBabel ;
141130
142131 const config = readCompilerOptions ( configPath , rootDir ) ;
143132 logOnce ( 'Original typescript config before modifications: ' , { ...config } ) ;
@@ -171,8 +160,6 @@ export function getTSConfig(
171160 config . module = tsc . ModuleKind . ES2015 ;
172161 }
173162
174- // cache result for future requests
175- tsConfigCache [ tsConfigCacheKey ] = config ;
176163 return config ;
177164}
178165
0 commit comments