Skip to content

Commit 19778bd

Browse files
Anh Phamahnpnl
Anh Pham
authored andcommitted
build: reference transform options via jest TransformOptions type
1 parent a5d6f2d commit 19778bd

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/legacy/config/config-set.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ import type {
2525
AstTransformerDesc,
2626
BabelConfig,
2727
BabelJestTransformer,
28-
ProjectConfigTsJest,
2928
TsJestAstTransformer,
30-
TsJestGlobalOptions,
29+
TsJestTransformOptions,
3130
TTypeScript,
3231
} from '../../types'
3332
import { TsCompilerInstance } from '../../types'
@@ -145,7 +144,7 @@ export class ConfigSet {
145144
/**
146145
* @internal
147146
*/
148-
private _jestCfg!: ProjectConfigTsJest
147+
private _jestCfg!: TsJestTransformOptions['config']
149148
/**
150149
* @internal
151150
*/
@@ -187,7 +186,7 @@ export class ConfigSet {
187186
tsBuildInfoFile: undefined,
188187
}
189188

190-
constructor(jestConfig: ProjectConfigTsJest | undefined, readonly parentLogger?: Logger) {
189+
constructor(jestConfig: TsJestTransformOptions['config'] | undefined, readonly parentLogger?: Logger) {
191190
this.logger = this.parentLogger
192191
? this.parentLogger.child({ [LogContexts.namespace]: 'config' })
193192
: rootLogger.child({ namespace: 'config' })
@@ -224,7 +223,7 @@ export class ConfigSet {
224223
/**
225224
* @internal
226225
*/
227-
private _backportJestCfg(jestCfg: ProjectConfigTsJest): void {
226+
private _backportJestCfg(jestCfg: TsJestTransformOptions['config']): void {
228227
const config = backportJestConfig(this.logger, jestCfg)
229228

230229
this.logger.debug({ jestConfig: config }, 'normalized jest config')
@@ -239,7 +238,7 @@ export class ConfigSet {
239238
/**
240239
* @internal
241240
*/
242-
private _setupConfigSet(options: TsJestGlobalOptions): void {
241+
private _setupConfigSet(options: TsJestTransformOptions['transformerConfig']): void {
243242
// useESM
244243
this.useESM = options.useESM ?? false
245244

src/legacy/ts-jest-transformer.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import type {
99
CompiledOutput,
1010
CompilerInstance,
1111
DepGraphInfo,
12-
ProjectConfigTsJest,
13-
TransformOptionsTsJest,
14-
TsJestGlobalOptions,
12+
TsJestTransformerOptions,
13+
TsJestTransformOptions,
1514
} from '../types'
1615
import { parse, stringify, JsonableValue, rootLogger } from '../utils'
1716
import { importer } from '../utils/importer'
@@ -24,7 +23,7 @@ import { ConfigSet } from './config/config-set'
2423

2524
interface CachedConfigSet {
2625
configSet: ConfigSet
27-
jestConfig: JsonableValue<ProjectConfigTsJest>
26+
jestConfig: JsonableValue<TsJestTransformOptions['config']>
2827
transformerCfgStr: string
2928
compiler: CompilerInstance
3029
depGraphs: Map<string, DepGraphInfo>
@@ -42,7 +41,7 @@ interface TsJestHooksMap {
4241
*/
4342
export const CACHE_KEY_EL_SEPARATOR = '\x00'
4443

45-
export class TsJestTransformer implements SyncTransformer {
44+
export class TsJestTransformer implements SyncTransformer<TsJestTransformerOptions> {
4645
/**
4746
* cache ConfigSet between test runs
4847
*
@@ -56,7 +55,7 @@ export class TsJestTransformer implements SyncTransformer {
5655
private _depGraphs: Map<string, DepGraphInfo> = new Map<string, DepGraphInfo>()
5756
private _watchMode = false
5857

59-
constructor(private readonly tsJestConfig?: TsJestGlobalOptions) {
58+
constructor(private readonly tsJestConfig?: TsJestTransformOptions['transformerConfig']) {
6059
this._logger = rootLogger.child({ namespace: 'ts-jest-transformer' })
6160
VersionCheckers.jest.warn()
6261
/**
@@ -72,7 +71,7 @@ export class TsJestTransformer implements SyncTransformer {
7271
process.env.TS_JEST = '1'
7372
}
7473

75-
private _configsFor(transformOptions: TransformOptionsTsJest): ConfigSet {
74+
private _configsFor(transformOptions: TsJestTransformOptions): ConfigSet {
7675
const { config, cacheFS } = transformOptions
7776
const ccs: CachedConfigSet | undefined = TsJestTransformer._cachedConfigSets.find(
7877
(cs) => cs.jestConfig.value === config,
@@ -148,7 +147,7 @@ export class TsJestTransformer implements SyncTransformer {
148147
}
149148

150149
// eslint-disable-next-line class-methods-use-this
151-
protected _createConfigSet(config: ProjectConfigTsJest | undefined): ConfigSet {
150+
protected _createConfigSet(config: TsJestTransformOptions['config'] | undefined): ConfigSet {
152151
return new ConfigSet(config)
153152
}
154153

@@ -159,7 +158,7 @@ export class TsJestTransformer implements SyncTransformer {
159158
/**
160159
* @public
161160
*/
162-
process(sourceText: string, sourcePath: string, transformOptions: TransformOptionsTsJest): TransformedSource {
161+
process(sourceText: string, sourcePath: string, transformOptions: TsJestTransformOptions): TransformedSource {
163162
this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath)
164163

165164
const configs = this._configsFor(transformOptions)
@@ -185,7 +184,7 @@ export class TsJestTransformer implements SyncTransformer {
185184
async processAsync(
186185
sourceText: string,
187186
sourcePath: string,
188-
transformOptions: TransformOptionsTsJest,
187+
transformOptions: TsJestTransformOptions,
189188
): Promise<TransformedSource> {
190189
this._logger.debug({ fileName: sourcePath, transformOptions }, 'processing', sourcePath)
191190

@@ -217,7 +216,7 @@ export class TsJestTransformer implements SyncTransformer {
217216
private processWithTs(
218217
sourceText: string,
219218
sourcePath: string,
220-
transformOptions: TransformOptionsTsJest,
219+
transformOptions: TsJestTransformOptions,
221220
): CompiledOutput {
222221
let result: TransformedSource
223222
const configs = this._configsFor(transformOptions)
@@ -269,7 +268,7 @@ export class TsJestTransformer implements SyncTransformer {
269268
private runTsJestHook(
270269
sourcePath: string,
271270
sourceText: string,
272-
transformOptions: TransformOptionsTsJest,
271+
transformOptions: TsJestTransformOptions,
273272
compiledOutput: TransformedSource,
274273
) {
275274
let hooksFile = process.env.TS_JEST_HOOKS
@@ -302,7 +301,7 @@ export class TsJestTransformer implements SyncTransformer {
302301
*
303302
* @public
304303
*/
305-
getCacheKey(fileContent: string, filePath: string, transformOptions: TransformOptionsTsJest): string {
304+
getCacheKey(fileContent: string, filePath: string, transformOptions: TsJestTransformOptions): string {
306305
const configs = this._configsFor(transformOptions)
307306

308307
this._logger.debug({ fileName: filePath, transformOptions }, 'computing cache key for', filePath)
@@ -365,7 +364,7 @@ export class TsJestTransformer implements SyncTransformer {
365364
async getCacheKeyAsync(
366365
sourceText: string,
367366
sourcePath: string,
368-
transformOptions: TransformOptionsTsJest,
367+
transformOptions: TsJestTransformOptions,
369368
): Promise<string> {
370369
return Promise.resolve(this.getCacheKey(sourceText, sourcePath, transformOptions))
371370
}

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ export interface InitialOptionsTsJest extends Config.InitialOptions {
188188
globals?: GlobalConfigTsJest
189189
}
190190
export type TsJestTransformerOptions = TsJestGlobalOptions
191+
192+
export type TsJestTransformOptions = TransformOptions<TsJestTransformerOptions>
193+
191194
export interface JestConfigWithTsJest extends Omit<Config.InitialOptions, 'transform'> {
192195
transform?: {
193196
[regex: string]:

0 commit comments

Comments
 (0)