Skip to content

Commit

Permalink
feat: mark ConfigSet as legacy (#3456)
Browse files Browse the repository at this point in the history
BREAKING CHANGE
Any imports `ts-jest/dist/config/config-set` should change to `ts-jest/dist/legacy/config/config-set`
  • Loading branch information
ahnpnl authored Apr 25, 2022
1 parent 1e880ff commit a986729
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/__helpers__/fakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Config } from '@jest/types'
import type { Logger } from 'bs-logger'

import { TsCompiler } from '../compiler'
import { ConfigSet } from '../config'
import { ConfigSet } from '../legacy/config/config-set'
import type { StringMap, TsJestGlobalOptions } from '../types'
import type { ImportReasons } from '../utils/messages'

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ts-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import type {
TranspileOutput,
} from 'typescript'

import type { ConfigSet } from '../config'
import { LINE_FEED, TS_TSX_REGEX } from '../constants'
import type { ConfigSet } from '../legacy/config/config-set'
import type {
DepGraphInfo,
StringMap,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/ts-jest-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TransformedSource } from '@jest/transform'

import type { ConfigSet } from '../config'
import type { ConfigSet } from '../legacy/config/config-set'
import type { CompilerInstance, StringMap, TsJestCompileOptions } from '../types'

import { TsCompiler } from './ts-compiler'
Expand Down
1 change: 0 additions & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './config-set'
export * from './paths-to-module-name-mapper'
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import type { Transformer } from '@jest/transform'
import { LogLevels, testing } from 'bs-logger'
import ts from 'typescript'

import { createConfigSet } from '../__helpers__/fakers'
import { logTargetMock } from '../__helpers__/mocks'
import type { AstTransformerDesc, TsJestGlobalOptions } from '../types'
import { stringify } from '../utils'
import * as _backports from '../utils/backports'
import { getPackageVersion } from '../utils/get-package-version'
import { normalizeSlashes } from '../utils/normalize-slashes'
import { sha1 } from '../utils/sha1'
import { createConfigSet } from '../../__helpers__/fakers'
import { logTargetMock } from '../../__helpers__/mocks'
import type { AstTransformerDesc, TsJestGlobalOptions } from '../../types'
import { stringify } from '../../utils'
import * as _backports from '../../utils/backports'
import { getPackageVersion } from '../../utils/get-package-version'
import { normalizeSlashes } from '../../utils/normalize-slashes'
import { sha1 } from '../../utils/sha1'

import { ConfigSet, MY_DIGEST } from './config-set'

jest.mock('../utils/backports')
jest.mock('../../utils/backports')
jest.mock('../index')
jest.mock('../utils/get-package-version')
jest.mock('../../utils/get-package-version')

const backports = jest.mocked(_backports)

