import { hasProperty } from "@rnx-kit/tools-language/properties" ; import { Terminal } from "metro-core" ; import type { TerminalReporter } from "metro/src/lib/TerminalReporter" ; import path from "path" ; export type MetroTerminal = { terminal : Terminal ; reporter : TerminalReporter ; } ; function getTerminalReporterClass ( customReporterPath ) { if ( customReporterPath === undefined ) { return require ( "metro/src/lib/TerminalReporter" ) ; } try { return require ( customReporterPath ) ; } catch ( e ) { if ( ! hasProperty ( e , "code" ) || e . code !== "MODULE_NOT_FOUND" ) { throw e ; } return require ( path . resolve ( customReporterPath ) ) ; } } export function createTerminal ( customReporterPath ? ) { const terminal = new Terminal ( process . stdout ) ; const TerminalReporterClass = getTerminalReporterClass ( customReporterPath ) ; const reporter = new TerminalReporterClass ( terminal ) ; return { terminal , reporter } ; }