Skip to content

Commit 2b1b6cd

Browse files
committedMar 20, 2025·
refactor: deprecate RawCompilerOptions interface
DEPRECATIONS `RawCompilerOptions` is deprecated in favor of `TsConfigJson.CompilerOptions` from `type-fest`
1 parent 27d4f7c commit 2b1b6cd

9 files changed

+142
-1029
lines changed
 

‎package-lock.json

+103-958
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"prepare": "npm run build",
2626
"prepublishOnly": "npm run test",
2727
"preversion": "npm run test",
28-
"version": "npm run changelog && git add CHANGELOG.md",
29-
"raw:options": "node scripts/generate-raw-compiler-options.js"
28+
"version": "npm run changelog && git add CHANGELOG.md"
3029
},
3130
"repository": {
3231
"type": "git",
@@ -59,6 +58,7 @@
5958
"lodash.memoize": "^4.1.2",
6059
"make-error": "^1.3.6",
6160
"semver": "^7.7.1",
61+
"type-fest": "^4.37.0",
6262
"yargs-parser": "^21.1.1"
6363
},
6464
"peerDependencies": {
@@ -127,7 +127,6 @@
127127
"husky": "^9.1.7",
128128
"jest": "^29.7.0",
129129
"js-yaml": "^4.1.0",
130-
"json-schema-to-typescript": "^13.1.2",
131130
"lint-staged": "^15.5.0",
132131
"prettier": "^2.8.8",
133132
"rimraf": "^5.0.10",

‎scripts/generate-raw-compiler-options.js

-39
This file was deleted.

‎scripts/post-build.js

-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
1-
const execa = require('execa')
2-
31
const { computePackageDigest } = require('./lib/bundle')
4-
const { generatedPath, rawCompilerOptionsFileName } = require('./lib/paths')
52

6-
try {
7-
execa.sync('git', ['--version'])
8-
if (execa.sync('git', ['diff-index', '--name-only', 'HEAD']).stdout.includes(rawCompilerOptionsFileName)) {
9-
throw new Error(
10-
`Tsconfig options have changed. Please check the modified generated ${generatedPath} and commit the change`
11-
)
12-
}
13-
} catch {
14-
console.log('git command is not available. Skip checking generated types')
15-
}
163
computePackageDigest()

‎src/config/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './paths-to-module-name-mapper'
2+
export * from './types'

‎src/config/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { TsConfigJson } from 'type-fest'
2+
3+
export type TsConfigCompilerOptionsJson = TsConfigJson.CompilerOptions

‎src/legacy/config/config-set.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { globsToMatcher } from 'jest-util'
1717
import json5 from 'json5'
1818
import type * as ts from 'typescript'
1919

20+
import type { TsConfigCompilerOptionsJson } from '../../config/types'
2021
import { DEFAULT_JEST_TEST_MATCH, JS_JSX_EXTENSIONS } from '../../constants'
2122
import type { RawCompilerOptions } from '../../raw-compiler-options'
2223
import * as hoistJestTransformer from '../../transformers/hoist-jest'
@@ -470,7 +471,7 @@ export class ConfigSet {
470471
* @internal
471472
*/
472473
private _getAndResolveTsConfig(
473-
compilerOptions?: RawCompilerOptions,
474+
compilerOptions?: RawCompilerOptions | TsConfigCompilerOptionsJson,
474475
resolvedConfigFile?: string,
475476
): ts.ParsedCommandLine {
476477
const result = this._resolveTsConfig(compilerOptions, resolvedConfigFile) as ts.ParsedCommandLine
@@ -566,10 +567,15 @@ export class ConfigSet {
566567
* Load TypeScript configuration. Returns the parsed TypeScript config and any `tsconfig` options specified in ts-jest
567568
* Subclasses which extend `ConfigSet` can override the default behavior
568569
*/
569-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
570-
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any>
571-
572-
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): ts.ParsedCommandLine {
570+
protected _resolveTsConfig(
571+
compilerOptions?: RawCompilerOptions | TsConfigCompilerOptionsJson,
572+
resolvedConfigFile?: string,
573+
): // eslint-disable-next-line @typescript-eslint/no-explicit-any
574+
Record<string, any>
575+
protected _resolveTsConfig(
576+
compilerOptions?: RawCompilerOptions | TsConfigCompilerOptionsJson,
577+
resolvedConfigFile?: string,
578+
): ts.ParsedCommandLine {
573579
let config = { compilerOptions: Object.create(null) }
574580
let basePath = normalizeSlashes(this.rootDir)
575581
const ts = this.compilerModule

‎src/raw-compiler-options.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2+
import type { TsConfigJson } from 'type-fest'
3+
4+
/**
5+
* @deprecated This interface will be replaced with {@link TsConfigJson.CompilerOptions} in the next major release.
6+
*/
17
export interface RawCompilerOptions {
28
/**
39
* Enable importing files with any extension, provided a declaration file is present.

‎src/types.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type * as babelJest from 'babel-jest'
44
import type * as _babel from 'babel__core'
55
import type * as _ts from 'typescript'
66

7+
import type { TsConfigCompilerOptionsJson } from './config/types'
78
import {
89
ESM_JS_TRANSFORM_PATTERN,
910
ESM_TS_JS_TRANSFORM_PATTERN,
@@ -57,7 +58,7 @@ export interface ConfigCustomTransformer {
5758
}
5859

5960
/**
60-
* @deprecated use `TsJestTransformerOptions` instead
61+
* @deprecated use {@link TsJestTransformerOptions} instead
6162
*/
6263
export interface TsJestGlobalOptions {
6364
/**
@@ -67,23 +68,27 @@ export interface TsJestGlobalOptions {
6768
* - `path/to/tsconfig.json`: path to a specific tsconfig file (<rootDir> can be used)
6869
* - `{...}`: an object with inline compiler options
6970
*
70-
* @default undefined uses the default tsconfig file
71+
* @default `undefined` (the default config file will be used if it exists)
72+
*
73+
* @remarks
74+
*
75+
* {@link RawCompilerOptions} will be replaced with {@link TsConfigCompilerOptionsJson} in the next major release
7176
*/
72-
tsconfig?: boolean | string | RawCompilerOptions
77+
tsconfig?: boolean | string | RawCompilerOptions | TsConfigCompilerOptionsJson
7378

7479
/**
75-
* @deprecated use `isolatedModules` in `tsconfig` instead
80+
* @deprecated use {@link TsConfigCompilerOptionsJson.isolatedModules} instead
7681
*
7782
* Compiles files as isolated modules (disables some features)
7883
*
79-
* @default undefined (disabled)
84+
* @default `undefined` (disables transpiling files with {@link _ts.transpileModule})
8085
*/
8186
isolatedModules?: boolean
8287

8388
/**
8489
* Compiler to use
8590
*
86-
* @default 'typescript'
91+
* @default `typescript`
8792
*/
8893
compiler?: 'typescript' | 'ttypescript' | string
8994

@@ -98,23 +103,23 @@ export interface TsJestGlobalOptions {
98103
* - `false`: hide diagnostics of all files (kind of useless)
99104
* - `{...}`: an inline object with fine grained settings
100105
*
101-
* @default undefined shows all diagnostics
106+
* @default `undefined`
102107
*/
103108
diagnostics?:
104109
| boolean
105110
| {
106111
/**
107112
* Enables colorful and pretty output of errors
108113
*
109-
* @default undefined (enabled)
114+
* @default `undefined` (enables formatting errors)
110115
*/
111116
pretty?: boolean
112117
/**
113118
* List of TypeScript diagnostic error codes to ignore
114119
* [here](https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json).
115120
*
116121
* @see https://github.com/Microsoft/TypeScript/blob/master/src/compiler/diagnosticMessages.json
117-
* @default [6059,18002,18003]
122+
* @default `[6059,18002,18003]`
118123
*/
119124
ignoreCodes?: number | string | Array<number | string>
120125
/**
@@ -124,7 +129,7 @@ export interface TsJestGlobalOptions {
124129
/**
125130
* Logs TypeScript errors to stderr instead of throwing exceptions
126131
*
127-
* @default undefined (disabled)
132+
* @default `undefined` (TypeScript errors will be thrown as exceptions)
128133
*/
129134
warnOnly?: boolean
130135
}
@@ -136,7 +141,7 @@ export interface TsJestGlobalOptions {
136141
* - `path/to/.babelrc`: path to a babelrc file (<rootDir> can be used)
137142
* - `{...}`: an object with inline babel options
138143
*
139-
* @default undefined does NOT use babel
144+
* @default `undefined` (not using `Babel`)
140145
*/
141146
babelConfig?: boolean | string | BabelConfig
142147

0 commit comments

Comments
 (0)
Please sign in to comment.