(options: CreateReplOptions = {})
| 148 | * @category REPL |
| 149 | */ |
| 150 | export function createRepl(options: CreateReplOptions = {}) { |
| 151 | const { ignoreDiagnosticsThatAreAnnoyingInInteractiveRepl = true } = options; |
| 152 | let service = options.service; |
| 153 | let nodeReplServer: REPLServer; |
| 154 | // If `useGlobal` is not true, then REPL creates a context when started. |
| 155 | // This stores a reference to it or to `global`, whichever is used, after REPL has started. |
| 156 | let context: Context | undefined; |
| 157 | const state = |
| 158 | options.state ?? new EvalState(join(process.cwd(), REPL_FILENAME)); |
| 159 | const evalAwarePartialHost = createEvalAwarePartialHost( |
| 160 | state, |
| 161 | options.composeWithEvalAwarePartialHost |
| 162 | ); |
| 163 | const stdin = options.stdin ?? process.stdin; |
| 164 | const stdout = options.stdout ?? process.stdout; |
| 165 | const stderr = options.stderr ?? process.stderr; |
| 166 | const _console = |
| 167 | stdout === process.stdout && stderr === process.stderr |
| 168 | ? console |
| 169 | : new Console(stdout, stderr); |
| 170 | |
| 171 | const replService: ReplService = { |
| 172 | state: options.state ?? new EvalState(join(process.cwd(), EVAL_FILENAME)), |
| 173 | setService, |
| 174 | evalCode, |
| 175 | evalCodeInternal, |
| 176 | nodeEval, |
| 177 | evalAwarePartialHost, |
| 178 | start, |
| 179 | startInternal, |
| 180 | stdin, |
| 181 | stdout, |
| 182 | stderr, |
| 183 | console: _console, |
| 184 | }; |
| 185 | |
| 186 | return replService; |
| 187 | |
| 188 | function setService(_service: Service) { |
| 189 | service = _service; |
| 190 | if (ignoreDiagnosticsThatAreAnnoyingInInteractiveRepl) { |
| 191 | service.addDiagnosticFilter({ |
| 192 | appliesToAllFiles: false, |
| 193 | filenamesAbsolute: [state.path], |
| 194 | diagnosticsIgnored: [ |
| 195 | 2393, // Duplicate function implementation: https://github.com/TypeStrong/ts-node/issues/729 |
| 196 | 6133, // <identifier> is declared but its value is never read. https://github.com/TypeStrong/ts-node/issues/850 |
| 197 | 7027, // Unreachable code detected. https://github.com/TypeStrong/ts-node/issues/469 |
| 198 | ...(service.shouldReplAwait ? topLevelAwaitDiagnosticCodes : []), |
| 199 | ], |
| 200 | }); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | function evalCode(code: string) { |
| 205 | const result = appendCompileAndEvalInput({ |
| 206 | service: service!, |
| 207 | state, |
no test coverage detected
searching dependent graphs…