Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add options parameter to repl #12924

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/core/repl/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { ReplContext } from './repl-context';
import { ReplLogger } from './repl-logger';
import { defineDefaultCommandsOnRepl } from './repl-native-commands';

export async function repl(module: Type | DynamicModule) {
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(),
Expand All @@ -21,6 +26,7 @@ export async function repl(module: Type | DynamicModule) {
const replServer = _repl.start({
prompt: clc.green('> '),
ignoreUndefined: true,
...replOptions,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so now users can change the prompt. That's good, to me

But I wonder if changing the ignoreUndefined will break the repl 🤔 I don't why we're using ignoreUndefined: true tbh

Copy link
Contributor Author

@othierry othierry Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered the same thing. Not really sure why ignoreUndefined is set to true but there's probably a reason behind ?

That's how it behaves :

  • node repl
> undefined
undefined
  • nestjs repl
> undefined
>

It's actually weird haha.

If we can confirm this is required, I can move the replOptions spread at the begining but that would prevent users to change the promp. I clould also force ignoreUndefined: true but keep the rest of replOptions. (and make it clear for users in typing like : Omit<ReplOptions, 'ignoreUndefined'>)

wdyt ?

});
assignToObject(replServer.context, replContext.globalScope);

Expand Down