summaryrefslogtreecommitdiff
path: root/cli/tsc.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2020-09-20 01:17:35 +0200
committerGitHub <noreply@github.com>2020-09-20 01:17:35 +0200
commitb657d743a22802b8232fbf558f2f00bf2942096f (patch)
treee3a3047e78b6bd9c9e3f551f99f5e80e32de079d /cli/tsc.rs
parentaaa5e6613a739f8e2ff7579b69c2504bcdc37d4f (diff)
refactor: remove CliState, use OpState, add CliModuleLoader (#7588)
- remove "CliState.workers" and "CliState.next_worker_id", instead store them on "OpState" using type aliases. - remove "CliState.global_timer" and "CliState.start_time", instead store them on "OpState" using type aliases. - remove "CliState.is_internal", instead pass it to Worker::new - move "CliState::permissions" to "OpState" - move "CliState::main_module" to "OpState" - move "CliState::global_state" to "OpState" - move "CliState::check_unstable()" to "GlobalState" - change "cli_state()" to "global_state()" - change "deno_core::ModuleLoader" trait to pass "OpState" to callbacks - rename "CliState" to "CliModuleLoader"
Diffstat (limited to 'cli/tsc.rs')
-rw-r--r--cli/tsc.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/cli/tsc.rs b/cli/tsc.rs
index 1e75b7041..c4102cc42 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -18,7 +18,7 @@ use crate::module_graph::ModuleGraphLoader;
use crate::ops;
use crate::permissions::Permissions;
use crate::source_maps::SourceMapGetter;
-use crate::state::CliState;
+use crate::state::CliModuleLoader;
use crate::tsc_config;
use crate::version;
use crate::worker::Worker;
@@ -48,7 +48,6 @@ use std::ops::DerefMut;
use std::path::Path;
use std::path::PathBuf;
use std::pin::Pin;
-use std::rc::Rc;
use std::str;
use std::sync::atomic::Ordering;
use std::sync::Arc;
@@ -132,9 +131,25 @@ pub struct CompilerWorker {
}
impl CompilerWorker {
- pub fn new(name: String, state: &Rc<CliState>) -> Self {
- let mut worker =
- Worker::new(name, Some(js::compiler_isolate_init()), state);
+ pub fn new(
+ name: String,
+ permissions: Permissions,
+ global_state: Arc<GlobalState>,
+ ) -> Self {
+ let main_module =
+ ModuleSpecifier::resolve_url_or_path("./$deno$compiler.ts").unwrap();
+ // TODO(bartlomieju): compiler worker shouldn't require any loader/state
+ let loader = CliModuleLoader::new(None);
+ let mut worker = Worker::new(
+ name,
+ Some(js::compiler_isolate_init()),
+ permissions,
+ main_module,
+ global_state,
+ loader,
+ false,
+ true,
+ );
let response = Arc::new(Mutex::new(None));
ops::runtime::init(&mut worker);
ops::errors::init(&mut worker);
@@ -215,17 +230,12 @@ fn create_compiler_worker(
global_state: &Arc<GlobalState>,
permissions: Permissions,
) -> CompilerWorker {
- let entry_point =
- ModuleSpecifier::resolve_url_or_path("./$deno$compiler.ts").unwrap();
- let worker_state =
- CliState::new(&global_state, Some(permissions), entry_point, None, true)
- .expect("Unable to create worker state");
-
// TODO(bartlomieju): this metric is never used anywhere
// Count how many times we start the compiler worker.
global_state.compiler_starts.fetch_add(1, Ordering::SeqCst);
- let mut worker = CompilerWorker::new("TS".to_string(), &worker_state);
+ let mut worker =
+ CompilerWorker::new("TS".to_string(), permissions, global_state.clone());
worker
.execute("globalThis.bootstrapCompilerRuntime()")
.unwrap();