diff --git a/src/legacy/config/config-set.ts b/src/legacy/config/config-set.ts index 9351739bc7..6502cb4732 100644 --- a/src/legacy/config/config-set.ts +++ b/src/legacy/config/config-set.ts @@ -25,9 +25,8 @@ import type { AstTransformerDesc, BabelConfig, BabelJestTransformer, - ProjectConfigTsJest, TsJestAstTransformer, - TsJestGlobalOptions, + TsJestTransformOptions, TTypeScript, } from '../../types' import { TsCompilerInstance } from '../../types' @@ -145,7 +144,7 @@ export class ConfigSet { /** * @internal */ - private _jestCfg!: ProjectConfigTsJest + private _jestCfg!: TsJestTransformOptions['config'] /** * @internal */ @@ -187,7 +186,7 @@ export class ConfigSet { tsBuildInfoFile: undefined, } - constructor(jestConfig: ProjectConfigTsJest | undefined, readonly parentLogger?: Logger) { + constructor(jestConfig: TsJestTransformOptions['config'] | undefined, readonly parentLogger?: Logger) { this.logger = this.parentLogger ? this.parentLogger.child({ [LogContexts.namespace]: 'config' }) : rootLogger.child({ namespace: 'config' }) @@ -224,7 +223,7 @@ export class ConfigSet { /** * @internal */ - private _backportJestCfg(jestCfg: ProjectConfigTsJest): void { + private _backportJestCfg(jestCfg: TsJestTransformOptions['config']): void { const config = backportJestConfig(this.logger, jestCfg) this.logger.debug({ jestConfig: config }, 'normalized jest config') @@ -239,7 +238,7 @@ export class ConfigSet { /** * @internal */ - private _setupConfigSet(options: TsJestGlobalOptions): void { + private _setupConfigSet(options: TsJestTransformOptions['transformerConfig']): void { // useESM this.useESM = options.useESM ?? false diff --git a/src/legacy/ts-jest-transformer.ts b/src/legacy/ts-jest-transformer.ts index 72b731dcde..a92cda873d 100644 --- a/src/legacy/ts-jest-transformer.ts +++ b/src/legacy/ts-jest-transformer.ts @@ -9,9 +9,8 @@ import type { CompiledOutput, CompilerInstance, DepGraphInfo, - ProjectConfigTsJest, - TransformOptionsTsJest, - TsJestGlobalOptions, + TsJestTransformerOptions, + TsJestTransformOptions, } from '../types' import { parse, stringify, JsonableValue, rootLogger } from '../utils' import { importer } from '../utils/importer' @@ -24,7 +23,7 @@ import { ConfigSet } from './config/config-set' interface CachedConfigSet { configSet: ConfigSet - jestConfig: JsonableValue + jestConfig: JsonableValue transformerCfgStr: string compiler: CompilerInstance depGraphs: Map @@ -42,7 +41,7 @@ interface TsJestHooksMap { */ export const CACHE_KEY_EL_SEPARATOR = '\x00' -export class TsJestTransformer implements SyncTransformer { +export class TsJestTransformer implements SyncTransformer { /** * cache ConfigSet between test runs * @@ -56,7 +55,7 @@ export class TsJestTransformer implements SyncTransformer { private _depGraphs: Map = new Map() private _watchMode = false - constructor(private readonly tsJestConfig?: TsJestGlobalOptions) { + constructor(private readonly tsJestConfig?: TsJestTransformOptions['transformerConfig']) { this._logger = rootLogger.child({ namespace: 'ts-jest-transformer' }) VersionCheckers.jest.warn() /** @@ -72,7 +71,7 @@ export class TsJestTransformer implements SyncTransformer { process.env.TS_JEST = '1' } - private _configsFor(transformOptions: TransformOptionsTsJest): ConfigSet { + private _configsFor(transformOptions: TsJestTransformOptions): ConfigSet { const { config, cacheFS } = transformOptions const ccs: CachedConfigSet | undefined = TsJestTransformer._cachedConfigSets.find( (cs) => cs.jestConfig.value === config, @@ -148,7 +147,7 @@ export class TsJestTransformer implements SyncTransformer { } // eslint-disable-next-line class-methods-use-this - protected _createConfigSet(config: ProjectConfigTsJest | undefined): ConfigSet { + protected _createConfigSet(config: TsJestTransformOptions['config'] | undefined): ConfigSet { return new ConfigSet(config) } @@ -159,7 +158,7 @@ export class TsJestTransformer implements SyncTransformer { /** * @public */ - process(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): TransformedSource { + process(sourceText: string, sourcePath: string, transformOptions: TsJestTransformOptions): TransformedSource { this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath) const configs = this._configsFor(transformOptions) @@ -185,7 +184,7 @@ export class TsJestTransformer implements SyncTransformer { async processAsync( sourceText: string, sourcePath: string, - transformOptions: TransformOptionsTsJest, + transformOptions: TsJestTransformOptions, ): Promise { this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath) @@ -217,7 +216,7 @@ export class TsJestTransformer implements SyncTransformer { private processWithTs( sourceText: string, sourcePath: string, - transformOptions: TransformOptionsTsJest, + transformOptions: TsJestTransformOptions, ): CompiledOutput { let result: TransformedSource const configs = this._configsFor(transformOptions) @@ -269,7 +268,7 @@ export class TsJestTransformer implements SyncTransformer { private runTsJestHook( sourcePath: string, sourceText: string, - transformOptions: TransformOptionsTsJest, + transformOptions: TsJestTransformOptions, compiledOutput: TransformedSource, ) { let hooksFile = process.env.TS_JEST_HOOKS @@ -302,7 +301,7 @@ export class TsJestTransformer implements SyncTransformer { * * @public */ - getCacheKey(fileContent: string, filePath: string, transformOptions: TransformOptionsTsJest): string { + getCacheKey(fileContent: string, filePath: string, transformOptions: TsJestTransformOptions): string { const configs = this._configsFor(transformOptions) this._logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath) @@ -365,7 +364,7 @@ export class TsJestTransformer implements SyncTransformer { async getCacheKeyAsync( sourceText: string, sourcePath: string, - transformOptions: TransformOptionsTsJest, + transformOptions: TsJestTransformOptions, ): Promise { return Promise.resolve(this.getCacheKey(sourceText, sourcePath, transformOptions)) } diff --git a/src/types.ts b/src/types.ts index e658a67342..3b1b6ebf24 100644 --- a/src/types.ts +++ b/src/types.ts @@ -188,6 +188,9 @@ export interface InitialOptionsTsJest extends Config.InitialOptions { globals?: GlobalConfigTsJest } export type TsJestTransformerOptions = TsJestGlobalOptions + +export type TsJestTransformOptions = TransformOptions + export interface JestConfigWithTsJest extends Omit { transform?: { [regex: string]: