Skip to content

Commit

Permalink
fix(typings): set correct typing for tsconfig/tsConfig option (#2377
Browse files Browse the repository at this point in the history
)

Closes #2368
  • Loading branch information
ahnpnl authored Feb 18, 2021
1 parent 9034677 commit d4f6aff
Show file tree
Hide file tree
Showing 10 changed files with 16,371 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
src/tsconfig-raw-types.d.ts

# Logs
logs
Expand Down
16,245 changes: 16,188 additions & 57 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"description": "A preprocessor with source maps support to help use TypeScript with Jest",
"scripts": {
"prebuild": "node scripts/clean-dist.js",
"prebuild": "node scripts/pre-build.js",
"build": "tsc -p tsconfig.build.json",
"postbuild": "node scripts/post-build.js",
"clean": "node scripts/clean.js",
Expand All @@ -32,7 +32,8 @@
"prepublishOnly": "npm run test",
"preversion": "npm run test",
"update:e2e": "node scripts/update-e2e-templates.js",
"version": "npm run changelog && git add CHANGELOG.md"
"version": "npm run changelog && git add CHANGELOG.md",
"raw-tsconfig-types": "node scripts/tsconfig-raw-types.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -114,7 +115,9 @@
"husky": "4.x",
"jest": "26.x",
"js-yaml": "latest",
"json-schema-to-typescript": "^10.1.3",
"lint-staged": "latest",
"node-fetch": "^2.6.1",
"npm-run-all": "latest",
"prettier": "2.x",
"source-map": "latest",
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions scripts/tsconfig-raw-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { compile } = require('json-schema-to-typescript')
const fs = require('fs')
const fetch = require('node-fetch')
const path = require('path')

void (async () => {
const response = await fetch('https://json.schemastore.org/tsconfig')
const tsconfigSchema = await response.json()
const rawTsconfig = await compile(tsconfigSchema)
fs.writeFileSync(path.join(process.cwd(), 'src', 'tsconfig-raw-types.d.ts'), rawTsconfig)
})()
1 change: 0 additions & 1 deletion src/config/config-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ describe('parsedTsConfig', () => {
})
expect(cs.parsedTsConfig.options).toMatchObject({
module: ts.ModuleKind.CommonJS,
rootDir: normalizeSlashes(resolve(__dirname, '..')),
skipLibCheck: true,
})
})
Expand Down
5 changes: 3 additions & 2 deletions src/config/config-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { Deprecations, Errors, ImportReasons, interpolate } from '../utils/messa
import { normalizeSlashes } from '../utils/normalize-slashes'
import { sha1 } from '../utils/sha1'
import { TSError } from '../utils/ts-error'
import type { RawCompilerOptions } from '../tsconfig-raw'

