import type vm from 'node:vm'import type { ReplConfig, ReplCallback } from '@wdio/repl'import WDIORepl from '@wdio/repl'import type { ChildProcess } from 'node:child_process'export default class WDIORunnerRepl extends WDIORepl {childProcess: ChildProcesscallback?: ReplCallbackcommandIsRunning = falseconstructor (childProcess: ChildProcess, options: ReplConfig) {super(options)this.childProcess = childProcess}private _getError (params: Record<string, string>) {if (!params.error) {return null}const err = new Error(params.message)err.stack = params.stackreturn err}eval (cmd: string, context: vm.Context, filename: string, callback: ReplCallback) {if (this.commandIsRunning) {return}this.commandIsRunning = truethis.childProcess.send({origin: 'debugger',name: 'eval',content: { cmd }})this.callback = callback}onResult (params: Record<string, string>) {const error = this._getError(params)if (this.callback) {this.callback(error, params.result)}this.commandIsRunning = false}start (context?: vm.Context) {this.childProcess.send({origin: 'debugger',name: 'start'})return super.start(context)}}