2022-01-26 17:16:26 -05:00
"use strict" ;
var _ _assign = ( this && this . _ _assign ) || function ( ) {
_ _assign = Object . assign || function ( t ) {
for ( var s , i = 1 , n = arguments . length ; i < n ; i ++ ) {
s = arguments [ i ] ;
for ( var p in s ) if ( Object . prototype . hasOwnProperty . call ( s , p ) )
t [ p ] = s [ p ] ;
}
return t ;
} ;
return _ _assign . apply ( this , arguments ) ;
} ;
var _ _decorate = ( this && this . _ _decorate ) || function ( decorators , target , key , desc ) {
var c = arguments . length , r = c < 3 ? target : desc === null ? desc = Object . getOwnPropertyDescriptor ( target , key ) : desc , d ;
if ( typeof Reflect === "object" && typeof Reflect . decorate === "function" ) r = Reflect . decorate ( decorators , target , key , desc ) ;
else for ( var i = decorators . length - 1 ; i >= 0 ; i -- ) if ( d = decorators [ i ] ) r = ( c < 3 ? d ( r ) : c > 3 ? d ( target , key , r ) : d ( target , key ) ) || r ;
return c > 3 && r && Object . defineProperty ( target , key , r ) , r ;
} ;
var _ _values = ( this && this . _ _values ) || function ( o ) {
var s = typeof Symbol === "function" && Symbol . iterator , m = s && o [ s ] , i = 0 ;
if ( m ) return m . call ( o ) ;
if ( o && typeof o . length === "number" ) return {
next : function ( ) {
if ( o && i >= o . length ) o = void 0 ;
return { value : o && o [ i ++ ] , done : ! o } ;
}
} ;
throw new TypeError ( s ? "Object is not iterable." : "Symbol.iterator is not defined." ) ;
} ;
var _ _read = ( this && this . _ _read ) || function ( o , n ) {
var m = typeof Symbol === "function" && o [ Symbol . iterator ] ;
if ( ! m ) return o ;
var i = m . call ( o ) , r , ar = [ ] , e ;
try {
while ( ( n === void 0 || n -- > 0 ) && ! ( r = i . next ( ) ) . done ) ar . push ( r . value ) ;
}
catch ( error ) { e = { error : error } ; }
finally {
try {
if ( r && ! r . done && ( m = i [ "return" ] ) ) m . call ( i ) ;
}
finally { if ( e ) throw e . error ; }
}
return ar ;
} ;
var _ _spread = ( this && this . _ _spread ) || function ( ) {
for ( var ar = [ ] , i = 0 ; i < arguments . length ; i ++ ) ar = ar . concat ( _ _read ( arguments [ i ] ) ) ;
return ar ;
} ;
2022-06-27 14:12:49 -04:00
var _a ;
2022-01-26 17:16:26 -05:00
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
2022-06-27 14:12:49 -04:00
exports . ConfigSet = exports . TS _JEST _OUT _DIR = exports . IGNORE _DIAGNOSTIC _CODES = exports . MY _DIGEST = void 0 ;
2022-01-26 17:16:26 -05:00
var bs _logger _1 = require ( "bs-logger" ) ;
var fs _1 = require ( "fs" ) ;
2022-06-27 14:12:49 -04:00
var jest _util _1 = require ( "jest-util" ) ;
2022-01-26 17:16:26 -05:00
var json5 = require ( "json5" ) ;
var path _1 = require ( "path" ) ;
2022-06-27 14:12:49 -04:00
var typescript _1 = require ( "typescript" ) ;
2022-01-26 17:16:26 -05:00
var instance _1 = require ( "../compiler/instance" ) ;
var constants _1 = require ( "../constants" ) ;
2022-06-27 14:12:49 -04:00
var hoist _jest _1 = require ( "../transformers/hoist-jest" ) ;
var backports _1 = require ( "../utils/backports" ) ;
var importer _1 = require ( "../utils/importer" ) ;
var json _1 = require ( "../utils/json" ) ;
var logger _1 = require ( "../utils/logger" ) ;
var memoize _1 = require ( "../utils/memoize" ) ;
var messages _1 = require ( "../utils/messages" ) ;
var normalize _slashes _1 = require ( "../utils/normalize-slashes" ) ;
var sha1 _1 = require ( "../utils/sha1" ) ;
var ts _error _1 = require ( "../utils/ts-error" ) ;
exports . MY _DIGEST = fs _1 . readFileSync ( path _1 . resolve ( _ _dirname , '..' , '..' , '.ts-jest-digest' ) , 'utf8' ) ;
2022-01-26 17:16:26 -05:00
exports . IGNORE _DIAGNOSTIC _CODES = [
6059 ,
18002 ,
18003 ,
] ;
exports . TS _JEST _OUT _DIR = '$$ts-jest$$' ;
2022-06-27 14:12:49 -04:00
var TARGET _TO _VERSION _MAPPING = ( _a = { } ,
_a [ typescript _1 . ScriptTarget . ES2018 ] = 'es2018' ,
_a [ typescript _1 . ScriptTarget . ES2019 ] = 'es2019' ,
_a [ typescript _1 . ScriptTarget . ES2020 ] = 'es2020' ,
_a [ typescript _1 . ScriptTarget . ESNext ] = 'ESNext' ,
_a ) ;
2022-01-26 17:16:26 -05:00
var normalizeRegex = function ( pattern ) {
return pattern ? ( typeof pattern === 'string' ? pattern : pattern . source ) : undefined ;
} ;
2022-06-27 14:12:49 -04:00
var toDiagnosticCode = function ( code ) { var _a ; return code ? ( _a = parseInt ( ( "" + code ) . trim ( ) . replace ( /^TS/ , '' ) , 10 ) ) !== null && _a !== void 0 ? _a : undefined : undefined ; } ;
2022-01-26 17:16:26 -05:00
var toDiagnosticCodeList = function ( items , into ) {
var e _1 , _a ;
if ( into === void 0 ) { into = [ ] ; }
try {
for ( var items _1 = _ _values ( items ) , items _1 _1 = items _1 . next ( ) ; ! items _1 _1 . done ; items _1 _1 = items _1 . next ( ) ) {
var item = items _1 _1 . value ;
2022-06-27 14:12:49 -04:00
if ( typeof item === 'string' ) {
2022-01-26 17:16:26 -05:00
var children = item . trim ( ) . split ( /\s*,\s*/g ) ;
if ( children . length > 1 ) {
toDiagnosticCodeList ( children , into ) ;
continue ;
}
item = children [ 0 ] ;
}
if ( ! item )
continue ;
var code = toDiagnosticCode ( item ) ;
if ( code && ! into . includes ( code ) )
into . push ( code ) ;
}
}
catch ( e _1 _1 ) { e _1 = { error : e _1 _1 } ; }
finally {
try {
if ( items _1 _1 && ! items _1 _1 . done && ( _a = items _1 . return ) ) _a . call ( items _1 ) ;
}
finally { if ( e _1 ) throw e _1 . error ; }
}
return into ;
} ;
var ConfigSet = ( function ( ) {
2022-06-27 14:12:49 -04:00
function ConfigSet ( jestConfig , parentLogger ) {
var _a , _b ;
var _c , _d , _e , _f ;
this . parentLogger = parentLogger ;
this . customTransformers = Object . create ( null ) ;
this . _overriddenCompilerOptions = {
sourceMap : true ,
inlineSourceMap : false ,
inlineSources : true ,
declaration : false ,
noEmit : false ,
removeComments : false ,
out : undefined ,
outFile : undefined ,
composite : undefined ,
declarationDir : undefined ,
declarationMap : undefined ,
emitDeclarationOnly : undefined ,
sourceRoot : undefined ,
tsBuildInfoFile : undefined ,
} ;
this . logger = this . parentLogger
? this . parentLogger . child ( ( _a = { } , _a [ bs _logger _1 . LogContexts . namespace ] = 'config' , _a ) )
: logger _1 . rootLogger . child ( { namespace : 'config' } ) ;
this . _backportJestCfg ( jestConfig !== null && jestConfig !== void 0 ? jestConfig : Object . create ( null ) ) ;
this . cwd = path _1 . normalize ( ( _c = this . _jestCfg . cwd ) !== null && _c !== void 0 ? _c : process . cwd ( ) ) ;
this . rootDir = path _1 . normalize ( ( _d = this . _jestCfg . rootDir ) !== null && _d !== void 0 ? _d : this . cwd ) ;
var tsJestCfg = this . _jestCfg . globals && this . _jestCfg . globals [ 'ts-jest' ] ;
var options = tsJestCfg !== null && tsJestCfg !== void 0 ? tsJestCfg : Object . create ( null ) ;
this . compilerModule = importer _1 . importer . typescript ( "Using \"ts-jest\" requires this package to be installed." , ( _e = options . compiler ) !== null && _e !== void 0 ? _e : 'typescript' ) ;
this . isolatedModules = ( _f = options . isolatedModules ) !== null && _f !== void 0 ? _f : false ;
this . logger . debug ( { compilerModule : this . compilerModule } , 'normalized compiler module config via ts-jest option' ) ;
this . _matchablePatterns = _ _spread ( this . _jestCfg . testMatch , this . _jestCfg . testRegex ) . filter ( function ( pattern ) {
return pattern instanceof RegExp || typeof pattern === 'string' ;
} ) ;
if ( ! this . _matchablePatterns . length ) {
( _b = this . _matchablePatterns ) . push . apply ( _b , _ _spread ( constants _1 . DEFAULT _JEST _TEST _MATCH ) ) ;
}
this . _matchTestFilePath = jest _util _1 . globsToMatcher ( this . _matchablePatterns . filter ( function ( pattern ) { return typeof pattern === 'string' ; } ) ) ;
this . _setupTsJestCfg ( options ) ;
this . _resolveTsCacheDir ( ) ;
2022-01-26 17:16:26 -05:00
}
2022-06-27 14:12:49 -04:00
ConfigSet . prototype . _backportJestCfg = function ( jestCfg ) {
var config = backports _1 . backportJestConfig ( this . logger , jestCfg ) ;
this . logger . debug ( { jestConfig : config } , 'normalized jest config' ) ;
this . _jestCfg = config ;
} ;
ConfigSet . prototype . _setupTsJestCfg = function ( options ) {
var _this = this ;
var _a , _b , _c , _d ;
if ( options . packageJson ) {
this . logger . warn ( "The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`" ) ;
}
if ( ! options . babelConfig ) {
this . logger . debug ( 'babel is disabled' ) ;
}
else {
var baseBabelCfg = { cwd : this . cwd } ;
if ( typeof options . babelConfig === 'string' ) {
var babelCfgPath = this . resolvePath ( options . babelConfig ) ;
if ( path _1 . extname ( options . babelConfig ) === '.js' ) {
this . _babelConfig = _ _assign ( _ _assign ( { } , baseBabelCfg ) , require ( babelCfgPath ) ) ;
2022-01-26 17:16:26 -05:00
}
2022-06-27 14:12:49 -04:00
else {
this . _babelConfig = _ _assign ( _ _assign ( { } , baseBabelCfg ) , json5 . parse ( fs _1 . readFileSync ( babelCfgPath , 'utf-8' ) ) ) ;
2022-01-26 17:16:26 -05:00
}
}
2022-06-27 14:12:49 -04:00
else if ( typeof options . babelConfig === 'object' ) {
this . _babelConfig = _ _assign ( _ _assign ( { } , baseBabelCfg ) , options . babelConfig ) ;
2022-01-26 17:16:26 -05:00
}
2022-06-27 14:12:49 -04:00
else {
this . _babelConfig = baseBabelCfg ;
2022-01-26 17:16:26 -05:00
}
2022-06-27 14:12:49 -04:00
this . logger . debug ( { babelConfig : this . _babelConfig } , 'normalized babel config via ts-jest option' ) ;
}
if ( ! this . _babelConfig ) {
this . _overriddenCompilerOptions . module = this . compilerModule . ModuleKind . CommonJS ;
}
else {
this . _babelJestTransformers = importer _1 . importer
. babelJest ( "Using \"babel-jest\" requires this package to be installed." )
. createTransformer ( this . _babelConfig ) ;
this . logger . debug ( 'created babel-jest transformer' ) ;
}
var diagnosticsOpt = ( _a = options . diagnostics ) !== null && _a !== void 0 ? _a : true ;
var ignoreList = _ _spread ( exports . IGNORE _DIAGNOSTIC _CODES ) ;
if ( typeof diagnosticsOpt === 'object' ) {
var ignoreCodes = diagnosticsOpt . ignoreCodes ;
if ( ignoreCodes ) {
Array . isArray ( ignoreCodes ) ? ignoreList . push . apply ( ignoreList , _ _spread ( ignoreCodes ) ) : ignoreList . push ( ignoreCodes ) ;
}
this . _diagnostics = {
pretty : ( _b = diagnosticsOpt . pretty ) !== null && _b !== void 0 ? _b : true ,
exclude : ( _c = diagnosticsOpt . exclude ) !== null && _c !== void 0 ? _c : [ ] ,
ignoreCodes : toDiagnosticCodeList ( ignoreList ) ,
throws : ! diagnosticsOpt . warnOnly ,
} ;
if ( diagnosticsOpt . pathRegex ) {
this . logger . warn ( "The option `pathRegex` is deprecated and will be removed in ts-jest 27, use `exclude` instead" ) ;
this . _diagnostics = _ _assign ( _ _assign ( { } , this . _diagnostics ) , { pathRegex : normalizeRegex ( diagnosticsOpt . pathRegex ) } ) ;
2022-01-26 17:16:26 -05:00
}
2022-06-27 14:12:49 -04:00
}
else {
this . _diagnostics = {
ignoreCodes : diagnosticsOpt ? toDiagnosticCodeList ( ignoreList ) : [ ] ,
exclude : [ ] ,
pretty : true ,
throws : diagnosticsOpt ,
} ;
}
if ( this . _diagnostics . pathRegex && ! this . _diagnostics . exclude . length ) {
this . _shouldGetDiagnosticsForFile = new RegExp ( this . _diagnostics . pathRegex ) ;
}
else {
this . _shouldGetDiagnosticsForFile = this . _diagnostics . exclude . length
? jest _util _1 . globsToMatcher ( this . _diagnostics . exclude )
: function ( ) { return true ; } ;
}
this . logger . debug ( { diagnostics : this . _diagnostics } , 'normalized diagnostics config via ts-jest option' ) ;
if ( options . tsConfig ) {
this . logger . warn ( "The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` instead" ) ;
}
var tsconfigOpt = ( _d = options . tsConfig ) !== null && _d !== void 0 ? _d : options . tsconfig ;
var configFilePath = typeof tsconfigOpt === 'string' ? this . resolvePath ( tsconfigOpt ) : undefined ;
this . parsedTsConfig = this . _resolveTsConfig ( typeof tsconfigOpt === 'object' ? tsconfigOpt : undefined , configFilePath ) ;
this . raiseDiagnostics ( this . parsedTsConfig . errors , configFilePath ) ;
this . logger . debug ( { tsconfig : this . parsedTsConfig } , 'normalized typescript config via ts-jest option' ) ;
var astTransformers = options . astTransformers ;
this . customTransformers = {
before : [ hoist _jest _1 . factory ( this ) ] ,
} ;
if ( astTransformers ) {
if ( Array . isArray ( astTransformers ) ) {
this . logger . warn ( "The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers" ) ;
this . customTransformers = {
before : _ _spread ( this . customTransformers . before , astTransformers . map ( function ( transformer ) {
var transformerPath = _this . resolvePath ( transformer , { nodeResolve : true } ) ;
return require ( transformerPath ) . factory ( _this ) ;
} ) ) ,
2022-01-26 17:16:26 -05:00
} ;
}
else {
2022-06-27 14:12:49 -04:00
var resolveTransformers = function ( transformers ) {
return transformers . map ( function ( transformer ) {
var transformerPath ;
if ( typeof transformer === 'string' ) {
transformerPath = _this . resolvePath ( transformer , { nodeResolve : true } ) ;
return require ( transformerPath ) . factory ( _this ) ;
}
else {
transformerPath = _this . resolvePath ( transformer . path , { nodeResolve : true } ) ;
return require ( transformerPath ) . factory ( _this , transformer . options ) ;
}
} ) ;
2022-01-26 17:16:26 -05:00
} ;
2022-06-27 14:12:49 -04:00
if ( astTransformers . before ) {
this . customTransformers = {
before : _ _spread ( this . customTransformers . before , resolveTransformers ( astTransformers . before ) ) ,
} ;
2022-01-26 17:16:26 -05:00
}
2022-06-27 14:12:49 -04:00
if ( astTransformers . after ) {
this . customTransformers = _ _assign ( _ _assign ( { } , this . customTransformers ) , { after : resolveTransformers ( astTransformers . after ) } ) ;
}
if ( astTransformers . afterDeclarations ) {
this . customTransformers = _ _assign ( _ _assign ( { } , this . customTransformers ) , { afterDeclarations : resolveTransformers ( astTransformers . afterDeclarations ) } ) ;
2022-01-26 17:16:26 -05:00
}
}
2022-06-27 14:12:49 -04:00
}
this . logger . debug ( { customTransformers : this . customTransformers } , 'normalized custom AST transformers via ts-jest option' ) ;
if ( options . stringifyContentPathRegex ) {
this . _stringifyContentRegExp =
typeof options . stringifyContentPathRegex === 'string'
? new RegExp ( normalizeRegex ( options . stringifyContentPathRegex ) )
: options . stringifyContentPathRegex ;
this . logger . debug ( { stringifyContentPathRegex : this . _stringifyContentRegExp } , 'normalized stringifyContentPathRegex config via ts-jest option' ) ;
}
} ;
ConfigSet . prototype . _resolveTsCacheDir = function ( ) {
if ( ! this . _jestCfg . cache ) {
this . logger . debug ( 'file caching disabled' ) ;
return undefined ;
}
var cacheSuffix = sha1 _1 . sha1 ( json _1 . stringify ( {
version : this . compilerModule . version ,
digest : this . tsJestDigest ,
compilerModule : this . compilerModule ,
compilerOptions : this . parsedTsConfig . options ,
isolatedModules : this . isolatedModules ,
diagnostics : this . _diagnostics ,
} ) ) ;
var res = path _1 . join ( this . _jestCfg . cacheDirectory , 'ts-jest' , cacheSuffix . substr ( 0 , 2 ) , cacheSuffix . substr ( 2 ) ) ;
this . logger . debug ( { cacheDirectory : res } , 'will use file caching' ) ;
this . tsCacheDir = res ;
2022-01-26 17:16:26 -05:00
} ;
2022-06-27 14:12:49 -04:00
ConfigSet . prototype . _resolveTsConfig = function ( compilerOptions , resolvedConfigFile ) {
2022-01-26 17:16:26 -05:00
var e _2 , _a ;
2022-06-27 14:12:49 -04:00
var _b ;
var config = { compilerOptions : Object . create ( null ) } ;
2022-01-26 17:16:26 -05:00
var basePath = normalize _slashes _1 . normalizeSlashes ( this . rootDir ) ;
var ts = this . compilerModule ;
2022-06-27 14:12:49 -04:00
var configFileName = resolvedConfigFile
? normalize _slashes _1 . normalizeSlashes ( resolvedConfigFile )
: ts . findConfigFile ( normalize _slashes _1 . normalizeSlashes ( this . rootDir ) , ts . sys . fileExists ) ;
if ( configFileName ) {
this . logger . debug ( { tsConfigFileName : configFileName } , 'readTsConfig(): reading' , configFileName ) ;
var result _1 = ts . readConfigFile ( configFileName , ts . sys . readFile ) ;
if ( result _1 . error ) {
return { errors : [ result _1 . error ] , fileNames : [ ] , options : { } } ;
}
config = result _1 . config ;
basePath = normalize _slashes _1 . normalizeSlashes ( path _1 . dirname ( configFileName ) ) ;
2022-01-26 17:16:26 -05:00
}
config . compilerOptions = _ _assign ( _ _assign ( { } , config . compilerOptions ) , compilerOptions ) ;
var result = ts . parseJsonConfigFileContent ( config , ts . sys , basePath , undefined , configFileName ) ;
2022-06-27 14:12:49 -04:00
if ( result . options . sourceMap === false ) {
this . logger . warn ( messages _1 . interpolate ( "Got `sourceMap: false` from tsconfig file \"{{path}}\". This will disable source map support in ts-jest 27. Please set `sourceMap: true` in your tsconfig file \"{{path}}\" if you want to keep source map support on" , {
path : result . options . configFilePath ,
} ) ) ;
}
var forcedOptions = this . _overriddenCompilerOptions ;
2022-01-26 17:16:26 -05:00
var finalOptions = result . options ;
if ( finalOptions . target === undefined ) {
finalOptions . target = ts . ScriptTarget . ES5 ;
}
var target = finalOptions . target ;
var defaultModule = [ ts . ScriptTarget . ES3 , ts . ScriptTarget . ES5 ] . includes ( target )
? ts . ModuleKind . CommonJS
: ts . ModuleKind . ESNext ;
var moduleValue = finalOptions . module == null ? defaultModule : finalOptions . module ;
if ( 'module' in forcedOptions &&
moduleValue !== forcedOptions . module &&
! ( finalOptions . esModuleInterop || finalOptions . allowSyntheticDefaultImports ) ) {
2022-06-27 14:12:49 -04:00
result . errors . push ( {
code : 151001 ,
messageText : "If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information." ,
2022-01-26 17:16:26 -05:00
category : ts . DiagnosticCategory . Message ,
2022-06-27 14:12:49 -04:00
file : undefined ,
start : undefined ,
length : undefined ,
} ) ;
2022-01-26 17:16:26 -05:00
if ( ! ( 'allowSyntheticDefaultImports' in config . compilerOptions ) ) {
finalOptions . allowSyntheticDefaultImports = true ;
}
}
if ( finalOptions . allowJs && ! finalOptions . outDir ) {
finalOptions . outDir = exports . TS _JEST _OUT _DIR ;
}
try {
2022-06-27 14:12:49 -04:00
for ( var _c = _ _values ( Object . keys ( forcedOptions ) ) , _d = _c . next ( ) ; ! _d . done ; _d = _c . next ( ) ) {
var key = _d . value ;
2022-01-26 17:16:26 -05:00
var val = forcedOptions [ key ] ;
if ( val === undefined ) {
delete finalOptions [ key ] ;
}
else {
finalOptions [ key ] = val ;
}
}
}
catch ( e _2 _1 ) { e _2 = { error : e _2 _1 } ; }
finally {
try {
2022-06-27 14:12:49 -04:00
if ( _d && ! _d . done && ( _a = _c . return ) ) _a . call ( _c ) ;
2022-01-26 17:16:26 -05:00
}
finally { if ( e _2 ) throw e _2 . error ; }
}
2022-06-27 14:12:49 -04:00
var nodeJsVer = process . version ;
var compilationTarget = result . options . target ;
if ( ! this . _babelConfig &&
( ( nodeJsVer . startsWith ( 'v10' ) && compilationTarget > typescript _1 . ScriptTarget . ES2018 ) ||
( nodeJsVer . startsWith ( 'v12' ) && compilationTarget > typescript _1 . ScriptTarget . ES2019 ) ) ) {
var message = messages _1 . interpolate ( "There is a mismatch between your NodeJs version {{nodeJsVer}} and your TypeScript target {{compilationTarget}}. This might lead to some unexpected errors when running tests with `ts-jest`. To fix this, you can check https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping" , {
nodeJsVer : process . version ,
compilationTarget : ( _b = config . compilerOptions . target ) !== null && _b !== void 0 ? _b : TARGET _TO _VERSION _MAPPING [ compilationTarget ] ,
} ) ;
this . logger . warn ( message ) ;
}
2022-01-26 17:16:26 -05:00
return result ;
} ;
2022-06-27 14:12:49 -04:00
Object . defineProperty ( ConfigSet . prototype , "tsCompiler" , {
get : function ( ) {
return instance _1 . createCompilerInstance ( this ) ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "babelConfig" , {
get : function ( ) {
return this . _babelConfig ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "babelJestTransformer" , {
get : function ( ) {
return this . _babelJestTransformers ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "tsJestDigest" , {
get : function ( ) {
return exports . MY _DIGEST ;
} ,
enumerable : false ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "hooks" , {
get : function ( ) {
var hooksFile = process . env . TS _JEST _HOOKS ;
if ( hooksFile ) {
hooksFile = path _1 . resolve ( this . cwd , hooksFile ) ;
return importer _1 . importer . tryTheseOr ( hooksFile , { } ) ;
}
return { } ;
} ,
enumerable : false ,
configurable : true
} ) ;
ConfigSet . prototype . isTestFile = function ( fileName ) {
var _this = this ;
return this . _matchablePatterns . some ( function ( pattern ) {
return typeof pattern === 'string' ? _this . _matchTestFilePath ( fileName ) : pattern . test ( fileName ) ;
} ) ;
} ;
ConfigSet . prototype . shouldStringifyContent = function ( filePath ) {
return this . _stringifyContentRegExp ? this . _stringifyContentRegExp . test ( filePath ) : false ;
} ;
ConfigSet . prototype . raiseDiagnostics = function ( diagnostics , filePath , logger ) {
var _this = this ;
var ignoreCodes = this . _diagnostics . ignoreCodes ;
var DiagnosticCategory = this . compilerModule . DiagnosticCategory ;
var filteredDiagnostics = filePath && ! this . shouldReportDiagnostics ( filePath )
? [ ]
: diagnostics . filter ( function ( diagnostic ) {
var _a ;
if ( ( ( _a = diagnostic . file ) === null || _a === void 0 ? void 0 : _a . fileName ) && ! _this . shouldReportDiagnostics ( diagnostic . file . fileName ) ) {
return false ;
}
return ! ignoreCodes . includes ( diagnostic . code ) ;
} ) ;
if ( ! filteredDiagnostics . length )
return ;
var error = this . _createTsError ( filteredDiagnostics ) ;
var importantCategories = [ DiagnosticCategory . Warning , DiagnosticCategory . Error ] ;
if ( this . _diagnostics . throws && filteredDiagnostics . some ( function ( d ) { return importantCategories . includes ( d . category ) ; } ) ) {
throw error ;
}
logger ? logger . warn ( { error : error } , error . message ) : this . logger . warn ( { error : error } , error . message ) ;
} ;
ConfigSet . prototype . shouldReportDiagnostics = function ( filePath ) {
return this . _shouldGetDiagnosticsForFile instanceof RegExp
? this . _shouldGetDiagnosticsForFile . test ( filePath )
: this . _shouldGetDiagnosticsForFile ( filePath ) ;
} ;
ConfigSet . prototype . _createTsError = function ( diagnostics ) {
var _this = this ;
var formatDiagnostics = this . _diagnostics . pretty
? this . compilerModule . formatDiagnosticsWithColorAndContext
: this . compilerModule . formatDiagnostics ;
var diagnosticHost = {
getNewLine : function ( ) { return '\n' ; } ,
getCurrentDirectory : function ( ) { return _this . cwd ; } ,
getCanonicalFileName : function ( path ) { return path ; } ,
} ;
var diagnosticText = formatDiagnostics ( diagnostics , diagnosticHost ) ;
var diagnosticCodes = diagnostics . map ( function ( x ) { return x . code ; } ) ;
return new ts _error _1 . TSError ( diagnosticText , diagnosticCodes ) ;
} ;
2022-01-26 17:16:26 -05:00
ConfigSet . prototype . resolvePath = function ( inputPath , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b . throwIfMissing , throwIfMissing = _c === void 0 ? true : _c , _d = _b . nodeResolve , nodeResolve = _d === void 0 ? false : _d ;
var path = inputPath ;
var nodeResolved = false ;
if ( path . startsWith ( '<rootDir>' ) ) {
path = path _1 . resolve ( path _1 . join ( this . rootDir , path . substr ( 9 ) ) ) ;
}
else if ( ! path _1 . isAbsolute ( path ) ) {
if ( ! path . startsWith ( '.' ) && nodeResolve ) {
try {
path = require . resolve ( path ) ;
nodeResolved = true ;
}
catch ( _ ) { }
}
if ( ! nodeResolved ) {
path = path _1 . resolve ( this . cwd , path ) ;
}
}
if ( ! nodeResolved && nodeResolve ) {
try {
path = require . resolve ( path ) ;
nodeResolved = true ;
}
catch ( _ ) { }
}
if ( throwIfMissing && ! fs _1 . existsSync ( path ) ) {
throw new Error ( messages _1 . interpolate ( "File not found: {{inputPath}} (resolved as: {{resolvedPath}})" , { inputPath : inputPath , resolvedPath : path } ) ) ;
}
this . logger . debug ( { fromPath : inputPath , toPath : path } , 'resolved path from' , inputPath , 'to' , path ) ;
return path ;
} ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "tsCompiler" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "tsJestDigest" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
2022-06-27 14:12:49 -04:00
] , ConfigSet . prototype , "hooks" , null ) ;
2022-01-26 17:16:26 -05:00
return ConfigSet ;
} ( ) ) ;
exports . ConfigSet = ConfigSet ;