/**
* @internal
Expand Down Expand Up @@ -421,9 +422,9 @@ export class ConfigSet {
* Load TypeScript configuration. Returns the parsed TypeScript config and
* any `tsConfig` options specified in ts-jest tsConfig
*/
protected _resolveTsConfig(compilerOptions?: CompilerOptions, resolvedConfigFile?: string): Record<string, any>
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): Record<string, any>
// eslint-disable-next-line no-dupe-class-members
protected _resolveTsConfig(compilerOptions?: CompilerOptions, resolvedConfigFile?: string): ParsedCommandLine {
protected _resolveTsConfig(compilerOptions?: RawCompilerOptions, resolvedConfigFile?: string): ParsedCommandLine {
let config = { compilerOptions: Object.create(null) }
let basePath = normalizeSlashes(this.rootDir)
const ts = this.compilerModule
Expand Down
160 changes: 160 additions & 0 deletions src/tsconfig-raw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
export interface RawCompilerOptions {
charset?: string
composite?: boolean
declaration?: boolean
declarationDir?: string | null
diagnostics?: boolean
disableReferencedProjectLoad?: boolean
emitBOM?: boolean
emitDeclarationOnly?: boolean
incremental?: boolean
tsBuildInfoFile?: string
inlineSourceMap?: boolean
inlineSources?: boolean
jsx?: 'preserve' | 'react' | 'react-jsx' | 'react-jsxdev' | 'react-native'
reactNamespace?: string
jsxFactory?: string
jsxFragmentFactory?: string
jsxImportSource?: string
listFiles?: boolean
mapRoot?: string
module?: 'CommonJS' | 'AMD' | 'System' | 'UMD' | 'ES6' | 'ES2015' | 'ES2020' | 'ESNext' | 'None' | string
moduleResolution?: 'Classic' | 'Node'
newLine?: 'crlf' | 'lf'
noEmit?: boolean
noEmitHelpers?: boolean
noEmitOnError?: boolean
noImplicitAny?: boolean
noImplicitThis?: boolean
noUnusedLocals?: boolean
noUnusedParameters?: boolean
noLib?: boolean
noResolve?: boolean
noStrictGenericChecks?: boolean
skipDefaultLibCheck?: boolean
skipLibCheck?: boolean
outFile?: string
outDir?: string
preserveConstEnums?: boolean
preserveSymlinks?: boolean
preserveWatchOutput?: boolean
pretty?: boolean
removeComments?: boolean
rootDir?: string
isolatedModules?: boolean
sourceMap?: boolean
sourceRoot?: string
suppressExcessPropertyErrors?: boolean
suppressImplicitAnyIndexErrors?: boolean
target?: 'ES3' | 'ES5' | 'ES6' | 'ES2015' | 'ES2016' | 'ES2017' | 'ES2018' | 'ES2019' | 'ES2020' | 'ESNext' | string
watch?: boolean
fallbackPolling?: 'fixedPollingInterval' | 'priorityPollingInterval' | 'dynamicPriorityPolling'
watchDirectory?: 'useFsEvents' | 'fixedPollingInterval' | 'dynamicPriorityPolling'
watchFile?:
| 'fixedPollingInterval'
| 'priorityPollingInterval'
| 'dynamicPriorityPolling'
| 'useFsEvents'
| 'useFsEventsOnParentDirectory'
experimentalDecorators?: boolean
emitDecoratorMetadata?: boolean
allowUnusedLabels?: boolean
noImplicitReturns?: boolean
noUncheckedIndexedAccess?: boolean
noFallthroughCasesInSwitch?: boolean
allowUnreachableCode?: boolean
forceConsistentCasingInFileNames?: boolean
generateCpuProfile?: string
baseUrl?: string
paths?: {
[k: string]: string[]
}
plugins?: {
name?: string
[k: string]: unknown
}[]
rootDirs?: string[]
typeRoots?: string[]
types?: string[]
traceResolution?: boolean
allowJs?: boolean
noErrorTruncation?: boolean
allowSyntheticDefaultImports?: boolean
noImplicitUseStrict?: boolean
listEmittedFiles?: boolean
disableSizeLimit?: boolean
lib?: (
| 'ES5'
| 'ES6'
| 'ES2015'
| 'ES2015.Collection'
| 'ES2015.Core'
| 'ES2015.Generator'
| 'ES2015.Iterable'
| 'ES2015.Promise'
| 'ES2015.Proxy'
| 'ES2015.Reflect'
| 'ES2015.Symbol.WellKnown'
| 'ES2015.Symbol'
| 'ES2016'
| 'ES2016.Array.Include'
| 'ES2017'
| 'ES2017.Intl'
| 'ES2017.Object'
| 'ES2017.SharedMemory'
| 'ES2017.String'
| 'ES2017.TypedArrays'
| 'ES2018'
| 'ES2018.AsyncGenerator'
| 'ES2018.AsyncIterable'
| 'ES2018.Intl'
| 'ES2018.Promise'
| 'ES2018.Regexp'
| 'ES2019'
| 'ES2019.Array'
| 'ES2019.Object'
| 'ES2019.String'
| 'ES2019.Symbol'
| 'ES2020'
| 'ES2020.BigInt'
| 'ES2020.Promise'
| 'ES2020.String'
| 'ES2020.Symbol.WellKnown'
| 'ESNext'
| 'ESNext.Array'
| 'ESNext.AsyncIterable'
| 'ESNext.BigInt'
| 'ESNext.Intl'
| 'ESNext.Promise'
| 'ESNext.String'
| 'ESNext.Symbol'
| 'DOM'
| 'DOM.Iterable'
| 'ScriptHost'
| 'WebWorker'
| 'WebWorker.ImportScripts'
)[]
strictNullChecks?: boolean
maxNodeModuleJsDepth?: number
importHelpers?: boolean
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error'
alwaysStrict?: boolean
strict?: boolean
strictBindCallApply?: boolean
downlevelIteration?: boolean
checkJs?: boolean
strictFunctionTypes?: boolean
strictPropertyInitialization?: boolean
esModuleInterop?: boolean
allowUmdGlobalAccess?: boolean
keyofStringsOnly?: boolean
useDefineForClassFields?: boolean
declarationMap?: boolean
resolveJsonModule?: boolean
assumeChangesOnlyAffectDirectDependencies?: boolean
extendedDiagnostics?: boolean
listFilesOnly?: boolean
disableSourceOfProjectReferenceRedirect?: boolean
disableSolutionSearching?: boolean
[k: string]: unknown
}
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type * as _babel from 'babel__core'
import type * as _ts from 'typescript'

import type { ConfigSet } from './config/config-set'
import type { RawCompilerOptions } from './tsconfig-raw'

/**
* @internal
Expand Down Expand Up @@ -47,7 +48,7 @@ export interface TsJestGlobalOptions {
* @default undefined uses the default tsconfig file
* @alias tsconfig
*/
tsConfig?: boolean | string | _ts.CompilerOptions
tsConfig?: boolean | string | RawCompilerOptions

/**
* Compiler options. It can be:
Expand All @@ -59,7 +60,7 @@ export interface TsJestGlobalOptions {
* @default undefined uses the default tsconfig file
* @alias tsConfig
*/
tsconfig?: boolean | string | _ts.CompilerOptions
tsconfig?: boolean | string | RawCompilerOptions

/**
* packageJson. It can be:
Expand Down
1 change: 0 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"removeComments": true,
"stripInternal": true,
"outDir": "dist",
"rootDir": "src"
},
"include": ["src"],
"exclude": [
Expand Down

0 comments on commit d4f6aff

Please sign in to comment.