diff --git a/cli/flags.rs b/cli/flags.rs index 2d1471bf46..7d065dd396 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -63,6 +63,8 @@ impl Default for DenoSubcommand { #[derive(Clone, Debug, PartialEq, Default)] pub struct DenoFlags { + /// Vector of CLI arguments - these are user script arguments, all Deno + /// specific flags are removed. pub argv: Vec, pub subcommand: DenoSubcommand, diff --git a/cli/global_state.rs b/cli/global_state.rs index fd4cf80471..c42b444b02 100644 --- a/cli/global_state.rs +++ b/cli/global_state.rs @@ -32,8 +32,6 @@ pub struct ThreadSafeGlobalState(Arc); /// It is shared by all created workers (thus V8 isolates). #[cfg_attr(feature = "cargo-clippy", allow(stutter))] pub struct GlobalState { - /// Vector of CLI arguments - these are user script arguments, all Deno specific flags are removed. - pub argv: Vec, /// Flags parsed from `argv` contents. pub flags: flags::DenoFlags, /// Entry script parsed from CLI arguments. @@ -67,7 +65,6 @@ impl Deref for ThreadSafeGlobalState { impl ThreadSafeGlobalState { pub fn new( flags: flags::DenoFlags, - argv_rest: Vec, progress: Progress, ) -> Result { let custom_root = env::var("DENO_DIR").map(String::into).ok(); @@ -88,10 +85,10 @@ impl ThreadSafeGlobalState { flags.config_path.clone(), )?; - let main_module: Option = if argv_rest.len() <= 1 { + let main_module: Option = if flags.argv.len() <= 1 { None } else { - let root_specifier = argv_rest[1].clone(); + let root_specifier = flags.argv[1].clone(); Some(ModuleSpecifier::resolve_url_or_path(&root_specifier)?) }; @@ -105,7 +102,6 @@ impl ThreadSafeGlobalState { let state = GlobalState { main_module, dir, - argv: argv_rest, permissions: DenoPermissions::from_flags(&flags), flags, metrics: Metrics::default(), @@ -231,8 +227,10 @@ impl ThreadSafeGlobalState { #[cfg(test)] pub fn mock(argv: Vec) -> ThreadSafeGlobalState { ThreadSafeGlobalState::new( - flags::DenoFlags::default(), - argv, + flags::DenoFlags { + argv, + ..flags::DenoFlags::default() + }, Progress::new(), ) .unwrap() @@ -252,10 +250,10 @@ fn thread_safe() { fn import_map_given_for_repl() { let _result = ThreadSafeGlobalState::new( flags::DenoFlags { + argv: vec![String::from("./deno")], import_map_path: Some("import_map.json".to_string()), ..flags::DenoFlags::default() }, - vec![String::from("./deno")], Progress::new(), ); } diff --git a/cli/lib.rs b/cli/lib.rs index c0bf57b5be..df4cbbdf0e 100644 --- a/cli/lib.rs +++ b/cli/lib.rs @@ -110,9 +110,7 @@ fn create_worker_and_state( } }); - // TODO(ry) Remove argv param from ThreadSafeGlobalState::new. - let argv = flags.argv.clone(); - let global_state = ThreadSafeGlobalState::new(flags, argv, progress) + let global_state = ThreadSafeGlobalState::new(flags, progress) .map_err(deno_error::print_err_and_exit) .unwrap(); @@ -297,8 +295,8 @@ fn fetch_command(flags: DenoFlags) { } fn eval_command(flags: DenoFlags) { - let (mut worker, state) = create_worker_and_state(flags); - let ts_source = state.argv[1].clone(); + let ts_source = flags.argv[1].clone(); + let (mut worker, _state) = create_worker_and_state(flags); // Force TypeScript compile. let main_module = ModuleSpecifier::resolve_url_or_path("./__$deno$eval.ts").unwrap(); diff --git a/cli/ops/os.rs b/cli/ops/os.rs index 78fd940de2..70e22cea60 100644 --- a/cli/ops/os.rs +++ b/cli/ops/os.rs @@ -44,7 +44,7 @@ fn op_start( Ok(JsonOp::Sync(json!({ "cwd": deno_fs::normalize_path(&env::current_dir().unwrap()), "pid": std::process::id(), - "argv": gs.argv, + "argv": gs.flags.argv, "mainModule": gs.main_module.as_ref().map(|x| x.to_string()), "debugFlag": gs.flags.log_level.map_or(false, |l| l == log::Level::Debug), "versionFlag": gs.flags.version, diff --git a/cli/worker.rs b/cli/worker.rs index 5a3bc7efa5..a8585b74e7 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -200,7 +200,6 @@ impl Future for WorkerReceiver { mod tests { use super::*; use crate::flags; - use crate::flags::DenoFlags; use crate::global_state::ThreadSafeGlobalState; use crate::progress::Progress; use crate::startup_data; @@ -238,10 +237,11 @@ mod tests { .to_owned(); let module_specifier = ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap(); - let argv = vec![String::from("./deno"), module_specifier.to_string()]; let global_state = ThreadSafeGlobalState::new( - flags::DenoFlags::default(), - argv, + flags::DenoFlags { + argv: vec![String::from("./deno"), module_specifier.to_string()], + ..flags::DenoFlags::default() + }, Progress::new(), ) .unwrap(); @@ -282,10 +282,14 @@ mod tests { .to_owned(); let module_specifier = ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap(); - let argv = vec![String::from("deno"), module_specifier.to_string()]; - let global_state = - ThreadSafeGlobalState::new(DenoFlags::default(), argv, Progress::new()) - .unwrap(); + let global_state = ThreadSafeGlobalState::new( + flags::DenoFlags { + argv: vec![String::from("deno"), module_specifier.to_string()], + ..flags::DenoFlags::default() + }, + Progress::new(), + ) + .unwrap(); let (int, ext) = ThreadSafeState::create_channels(); let state = ThreadSafeState::new( global_state, @@ -325,11 +329,11 @@ mod tests { .to_owned(); let module_specifier = ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap(); - let argv = vec![String::from("deno"), module_specifier.to_string()]; let mut flags = flags::DenoFlags::default(); + flags.argv = vec![String::from("deno"), module_specifier.to_string()]; flags.reload = true; let global_state = - ThreadSafeGlobalState::new(flags, argv, Progress::new()).unwrap(); + ThreadSafeGlobalState::new(flags, Progress::new()).unwrap(); let (int, ext) = ThreadSafeState::create_channels(); let state = ThreadSafeState::new( global_state.clone(),