mirror of
https://github.com/denoland/deno.git
synced 2025-01-18 11:53:59 -05:00
feat(compat): inject Node globals in REPL (#12352)
This commit is contained in:
parent
6b43e862fd
commit
c49a057599
2 changed files with 20 additions and 1 deletions
|
@ -821,9 +821,14 @@ async fn format_command(
|
||||||
async fn run_repl(flags: Flags, repl_flags: ReplFlags) -> Result<(), AnyError> {
|
async fn run_repl(flags: Flags, repl_flags: ReplFlags) -> Result<(), AnyError> {
|
||||||
let main_module = resolve_url_or_path("./$deno$repl.ts").unwrap();
|
let main_module = resolve_url_or_path("./$deno$repl.ts").unwrap();
|
||||||
let permissions = Permissions::from_options(&flags.clone().into());
|
let permissions = Permissions::from_options(&flags.clone().into());
|
||||||
let ps = ProcState::build(flags).await?;
|
let ps = ProcState::build(flags.clone()).await?;
|
||||||
let mut worker =
|
let mut worker =
|
||||||
create_main_worker(&ps, main_module.clone(), permissions, None);
|
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?;
|
worker.run_event_loop(false).await?;
|
||||||
|
|
||||||
tools::repl::run(&ps, worker, repl_flags.eval).await
|
tools::repl::run(&ps, worker, repl_flags.eval).await
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use crate::itest;
|
use crate::itest;
|
||||||
|
use test_util as util;
|
||||||
|
|
||||||
itest!(globals {
|
itest!(globals {
|
||||||
args: "run --compat --unstable --allow-read --allow-env compat/globals.ts",
|
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",
|
output: "compat/existing_import_map.out",
|
||||||
exit_code: 1,
|
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"));
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue