import * as tsNode from 'ts-node/esm' ; import { optimizeJSX } from '@deepkit/template' ; import { inDebugMode } from '@deepkit/core' ; import { importedFiles } from './src/watch' ; export async function resolve ( specifier , context , defaultResolve ) { const res = await tsNode . resolve ( specifier , context , defaultResolve ) ; if ( res . url ) { importedFiles . add ( res . url . replace ( 'file://' , '' ) ) ; } return res ; } export function getFormat ( url , context , defaultGetFormat ) { return tsNode . getFormat ( url , context , defaultGetFormat ) ; } export async function transformSource ( source , context , defaultTransformSource ) { const code = await tsNode . transformSource ( source , context , defaultTransformSource ) ; if ( inDebugMode ( ) ) return code ; if ( context . url . endsWith ( '.tsx' ) ) { if ( code . source . indexOf ( '@deepkit/framework/jsx-runtime' ) === - 1 ) return code ; if ( code . source . startsWith ( '#!' ) ) { code . source = code . source . substr ( code . source . indexOf ( '\n' ) ) ; } const optimized = optimizeJSX ( code . source ) ; code . source = optimized ; } return code ; }