Expand Down Expand Up @@ -305,7 +305,7 @@ describe('babelJestTransformer', () => {

it('should return babelJestTransformer with loaded config object', () => {
/* eslint-disable-next-line jest/no-mocks-import */
const babelConfig = require('../__mocks__/babel-foo.config')
const babelConfig = require('../../__mocks__/babel-foo.config')
const cs = createConfigSet({
jestConfig: {
globals: {
Expand Down Expand Up @@ -668,7 +668,9 @@ describe('resolvePath', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const cs = createConfigSet({ jestConfig: { rootDir: '/root', cwd: '/cwd' } as any, resolve: null })
const doResolve = (path: string) => cs.resolvePath(path, { throwIfMissing: false, nodeResolve: true })
expect(doResolve('json5')).toBe(resolve(__dirname, '../../node_modules/json5', require('json5/package.json').main))
expect(doResolve('json5')).toBe(
resolve(__dirname, '../../../node_modules/json5', require('json5/package.json').main),
)
expect(doResolve('./bar.js')).toBe(resolve('/cwd/bar.js'))
expect(doResolve('<rootDir>bar.js')).toBe(resolve('/root/bar.js'))
expect(doResolve('<rootDir>/bar.js')).toBe(resolve('/root//bar.js'))
Expand Down
26 changes: 13 additions & 13 deletions src/config/config-set.ts → src/legacy/config/config-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { globsToMatcher } from 'jest-util'
import json5 from 'json5'
import type * as ts from 'typescript'

import { DEFAULT_JEST_TEST_MATCH, JS_JSX_EXTENSIONS } from '../constants'
import type { RawCompilerOptions } from '../raw-compiler-options'
import { DEFAULT_JEST_TEST_MATCH, JS_JSX_EXTENSIONS } from '../../constants'
import type { RawCompilerOptions } from '../../raw-compiler-options'
import type {
AstTransformer,
AstTransformerDesc,
Expand All @@ -29,20 +29,20 @@ import type {
TsJestDiagnosticsCfg,
TsJestGlobalOptions,
TTypeScript,
} from '../types'
import { TsCompilerInstance } from '../types'
import { rootLogger, stringify } from '../utils'
import { backportJestConfig } from '../utils/backports'
import { importer } from '../utils/importer'
import { Errors, ImportReasons, interpolate } from '../utils/messages'
import { normalizeSlashes } from '../utils/normalize-slashes'
import { sha1 } from '../utils/sha1'
import { TSError } from '../utils/ts-error'
} from '../../types'
import { TsCompilerInstance } from '../../types'
import { rootLogger, stringify } from '../../utils'
import { backportJestConfig } from '../../utils/backports'
import { importer } from '../../utils/importer'
import { Errors, ImportReasons, interpolate } from '../../utils/messages'
import { normalizeSlashes } from '../../utils/normalize-slashes'
import { sha1 } from '../../utils/sha1'
import { TSError } from '../../utils/ts-error'

/**
* @internal
*/
export const MY_DIGEST: string = readFileSync(resolve(__dirname, '..', '..', '.ts-jest-digest'), 'utf8')
export const MY_DIGEST: string = readFileSync(resolve(__dirname, '../../../.ts-jest-digest'), 'utf8')

/**
* @internal
Expand Down Expand Up @@ -313,7 +313,7 @@ export class ConfigSet {
this.logger.debug({ tsconfig: this.parsedTsConfig }, 'normalized typescript config via ts-jest option')

// transformers
this.resolvedTransformers.before = [require('../transformers/hoist-jest')]
this.resolvedTransformers.before = [require('../../transformers/hoist-jest')]
const { astTransformers } = options
if (astTransformers) {
const resolveTransformerFunc = (transformerPath: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { SyncTransformer, TransformedSource } from '@jest/transform'
import type { Logger } from 'bs-logger'

import { TsJestCompiler } from '../compiler'
import { ConfigSet } from '../config'
import { DECLARATION_TYPE_EXT, JS_JSX_REGEX, TS_TSX_REGEX } from '../constants'
import type { CompilerInstance, DepGraphInfo, ProjectConfigTsJest, TransformOptionsTsJest } from '../types'
import { parse, stringify, JsonableValue, rootLogger } from '../utils'
Expand All @@ -14,6 +13,8 @@ import { Deprecations, Errors, interpolate } from '../utils/messages'
import { sha1 } from '../utils/sha1'
import { VersionCheckers } from '../utils/version-checkers'

import { ConfigSet } from './config/config-set'

interface CachedConfigSet {
configSet: ConfigSet
jestConfig: JsonableValue<ProjectConfigTsJest>
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type * as babelJest from 'babel-jest'
import type * as _babel from 'babel__core'
import type * as _ts from 'typescript'

import type { ConfigSet } from './config'
import type { ConfigSet } from './legacy/config/config-set'
import type { RawCompilerOptions } from './raw-compiler-options'

declare module '@jest/types' {
Expand Down

0 comments on commit a986729

Please sign in to comment.