import { RedspotConfig } from '../../types' ; import { resolveConfigPath } from './config/config-loading' ; import { RedspotError } from './errors' ; import { ERRORS } from './errors-list' ; import { isRunningRedspotCoreTests } from './execution-mode' ; let cachedIsTypescriptSupported ; param configPath export function willRunWithTypescript ( configPath ? ) { const config = resolveConfigPath ( configPath ) ; return isTypescriptFile ( config ) ; } /**
 * Returns true if an Redspot is already running with typescript.
 */ export function isRunningWithTypescript ( config ) { return isTypescriptFile ( config . paths . configFile ) ; } export function isTypescriptSupported ( ) { if ( cachedIsTypescriptSupported === undefined ) { try { require . resolve ( 'typescript' ) ; require . resolve ( 'ts-node' ) ; cachedIsTypescriptSupported = true ; } catch { cachedIsTypescriptSupported = false ; } } return cachedIsTypescriptSupported ; } export function loadTsNode ( ) { try { require . resolve ( 'typescript' ) ; } catch ( error ) { throw new RedspotError ( ERRORS . GENERAL . TYPESCRIPT_NOT_INSTALLED ) ; } try { require . resolve ( 'ts-node' ) ; } catch ( error ) { throw new RedspotError ( ERRORS . GENERAL . TS_NODE_NOT_INSTALLED ) ; } if ( isRunningRedspotCoreTests ( ) || process . env . TS_NODE_TRANSPILE_ONLY === undefined ) { require ( 'ts-node/register/transpile-only' ) ; return ; } if ( process . env . TS_NODE_FILES === undefined ) { process . env . TS_NODE_FILES = 'true' ; } require ( 'ts-node/register' ) ; } function isTypescriptFile ( path ) { return path . endsWith ( '.ts' ) ; }