2020-03-31 20:42:07 +08: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 ;
} ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
var bs _logger _1 = require ( "bs-logger" ) ;
var fs _1 = require ( "fs" ) ;
var json5 = require ( "json5" ) ;
var path _1 = require ( "path" ) ;
var _ _1 = require ( ".." ) ;
var instance _1 = require ( "../compiler/instance" ) ;
2020-05-15 05:33:08 +08:00
var constants _1 = require ( "../constants" ) ;
2020-03-31 20:42:07 +08:00
var transformers _1 = require ( "../transformers" ) ;
var backports _1 = require ( "../util/backports" ) ;
var get _package _version _1 = require ( "../util/get-package-version" ) ;
var importer _1 = require ( "../util/importer" ) ;
var json _1 = require ( "../util/json" ) ;
var jsonable _value _1 = require ( "../util/jsonable-value" ) ;
var logger _1 = require ( "../util/logger" ) ;
var memoize _1 = require ( "../util/memoize" ) ;
var messages _1 = require ( "../util/messages" ) ;
var normalize _slashes _1 = require ( "../util/normalize-slashes" ) ;
var sha1 _1 = require ( "../util/sha1" ) ;
var ts _error _1 = require ( "../util/ts-error" ) ;
var logger = logger _1 . rootLogger . child ( { namespace : 'config' } ) ;
exports . MATCH _NOTHING = /a^/ ;
exports . IGNORE _DIAGNOSTIC _CODES = [
6059 ,
18002 ,
18003 ,
] ;
2020-04-30 20:40:07 +08:00
exports . TS _JEST _OUT _DIR = '$$ts-jest$$' ;
2020-03-31 20:42:07 +08:00
var normalizeRegex = function ( pattern ) {
return pattern ? ( typeof pattern === 'string' ? pattern : pattern . source ) : undefined ;
} ;
var toDiagnosticCode = function ( code ) {
return code ? parseInt ( ( "" + code ) . trim ( ) . replace ( /^TS/ , '' ) , 10 ) || undefined : undefined ;
} ;
var toDiagnosticCodeList = function ( items , into ) {
var e _1 , _a ;
if ( into === void 0 ) { into = [ ] ; }
if ( ! Array . isArray ( items ) )
items = [ items ] ;
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 ;
if ( ! item )
continue ;
if ( Array . isArray ( item ) ) {
toDiagnosticCodeList ( item , into ) ;
continue ;
}
else if ( typeof item === 'string' ) {
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 ( ) {
function ConfigSet ( jestConfig , parentOptions , parentLogger ) {
var _a ;
this . parentOptions = parentOptions ;
this . _jestConfig = jestConfig ;
this . logger = parentLogger ? parentLogger . child ( ( _a = { } , _a [ bs _logger _1 . LogContexts . namespace ] = 'config' , _a ) ) : logger ;
}
Object . defineProperty ( ConfigSet . prototype , "projectPackageJson" , {
get : function ( ) {
var packageJson = this . tsJest . packageJson ;
if ( packageJson && packageJson . kind === 'inline' ) {
return packageJson . value ;
}
if ( packageJson && packageJson . kind === 'file' && packageJson . value ) {
var path = this . resolvePath ( packageJson . value ) ;
if ( fs _1 . existsSync ( path ) ) {
return require ( path ) ;
}
this . logger . warn ( "Unable to find the root of the project where ts-jest has been installed." ) ;
return { } ;
}
var tsJestRoot = path _1 . resolve ( _ _dirname , '..' , '..' ) ;
var pkgPath = path _1 . resolve ( tsJestRoot , '..' , '..' , 'package.json' ) ;
if ( fs _1 . existsSync ( pkgPath ) ) {
return require ( pkgPath ) ;
}
if ( fs _1 . realpathSync ( this . rootDir ) === fs _1 . realpathSync ( tsJestRoot ) ) {
pkgPath = path _1 . resolve ( tsJestRoot , 'package.json' ) ;
if ( fs _1 . existsSync ( pkgPath ) ) {
return require ( pkgPath ) ;
}
}
this . logger . warn ( "Unable to find the root of the project where ts-jest has been installed." ) ;
return { } ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "projectDependencies" , {
get : function ( ) {
var pkg = this . projectPackageJson ;
var names = Object . keys ( _ _assign ( _ _assign ( _ _assign ( _ _assign ( { } , pkg . optionalDependencies ) , pkg . peerDependencies ) , pkg . devDependencies ) , pkg . dependencies ) ) ;
return names . reduce ( function ( map , name ) {
var version = get _package _version _1 . getPackageVersion ( name ) ;
if ( version )
map [ name ] = version ;
return map ;
} , { } ) ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "jest" , {
get : function ( ) {
var _a ;
var config = backports _1 . backportJestConfig ( this . logger , this . _jestConfig ) ;
if ( this . parentOptions ) {
var globals = ( _a = config . globals ) !== null && _a !== void 0 ? _a : { } ;
globals [ 'ts-jest' ] = _ _assign ( _ _assign ( { } , this . parentOptions ) , globals [ 'ts-jest' ] ) ;
}
this . logger . debug ( { jestConfig : config } , 'normalized jest config' ) ;
return config ;
} ,
enumerable : true ,
configurable : true
} ) ;
2020-04-30 20:40:07 +08:00
Object . defineProperty ( ConfigSet . prototype , "testMatchPatterns" , {
get : function ( ) {
2020-05-15 05:33:08 +08:00
var matchablePatterns = _ _spread ( this . jest . testMatch , this . jest . testRegex ) . filter ( function ( pattern ) {
return pattern instanceof RegExp || typeof pattern === 'string' ;
} ) ;
if ( ! matchablePatterns . length ) {
matchablePatterns . push . apply ( matchablePatterns , _ _spread ( constants _1 . DEFAULT _JEST _TEST _MATCH ) ) ;
}
return matchablePatterns ;
2020-04-30 20:40:07 +08:00
} ,
enumerable : true ,
configurable : true
} ) ;
2020-03-31 20:42:07 +08:00
Object . defineProperty ( ConfigSet . prototype , "tsJest" , {
get : function ( ) {
var _this = this ;
var _a , _b , _c ;
var parsedConfig = this . jest ;
var _d = parsedConfig . globals , globals = _d === void 0 ? { } : _d ;
var options = _ _assign ( { } , globals [ 'ts-jest' ] ) ;
2020-05-15 05:33:08 +08:00
var tsConfigOpt = ( _b = ( _a = options . tsConfig ) !== null && _a !== void 0 ? _a : options . tsconfig ) !== null && _b !== void 0 ? _b : true ;
2020-03-31 20:42:07 +08:00
var tsConfig ;
2020-05-15 05:33:08 +08:00
if ( typeof tsConfigOpt === 'string' || tsConfigOpt === true ) {
2020-03-31 20:42:07 +08:00
tsConfig = {
kind : 'file' ,
value : typeof tsConfigOpt === 'string' ? this . resolvePath ( tsConfigOpt ) : undefined ,
} ;
}
else if ( typeof tsConfigOpt === 'object' ) {
tsConfig = {
kind : 'inline' ,
value : tsConfigOpt ,
} ;
}
var packageJsonOpt = options . packageJson ;
var packageJson ;
if ( typeof packageJsonOpt === 'string' || packageJsonOpt == null || packageJsonOpt === true ) {
packageJson = {
kind : 'file' ,
value : typeof packageJsonOpt === 'string' ? this . resolvePath ( packageJsonOpt ) : undefined ,
} ;
}
else if ( typeof packageJsonOpt === 'object' ) {
packageJson = {
kind : 'inline' ,
value : packageJsonOpt ,
} ;
}
var transformers = ( options . astTransformers || [ ] ) . map ( function ( mod ) { return _this . resolvePath ( mod , { nodeResolve : true } ) ; } ) ;
var babelConfigOpt = options . babelConfig ;
var babelConfig ;
if ( typeof babelConfigOpt === 'string' || babelConfigOpt === true ) {
babelConfig = {
kind : 'file' ,
value : babelConfigOpt === true ? undefined : this . resolvePath ( babelConfigOpt ) ,
} ;
}
else if ( babelConfigOpt ) {
babelConfig = {
kind : 'inline' ,
value : babelConfigOpt ,
} ;
}
var diagnostics ;
var _e = options . diagnostics , diagnosticsOpt = _e === void 0 ? true : _e ;
var ignoreList = [ exports . IGNORE _DIAGNOSTIC _CODES , process . env . TS _JEST _IGNORE _DIAGNOSTICS ] ;
if ( diagnosticsOpt === true || diagnosticsOpt == null ) {
diagnostics = { ignoreCodes : [ ] , pretty : true , throws : true } ;
}
else if ( diagnosticsOpt === false ) {
diagnostics = {
throws : false ,
pretty : true ,
ignoreCodes : [ ] ,
pathRegex : exports . MATCH _NOTHING . source ,
} ;
}
else {
ignoreList . push ( diagnosticsOpt . ignoreCodes ) ;
diagnostics = {
pretty : diagnosticsOpt . pretty == null ? true : ! ! diagnosticsOpt . pretty ,
ignoreCodes : [ ] ,
pathRegex : normalizeRegex ( diagnosticsOpt . pathRegex ) ,
throws : ! diagnosticsOpt . warnOnly ,
} ;
}
diagnostics . ignoreCodes = toDiagnosticCodeList ( ignoreList ) ;
var stringifyContentPathRegex = normalizeRegex ( options . stringifyContentPathRegex ) ;
var res = {
tsConfig : tsConfig ,
packageJson : packageJson ,
babelConfig : babelConfig ,
diagnostics : diagnostics ,
isolatedModules : ! ! options . isolatedModules ,
compiler : ( _c = options . compiler ) !== null && _c !== void 0 ? _c : 'typescript' ,
transformers : transformers ,
stringifyContentPathRegex : stringifyContentPathRegex ,
} ;
this . logger . debug ( { tsJestConfig : res } , 'normalized ts-jest config' ) ;
return res ;
} ,
enumerable : true ,
configurable : true
} ) ;
2020-05-15 05:33:08 +08:00
Object . defineProperty ( ConfigSet . prototype , "parsedTsConfig" , {
2020-03-31 20:42:07 +08:00
get : function ( ) {
2020-05-15 05:33:08 +08:00
return this . _parsedTsConfig ;
2020-03-31 20:42:07 +08:00
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "versions" , {
get : function ( ) {
var modules = [ 'jest' , this . tsJest . compiler ] ;
if ( this . tsJest . babelConfig ) {
modules . push ( '@babel/core' , 'babel-jest' ) ;
}
return modules . reduce ( function ( map , name ) {
var _a ;
map [ name ] = ( _a = get _package _version _1 . getPackageVersion ( name ) ) !== null && _a !== void 0 ? _a : '-' ;
return map ;
} , { 'ts-jest' : _ _1 . version } ) ;
} ,
enumerable : true ,
configurable : true
} ) ;
2020-05-15 05:33:08 +08:00
Object . defineProperty ( ConfigSet . prototype , "_parsedTsConfig" , {
2020-03-31 20:42:07 +08:00
get : function ( ) {
var tsConfig = this . tsJest . tsConfig ;
var configFilePath = tsConfig && tsConfig . kind === 'file' ? tsConfig . value : undefined ;
var result = this . readTsConfig ( tsConfig && tsConfig . kind === 'inline' ? tsConfig . value : undefined , configFilePath , tsConfig == null ) ;
2020-05-15 05:33:08 +08:00
this . raiseDiagnostics ( result . errors , configFilePath ) ;
2020-03-31 20:42:07 +08:00
this . logger . debug ( { tsconfig : result } , 'normalized typescript config' ) ;
return result ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "raiseDiagnostics" , {
get : function ( ) {
var _this = this ;
var _a = this , createTsError = _a . createTsError , filterDiagnostics = _a . filterDiagnostics , throws = _a . tsJest . diagnostics . throws , DiagnosticCategory = _a . compilerModule . DiagnosticCategory ;
return function ( diagnostics , filePath , logger ) {
if ( logger === void 0 ) { logger = _this . logger ; }
var filteredDiagnostics = filterDiagnostics ( diagnostics , filePath ) ;
if ( ! filteredDiagnostics . length )
return ;
var error = createTsError ( filteredDiagnostics ) ;
var importantCategories = [ DiagnosticCategory . Warning , DiagnosticCategory . Error ] ;
if ( throws && filteredDiagnostics . some ( function ( d ) { return importantCategories . includes ( d . category ) ; } ) ) {
throw error ;
}
logger . warn ( { error : error } , error . message ) ;
} ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "babel" , {
get : function ( ) {
var babelConfig = this . tsJest . babelConfig ;
if ( babelConfig == null ) {
this . logger . debug ( 'babel is disabled' ) ;
2020-05-15 05:33:08 +08:00
return undefined ;
2020-03-31 20:42:07 +08:00
}
var base = { cwd : this . cwd } ;
if ( babelConfig . kind === 'file' ) {
if ( babelConfig . value ) {
if ( path _1 . extname ( babelConfig . value ) === '.js' ) {
base = _ _assign ( _ _assign ( { } , base ) , require ( babelConfig . value ) ) ;
}
else {
base = _ _assign ( _ _assign ( { } , base ) , json5 . parse ( fs _1 . readFileSync ( babelConfig . value , 'utf8' ) ) ) ;
}
}
}
else if ( babelConfig . kind === 'inline' ) {
base = _ _assign ( _ _assign ( { } , base ) , babelConfig . value ) ;
}
this . logger . debug ( { babelConfig : base } , 'normalized babel config via ts-jest option' ) ;
return base ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "compilerModule" , {
get : function ( ) {
return importer _1 . importer . typescript ( "Using \"ts-jest\" requires this package to be installed." , this . tsJest . compiler ) ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "babelJestTransformer" , {
get : function ( ) {
var babel = this . babel ;
if ( ! babel )
2020-05-15 05:33:08 +08:00
return undefined ;
2020-03-31 20:42:07 +08:00
this . logger . debug ( 'creating babel-jest transformer' ) ;
return importer _1 . importer . babelJest ( "Using \"babel-jest\" requires this package to be installed." ) . createTransformer ( babel ) ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "tsCompiler" , {
get : function ( ) {
2020-05-15 05:33:08 +08:00
return instance _1 . createCompilerInstance ( this ) ;
2020-03-31 20:42:07 +08:00
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "astTransformers" , {
get : function ( ) {
return _ _spread ( transformers _1 . internals , this . tsJest . transformers . map ( function ( m ) { return require ( m ) ; } ) ) ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "tsCustomTransformers" , {
get : function ( ) {
var _this = this ;
return {
before : this . astTransformers . map ( function ( t ) { return t . factory ( _this ) ; } ) ,
} ;
} ,
enumerable : true ,
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 : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "filterDiagnostics" , {
get : function ( ) {
var _a = this , ignoreCodes = _a . tsJest . diagnostics . ignoreCodes , shouldReportDiagnostic = _a . shouldReportDiagnostic ;
return function ( diagnostics , filePath ) {
if ( filePath && ! shouldReportDiagnostic ( filePath ) )
return [ ] ;
return diagnostics . filter ( function ( diagnostic ) {
var _a ;
if ( ( ( _a = diagnostic . file ) === null || _a === void 0 ? void 0 : _a . fileName ) && ! shouldReportDiagnostic ( diagnostic . file . fileName ) ) {
return false ;
}
2020-05-15 05:33:08 +08:00
return ! ignoreCodes . includes ( diagnostic . code ) ;
2020-03-31 20:42:07 +08:00
} ) ;
} ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "shouldReportDiagnostic" , {
get : function ( ) {
var pathRegex = this . tsJest . diagnostics . pathRegex ;
if ( pathRegex ) {
var regex _1 = new RegExp ( pathRegex ) ;
return function ( file ) { return regex _1 . test ( file ) ; } ;
}
else {
return function ( ) { return true ; } ;
}
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "shouldStringifyContent" , {
get : function ( ) {
var stringifyContentPathRegex = this . tsJest . stringifyContentPathRegex ;
if ( stringifyContentPathRegex ) {
var regex _2 = new RegExp ( stringifyContentPathRegex ) ;
return function ( file ) { return regex _2 . test ( file ) ; } ;
}
else {
return function ( ) { return false ; } ;
}
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "createTsError" , {
get : function ( ) {
var _this = this ;
var pretty = this . tsJest . diagnostics . pretty ;
var formatDiagnostics = pretty
? this . compilerModule . formatDiagnosticsWithColorAndContext
: this . compilerModule . formatDiagnostics ;
var diagnosticHost = {
getNewLine : function ( ) { return '\n' ; } ,
getCurrentDirectory : function ( ) { return _this . cwd ; } ,
getCanonicalFileName : function ( path ) { return path ; } ,
} ;
return function ( diagnostics ) {
var diagnosticText = formatDiagnostics ( diagnostics , diagnosticHost ) ;
var diagnosticCodes = diagnostics . map ( function ( x ) { return x . code ; } ) ;
return new ts _error _1 . TSError ( diagnosticText , diagnosticCodes ) ;
} ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "tsCacheDir" , {
get : function ( ) {
if ( ! this . jest . cache ) {
logger . debug ( 'file caching disabled' ) ;
2020-05-15 05:33:08 +08:00
return undefined ;
2020-03-31 20:42:07 +08:00
}
var cacheSuffix = sha1 _1 . sha1 ( json _1 . stringify ( {
version : this . compilerModule . version ,
digest : this . tsJestDigest ,
dependencies : this . projectDependencies ,
compiler : this . tsJest . compiler ,
2020-05-15 05:33:08 +08:00
compilerOptions : this . parsedTsConfig . options ,
2020-03-31 20:42:07 +08:00
isolatedModules : this . tsJest . isolatedModules ,
diagnostics : this . tsJest . diagnostics ,
} ) ) ;
var res = path _1 . join ( this . jest . cacheDirectory , 'ts-jest' , cacheSuffix . substr ( 0 , 2 ) , cacheSuffix . substr ( 2 ) ) ;
logger . debug ( { cacheDirectory : res } , 'will use file caching' ) ;
return res ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "overriddenCompilerOptions" , {
get : function ( ) {
var options = {
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 ,
} ;
if ( ! this . tsJest . babelConfig ) {
options . module = this . compilerModule . ModuleKind . CommonJS ;
}
return options ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "rootDir" , {
get : function ( ) {
return path _1 . normalize ( this . jest . rootDir || this . cwd ) ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "cwd" , {
get : function ( ) {
return path _1 . normalize ( this . jest . cwd || process . cwd ( ) ) ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "tsJestDigest" , {
get : function ( ) {
return _ _1 . digest ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "jsonValue" , {
get : function ( ) {
var jest = _ _assign ( { } , this . jest ) ;
var globals = ( jest . globals = _ _assign ( { } , jest . globals ) ) ;
delete jest . name ;
delete jest . cacheDirectory ;
delete globals [ 'ts-jest' ] ;
return new jsonable _value _1 . JsonableValue ( {
versions : this . versions ,
projectDepVersions : this . projectDependencies ,
digest : this . tsJestDigest ,
transformers : this . astTransformers . map ( function ( t ) { return t . name + "@" + t . version ; } ) ,
jest : jest ,
tsJest : this . tsJest ,
babel : this . babel ,
2020-05-15 05:33:08 +08:00
tsconfig : this . parsedTsConfig . options ,
2020-03-31 20:42:07 +08:00
} ) ;
} ,
enumerable : true ,
configurable : true
} ) ;
Object . defineProperty ( ConfigSet . prototype , "cacheKey" , {
get : function ( ) {
return this . jsonValue . serialized ;
} ,
enumerable : true ,
configurable : true
} ) ;
ConfigSet . prototype . makeDiagnostic = function ( code , messageText , options ) {
if ( options === void 0 ) { options = { } ; }
var _a = options . category , category = _a === void 0 ? this . compilerModule . DiagnosticCategory . Warning : _a , file = options . file , start = options . start , length = options . length ;
return {
code : code ,
messageText : messageText ,
category : category ,
file : file ,
start : start ,
length : length ,
} ;
} ;
ConfigSet . prototype . readTsConfig = function ( compilerOptions , resolvedConfigFile , noProject ) {
var e _2 , _a ;
var config = { compilerOptions : { } } ;
var basePath = normalize _slashes _1 . normalizeSlashes ( this . rootDir ) ;
var configFileName ;
var ts = this . compilerModule ;
2020-05-15 05:33:08 +08:00
if ( ! noProject ) {
2020-03-31 20:42:07 +08:00
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 ) {
2020-05-15 05:33:08 +08:00
return { errors : [ result _1 . error ] , fileNames : [ ] , options : { } } ;
2020-03-31 20:42:07 +08:00
}
config = result _1 . config ;
basePath = normalize _slashes _1 . normalizeSlashes ( path _1 . dirname ( configFileName ) ) ;
}
}
config . compilerOptions = _ _assign ( _ _assign ( { } , config . compilerOptions ) , compilerOptions ) ;
var result = ts . parseJsonConfigFileContent ( config , ts . sys , basePath , undefined , configFileName ) ;
var forcedOptions = this . overriddenCompilerOptions ;
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 ) ) {
result . errors . push ( this . makeDiagnostic ( 151001 , "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." , {
category : ts . DiagnosticCategory . Message ,
} ) ) ;
if ( ! ( 'allowSyntheticDefaultImports' in config . compilerOptions ) ) {
finalOptions . allowSyntheticDefaultImports = true ;
}
}
2020-04-30 20:40:07 +08:00
if ( finalOptions . allowJs && ! finalOptions . outDir ) {
finalOptions . outDir = exports . TS _JEST _OUT _DIR ;
}
2020-03-31 20:42:07 +08:00
try {
for ( var _b = _ _values ( Object . keys ( forcedOptions ) ) , _c = _b . next ( ) ; ! _c . done ; _c = _b . next ( ) ) {
var key = _c . value ;
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 {
if ( _c && ! _c . done && ( _a = _b . return ) ) _a . call ( _b ) ;
}
finally { if ( e _2 ) throw e _2 . error ; }
}
2020-05-15 05:33:08 +08:00
return result ;
2020-03-31 20:42:07 +08: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 ;
} ;
ConfigSet . prototype . toJSON = function ( ) {
return this . jsonValue . value ;
} ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "projectPackageJson" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "projectDependencies" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "jest" , null ) ;
2020-04-30 20:40:07 +08:00
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "testMatchPatterns" , null ) ;
2020-03-31 20:42:07 +08:00
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "tsJest" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "versions" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
2020-05-15 05:33:08 +08:00
] , ConfigSet . prototype , "_parsedTsConfig" , null ) ;
2020-03-31 20:42:07 +08:00
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "raiseDiagnostics" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "babel" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "compilerModule" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "babelJestTransformer" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "tsCompiler" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "astTransformers" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "tsCustomTransformers" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "hooks" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "filterDiagnostics" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "shouldReportDiagnostic" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "shouldStringifyContent" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "createTsError" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "tsCacheDir" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "overriddenCompilerOptions" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "rootDir" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "cwd" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "tsJestDigest" , null ) ;
_ _decorate ( [
memoize _1 . Memoize ( )
] , ConfigSet . prototype , "jsonValue" , null ) ;
return ConfigSet ;
} ( ) ) ;
exports . ConfigSet = ConfigSet ;