@@ -112,18 +112,36 @@ const toDiagnosticCodeList = (items: (string | number)[], into: number[] = []):
112
112
113
113
export class ConfigSet {
114
114
readonly logger : Logger
115
- private readonly _cwd : string
116
- private readonly _rootDir : string
115
+ readonly compilerModule : TTypeScript
116
+ readonly isolatedModules : boolean
117
+ readonly cwd : string
118
+ tsCacheDir : string | undefined
119
+ parsedTsConfig ! : ParsedCommandLine
120
+ customTransformers : CustomTransformers = Object . create ( null )
121
+ readonly rootDir : string
122
+ /**
123
+ * @internal
124
+ */
117
125
private _jestCfg ! : Config . ProjectConfig
118
- private _isolatedModules ! : boolean
119
- private _parsedTsConfig ! : ParsedCommandLine
120
- private _customTransformers : CustomTransformers = Object . create ( null )
126
+ /**
127
+ * @internal
128
+ */
121
129
private _babelConfig : BabelConfig | undefined
130
+ /**
131
+ * @internal
132
+ */
122
133
private _babelJestTransformers : BabelJestTransformer | undefined
134
+ /**
135
+ * @internal
136
+ */
123
137
private _diagnostics ! : TsJestDiagnosticsCfg
138
+ /**
139
+ * @internal
140
+ */
124
141
private _stringifyContentRegExp : RegExp | undefined
125
- private readonly _compilerModule ! : TTypeScript
126
- private _tsCacheDir : string | undefined
142
+ /**
143
+ * @internal
144
+ */
127
145
private _overriddenCompilerOptions : Partial < CompilerOptions > = {
128
146
// we handle sourcemaps this way and not another
129
147
sourceMap : true ,
@@ -146,27 +164,39 @@ export class ConfigSet {
146
164
}
147
165
148
166
constructor (
167
+ /**
168
+ * @internal
169
+ */
149
170
private readonly jestConfig : Config . ProjectConfig ,
150
- // mainly for testing logging
171
+ /**
172
+ * Mainly for testing logging
173
+ *
174
+ * @internal
175
+ */
151
176
private readonly parentLogger ?: Logger ,
152
177
) {
153
178
this . logger = this . parentLogger
154
179
? this . parentLogger . child ( { [ LogContexts . namespace ] : 'config' } )
155
180
: rootLogger . child ( { namespace : 'config' } )
156
- this . _cwd = normalize ( this . jestConfig . cwd ?? process . cwd ( ) )
157
- this . _rootDir = normalize ( this . jestConfig . rootDir ?? this . _cwd )
181
+ this . cwd = normalize ( this . jestConfig . cwd ?? process . cwd ( ) )
182
+ this . rootDir = normalize ( this . jestConfig . rootDir ?? this . cwd )
158
183
const tsJestCfg = this . jestConfig . globals && this . jestConfig . globals [ 'ts-jest' ]
159
184
const options : TsJestGlobalOptions = tsJestCfg ?? Object . create ( null )
160
185
// compiler module
161
- this . _compilerModule = importer . typescript ( ImportReasons . TsJest , options . compiler ?? 'typescript' )
186
+ this . compilerModule = importer . typescript ( ImportReasons . TsJest , options . compiler ?? 'typescript' )
187
+ // isolatedModules
188
+ this . isolatedModules = options . isolatedModules ?? false
162
189
163
- this . logger . debug ( { compilerModule : this . _compilerModule } , 'normalized compiler module config via ts-jest option' )
190
+ this . logger . debug ( { compilerModule : this . compilerModule } , 'normalized compiler module config via ts-jest option' )
164
191
165
192
this . _backportJestCfg ( )
166
193
this . _setupTsJestCfg ( options )
167
194
this . _resolveTsCacheDir ( )
168
195
}
169
196
197
+ /**
198
+ * @internal
199
+ */
170
200
private _backportJestCfg ( ) : void {
171
201
const config = backportJestConfig ( this . logger , this . jestConfig )
172
202
@@ -175,10 +205,10 @@ export class ConfigSet {
175
205
this . _jestCfg = config
176
206
}
177
207
208
+ /**
209
+ * @internal
210
+ */
178
211
private _setupTsJestCfg ( options : TsJestGlobalOptions ) : void {
179
- // isolatedModules
180
- this . _isolatedModules = options . isolatedModules ?? false
181
-
182
212
if ( options . packageJson ) {
183
213
this . logger . warn ( Deprecations . PackageJson )
184
214
}
@@ -187,7 +217,7 @@ export class ConfigSet {
187
217
if ( ! options . babelConfig ) {
188
218
this . logger . debug ( 'babel is disabled' )
189
219
} else {
190
- const baseBabelCfg = { cwd : this . _cwd }
220
+ const baseBabelCfg = { cwd : this . cwd }
191
221
if ( typeof options . babelConfig === 'string' ) {
192
222
if ( extname ( options . babelConfig ) === '.js' ) {
193
223
this . _babelConfig = {
@@ -251,24 +281,24 @@ export class ConfigSet {
251
281
}
252
282
const tsconfigOpt = options . tsConfig ?? options . tsconfig
253
283
const configFilePath = typeof tsconfigOpt === 'string' ? this . resolvePath ( tsconfigOpt ) : undefined
254
- this . _parsedTsConfig = this . _readTsConfig ( typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined , configFilePath )
284
+ this . parsedTsConfig = this . _readTsConfig ( typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined , configFilePath )
255
285
// throw errors if any matching wanted diagnostics
256
- this . raiseDiagnostics ( this . _parsedTsConfig . errors , configFilePath )
286
+ this . raiseDiagnostics ( this . parsedTsConfig . errors , configFilePath )
257
287
258
- this . logger . debug ( { tsconfig : this . _parsedTsConfig } , 'normalized typescript config via ts-jest option' )
288
+ this . logger . debug ( { tsconfig : this . parsedTsConfig } , 'normalized typescript config via ts-jest option' )
259
289
260
290
// transformers
261
291
const { astTransformers } = options
262
- this . _customTransformers = {
292
+ this . customTransformers = {
263
293
before : [ hoisting ( this ) ] ,
264
294
}
265
295
if ( astTransformers ) {
266
296
if ( Array . isArray ( astTransformers ) ) {
267
297
this . logger . warn ( Deprecations . AstTransformerArrayConfig )
268
298
269
- this . _customTransformers = {
299
+ this . customTransformers = {
270
300
before : [
271
- ...this . _customTransformers . before ,
301
+ ...this . customTransformers . before ,
272
302
...astTransformers . map ( ( transformer ) => {
273
303
const transformerPath = this . resolvePath ( transformer , { nodeResolve : true } )
274
304
@@ -291,27 +321,27 @@ export class ConfigSet {
291
321
}
292
322
} )
293
323
if ( astTransformers . before ) {
294
- this . _customTransformers = {
295
- before : [ ...this . _customTransformers . before , ...resolveTransformers ( astTransformers . before ) ] ,
324
+ this . customTransformers = {
325
+ before : [ ...this . customTransformers . before , ...resolveTransformers ( astTransformers . before ) ] ,
296
326
}
297
327
}
298
328
if ( astTransformers . after ) {
299
- this . _customTransformers = {
300
- ...this . _customTransformers ,
329
+ this . customTransformers = {
330
+ ...this . customTransformers ,
301
331
after : resolveTransformers ( astTransformers . after ) ,
302
332
}
303
333
}
304
334
if ( astTransformers . afterDeclarations ) {
305
- this . _customTransformers = {
306
- ...this . _customTransformers ,
335
+ this . customTransformers = {
336
+ ...this . customTransformers ,
307
337
afterDeclarations : resolveTransformers ( astTransformers . afterDeclarations ) ,
308
338
}
309
339
}
310
340
}
311
341
}
312
342
313
343
this . logger . debug (
314
- { customTransformers : this . _customTransformers } ,
344
+ { customTransformers : this . customTransformers } ,
315
345
'normalized custom AST transformers via ts-jest option' ,
316
346
)
317
347
@@ -329,6 +359,9 @@ export class ConfigSet {
329
359
}
330
360
}
331
361
362
+ /**
363
+ * @internal
364
+ */
332
365
private _resolveTsCacheDir ( ) : void {
333
366
if ( ! this . _jestCfg . cache ) {
334
367
this . logger . debug ( 'file caching disabled' )
@@ -337,19 +370,19 @@ export class ConfigSet {
337
370
}
338
371
const cacheSuffix = sha1 (
339
372
stringify ( {
340
- version : this . _compilerModule . version ,
373
+ version : this . compilerModule . version ,
341
374
digest : this . tsJestDigest ,
342
- compilerModule : this . _compilerModule ,
343
- compilerOptions : this . _parsedTsConfig . options ,
344
- isolatedModules : this . _isolatedModules ,
375
+ compilerModule : this . compilerModule ,
376
+ compilerOptions : this . parsedTsConfig . options ,
377
+ isolatedModules : this . isolatedModules ,
345
378
diagnostics : this . _diagnostics ,
346
379
} ) ,
347
380
)
348
381
const res = join ( this . _jestCfg . cacheDirectory , 'ts-jest' , cacheSuffix . substr ( 0 , 2 ) , cacheSuffix . substr ( 2 ) )
349
382
350
383
this . logger . debug ( { cacheDirectory : res } , 'will use file caching' )
351
384
352
- this . _tsCacheDir = res
385
+ this . tsCacheDir = res
353
386
}
354
387
355
388
/**
@@ -360,12 +393,12 @@ export class ConfigSet {
360
393
*/
361
394
private _readTsConfig ( compilerOptions ?: CompilerOptions , resolvedConfigFile ?: string ) : ParsedCommandLine {
362
395
let config = { compilerOptions : Object . create ( null ) }
363
- let basePath = normalizeSlashes ( this . _rootDir )
364
- const ts = this . _compilerModule
396
+ let basePath = normalizeSlashes ( this . rootDir )
397
+ const ts = this . compilerModule
365
398
// Read project configuration when available.
366
399
const configFileName : string | undefined = resolvedConfigFile
367
400
? normalizeSlashes ( resolvedConfigFile )
368
- : ts . findConfigFile ( normalizeSlashes ( this . _rootDir ) , ts . sys . fileExists )
401
+ : ts . findConfigFile ( normalizeSlashes ( this . rootDir ) , ts . sys . fileExists )
369
402
if ( configFileName ) {
370
403
this . logger . debug ( { tsConfigFileName : configFileName } , 'readTsConfig(): reading' , configFileName )
371
404
const result = ts . readConfigFile ( configFileName , ts . sys . readFile )
@@ -456,25 +489,9 @@ export class ConfigSet {
456
489
return result
457
490
}
458
491
459
- get parsedTsConfig ( ) : ParsedCommandLine {
460
- return this . _parsedTsConfig
461
- }
462
-
463
- get isolatedModules ( ) : boolean {
464
- return this . _isolatedModules
465
- }
466
-
467
492
/**
468
- * This API can be used by custom transformers
493
+ * @internal
469
494
*/
470
- get compilerModule ( ) : TTypeScript {
471
- return this . _compilerModule
472
- }
473
-
474
- get customTransformers ( ) : CustomTransformers {
475
- return this . _customTransformers
476
- }
477
-
478
495
@Memoize ( )
479
496
get tsCompiler ( ) : TsCompiler {
480
497
return createCompilerInstance ( this )
@@ -494,14 +511,6 @@ export class ConfigSet {
494
511
return this . _babelJestTransformers
495
512
}
496
513
497
- get cwd ( ) : string {
498
- return this . _cwd
499
- }
500
-
501
- get tsCacheDir ( ) : string | undefined {
502
- return this . _tsCacheDir
503
- }
504
-
505
514
/**
506
515
* Use by e2e, don't mark as internal
507
516
*/
@@ -518,7 +527,7 @@ export class ConfigSet {
518
527
get hooks ( ) : TsJestHooksMap {
519
528
let hooksFile = process . env . TS_JEST_HOOKS
520
529
if ( hooksFile ) {
521
- hooksFile = resolve ( this . _cwd , hooksFile )
530
+ hooksFile = resolve ( this . cwd , hooksFile )
522
531
523
532
return importer . tryTheseOr ( hooksFile , { } )
524
533
}
@@ -546,16 +555,13 @@ export class ConfigSet {
546
555
matchablePatterns . some ( ( pattern ) => ( typeof pattern === 'string' ? isMatch ( fileName ) : pattern . test ( fileName ) ) )
547
556
}
548
557
549
- /**
550
- * @internal
551
- */
552
558
shouldStringifyContent ( filePath : string ) : boolean {
553
559
return this . _stringifyContentRegExp ? this . _stringifyContentRegExp . test ( filePath ) : false
554
560
}
555
561
556
562
raiseDiagnostics ( diagnostics : Diagnostic [ ] , filePath ?: string , logger ?: Logger ) : void {
557
563
const { ignoreCodes } = this . _diagnostics
558
- const { DiagnosticCategory } = this . _compilerModule
564
+ const { DiagnosticCategory } = this . compilerModule
559
565
const filteredDiagnostics =
560
566
filePath && ! this . shouldReportDiagnostics ( filePath )
561
567
? [ ]
@@ -614,7 +620,7 @@ export class ConfigSet {
614
620
let path : string = inputPath
615
621
let nodeResolved = false
616
622
if ( path . startsWith ( '<rootDir>' ) ) {
617
- path = resolve ( join ( this . _rootDir , path . substr ( 9 ) ) )
623
+ path = resolve ( join ( this . rootDir , path . substr ( 9 ) ) )
618
624
} else if ( ! isAbsolute ( path ) ) {
619
625
if ( ! path . startsWith ( '.' ) && nodeResolve ) {
620
626
try {
0 commit comments