2020-05-11 17:33:36 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2019-09-03 22:12:21 -04:00
|
|
|
|
2020-09-18 12:31:30 -04:00
|
|
|
#![deny(warnings)]
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
|
2020-09-14 08:27:44 -04:00
|
|
|
mod ast;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod checksum;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod colors;
|
2020-09-13 09:01:30 -04:00
|
|
|
mod coverage;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod deno_dir;
|
|
|
|
mod diagnostics;
|
2020-05-23 09:22:08 -04:00
|
|
|
mod diff;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod disk_cache;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod errors;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod file_fetcher;
|
2020-09-11 12:19:49 -04:00
|
|
|
mod file_watcher;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod flags;
|
2020-06-26 08:09:02 -04:00
|
|
|
mod flags_allow_net;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod fmt;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod fmt_errors;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod fs;
|
|
|
|
mod global_timer;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod http_cache;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod http_util;
|
|
|
|
mod import_map;
|
2020-09-07 09:59:47 -04:00
|
|
|
mod info;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod inspector;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod installer;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod js;
|
2020-06-10 17:29:48 -04:00
|
|
|
mod lint;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod lockfile;
|
2020-09-15 10:33:14 -04:00
|
|
|
mod media_type;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod metrics;
|
2020-05-18 06:59:29 -04:00
|
|
|
mod module_graph;
|
2020-10-07 01:24:15 -04:00
|
|
|
mod module_graph2;
|
2020-10-13 07:35:35 -04:00
|
|
|
mod module_loader;
|
2020-07-20 19:49:57 -04:00
|
|
|
mod op_fetch_asset;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod ops;
|
|
|
|
mod permissions;
|
2020-10-13 07:35:35 -04:00
|
|
|
mod program_state;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod repl;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod resolve_addr;
|
|
|
|
mod signal;
|
|
|
|
mod source_maps;
|
2020-09-24 18:31:17 -04:00
|
|
|
mod specifier_handler;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod test_runner;
|
2020-08-03 17:39:48 -04:00
|
|
|
mod text_encoding;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod tokio_util;
|
|
|
|
mod tsc;
|
2020-10-13 19:52:49 -04:00
|
|
|
pub mod tsc2;
|
2020-08-31 14:12:24 -04:00
|
|
|
mod tsc_config;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod upgrade;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod version;
|
|
|
|
mod worker;
|
2020-05-11 17:33:36 -04:00
|
|
|
|
2020-09-13 09:01:30 -04:00
|
|
|
use crate::coverage::CoverageCollector;
|
|
|
|
use crate::coverage::PrettyCoverageReporter;
|
2020-05-11 17:33:36 -04:00
|
|
|
use crate::file_fetcher::SourceFile;
|
|
|
|
use crate::file_fetcher::SourceFileFetcher;
|
2020-05-18 06:59:29 -04:00
|
|
|
use crate::fs as deno_fs;
|
2020-09-15 10:33:14 -04:00
|
|
|
use crate::media_type::MediaType;
|
2020-05-11 17:33:36 -04:00
|
|
|
use crate::permissions::Permissions;
|
2020-10-13 07:35:35 -04:00
|
|
|
use crate::program_state::ProgramState;
|
2020-05-11 17:33:36 -04:00
|
|
|
use crate::worker::MainWorker;
|
2020-09-14 12:48:57 -04:00
|
|
|
use deno_core::error::AnyError;
|
2020-09-21 12:36:37 -04:00
|
|
|
use deno_core::futures::future::FutureExt;
|
|
|
|
use deno_core::futures::Future;
|
|
|
|
use deno_core::serde_json;
|
|
|
|
use deno_core::serde_json::json;
|
2020-09-16 14:28:07 -04:00
|
|
|
use deno_core::url::Url;
|
2020-05-11 17:33:36 -04:00
|
|
|
use deno_core::v8_set_flags;
|
|
|
|
use deno_core::ModuleSpecifier;
|
2020-08-19 13:13:43 -04:00
|
|
|
use deno_doc as doc;
|
|
|
|
use deno_doc::parser::DocFileLoader;
|
2020-05-11 17:33:36 -04:00
|
|
|
use flags::DenoSubcommand;
|
|
|
|
use flags::Flags;
|
2020-10-11 19:05:46 -04:00
|
|
|
use import_map::ImportMap;
|
2020-05-11 17:33:36 -04:00
|
|
|
use log::Level;
|
2020-09-17 14:38:57 -04:00
|
|
|
use log::LevelFilter;
|
2020-10-13 07:35:35 -04:00
|
|
|
use program_state::exit_unstable;
|
2020-10-11 22:25:27 -04:00
|
|
|
use std::cell::RefCell;
|
2020-05-11 17:33:36 -04:00
|
|
|
use std::env;
|
2020-06-11 10:58:09 -04:00
|
|
|
use std::io::Read;
|
2020-05-11 17:33:36 -04:00
|
|
|
use std::io::Write;
|
2020-08-07 18:51:59 -04:00
|
|
|
use std::iter::once;
|
2020-05-11 17:33:36 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use std::pin::Pin;
|
2020-10-11 22:25:27 -04:00
|
|
|
use std::rc::Rc;
|
2020-08-18 12:30:13 -04:00
|
|
|
use std::sync::Arc;
|
2020-05-11 17:33:36 -04:00
|
|
|
use upgrade::upgrade_command;
|
|
|
|
|
|
|
|
fn write_to_stdout_ignore_sigpipe(bytes: &[u8]) -> Result<(), std::io::Error> {
|
|
|
|
use std::io::ErrorKind;
|
|
|
|
|
|
|
|
match std::io::stdout().write_all(bytes) {
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Err(e) => match e.kind() {
|
|
|
|
ErrorKind::BrokenPipe => Ok(()),
|
|
|
|
_ => Err(e),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
fn write_json_to_stdout<T>(value: &T) -> Result<(), AnyError>
|
2020-07-08 10:50:12 -04:00
|
|
|
where
|
|
|
|
T: ?Sized + serde::ser::Serialize,
|
|
|
|
{
|
|
|
|
let writer = std::io::BufWriter::new(std::io::stdout());
|
2020-09-14 12:48:57 -04:00
|
|
|
serde_json::to_writer_pretty(writer, value).map_err(AnyError::from)
|
2020-07-08 10:50:12 -04:00
|
|
|
}
|
|
|
|
|
2020-08-18 12:30:13 -04:00
|
|
|
fn print_cache_info(
|
2020-10-13 07:35:35 -04:00
|
|
|
state: &Arc<ProgramState>,
|
2020-08-18 12:30:13 -04:00
|
|
|
json: bool,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-07-08 10:50:12 -04:00
|
|
|
let deno_dir = &state.dir.root;
|
|
|
|
let modules_cache = &state.file_fetcher.http_cache.location;
|
|
|
|
let typescript_cache = &state.dir.gen_cache.location;
|
|
|
|
if json {
|
|
|
|
let output = json!({
|
|
|
|
"denoDir": deno_dir,
|
|
|
|
"modulesCache": modules_cache,
|
|
|
|
"typescriptCache": typescript_cache,
|
|
|
|
});
|
|
|
|
write_json_to_stdout(&output)
|
|
|
|
} else {
|
|
|
|
println!("{} {:?}", colors::bold("DENO_DIR location:"), deno_dir);
|
|
|
|
println!(
|
|
|
|
"{} {:?}",
|
|
|
|
colors::bold("Remote modules cache:"),
|
|
|
|
modules_cache
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"{} {:?}",
|
|
|
|
colors::bold("TypeScript compiler cache:"),
|
|
|
|
typescript_cache
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
fn get_types(unstable: bool) -> String {
|
2020-08-04 10:08:41 -04:00
|
|
|
let mut types = format!(
|
2020-09-18 09:20:55 -04:00
|
|
|
"{}\n{}\n{}\n{}\n{}",
|
2020-08-04 10:08:41 -04:00
|
|
|
crate::js::DENO_NS_LIB,
|
2020-08-07 10:55:02 -04:00
|
|
|
crate::js::DENO_WEB_LIB,
|
2020-09-18 09:20:55 -04:00
|
|
|
crate::js::DENO_FETCH_LIB,
|
2020-08-04 10:08:41 -04:00
|
|
|
crate::js::SHARED_GLOBALS_LIB,
|
|
|
|
crate::js::WINDOW_LIB,
|
|
|
|
);
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
if unstable {
|
2020-08-04 10:08:41 -04:00
|
|
|
types.push_str(&format!("\n{}", crate::js::UNSTABLE_NS_LIB,));
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
2020-08-04 10:08:41 -04:00
|
|
|
|
|
|
|
types
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn info_command(
|
|
|
|
flags: Flags,
|
2020-10-11 22:25:27 -04:00
|
|
|
maybe_specifier: Option<String>,
|
2020-07-08 10:50:12 -04:00
|
|
|
json: bool,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-07-08 10:50:12 -04:00
|
|
|
if json && !flags.unstable {
|
|
|
|
exit_unstable("--json");
|
|
|
|
}
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags)?;
|
2020-10-11 22:25:27 -04:00
|
|
|
if let Some(specifier) = maybe_specifier {
|
|
|
|
let specifier = ModuleSpecifier::resolve_url_or_path(&specifier)?;
|
|
|
|
let handler = Rc::new(RefCell::new(specifier_handler::FetchHandler::new(
|
2020-10-13 07:35:35 -04:00
|
|
|
&program_state,
|
2020-10-11 22:25:27 -04:00
|
|
|
Permissions::allow_all(),
|
|
|
|
)?));
|
|
|
|
let mut builder = module_graph2::GraphBuilder2::new(
|
|
|
|
handler,
|
2020-10-13 07:35:35 -04:00
|
|
|
program_state.maybe_import_map.clone(),
|
2020-10-11 22:25:27 -04:00
|
|
|
);
|
|
|
|
builder.insert(&specifier).await?;
|
2020-10-13 07:35:35 -04:00
|
|
|
let graph = builder.get_graph(&program_state.lockfile)?;
|
2020-10-11 22:25:27 -04:00
|
|
|
let info = graph.info()?;
|
2020-09-07 09:59:47 -04:00
|
|
|
|
|
|
|
if json {
|
2020-10-11 22:25:27 -04:00
|
|
|
write_json_to_stdout(&json!(info))?;
|
2020-09-07 09:59:47 -04:00
|
|
|
} else {
|
2020-10-11 22:25:27 -04:00
|
|
|
write_to_stdout_ignore_sigpipe(format!("{}", info).as_bytes())?;
|
2020-09-07 09:59:47 -04:00
|
|
|
}
|
2020-10-11 22:25:27 -04:00
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
// If it was just "deno info" print location of caches and exit
|
2020-10-13 07:35:35 -04:00
|
|
|
print_cache_info(&program_state, json)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn install_command(
|
|
|
|
flags: Flags,
|
|
|
|
module_url: String,
|
|
|
|
args: Vec<String>,
|
|
|
|
name: Option<String>,
|
|
|
|
root: Option<PathBuf>,
|
|
|
|
force: bool,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags.clone())?;
|
2020-09-16 11:56:06 -04:00
|
|
|
let main_module = ModuleSpecifier::resolve_url_or_path(&module_url)?;
|
2020-10-13 07:35:35 -04:00
|
|
|
let mut worker = MainWorker::new(&program_state, main_module.clone());
|
2020-09-20 08:05:11 -04:00
|
|
|
// First, fetch and compile the module; this step ensures that the module exists.
|
2020-09-16 11:56:06 -04:00
|
|
|
worker.preload_module(&main_module).await?;
|
|
|
|
installer::install(flags, &module_url, args, name, root, force)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 10:42:12 -04:00
|
|
|
async fn lint_command(
|
|
|
|
flags: Flags,
|
|
|
|
files: Vec<String>,
|
|
|
|
list_rules: bool,
|
2020-08-12 09:47:44 -04:00
|
|
|
ignore: Vec<String>,
|
2020-08-13 11:30:46 -04:00
|
|
|
json: bool,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-08-04 10:08:41 -04:00
|
|
|
if !flags.unstable {
|
|
|
|
exit_unstable("lint");
|
|
|
|
}
|
2020-06-12 10:42:12 -04:00
|
|
|
|
|
|
|
if list_rules {
|
|
|
|
lint::print_rules_list();
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
2020-08-13 11:30:46 -04:00
|
|
|
lint::lint_files(files, ignore, json).await
|
2020-06-08 08:06:20 -04:00
|
|
|
}
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
async fn cache_command(
|
|
|
|
flags: Flags,
|
|
|
|
files: Vec<String>,
|
|
|
|
) -> Result<(), AnyError> {
|
2020-05-11 17:33:36 -04:00
|
|
|
let main_module =
|
2020-09-12 05:33:51 -04:00
|
|
|
ModuleSpecifier::resolve_url_or_path("./$deno$cache.ts").unwrap();
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags)?;
|
|
|
|
let mut worker = MainWorker::new(&program_state, main_module.clone());
|
2020-05-11 17:33:36 -04:00
|
|
|
|
|
|
|
for file in files {
|
|
|
|
let specifier = ModuleSpecifier::resolve_url_or_path(&file)?;
|
2020-10-13 07:35:35 -04:00
|
|
|
// TODO(bartlomieju): don't use `preload_module` in favor of calling "ProgramState::prepare_module_load()"
|
2020-09-11 12:19:49 -04:00
|
|
|
// explicitly? Seems wasteful to create multiple worker just to run TS compiler
|
2020-05-11 17:33:36 -04:00
|
|
|
worker.preload_module(&specifier).await.map(|_| ())?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn eval_command(
|
|
|
|
flags: Flags,
|
|
|
|
code: String,
|
|
|
|
as_typescript: bool,
|
2020-05-21 10:35:36 -04:00
|
|
|
print: bool,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-05-11 17:33:36 -04:00
|
|
|
// Force TypeScript compile.
|
|
|
|
let main_module =
|
2020-09-12 05:33:51 -04:00
|
|
|
ModuleSpecifier::resolve_url_or_path("./$deno$eval.ts").unwrap();
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags)?;
|
|
|
|
let mut worker = MainWorker::new(&program_state, main_module.clone());
|
2020-05-11 17:33:36 -04:00
|
|
|
let main_module_url = main_module.as_url().to_owned();
|
|
|
|
// Create a dummy source file.
|
2020-05-21 10:35:36 -04:00
|
|
|
let source_code = if print {
|
2020-08-04 10:08:41 -04:00
|
|
|
format!("console.log({})", code)
|
2020-05-21 10:35:36 -04:00
|
|
|
} else {
|
2020-08-04 10:08:41 -04:00
|
|
|
code
|
2020-05-21 10:35:36 -04:00
|
|
|
}
|
|
|
|
.into_bytes();
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
let source_file = SourceFile {
|
|
|
|
filename: main_module_url.to_file_path().unwrap(),
|
|
|
|
url: main_module_url,
|
2020-05-18 06:59:29 -04:00
|
|
|
types_header: None,
|
2020-05-11 17:33:36 -04:00
|
|
|
media_type: if as_typescript {
|
|
|
|
MediaType::TypeScript
|
|
|
|
} else {
|
|
|
|
MediaType::JavaScript
|
|
|
|
},
|
2020-10-07 07:43:44 -04:00
|
|
|
source_code: String::from_utf8(source_code)?,
|
2020-05-11 17:33:36 -04:00
|
|
|
};
|
|
|
|
// Save our fake file into file fetcher cache
|
2020-08-04 10:08:41 -04:00
|
|
|
// to allow module access by TS compiler.
|
2020-10-13 07:35:35 -04:00
|
|
|
program_state
|
2020-05-11 17:33:36 -04:00
|
|
|
.file_fetcher
|
|
|
|
.save_source_file_in_cache(&main_module, source_file);
|
|
|
|
debug!("main_module {}", &main_module);
|
|
|
|
worker.execute_module(&main_module).await?;
|
|
|
|
worker.execute("window.dispatchEvent(new Event('load'))")?;
|
2020-10-11 07:20:40 -04:00
|
|
|
worker.run_event_loop().await?;
|
2020-05-11 17:33:36 -04:00
|
|
|
worker.execute("window.dispatchEvent(new Event('unload'))")?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn bundle_command(
|
|
|
|
flags: Flags,
|
|
|
|
source_file: String,
|
|
|
|
out_file: Option<PathBuf>,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-07-16 04:53:07 -04:00
|
|
|
let module_specifier = ModuleSpecifier::resolve_url_or_path(&source_file)?;
|
2020-05-18 06:59:29 -04:00
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
debug!(">>>>> bundle START");
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags)?;
|
2020-05-20 10:25:40 -04:00
|
|
|
|
2020-06-24 05:58:23 -04:00
|
|
|
info!(
|
|
|
|
"{} {}",
|
2020-06-29 08:17:37 -04:00
|
|
|
colors::green("Bundle"),
|
2020-06-24 05:58:23 -04:00
|
|
|
module_specifier.to_string()
|
|
|
|
);
|
2020-05-29 10:32:15 -04:00
|
|
|
|
2020-10-13 07:35:35 -04:00
|
|
|
let output = program_state
|
2020-06-30 07:10:51 -04:00
|
|
|
.ts_compiler
|
2020-10-13 07:35:35 -04:00
|
|
|
.bundle(&program_state, module_specifier)
|
2020-06-30 07:10:51 -04:00
|
|
|
.await?;
|
2020-05-20 10:25:40 -04:00
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
debug!(">>>>> bundle END");
|
2020-05-29 10:32:15 -04:00
|
|
|
|
|
|
|
if let Some(out_file_) = out_file.as_ref() {
|
2020-06-04 08:36:25 -04:00
|
|
|
let output_bytes = output.as_bytes();
|
2020-05-29 10:32:15 -04:00
|
|
|
let output_len = output_bytes.len();
|
|
|
|
deno_fs::write_file(out_file_, output_bytes, 0o666)?;
|
2020-06-24 05:58:23 -04:00
|
|
|
info!(
|
|
|
|
"{} {:?} ({})",
|
2020-06-29 08:17:37 -04:00
|
|
|
colors::green("Emit"),
|
2020-06-24 05:58:23 -04:00
|
|
|
out_file_,
|
2020-09-07 09:59:47 -04:00
|
|
|
colors::gray(&info::human_size(output_len as f64))
|
2020-06-24 05:58:23 -04:00
|
|
|
);
|
2020-05-29 10:32:15 -04:00
|
|
|
} else {
|
2020-06-04 08:36:25 -04:00
|
|
|
println!("{}", output);
|
2020-05-29 10:32:15 -04:00
|
|
|
}
|
|
|
|
Ok(())
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2020-10-11 19:05:46 -04:00
|
|
|
struct DocLoader {
|
|
|
|
fetcher: SourceFileFetcher,
|
|
|
|
maybe_import_map: Option<ImportMap>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DocFileLoader for DocLoader {
|
|
|
|
fn resolve(
|
|
|
|
&self,
|
|
|
|
specifier: &str,
|
|
|
|
referrer: &str,
|
|
|
|
) -> Result<String, doc::DocError> {
|
|
|
|
let maybe_resolved =
|
|
|
|
if let Some(import_map) = self.maybe_import_map.as_ref() {
|
|
|
|
import_map
|
|
|
|
.resolve(specifier, referrer)
|
|
|
|
.map_err(|e| doc::DocError::Resolve(e.to_string()))?
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
let resolved_specifier = if let Some(resolved) = maybe_resolved {
|
|
|
|
resolved
|
|
|
|
} else {
|
|
|
|
ModuleSpecifier::resolve_import(specifier, referrer)
|
|
|
|
.map_err(|e| doc::DocError::Resolve(e.to_string()))?
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(resolved_specifier.to_string())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn load_source_code(
|
|
|
|
&self,
|
|
|
|
specifier: &str,
|
|
|
|
) -> Pin<Box<dyn Future<Output = Result<String, doc::DocError>>>> {
|
|
|
|
let fetcher = self.fetcher.clone();
|
|
|
|
let specifier = ModuleSpecifier::resolve_url_or_path(specifier)
|
|
|
|
.expect("Expected valid specifier");
|
|
|
|
async move {
|
|
|
|
let source_file = fetcher
|
|
|
|
.fetch_source_file(&specifier, None, Permissions::allow_all())
|
|
|
|
.await
|
|
|
|
.map_err(|e| {
|
|
|
|
doc::DocError::Io(std::io::Error::new(
|
|
|
|
std::io::ErrorKind::Other,
|
|
|
|
e.to_string(),
|
|
|
|
))
|
|
|
|
})?;
|
|
|
|
Ok(source_file.source_code)
|
|
|
|
}
|
|
|
|
.boxed_local()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
async fn doc_command(
|
|
|
|
flags: Flags,
|
|
|
|
source_file: Option<String>,
|
|
|
|
json: bool,
|
|
|
|
maybe_filter: Option<String>,
|
2020-07-12 08:16:33 -04:00
|
|
|
private: bool,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags.clone())?;
|
2020-05-11 17:33:36 -04:00
|
|
|
let source_file = source_file.unwrap_or_else(|| "--builtin".to_string());
|
|
|
|
|
2020-10-11 19:05:46 -04:00
|
|
|
let loader = Box::new(DocLoader {
|
2020-10-13 07:35:35 -04:00
|
|
|
fetcher: program_state.file_fetcher.clone(),
|
|
|
|
maybe_import_map: program_state.maybe_import_map.clone(),
|
2020-10-11 19:05:46 -04:00
|
|
|
});
|
2020-07-12 08:16:33 -04:00
|
|
|
let doc_parser = doc::DocParser::new(loader, private);
|
2020-05-11 17:33:36 -04:00
|
|
|
|
|
|
|
let parse_result = if source_file == "--builtin" {
|
2020-09-15 10:33:14 -04:00
|
|
|
let syntax = ast::get_syntax(&MediaType::Dts);
|
2020-08-19 13:13:43 -04:00
|
|
|
doc_parser.parse_source(
|
|
|
|
"lib.deno.d.ts",
|
|
|
|
syntax,
|
|
|
|
get_types(flags.unstable).as_str(),
|
|
|
|
)
|
2020-05-11 17:33:36 -04:00
|
|
|
} else {
|
2020-08-23 09:48:35 -04:00
|
|
|
let path = PathBuf::from(&source_file);
|
2020-09-14 08:27:44 -04:00
|
|
|
let media_type = MediaType::from(&path);
|
|
|
|
let syntax = ast::get_syntax(&media_type);
|
2020-05-11 17:33:36 -04:00
|
|
|
let module_specifier =
|
|
|
|
ModuleSpecifier::resolve_url_or_path(&source_file).unwrap();
|
|
|
|
doc_parser
|
2020-08-19 13:13:43 -04:00
|
|
|
.parse_with_reexports(&module_specifier.to_string(), syntax)
|
2020-05-11 17:33:36 -04:00
|
|
|
.await
|
|
|
|
};
|
|
|
|
|
2020-08-10 11:41:19 -04:00
|
|
|
let mut doc_nodes = match parse_result {
|
2020-05-11 17:33:36 -04:00
|
|
|
Ok(nodes) => nodes,
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("{}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if json {
|
2020-07-08 10:50:12 -04:00
|
|
|
write_json_to_stdout(&doc_nodes)
|
2020-05-11 17:33:36 -04:00
|
|
|
} else {
|
2020-08-10 11:41:19 -04:00
|
|
|
doc_nodes.retain(|doc_node| doc_node.kind != doc::DocNodeKind::Import);
|
2020-05-11 17:33:36 -04:00
|
|
|
let details = if let Some(filter) = maybe_filter {
|
2020-06-09 08:12:47 -04:00
|
|
|
let nodes =
|
|
|
|
doc::find_nodes_by_name_recursively(doc_nodes, filter.clone());
|
|
|
|
if nodes.is_empty() {
|
2020-05-11 17:33:36 -04:00
|
|
|
eprintln!("Node {} was not found!", filter);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
2020-08-19 13:13:43 -04:00
|
|
|
format!(
|
|
|
|
"{}",
|
|
|
|
doc::DocPrinter::new(&nodes, colors::use_color(), private)
|
|
|
|
)
|
2020-05-11 17:33:36 -04:00
|
|
|
} else {
|
2020-08-19 13:13:43 -04:00
|
|
|
format!(
|
|
|
|
"{}",
|
|
|
|
doc::DocPrinter::new(&doc_nodes, colors::use_color(), private)
|
|
|
|
)
|
2020-05-11 17:33:36 -04:00
|
|
|
};
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
write_to_stdout_ignore_sigpipe(details.as_bytes()).map_err(AnyError::from)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
async fn run_repl(flags: Flags) -> Result<(), AnyError> {
|
2020-05-11 17:33:36 -04:00
|
|
|
let main_module =
|
2020-09-12 05:33:51 -04:00
|
|
|
ModuleSpecifier::resolve_url_or_path("./$deno$repl.ts").unwrap();
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags)?;
|
|
|
|
let mut worker = MainWorker::new(&program_state, main_module.clone());
|
2020-10-11 07:20:40 -04:00
|
|
|
worker.run_event_loop().await?;
|
2020-10-01 19:14:55 -04:00
|
|
|
|
2020-10-13 07:35:35 -04:00
|
|
|
repl::run(&program_state, worker).await
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
async fn run_from_stdin(flags: Flags) -> Result<(), AnyError> {
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags.clone())?;
|
2020-09-11 12:19:49 -04:00
|
|
|
let main_module =
|
2020-09-12 05:33:51 -04:00
|
|
|
ModuleSpecifier::resolve_url_or_path("./$deno$stdin.ts").unwrap();
|
2020-10-13 07:35:35 -04:00
|
|
|
let mut worker = MainWorker::new(&program_state.clone(), main_module.clone());
|
2020-09-11 12:19:49 -04:00
|
|
|
|
|
|
|
let mut source = Vec::new();
|
|
|
|
std::io::stdin().read_to_end(&mut source)?;
|
|
|
|
let main_module_url = main_module.as_url().to_owned();
|
|
|
|
// Create a dummy source file.
|
|
|
|
let source_file = SourceFile {
|
|
|
|
filename: main_module_url.to_file_path().unwrap(),
|
|
|
|
url: main_module_url,
|
|
|
|
types_header: None,
|
|
|
|
media_type: MediaType::TypeScript,
|
2020-10-07 07:43:44 -04:00
|
|
|
source_code: String::from_utf8(source)?,
|
2020-06-11 10:58:09 -04:00
|
|
|
};
|
2020-09-11 12:19:49 -04:00
|
|
|
// Save our fake file into file fetcher cache
|
|
|
|
// to allow module access by TS compiler
|
2020-10-13 07:35:35 -04:00
|
|
|
program_state
|
2020-09-11 12:19:49 -04:00
|
|
|
.file_fetcher
|
|
|
|
.save_source_file_in_cache(&main_module, source_file);
|
|
|
|
|
|
|
|
debug!("main_module {}", main_module);
|
|
|
|
worker.execute_module(&main_module).await?;
|
|
|
|
worker.execute("window.dispatchEvent(new Event('load'))")?;
|
2020-10-11 07:20:40 -04:00
|
|
|
worker.run_event_loop().await?;
|
2020-09-11 12:19:49 -04:00
|
|
|
worker.execute("window.dispatchEvent(new Event('unload'))")?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
async fn run_with_watch(flags: Flags, script: String) -> Result<(), AnyError> {
|
2020-09-11 12:19:49 -04:00
|
|
|
let main_module = ModuleSpecifier::resolve_url_or_path(&script)?;
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags.clone())?;
|
2020-09-11 12:19:49 -04:00
|
|
|
|
|
|
|
let mut module_graph_loader = module_graph::ModuleGraphLoader::new(
|
2020-10-13 07:35:35 -04:00
|
|
|
program_state.file_fetcher.clone(),
|
|
|
|
program_state.maybe_import_map.clone(),
|
2020-09-11 12:19:49 -04:00
|
|
|
Permissions::allow_all(),
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
module_graph_loader.add_to_graph(&main_module, None).await?;
|
|
|
|
let module_graph = module_graph_loader.get_graph();
|
|
|
|
|
|
|
|
// Find all local files in graph
|
2020-09-23 07:56:16 -04:00
|
|
|
let mut paths_to_watch: Vec<PathBuf> = module_graph
|
2020-09-11 12:19:49 -04:00
|
|
|
.values()
|
|
|
|
.map(|f| Url::parse(&f.url).unwrap())
|
|
|
|
.filter(|url| url.scheme() == "file")
|
|
|
|
.map(|url| url.to_file_path().unwrap())
|
|
|
|
.collect();
|
|
|
|
|
2020-10-13 07:35:35 -04:00
|
|
|
if let Some(import_map) = program_state.flags.import_map_path.clone() {
|
2020-09-23 07:56:16 -04:00
|
|
|
paths_to_watch.push(
|
|
|
|
Url::parse(&format!("file://{}", &import_map))?
|
|
|
|
.to_file_path()
|
|
|
|
.unwrap(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-11 12:19:49 -04:00
|
|
|
// FIXME(bartlomieju): new file watcher is created on after each restart
|
|
|
|
file_watcher::watch_func(&paths_to_watch, move || {
|
2020-10-13 07:35:35 -04:00
|
|
|
// FIXME(bartlomieju): ProgramState must be created on each restart - otherwise file fetcher
|
2020-09-11 12:19:49 -04:00
|
|
|
// will use cached source files
|
2020-10-13 07:35:35 -04:00
|
|
|
let gs = ProgramState::new(flags.clone()).unwrap();
|
2020-09-11 12:19:49 -04:00
|
|
|
let main_module = main_module.clone();
|
|
|
|
async move {
|
2020-09-26 12:16:33 -04:00
|
|
|
let mut worker = MainWorker::new(&gs, main_module.clone());
|
2020-09-11 12:19:49 -04:00
|
|
|
debug!("main_module {}", main_module);
|
|
|
|
worker.execute_module(&main_module).await?;
|
|
|
|
worker.execute("window.dispatchEvent(new Event('load'))")?;
|
2020-10-11 07:20:40 -04:00
|
|
|
worker.run_event_loop().await?;
|
2020-09-11 12:19:49 -04:00
|
|
|
worker.execute("window.dispatchEvent(new Event('unload'))")?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
.boxed_local()
|
|
|
|
})
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
async fn run_command(flags: Flags, script: String) -> Result<(), AnyError> {
|
2020-09-11 12:19:49 -04:00
|
|
|
// Read script content from stdin
|
|
|
|
if script == "-" {
|
|
|
|
return run_from_stdin(flags).await;
|
|
|
|
}
|
|
|
|
|
|
|
|
if flags.watch {
|
|
|
|
return run_with_watch(flags, script).await;
|
|
|
|
}
|
2020-06-11 10:58:09 -04:00
|
|
|
|
2020-09-11 12:19:49 -04:00
|
|
|
let main_module = ModuleSpecifier::resolve_url_or_path(&script)?;
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags.clone())?;
|
|
|
|
let mut worker = MainWorker::new(&program_state, main_module.clone());
|
2020-05-11 17:33:36 -04:00
|
|
|
debug!("main_module {}", main_module);
|
|
|
|
worker.execute_module(&main_module).await?;
|
|
|
|
worker.execute("window.dispatchEvent(new Event('load'))")?;
|
2020-10-11 07:20:40 -04:00
|
|
|
worker.run_event_loop().await?;
|
2020-05-11 17:33:36 -04:00
|
|
|
worker.execute("window.dispatchEvent(new Event('unload'))")?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn test_command(
|
|
|
|
flags: Flags,
|
|
|
|
include: Option<Vec<String>>,
|
|
|
|
fail_fast: bool,
|
|
|
|
quiet: bool,
|
|
|
|
allow_none: bool,
|
|
|
|
filter: Option<String>,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-10-13 07:35:35 -04:00
|
|
|
let program_state = ProgramState::new(flags.clone())?;
|
2020-05-11 17:33:36 -04:00
|
|
|
let cwd = std::env::current_dir().expect("No current directory");
|
|
|
|
let include = include.unwrap_or_else(|| vec![".".to_string()]);
|
|
|
|
let test_modules = test_runner::prepare_test_modules_urls(include, &cwd)?;
|
|
|
|
|
|
|
|
if test_modules.is_empty() {
|
|
|
|
println!("No matching test modules found");
|
|
|
|
if !allow_none {
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
2020-09-27 14:21:11 -04:00
|
|
|
let test_file_path = cwd.join("$deno$test.ts");
|
2020-05-11 17:33:36 -04:00
|
|
|
let test_file_url =
|
|
|
|
Url::from_file_path(&test_file_path).expect("Should be valid file url");
|
2020-09-13 09:01:30 -04:00
|
|
|
let test_file = test_runner::render_test_file(
|
|
|
|
test_modules.clone(),
|
|
|
|
fail_fast,
|
|
|
|
quiet,
|
|
|
|
filter,
|
|
|
|
);
|
2020-05-11 17:33:36 -04:00
|
|
|
let main_module =
|
|
|
|
ModuleSpecifier::resolve_url(&test_file_url.to_string()).unwrap();
|
2020-10-13 07:35:35 -04:00
|
|
|
let mut worker = MainWorker::new(&program_state, main_module.clone());
|
2020-05-11 17:33:36 -04:00
|
|
|
// Create a dummy source file.
|
|
|
|
let source_file = SourceFile {
|
|
|
|
filename: test_file_url.to_file_path().unwrap(),
|
2020-09-13 09:01:30 -04:00
|
|
|
url: test_file_url.clone(),
|
2020-05-18 06:59:29 -04:00
|
|
|
types_header: None,
|
2020-05-11 17:33:36 -04:00
|
|
|
media_type: MediaType::TypeScript,
|
2020-10-07 07:43:44 -04:00
|
|
|
source_code: test_file.clone(),
|
2020-05-11 17:33:36 -04:00
|
|
|
};
|
|
|
|
// Save our fake file into file fetcher cache
|
2020-08-04 10:08:41 -04:00
|
|
|
// to allow module access by TS compiler
|
2020-10-13 07:35:35 -04:00
|
|
|
program_state
|
2020-05-11 17:33:36 -04:00
|
|
|
.file_fetcher
|
|
|
|
.save_source_file_in_cache(&main_module, source_file);
|
2020-09-13 09:01:30 -04:00
|
|
|
|
2020-09-28 06:22:29 -04:00
|
|
|
let mut maybe_coverage_collector = if flags.coverage {
|
2020-10-11 07:20:40 -04:00
|
|
|
let session = worker.create_inspector_session();
|
|
|
|
let mut coverage_collector = CoverageCollector::new(session);
|
2020-09-13 09:01:30 -04:00
|
|
|
coverage_collector.start_collecting().await?;
|
|
|
|
|
|
|
|
Some(coverage_collector)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
let execute_result = worker.execute_module(&main_module).await;
|
|
|
|
execute_result?;
|
|
|
|
worker.execute("window.dispatchEvent(new Event('load'))")?;
|
2020-10-11 07:20:40 -04:00
|
|
|
worker.run_event_loop().await?;
|
2020-09-13 09:01:30 -04:00
|
|
|
worker.execute("window.dispatchEvent(new Event('unload'))")?;
|
2020-10-11 07:20:40 -04:00
|
|
|
worker.run_event_loop().await?;
|
2020-09-13 09:01:30 -04:00
|
|
|
|
|
|
|
if let Some(coverage_collector) = maybe_coverage_collector.as_mut() {
|
2020-09-23 14:12:24 -04:00
|
|
|
let coverages = coverage_collector.collect().await?;
|
2020-09-13 09:01:30 -04:00
|
|
|
coverage_collector.stop_collecting().await?;
|
|
|
|
|
2020-09-23 14:12:24 -04:00
|
|
|
let filtered_coverages =
|
|
|
|
coverage::filter_script_coverages(coverages, test_file_url, test_modules);
|
2020-09-13 09:01:30 -04:00
|
|
|
|
2020-09-23 14:12:24 -04:00
|
|
|
let mut coverage_reporter = PrettyCoverageReporter::new(quiet);
|
|
|
|
for coverage in filtered_coverages {
|
|
|
|
coverage_reporter.visit_coverage(&coverage);
|
|
|
|
}
|
2020-09-13 09:01:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
#[cfg(windows)]
|
|
|
|
colors::enable_ansi(); // For Windows 10
|
|
|
|
|
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
let flags = flags::flags_from_vec(args);
|
|
|
|
|
|
|
|
if let Some(ref v8_flags) = flags.v8_flags {
|
2020-08-07 18:51:59 -04:00
|
|
|
let v8_flags_includes_help = v8_flags
|
|
|
|
.iter()
|
|
|
|
.any(|flag| flag == "-help" || flag == "--help");
|
|
|
|
let v8_flags = once("UNUSED_BUT_NECESSARY_ARG0".to_owned())
|
|
|
|
.chain(v8_flags.iter().cloned())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let unrecognized_v8_flags = v8_set_flags(v8_flags)
|
|
|
|
.into_iter()
|
|
|
|
.skip(1)
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
if !unrecognized_v8_flags.is_empty() {
|
|
|
|
for f in unrecognized_v8_flags {
|
|
|
|
eprintln!("error: V8 did not recognize flag '{}'", f);
|
|
|
|
}
|
|
|
|
eprintln!();
|
|
|
|
eprintln!("For a list of V8 flags, use '--v8-flags=--help'");
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
if v8_flags_includes_help {
|
|
|
|
std::process::exit(0);
|
|
|
|
}
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
let log_level = match flags.log_level {
|
|
|
|
Some(level) => level,
|
|
|
|
None => Level::Info, // Default log level
|
|
|
|
};
|
2020-09-03 16:16:49 -04:00
|
|
|
env_logger::Builder::from_env(
|
|
|
|
env_logger::Env::default()
|
|
|
|
.default_filter_or(log_level.to_level_filter().to_string()),
|
|
|
|
)
|
2020-09-17 14:38:57 -04:00
|
|
|
// https://github.com/denoland/deno/issues/6641
|
|
|
|
.filter_module("rustyline", LevelFilter::Off)
|
2020-09-03 16:16:49 -04:00
|
|
|
.format(|buf, record| {
|
|
|
|
let mut target = record.target().to_string();
|
|
|
|
if let Some(line_no) = record.line() {
|
2020-09-14 18:05:17 -04:00
|
|
|
target.push(':');
|
2020-09-03 16:16:49 -04:00
|
|
|
target.push_str(&line_no.to_string());
|
|
|
|
}
|
2020-09-22 11:08:10 -04:00
|
|
|
if record.level() <= Level::Info {
|
|
|
|
// Print ERROR, WARN, INFO logs as they are
|
2020-09-03 16:16:49 -04:00
|
|
|
writeln!(buf, "{}", record.args())
|
|
|
|
} else {
|
2020-09-22 11:08:10 -04:00
|
|
|
// Add prefix to DEBUG or TRACE logs
|
2020-09-03 16:16:49 -04:00
|
|
|
writeln!(
|
|
|
|
buf,
|
|
|
|
"{} RS - {} - {}",
|
|
|
|
record.level(),
|
|
|
|
target,
|
|
|
|
record.args()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.init();
|
2020-05-11 17:33:36 -04:00
|
|
|
|
|
|
|
let fut = match flags.clone().subcommand {
|
|
|
|
DenoSubcommand::Bundle {
|
|
|
|
source_file,
|
|
|
|
out_file,
|
|
|
|
} => bundle_command(flags, source_file, out_file).boxed_local(),
|
|
|
|
DenoSubcommand::Doc {
|
|
|
|
source_file,
|
|
|
|
json,
|
|
|
|
filter,
|
2020-07-12 08:16:33 -04:00
|
|
|
private,
|
|
|
|
} => doc_command(flags, source_file, json, filter, private).boxed_local(),
|
2020-05-11 17:33:36 -04:00
|
|
|
DenoSubcommand::Eval {
|
2020-05-21 10:35:36 -04:00
|
|
|
print,
|
2020-05-11 17:33:36 -04:00
|
|
|
code,
|
|
|
|
as_typescript,
|
2020-05-21 10:35:36 -04:00
|
|
|
} => eval_command(flags, code, as_typescript, print).boxed_local(),
|
2020-05-11 17:33:36 -04:00
|
|
|
DenoSubcommand::Cache { files } => {
|
|
|
|
cache_command(flags, files).boxed_local()
|
|
|
|
}
|
2020-07-30 12:09:08 -04:00
|
|
|
DenoSubcommand::Fmt {
|
|
|
|
check,
|
|
|
|
files,
|
|
|
|
ignore,
|
|
|
|
} => fmt::format(files, check, ignore).boxed_local(),
|
2020-07-08 10:50:12 -04:00
|
|
|
DenoSubcommand::Info { file, json } => {
|
|
|
|
info_command(flags, file, json).boxed_local()
|
|
|
|
}
|
2020-05-11 17:33:36 -04:00
|
|
|
DenoSubcommand::Install {
|
|
|
|
module_url,
|
|
|
|
args,
|
|
|
|
name,
|
|
|
|
root,
|
|
|
|
force,
|
|
|
|
} => {
|
|
|
|
install_command(flags, module_url, args, name, root, force).boxed_local()
|
|
|
|
}
|
2020-08-12 09:47:44 -04:00
|
|
|
DenoSubcommand::Lint {
|
|
|
|
files,
|
|
|
|
rules,
|
|
|
|
ignore,
|
2020-08-13 11:30:46 -04:00
|
|
|
json,
|
|
|
|
} => lint_command(flags, files, rules, ignore, json).boxed_local(),
|
2020-05-11 17:33:36 -04:00
|
|
|
DenoSubcommand::Repl => run_repl(flags).boxed_local(),
|
|
|
|
DenoSubcommand::Run { script } => run_command(flags, script).boxed_local(),
|
|
|
|
DenoSubcommand::Test {
|
|
|
|
fail_fast,
|
|
|
|
quiet,
|
|
|
|
include,
|
|
|
|
allow_none,
|
|
|
|
filter,
|
2020-09-28 06:22:29 -04:00
|
|
|
} => test_command(flags, include, fail_fast, quiet, allow_none, filter)
|
|
|
|
.boxed_local(),
|
2020-05-11 17:33:36 -04:00
|
|
|
DenoSubcommand::Completions { buf } => {
|
|
|
|
if let Err(e) = write_to_stdout_ignore_sigpipe(&buf) {
|
|
|
|
eprintln!("{}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DenoSubcommand::Types => {
|
|
|
|
let types = get_types(flags.unstable);
|
|
|
|
if let Err(e) = write_to_stdout_ignore_sigpipe(types.as_bytes()) {
|
|
|
|
eprintln!("{}", e);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DenoSubcommand::Upgrade {
|
|
|
|
force,
|
|
|
|
dry_run,
|
|
|
|
version,
|
2020-07-06 18:21:26 -04:00
|
|
|
output,
|
2020-07-05 23:58:23 -04:00
|
|
|
ca_file,
|
2020-07-06 18:21:26 -04:00
|
|
|
} => {
|
|
|
|
upgrade_command(dry_run, force, version, output, ca_file).boxed_local()
|
|
|
|
}
|
2020-05-11 17:33:36 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
let result = tokio_util::run_basic(fut);
|
|
|
|
if let Err(err) = result {
|
2020-06-29 08:17:37 -04:00
|
|
|
let msg = format!("{}: {}", colors::red_bold("error"), err.to_string(),);
|
2020-05-11 17:33:36 -04:00
|
|
|
eprintln!("{}", msg);
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
2018-06-15 19:43:23 -04:00
|
|
|
}
|