import path from 'path' ; require ( "@nomiclabs/hardhat-ethers" ) ; import { extendConfig , extendEnvironment , task , subtask , experimentalAddHardhatNetworkMessageTraceHook } from "hardhat/config" ; import { lazyObject , HardhatPluginError } from "hardhat/plugins" ; import { HardhatConfig , HardhatUserConfig , ActionType , RunTaskFunction , HardhatRuntimeEnvironment } from "hardhat/types" ; import { TASK_NODE_SERVER_READY } from "hardhat/builtin-tasks/task-names" ; import { Ethernal } from "./Ethernal" ; import { Artifact , ContractInput } from './types' ; import "./type-extensions" ; export const PluginName = 'hardhat-ethernal' ; subtask ( TASK_NODE_SERVER_READY ) . setAction ( async ( args , hre , runSuper ) => { if ( hre . ethernalSync ) { hre . ethernal . startListening ( ) ; } else console . log ( '[Ethernal] Not syncing' ) ; await runSuper ( args ) ; } ) ; experimentalAddHardhatNetworkMessageTraceHook ( async ( hre , trace , isMessageTraceFromACall ) => { hre . ethernal . traceHandler ( trace , isMessageTraceFromACall ) ; } ) ; extendConfig ( ( config , userConfig ) => { const userPath = userConfig . paths ?. newPath ; let newPath ; if ( userPath === undefined ) { newPath = path . join ( config . paths . root , "newPath" ) ; } else { if ( path . isAbsolute ( userPath ) ) { newPath = userPath ; } else { newPath = path . normalize ( path . join ( config . paths . root , userPath ) ) ; } } config . paths . newPath = newPath ; } ) ; extendEnvironment ( ( hre ) => { hre . ethernalSync = hre . ethernalSync ? hre . ethernalSync : true ; hre . ethernalTrace = hre . ethernalTrace ? hre . ethernalTrace : true ; hre . ethernal = lazyObject ( ( ) => new Ethernal ( hre ) ) ; } ) ;