@@ -13,10 +13,9 @@ import Module from 'module'
13
13
import { dirname , extname , isAbsolute , join , normalize , resolve } from 'path'
14
14
15
15
import { LogContexts , Logger } from 'bs-logger'
16
- import { transformSync } from 'esbuild'
17
16
import { globsToMatcher } from 'jest-util'
18
17
import json5 from 'json5'
19
- import type { CompilerOptions , Diagnostic , FormatDiagnosticsHost , ParsedCommandLine } from 'typescript'
18
+ import type * as ts from 'typescript'
20
19
21
20
import { DEFAULT_JEST_TEST_MATCH , JS_JSX_EXTENSIONS } from '../constants'
22
21
import type { RawCompilerOptions } from '../raw-compiler-options'
@@ -31,7 +30,8 @@ import type {
31
30
TsJestGlobalOptions ,
32
31
TTypeScript ,
33
32
} from '../types'
34
- import { stringify , rootLogger } from '../utils'
33
+ import { TsCompilerInstance } from '../types'
34
+ import { rootLogger , stringify } from '../utils'
35
35
import { backportJestConfig } from '../utils/backports'
36
36
import { importer } from '../utils/importer'
37
37
import { Errors , ImportReasons , interpolate } from '../utils/messages'
@@ -119,7 +119,7 @@ export class ConfigSet {
119
119
cacheSuffix ! : string
120
120
tsCacheDir : string | undefined
121
121
// eslint-disable-next-line @typescript-eslint/no-explicit-any
122
- parsedTsConfig ! : ParsedCommandLine | Record < string , any >
122
+ parsedTsConfig ! : ts . ParsedCommandLine | Record < string , any >
123
123
resolvedTransformers : TsJestAstTransformer = {
124
124
before : [ ] ,
125
125
after : [ ] ,
@@ -161,7 +161,7 @@ export class ConfigSet {
161
161
/**
162
162
* @internal
163
163
*/
164
- private readonly _overriddenCompilerOptions : Partial < CompilerOptions > = {
164
+ private readonly _overriddenCompilerOptions : Partial < ts . CompilerOptions > = {
165
165
inlineSourceMap : false ,
166
166
// we don't want to create declaration files
167
167
declaration : false ,
@@ -316,13 +316,22 @@ export class ConfigSet {
316
316
const { astTransformers } = options
317
317
if ( astTransformers ) {
318
318
const resolveTransformerFunc = ( transformerPath : string ) => {
319
- let transformerFunc
319
+ let transformerFunc : {
320
+ version : number
321
+ name : string
322
+ factory : (
323
+ compilerInstance : TsCompilerInstance ,
324
+ options ?: Record < string , unknown > ,
325
+ ) => ( ctx : ts . TransformationContext ) => ts . Transformer < ts . SourceFile >
326
+ }
320
327
if ( extname ( transformerPath ) === '.ts' ) {
321
- const compiledTransformer = transformSync ( readFileSync ( transformerPath , 'utf-8' ) , {
322
- loader : 'ts' ,
323
- format : 'cjs' ,
324
- target : 'es2015' ,
325
- } ) . code
328
+ const compiledTransformer = importer
329
+ . esBuild ( ImportReasons . EsBuild )
330
+ . transformSync ( readFileSync ( transformerPath , 'utf-8' ) , {
331
+ loader : 'ts' ,
332
+ format : 'cjs' ,
333
+ target : 'es2015' ,
334
+ } ) . code
326
335
transformerFunc = requireFromString ( compiledTransformer , transformerPath . replace ( '.ts' , '.js' ) )
327
336
} else {
328
337
transformerFunc = require ( transformerPath )
@@ -423,8 +432,11 @@ export class ConfigSet {
423
432
/**
424
433
* @internal
425
434
*/
426
- private _getAndResolveTsConfig ( compilerOptions ?: RawCompilerOptions , resolvedConfigFile ?: string ) : ParsedCommandLine {
427
- const result = this . _resolveTsConfig ( compilerOptions , resolvedConfigFile ) as ParsedCommandLine
435
+ private _getAndResolveTsConfig (
436
+ compilerOptions ?: RawCompilerOptions ,
437
+ resolvedConfigFile ?: string ,
438
+ ) : ts . ParsedCommandLine {
439
+ const result = this . _resolveTsConfig ( compilerOptions , resolvedConfigFile ) as ts . ParsedCommandLine
428
440
const { _overriddenCompilerOptions : forcedOptions } = this
429
441
const finalOptions = result . options
430
442
// Target ES2015 output by default (instead of ES3).
@@ -519,7 +531,7 @@ export class ConfigSet {
519
531
// eslint-disable-next-line @typescript-eslint/no-explicit-any
520
532
protected _resolveTsConfig ( compilerOptions ?: RawCompilerOptions , resolvedConfigFile ?: string ) : Record < string , any >
521
533
// eslint-disable-next-line no-dupe-class-members
522
- protected _resolveTsConfig ( compilerOptions ?: RawCompilerOptions , resolvedConfigFile ?: string ) : ParsedCommandLine {
534
+ protected _resolveTsConfig ( compilerOptions ?: RawCompilerOptions , resolvedConfigFile ?: string ) : ts . ParsedCommandLine {
523
535
let config = { compilerOptions : Object . create ( null ) }
524
536
let basePath = normalizeSlashes ( this . rootDir )
525
537
const ts = this . compilerModule
@@ -559,7 +571,7 @@ export class ConfigSet {
559
571
return this . _stringifyContentRegExp ? this . _stringifyContentRegExp . test ( filePath ) : false
560
572
}
561
573
562
- raiseDiagnostics ( diagnostics : Diagnostic [ ] , filePath ?: string , logger ?: Logger ) : void {
574
+ raiseDiagnostics ( diagnostics : ts . Diagnostic [ ] , filePath ?: string , logger ?: Logger ) : void {
563
575
const { ignoreCodes } = this . _diagnostics
564
576
const { DiagnosticCategory } = this . compilerModule
565
577
const filteredDiagnostics =
@@ -594,12 +606,12 @@ export class ConfigSet {
594
606
/**
595
607
* @internal
596
608
*/
597
- private _createTsError ( diagnostics : readonly Diagnostic [ ] ) : TSError {
609
+ private _createTsError ( diagnostics : readonly ts . Diagnostic [ ] ) : TSError {
598
610
const formatDiagnostics = this . _diagnostics . pretty
599
611
? this . compilerModule . formatDiagnosticsWithColorAndContext
600
612
: this . compilerModule . formatDiagnostics
601
613
/* istanbul ignore next (not possible to cover) */
602
- const diagnosticHost : FormatDiagnosticsHost = {
614
+ const diagnosticHost : ts . FormatDiagnosticsHost = {
603
615
getNewLine : ( ) => '\n' ,
604
616
getCurrentDirectory : ( ) => this . cwd ,
605
617
getCanonicalFileName : ( path : string ) => path ,
0 commit comments