feat(repl): add --eval flag for evaluating code when the repl starts (#11590)

This commit is contained in:
David Sherret 2021-08-06 17:30:28 -04:00 committed by GitHub
parent 33c8d790c3
commit 864ce6e832
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 133 additions and 15 deletions

View file

@ -774,7 +774,10 @@ async fn format_command(
Ok(())
}
async fn run_repl(flags: Flags) -> Result<(), AnyError> {
async fn run_repl(
flags: Flags,
maybe_eval: Option<String>,
) -> Result<(), AnyError> {
let main_module = resolve_url_or_path("./$deno$repl.ts").unwrap();
let permissions = Permissions::from_options(&flags.clone().into());
let program_state = ProgramState::build(flags).await?;
@ -782,7 +785,7 @@ async fn run_repl(flags: Flags) -> Result<(), AnyError> {
create_main_worker(&program_state, main_module.clone(), permissions, false);
worker.run_event_loop(false).await?;
tools::repl::run(&program_state, worker).await
tools::repl::run(&program_state, worker, maybe_eval).await
}
async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> {
@ -1341,7 +1344,7 @@ fn get_subcommand(
ignore,
json,
} => lint_command(flags, files, rules, ignore, json).boxed_local(),
DenoSubcommand::Repl => run_repl(flags).boxed_local(),
DenoSubcommand::Repl { eval } => run_repl(flags, eval).boxed_local(),
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
DenoSubcommand::Test {
no_run,