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