/
githubmirror
/
nest
Обзор
Документация
Войти
/
githubmirror
/
nest
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
packages/core/repl/repl.ts
40 строк
1 KB
Dmitry Zhlobo
fix(core): gracefully shutdown the app when repl exits
28 май 2025, 15:59
28 май 2025, 15:59
b84c1fe
Код
Авторство
О чём код?
import { DynamicModule, Logger, Type } from '@nestjs/common'; import { clc } from '@nestjs/common/utils/cli-colors.util'; import { NestFactory } from '../nest-factory'; import { assignToObject } from './assign-to-object.util'; import { REPL_INITIALIZED_MESSAGE } from './constants'; import { ReplContext } from './repl-context'; import { ReplLogger } from './repl-logger'; import { defineDefaultCommandsOnRepl } from './repl-native-commands'; import type { ReplOptions } from 'repl'; export async function repl( module: Type | DynamicModule, replOptions: ReplOptions = {}, ) { const app = await NestFactory.createApplicationContext(module, { abortOnError: false, logger: new ReplLogger(), }); await app.init(); const replContext = new ReplContext(app); Logger.log(REPL_INITIALIZED_MESSAGE); const _repl = await import('repl'); const replServer = _repl.start({ prompt: clc.green('> '), ignoreUndefined: true, ...replOptions, }); assignToObject(replServer.context, replContext.globalScope); defineDefaultCommandsOnRepl(replServer); replServer.on('exit', async () => { await app.close(); }); return replServer; }