diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-07-18 00:15:30 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-07-17 18:15:30 -0400 |
commit | 8214b686cea3f6ad57d7da49a44d33185fdeb098 (patch) | |
tree | 00517c7b8f4bb835ce050e89f29ec1826bac92ce /cli/main.rs | |
parent | 481a82c983e40201589e105e28be4ce809e46a60 (diff) |
Refactor DenoDir (#2636)
* rename `ModuleMetaData` to `SourceFile` and remove TS specific
functionality
* add `TsCompiler` struct encapsulating processing of TypeScript files
* move `SourceMapGetter` trait implementation to `//cli/compiler.rs`
* add low-level `DiskCache` API for general purpose caches and use it in
`DenoDir` and `TsCompiler` for filesystem access
* don't use hash-like filenames for compiled modules, instead use
metadata file for storing compilation hash
* add `SourceFileCache` for in-process caching of loaded files for fast
subsequent access
* define `SourceFileFetcher` trait encapsulating loading of local and
remote files and implement it for `DenoDir`
* define `use_cache` and `no_fetch` flags on `DenoDir` instead of using
in fetch methods
Diffstat (limited to 'cli/main.rs')
-rw-r--r-- | cli/main.rs | 112 |
1 files changed, 69 insertions, 43 deletions
diff --git a/cli/main.rs b/cli/main.rs index ec6c46616..26bd810c8 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -13,12 +13,14 @@ extern crate indexmap; #[cfg(unix)] extern crate nix; extern crate rand; +extern crate url; mod ansi; pub mod compiler; pub mod deno_dir; pub mod deno_error; pub mod diagnostics; +mod disk_cache; mod dispatch_minimal; pub mod flags; pub mod fmt_errors; @@ -45,7 +47,7 @@ mod tokio_write; pub mod version; pub mod worker; -use crate::compiler::bundle_async; +use crate::deno_dir::SourceFileFetcher; use crate::progress::Progress; use crate::state::ThreadSafeState; use crate::worker::Worker; @@ -101,55 +103,77 @@ pub fn print_file_info( worker: Worker, module_specifier: &ModuleSpecifier, ) -> impl Future<Item = Worker, Error = ()> { - state::fetch_module_meta_data_and_maybe_compile_async( - &worker.state, - module_specifier, - ).and_then(move |out| { - println!( - "{} {}", - ansi::bold("local:".to_string()), - out.filename.to_str().unwrap() - ); - - println!( - "{} {}", - ansi::bold("type:".to_string()), - msg::enum_name_media_type(out.media_type) - ); - - if out.maybe_output_code_filename.is_some() { + let state_ = worker.state.clone(); + let module_specifier_ = module_specifier.clone(); + + state_ + .dir + .fetch_source_file_async(&module_specifier) + .map_err(|err| println!("{}", err)) + .and_then(move |out| { println!( "{} {}", - ansi::bold("compiled:".to_string()), - out.maybe_output_code_filename.unwrap().to_str().unwrap(), + ansi::bold("local:".to_string()), + out.filename.to_str().unwrap() ); - } - if out.maybe_source_map_filename.is_some() { println!( "{} {}", - ansi::bold("map:".to_string()), - out.maybe_source_map_filename.unwrap().to_str().unwrap() + ansi::bold("type:".to_string()), + msg::enum_name_media_type(out.media_type) ); - } - if let Some(deps) = - worker.state.modules.lock().unwrap().deps(&out.module_name) - { - println!("{}{}", ansi::bold("deps:\n".to_string()), deps.name); - if let Some(ref depsdeps) = deps.deps { - for d in depsdeps { - println!("{}", d); - } - } - } else { - println!( - "{} cannot retrieve full dependency graph", - ansi::bold("deps:".to_string()), - ); - } - Ok(worker) - }).map_err(|err| println!("{}", err)) + state_ + .clone() + .ts_compiler + .compile_async(state_.clone(), &out) + .map_err(|e| { + debug!("compiler error exiting!"); + eprintln!("\n{}", e.to_string()); + std::process::exit(1); + }).and_then(move |compiled| { + if out.media_type == msg::MediaType::TypeScript { + println!( + "{} {}", + ansi::bold("compiled:".to_string()), + compiled.filename.to_str().unwrap(), + ); + } + + if let Ok(source_map) = state_ + .clone() + .ts_compiler + .get_source_map_file(&module_specifier_) + { + println!( + "{} {}", + ansi::bold("map:".to_string()), + source_map.filename.to_str().unwrap() + ); + } + + if let Some(deps) = worker + .state + .modules + .lock() + .unwrap() + .deps(&compiled.url.to_string()) + { + println!("{}{}", ansi::bold("deps:\n".to_string()), deps.name); + if let Some(ref depsdeps) = deps.deps { + for d in depsdeps { + println!("{}", d); + } + } + } else { + println!( + "{} cannot retrieve full dependency graph", + ansi::bold("deps:".to_string()), + ); + } + Ok(worker) + }) + }) } fn create_worker_and_state( @@ -273,7 +297,9 @@ fn bundle_command(flags: DenoFlags, argv: Vec<String>) { assert!(state.argv.len() >= 3); let out_file = state.argv[2].clone(); debug!(">>>>> bundle_async START"); - let bundle_future = bundle_async(state, main_module.to_string(), out_file) + let bundle_future = state + .ts_compiler + .bundle_async(state.clone(), main_module.to_string(), out_file) .map_err(|err| { debug!("diagnostics returned, exiting!"); eprintln!(""); |