summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-06-12 21:00:08 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-06-12 12:00:08 -0700
commitb3c4307d02d627287cd28486b208b53c3bd378f0 (patch)
tree2ae6de97a03f5a8f9188e3a1a02ae7fe575259f9 /cli/main.rs
parent2a5138a5166f0945d5fda68c89fa8e23c66fb681 (diff)
Refactor module resolving (#2493)
Adds ModuleSpecifier, which wraps a URL. This is now passed around instead of specifier and resolver strings.
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs90
1 files changed, 44 insertions, 46 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 5976d42ba..11575ef63 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -27,6 +27,7 @@ mod http_body;
mod http_util;
mod import_map;
pub mod js_errors;
+mod module_specifier;
pub mod msg;
pub mod msg_util;
pub mod ops;
@@ -45,9 +46,9 @@ pub mod worker;
use crate::compiler::bundle_async;
use crate::errors::RustOrJsError;
+use crate::module_specifier::ModuleSpecifier;
use crate::progress::Progress;
use crate::state::ThreadSafeState;
-use crate::worker::root_specifier_to_url;
use crate::worker::Worker;
use deno::v8_set_flags;
use flags::DenoFlags;
@@ -98,51 +99,53 @@ where
pub fn print_file_info(
worker: Worker,
- url: &str,
+ module_specifier: &ModuleSpecifier,
) -> impl Future<Item = Worker, Error = ()> {
- state::fetch_module_meta_data_and_maybe_compile_async(&worker.state, url, ".")
- .and_then(move |out| {
- println!("{} {}", ansi::bold("local:".to_string()), &(out.filename));
-
+ 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));
+
+ println!(
+ "{} {}",
+ ansi::bold("type:".to_string()),
+ msg::enum_name_media_type(out.media_type)
+ );
+
+ if out.maybe_output_code_filename.is_some() {
println!(
"{} {}",
- ansi::bold("type:".to_string()),
- msg::enum_name_media_type(out.media_type)
+ ansi::bold("compiled:".to_string()),
+ out.maybe_output_code_filename.as_ref().unwrap(),
);
+ }
- if out.maybe_output_code_filename.is_some() {
- println!(
- "{} {}",
- ansi::bold("compiled:".to_string()),
- out.maybe_output_code_filename.as_ref().unwrap(),
- );
- }
-
- if out.maybe_source_map_filename.is_some() {
- println!(
- "{} {}",
- ansi::bold("map:".to_string()),
- out.maybe_source_map_filename.as_ref().unwrap()
- );
- }
+ if out.maybe_source_map_filename.is_some() {
+ println!(
+ "{} {}",
+ ansi::bold("map:".to_string()),
+ out.maybe_source_map_filename.as_ref().unwrap()
+ );
+ }
- 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);
- }
+ 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))
+ } else {
+ println!(
+ "{} cannot retrieve full dependency graph",
+ ansi::bold("deps:".to_string()),
+ );
+ }
+ Ok(worker)
+ }).map_err(|err| println!("{}", err))
}
fn create_worker_and_state(
@@ -193,10 +196,8 @@ fn fetch_or_info_command(
js_check(worker.execute("denoMain()"));
debug!("main_module {}", main_module);
- let main_url = root_specifier_to_url(&main_module).unwrap();
-
worker
- .execute_mod_async(&main_url, true)
+ .execute_mod_async(&main_module, true)
.map_err(print_err_and_exit)
.and_then(move |()| {
if print_info {
@@ -269,11 +270,10 @@ fn bundle_command(flags: DenoFlags, argv: Vec<String>) {
let (mut _worker, state) = create_worker_and_state(flags, argv);
let main_module = state.main_module().unwrap();
- let main_url = root_specifier_to_url(&main_module).unwrap();
assert!(state.argv.len() >= 3);
let out_file = state.argv[2].clone();
debug!(">>>>> bundle_async START");
- let bundle_future = bundle_async(state, main_url.to_string(), out_file)
+ let bundle_future = bundle_async(state, main_module.to_string(), out_file)
.map_err(|e| {
debug!("diagnostics returned, exiting!");
eprintln!("\n{}", e.to_string());
@@ -313,10 +313,8 @@ fn run_script(flags: DenoFlags, argv: Vec<String>) {
js_check(worker.execute("denoMain()"));
debug!("main_module {}", main_module);
- let main_url = root_specifier_to_url(&main_module).unwrap();
-
worker
- .execute_mod_async(&main_url, false)
+ .execute_mod_async(&main_module, false)
.and_then(move |()| {
worker.then(|result| {
js_check(result);