1
- import { existsSync , readFileSync , statSync , writeFileSync , mkdirSync } from 'fs'
1
+ import { existsSync , statSync } from 'fs'
2
2
import path from 'path'
3
3
4
4
import type { SyncTransformer , TransformedSource } from '@jest/transform'
@@ -12,7 +12,7 @@ import type {
12
12
TsJestTransformerOptions ,
13
13
TsJestTransformOptions ,
14
14
} from '../types'
15
- import { parse , stringify , JsonableValue , rootLogger } from '../utils'
15
+ import { stringify , JsonableValue , rootLogger } from '../utils'
16
16
import { importer } from '../utils/importer'
17
17
import { Deprecations , Errors , interpolate } from '../utils/messages'
18
18
import { sha1 } from '../utils/sha1'
@@ -27,7 +27,6 @@ interface CachedConfigSet {
27
27
transformerCfgStr : string
28
28
compiler : CompilerInstance
29
29
depGraphs : Map < string , DepGraphInfo >
30
- tsResolvedModulesCachePath : string | undefined
31
30
watchMode : boolean
32
31
}
33
32
@@ -50,7 +49,6 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
50
49
private static readonly _cachedConfigSets : CachedConfigSet [ ] = [ ]
51
50
private readonly _logger : Logger
52
51
protected _compiler ! : CompilerInstance
53
- private _tsResolvedModulesCachePath : string | undefined
54
52
private _transformCfgStr ! : string
55
53
private _depGraphs : Map < string , DepGraphInfo > = new Map < string , DepGraphInfo > ( )
56
54
private _watchMode = false
@@ -81,7 +79,6 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
81
79
this . _transformCfgStr = ccs . transformerCfgStr
82
80
this . _compiler = ccs . compiler
83
81
this . _depGraphs = ccs . depGraphs
84
- this . _tsResolvedModulesCachePath = ccs . tsResolvedModulesCachePath
85
82
this . _watchMode = ccs . watchMode
86
83
configSet = ccs . configSet
87
84
} else {
@@ -98,7 +95,6 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
98
95
this . _transformCfgStr = serializedCcs . transformerCfgStr
99
96
this . _compiler = serializedCcs . compiler
100
97
this . _depGraphs = serializedCcs . depGraphs
101
- this . _tsResolvedModulesCachePath = serializedCcs . tsResolvedModulesCachePath
102
98
this . _watchMode = serializedCcs . watchMode
103
99
configSet = serializedCcs . configSet
104
100
} else {
@@ -129,15 +125,13 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
129
125
jest . cacheDirectory = undefined as any // eslint-disable-line @typescript-eslint/no-explicit-any
130
126
this . _transformCfgStr = `${ new JsonableValue ( jest ) . serialized } ${ configSet . cacheSuffix } `
131
127
this . _createCompiler ( configSet , cacheFS )
132
- this . _getFsCachedResolvedModules ( configSet )
133
128
this . _watchMode = process . argv . includes ( '--watch' )
134
129
TsJestTransformer . _cachedConfigSets . push ( {
135
130
jestConfig : new JsonableValue ( config ) ,
136
131
configSet,
137
132
transformerCfgStr : this . _transformCfgStr ,
138
133
compiler : this . _compiler ,
139
134
depGraphs : this . _depGraphs ,
140
- tsResolvedModulesCachePath : this . _tsResolvedModulesCachePath ,
141
135
watchMode : this . _watchMode ,
142
136
} )
143
137
}
@@ -321,7 +315,7 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
321
315
CACHE_KEY_EL_SEPARATOR ,
322
316
filePath ,
323
317
]
324
- if ( ! configs . isolatedModules && this . _tsResolvedModulesCachePath ) {
318
+ if ( ! configs . isolatedModules && configs . tsCacheDir ) {
325
319
let resolvedModuleNames : string [ ]
326
320
if ( this . _depGraphs . get ( filePath ) ?. fileContent === fileContent ) {
327
321
this . _logger . debug (
@@ -346,7 +340,6 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
346
340
fileContent,
347
341
resolvedModuleNames,
348
342
} )
349
- writeFileSync ( this . _tsResolvedModulesCachePath , stringify ( [ ...this . _depGraphs ] ) )
350
343
}
351
344
resolvedModuleNames . forEach ( ( moduleName ) => {
352
345
constructingCacheKeyElements . push (
@@ -368,20 +361,4 @@ export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptio
368
361
) : Promise < string > {
369
362
return Promise . resolve ( this . getCacheKey ( sourceText , sourcePath , transformOptions ) )
370
363
}
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
- }
387
364
}
0 commit comments