mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
remove duplicated argv member from ThreadSafeGlobalState (#3433)
This commit is contained in:
parent
00844b4142
commit
ee013102ff
5 changed files with 27 additions and 25 deletions
|
@ -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<String>,
|
||||
pub subcommand: DenoSubcommand,
|
||||
|
||||
|
|
|
@ -32,8 +32,6 @@ pub struct ThreadSafeGlobalState(Arc<GlobalState>);
|
|||
/// 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<String>,
|
||||
/// 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<String>,
|
||||
progress: Progress,
|
||||
) -> Result<Self, ErrBox> {
|
||||
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<ModuleSpecifier> = if argv_rest.len() <= 1 {
|
||||
let main_module: Option<ModuleSpecifier> = 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<String>) -> 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(),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Reference in a new issue