1- import { existsSync , readFileSync , statSync , writeFileSync , mkdirSync } from 'fs'
1+ import { existsSync , statSync } from 'fs'
22import path from 'path'
33
44import type { SyncTransformer , TransformedSource } from '@jest/transform'
@@ -12,7 +12,7 @@ import type {
1212 TsJestTransformerOptions ,
1313 TsJestTransformOptions ,
1414} from '../types'
15- import { parse , stringify , JsonableValue , rootLogger } from '../utils'
15+ import { stringify , JsonableValue , rootLogger } from '../utils'
1616import { importer } from '../utils/importer'
1717import { Deprecations , Errors , interpolate } from '../utils/messages'
1818import { sha1 } from '../utils/sha1'
@@ -27,7 +27,6 @@ interface CachedConfigSet {
2727 transformerCfgStr : string
2828 compiler : CompilerInstance
2929 depGraphs : Map < string , DepGraphInfo >
30- tsResolvedModulesCachePath : string | undefined
3130 watchMode : boolean
3231}
3332
@@ -50,7 +49,6 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
5049 private static readonly _cachedConfigSets : CachedConfigSet [ ] = [ ]
5150 private readonly _logger : Logger
5251 protected _compiler ! : CompilerInstance
53- private _tsResolvedModulesCachePath : string | undefined
5452 private _transformCfgStr ! : string
5553 private _depGraphs : Map < string , DepGraphInfo > = new Map < string , DepGraphInfo > ( )
5654 private _watchMode = false
@@ -81,7 +79,6 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
8179 this . _transformCfgStr = ccs . transformerCfgStr
8280 this . _compiler = ccs . compiler
8381 this . _depGraphs = ccs . depGraphs
84- this . _tsResolvedModulesCachePath = ccs . tsResolvedModulesCachePath
8582 this . _watchMode = ccs . watchMode
8683 configSet = ccs . configSet
8784 } else {
@@ -98,7 +95,6 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
9895 this . _transformCfgStr = serializedCcs . transformerCfgStr
9996 this . _compiler = serializedCcs . compiler
10097 this . _depGraphs = serializedCcs . depGraphs
101- this . _tsResolvedModulesCachePath = serializedCcs . tsResolvedModulesCachePath
10298 this . _watchMode = serializedCcs . watchMode
10399 configSet = serializedCcs . configSet
104100 } else {
@@ -129,15 +125,13 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
129125 jest . cacheDirectory = undefined as any // eslint-disable-line @typescript-eslint/no-explicit-any
130126 this . _transformCfgStr = `${ new JsonableValue ( jest ) . serialized } ${ configSet . cacheSuffix } `
131127 this . _createCompiler ( configSet , cacheFS )
132- this . _getFsCachedResolvedModules ( configSet )
133128 this . _watchMode = process . argv . includes ( '--watch' )
134129 TsJestTransformer . _cachedConfigSets . push ( {
135130 jestConfig : new JsonableValue ( config ) ,
136131 configSet,
137132 transformerCfgStr : this . _transformCfgStr ,
138133 compiler : this . _compiler ,
139134 depGraphs : this . _depGraphs ,
140- tsResolvedModulesCachePath : this . _tsResolvedModulesCachePath ,
141135 watchMode : this . _watchMode ,
142136 } )
143137 }
@@ -321,7 +315,7 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
321315 CACHE_KEY_EL_SEPARATOR ,
322316 filePath ,
323317 ]
324- if ( ! configs . isolatedModules && this . _tsResolvedModulesCachePath ) {
318+ if ( ! configs . isolatedModules && configs . tsCacheDir ) {
325319 let resolvedModuleNames : string [ ]
326320 if ( this . _depGraphs . get ( filePath ) ?. fileContent === fileContent ) {
327321 this . _logger . debug (
@@ -346,7 +340,6 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
346340 fileContent,
347341 resolvedModuleNames,
348342 } )
349- writeFileSync ( this . _tsResolvedModulesCachePath , stringify ( [ ...this . _depGraphs ] ) )
350343 }
351344 resolvedModuleNames . forEach ( ( moduleName ) => {
352345 constructingCacheKeyElements . push (
@@ -368,20 +361,4 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
368361 ) : Promise < string > {
369362 return Promise . resolve ( this . getCacheKey ( sourceText , sourcePath , transformOptions ) )
370363 }
371-
372- /**
373- * Subclasses extends `TsJestTransformer` can call this method to get resolved module disk cache
374- */
375- private _getFsCachedResolvedModules ( configSet : ConfigSet ) : void {
376- const cacheDir = configSet . tsCacheDir
377- if ( ! configSet . isolatedModules && cacheDir ) {
378- // Make sure the cache directory exists before continuing.
379- mkdirSync ( cacheDir , { recursive : true } )
380- this . _tsResolvedModulesCachePath = path . join ( cacheDir , sha1 ( 'ts-jest-resolved-modules' , CACHE_KEY_EL_SEPARATOR ) )
381- try {
382- const cachedTSResolvedModules = readFileSync ( this . _tsResolvedModulesCachePath , 'utf-8' )
383- this . _depGraphs = new Map ( parse ( cachedTSResolvedModules ) )
384- } catch ( e ) { }
385- }
386- }
387364}
0 commit comments