Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { LogContexts } from 'bs-logger'
import { CompilerOptions } from 'typescript'
import { rootLogger } from '../util/logger'
import { Errors, interpolate } from '../util/messages'
type TsPathMapping = Exclude
type JestPathMapping = jest.InitialOptions['moduleNameMapper']
// we don't need to escape all chars, so commented out is the real one
// const escapeRegex = (str: string) => str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
const escapeRegex = (str: string) => str.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
const logger = rootLogger.child({ [LogContexts.namespace]: 'path-mapper' })
export const pathsToModuleNameMapper = (
mapping: TsPathMapping,
{ prefix = '' }: { prefix?: string } = {},
): JestPathMapping => {
const jestMap: JestPathMapping = {}
for (const fromPath of Object.keys(mapping)) {
let pattern: string
const toPaths = mapping[fromPath]
// check that we have only one target path
if (toPaths.length === 0) {
logger.warn(interpolate(Errors.NotMappingPathWithEmptyMap, { path: fromPath }))
continue
} else if (toPaths.length > 1) {
logger.warn(
interpolate(Errors.MappingOnlyFirstTargetOfPath, {
import { LogContexts, Logger } from 'bs-logger'
import { Deprecateds, Helps, interpolate } from './messages'
const context = { [LogContexts.namespace]: 'backports' }
/**
* @internal
*/
export const backportJestConfig = (
logger: Logger,
config: T,
): T => {
logger.debug({ ...context, config }, 'backporting config')
const { globals = {} } = (config || {}) as any
const { 'ts-jest': tsJest = {} } = globals as any
const mergeTsJest: any = {}
let hadWarnings = false
const warnConfig = (oldPath: string, newPath: string, note?: string) => {
hadWarnings = true
constructor(jestConfig: jest.ProjectConfig, readonly parentOptions?: TsJestGlobalOptions, parentLogger?: Logger) {
this._jestConfig = jestConfig
this.logger = parentLogger ? parentLogger.child({ [LogContexts.namespace]: 'config' }) : logger
}