summaryrefslogtreecommitdiff
path: root/cli/global_state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/global_state.rs')
-rw-r--r--cli/global_state.rs59
1 files changed, 31 insertions, 28 deletions
diff --git a/cli/global_state.rs b/cli/global_state.rs
index ca040c40c..202bf8c75 100644
--- a/cli/global_state.rs
+++ b/cli/global_state.rs
@@ -14,6 +14,7 @@ use crate::metrics::Metrics;
use crate::msg;
use crate::permissions::DenoPermissions;
use crate::progress::Progress;
+use crate::shell::Shell;
use deno_core::ErrBox;
use deno_core::ModuleSpecifier;
use std;
@@ -27,13 +28,12 @@ use tokio::sync::Mutex as AsyncMutex;
/// Holds state of the program and can be accessed by V8 isolate.
#[derive(Clone)]
-pub struct ThreadSafeGlobalState(Arc<GlobalState>);
+pub struct GlobalState(Arc<GlobalStateInner>);
/// This structure represents state of single "deno" program.
///
/// It is shared by all created workers (thus V8 isolates).
-#[cfg_attr(feature = "cargo-clippy", allow(stutter))]
-pub struct GlobalState {
+pub struct GlobalStateInner {
/// Flags parsed from `argv` contents.
pub flags: flags::DenoFlags,
/// Permissions parsed from `flags`.
@@ -50,21 +50,30 @@ pub struct GlobalState {
compile_lock: AsyncMutex<()>,
}
-impl Deref for ThreadSafeGlobalState {
- type Target = Arc<GlobalState>;
+impl Deref for GlobalState {
+ type Target = GlobalStateInner;
fn deref(&self) -> &Self::Target {
&self.0
}
}
-impl ThreadSafeGlobalState {
- pub fn new(
- flags: flags::DenoFlags,
- progress: Progress,
- ) -> Result<Self, ErrBox> {
+impl GlobalState {
+ pub fn new(flags: flags::DenoFlags) -> Result<Self, ErrBox> {
let custom_root = env::var("DENO_DIR").map(String::into).ok();
let dir = deno_dir::DenoDir::new(custom_root)?;
+ // TODO(ry) Shell is a useless abstraction and should be removed at
+ // some point.
+ let shell = Arc::new(Mutex::new(Shell::new()));
+
+ let progress = Progress::new();
+ progress.set_callback(move |_done, _completed, _total, status, msg| {
+ if !status.is_empty() {
+ let mut s = shell.lock().unwrap();
+ s.status(status, msg).expect("shell problem");
+ }
+ });
+
let file_fetcher = SourceFileFetcher::new(
dir.deps_cache.clone(),
progress.clone(),
@@ -88,7 +97,7 @@ impl ThreadSafeGlobalState {
None
};
- let state = GlobalState {
+ let inner = GlobalStateInner {
dir,
permissions: DenoPermissions::from_flags(&flags),
flags,
@@ -103,7 +112,7 @@ impl ThreadSafeGlobalState {
compile_lock: AsyncMutex::new(()),
};
- Ok(ThreadSafeGlobalState(Arc::new(state)))
+ Ok(GlobalState(Arc::new(inner)))
}
pub async fn fetch_compiled_module(
@@ -231,14 +240,11 @@ impl ThreadSafeGlobalState {
}
#[cfg(test)]
- pub fn mock(argv: Vec<String>) -> ThreadSafeGlobalState {
- ThreadSafeGlobalState::new(
- flags::DenoFlags {
- argv,
- ..flags::DenoFlags::default()
- },
- Progress::new(),
- )
+ pub fn mock(argv: Vec<String>) -> GlobalState {
+ GlobalState::new(flags::DenoFlags {
+ argv,
+ ..flags::DenoFlags::default()
+ })
.unwrap()
}
}
@@ -246,7 +252,7 @@ impl ThreadSafeGlobalState {
#[test]
fn thread_safe() {
fn f<S: Send + Sync>(_: S) {}
- f(ThreadSafeGlobalState::mock(vec![
+ f(GlobalState::mock(vec![
String::from("./deno"),
String::from("hello.js"),
]));
@@ -254,11 +260,8 @@ fn thread_safe() {
#[test]
fn import_map_given_for_repl() {
- let _result = ThreadSafeGlobalState::new(
- flags::DenoFlags {
- import_map_path: Some("import_map.json".to_string()),
- ..flags::DenoFlags::default()
- },
- Progress::new(),
- );
+ let _result = GlobalState::new(flags::DenoFlags {
+ import_map_path: Some("import_map.json".to_string()),
+ ..flags::DenoFlags::default()
+ });
}