import * as path from 'path' ; import type * as ts from 'typescript' ; import { TransformerLogger } from '../logger/transformerLogger' ; import { core } from '../core/core' ; export interface CustomFunction { sourceUrl : string ; sourceDts : string ; isHandledFunction ( node , declaration ) : boolean ; run ( node ) : ts . Node ; } function isHandledDeclarationType ( declaration ) { return ( declaration && ( core . ts . isFunctionDeclaration ( declaration ) || core . ts . isMethodSignature ( declaration ) ) ) ; } export function getMatchingCustomFunction ( node , declaration , customFunctions ) { if ( ! isHandledDeclarationType ( declaration ) ) { return ; } const fileName = declaration . getSourceFile ( ) . fileName ; return customFunctions . find ( ( customFunction ) => { const functionUrl = path . join ( __dirname , customFunction . sourceUrl ) ; const isFileNameFunctionUrl = path . relative ( fileName , functionUrl ) === '' ; if ( fileName . includes ( customFunction . sourceDts ) && ! isFileNameFunctionUrl ) { TransformerLogger ( ) . unexpectedCreateMock ( fileName , functionUrl ) ; } return ( isFileNameFunctionUrl && customFunction . isHandledFunction ( node , declaration ) ) ; } ) ; }