From c49a057599d68b27c88cc123a9fcd6703b49310c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 8 Oct 2021 17:11:33 +0200 Subject: [PATCH] feat(compat): inject Node globals in REPL (#12352) --- cli/main.rs | 7 ++++++- cli/tests/integration/compat_tests.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cli/main.rs b/cli/main.rs index 7c6265fb40..4ffa8340c7 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -821,9 +821,14 @@ async fn format_command( async fn run_repl(flags: Flags, repl_flags: ReplFlags) -> Result<(), AnyError> { let main_module = resolve_url_or_path("./$deno$repl.ts").unwrap(); let permissions = Permissions::from_options(&flags.clone().into()); - let ps = ProcState::build(flags).await?; + let ps = ProcState::build(flags.clone()).await?; let mut worker = create_main_worker(&ps, main_module.clone(), permissions, None); + if flags.compat { + worker + .execute_side_module(&compat::get_node_globals_url()) + .await?; + } worker.run_event_loop(false).await?; tools::repl::run(&ps, worker, repl_flags.eval).await diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs index 6743dada15..8f512fca33 100644 --- a/cli/tests/integration/compat_tests.rs +++ b/cli/tests/integration/compat_tests.rs @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use crate::itest; +use test_util as util; itest!(globals { args: "run --compat --unstable --allow-read --allow-env compat/globals.ts", @@ -22,3 +23,16 @@ itest!(existing_import_map { output: "compat/existing_import_map.out", exit_code: 1, }); + +#[test] +fn globals_in_repl() { + let (out, err) = util::run_and_collect_output_with_args( + true, + vec!["repl", "--compat", "--unstable", "--quiet"], + Some(vec!["global == window"]), + None, + false, + ); + assert!(out.contains("true")); + assert!(err.contains("Implicitly using latest version")); +}