2019-01-01 19:58:40 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-07-26 17:54:22 -04:00
|
|
|
#[macro_use]
|
2018-09-24 19:51:37 -04:00
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
2018-07-26 17:54:22 -04:00
|
|
|
extern crate log;
|
2018-10-26 21:34:42 -04:00
|
|
|
#[macro_use]
|
|
|
|
extern crate futures;
|
2019-01-09 12:59:46 -05:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_json;
|
2018-07-26 17:54:22 -04:00
|
|
|
|
2019-01-09 12:59:46 -05:00
|
|
|
pub mod compiler;
|
2018-10-31 11:11:10 -07:00
|
|
|
pub mod deno_dir;
|
|
|
|
pub mod errors;
|
|
|
|
pub mod flags;
|
2018-07-26 17:54:22 -04:00
|
|
|
mod fs;
|
2018-10-25 19:14:04 -04:00
|
|
|
mod http_body;
|
2018-10-10 13:35:10 -04:00
|
|
|
mod http_util;
|
2018-10-31 11:11:10 -07:00
|
|
|
pub mod isolate;
|
2018-12-06 23:05:36 -05:00
|
|
|
pub mod js_errors;
|
2018-10-31 11:11:10 -07:00
|
|
|
pub mod libdeno;
|
|
|
|
pub mod msg;
|
2018-11-02 20:09:10 -04:00
|
|
|
pub mod msg_util;
|
2018-10-03 20:48:02 -04:00
|
|
|
pub mod ops;
|
2018-10-31 11:11:10 -07:00
|
|
|
pub mod permissions;
|
2018-11-05 09:55:59 -08:00
|
|
|
mod repl;
|
2019-01-13 22:14:59 -05:00
|
|
|
pub mod resolve_addr;
|
2018-10-31 11:11:10 -07:00
|
|
|
pub mod resources;
|
|
|
|
pub mod snapshot;
|
2018-09-18 11:53:16 -07:00
|
|
|
mod tokio_util;
|
2018-10-19 16:10:25 -04:00
|
|
|
mod tokio_write;
|
2018-10-31 11:11:10 -07:00
|
|
|
pub mod version;
|
2019-01-09 12:59:46 -05:00
|
|
|
pub mod workers;
|
2018-07-04 14:50:28 -04:00
|
|
|
|
2018-10-24 03:12:21 +02:00
|
|
|
#[cfg(unix)]
|
|
|
|
mod eager_unix;
|
|
|
|
|
2019-01-30 00:37:27 +09:00
|
|
|
use log::{LevelFilter, Metadata, Record};
|
2018-07-25 18:27:27 -07:00
|
|
|
use std::env;
|
2018-11-30 11:03:00 +08:00
|
|
|
use std::sync::Arc;
|
2018-07-26 17:37:09 -04:00
|
|
|
|
|
|
|
static LOGGER: Logger = Logger;
|
|
|
|
|
|
|
|
struct Logger;
|
|
|
|
|
|
|
|
impl log::Log for Logger {
|
2019-01-30 00:37:27 +09:00
|
|
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
2018-08-07 13:33:36 -04:00
|
|
|
metadata.level() <= log::max_level()
|
2018-07-26 17:37:09 -04:00
|
|
|
}
|
|
|
|
|
2019-01-30 00:37:27 +09:00
|
|
|
fn log(&self, record: &Record) {
|
2018-07-26 17:37:09 -04:00
|
|
|
if self.enabled(record.metadata()) {
|
2018-08-17 16:34:30 -04:00
|
|
|
println!("{} RS - {}", record.level(), record.args());
|
2018-07-26 17:37:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
fn flush(&self) {}
|
|
|
|
}
|
|
|
|
|
2019-02-02 01:58:53 -05:00
|
|
|
fn print_err_and_exit(err: errors::RustOrJsError) {
|
2018-12-10 17:50:41 -05:00
|
|
|
eprintln!("{}", err.to_string());
|
2018-12-06 23:05:36 -05:00
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
|
2018-06-16 01:43:23 +02:00
|
|
|
fn main() {
|
2019-02-08 00:19:50 +03:00
|
|
|
#[cfg(windows)]
|
|
|
|
ansi_term::enable_ansi_support().ok(); // For Windows 10
|
|
|
|
|
2018-07-26 17:37:09 -04:00
|
|
|
log::set_logger(&LOGGER).unwrap();
|
2018-09-22 01:03:24 -04:00
|
|
|
let args = env::args().collect();
|
2019-02-01 18:29:00 -05:00
|
|
|
let (mut flags, mut rest_argv, usage_string) = flags::set_flags(args)
|
|
|
|
.unwrap_or_else(|err| {
|
2018-10-23 21:02:43 -07:00
|
|
|
eprintln!("{}", err);
|
|
|
|
std::process::exit(1)
|
|
|
|
});
|
2018-11-05 22:41:39 -08:00
|
|
|
|
|
|
|
if flags.help {
|
|
|
|
println!("{}", &usage_string);
|
|
|
|
std::process::exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
log::set_max_level(if flags.log_debug {
|
2019-01-30 00:37:27 +09:00
|
|
|
LevelFilter::Debug
|
2018-11-05 22:41:39 -08:00
|
|
|
} else {
|
2019-01-30 00:37:27 +09:00
|
|
|
LevelFilter::Warn
|
2018-11-05 22:41:39 -08:00
|
|
|
});
|
|
|
|
|
2019-02-01 18:29:00 -05:00
|
|
|
if flags.fmt {
|
|
|
|
rest_argv.insert(1, "https://deno.land/x/std/prettier/main.ts".to_string());
|
|
|
|
flags.allow_write = true;
|
|
|
|
}
|
|
|
|
|
2019-01-15 09:19:58 -08:00
|
|
|
let should_prefetch = flags.prefetch;
|
2019-02-01 22:28:31 -08:00
|
|
|
let should_display_info = flags.info;
|
2019-01-15 09:19:58 -08:00
|
|
|
|
2019-01-08 14:44:06 -05:00
|
|
|
let state = Arc::new(isolate::IsolateState::new(flags, rest_argv, None));
|
2018-11-12 17:17:30 -08:00
|
|
|
let snapshot = snapshot::deno_snapshot();
|
2019-01-30 17:21:31 -05:00
|
|
|
let mut isolate = isolate::Isolate::new(snapshot, state, ops::dispatch);
|
2019-01-09 12:59:46 -05:00
|
|
|
|
2018-09-18 11:53:16 -07:00
|
|
|
tokio_util::init(|| {
|
2019-01-09 12:59:46 -05:00
|
|
|
// Setup runtime.
|
2018-09-18 11:53:16 -07:00
|
|
|
isolate
|
2018-12-11 14:03:58 -05:00
|
|
|
.execute("denoMain();")
|
2019-02-02 01:58:53 -05:00
|
|
|
.map_err(errors::RustOrJsError::from)
|
2018-12-06 23:05:36 -05:00
|
|
|
.unwrap_or_else(print_err_and_exit);
|
2019-01-09 12:59:46 -05:00
|
|
|
|
|
|
|
// Execute input file.
|
|
|
|
if isolate.state.argv.len() > 1 {
|
2019-01-30 17:21:31 -05:00
|
|
|
let input_filename = isolate.state.argv[1].clone();
|
2019-02-02 14:39:28 -08:00
|
|
|
if should_display_info {
|
|
|
|
// Display file info and exit. Do not run file
|
|
|
|
isolate.state.dir.print_file_info(input_filename);
|
|
|
|
std::process::exit(0);
|
|
|
|
}
|
2019-01-09 12:59:46 -05:00
|
|
|
isolate
|
2019-01-30 17:21:31 -05:00
|
|
|
.execute_mod(&input_filename, should_prefetch)
|
2019-01-09 12:59:46 -05:00
|
|
|
.unwrap_or_else(print_err_and_exit);
|
|
|
|
}
|
|
|
|
|
2019-02-02 01:58:53 -05:00
|
|
|
isolate
|
|
|
|
.event_loop()
|
|
|
|
.map_err(errors::RustOrJsError::from)
|
|
|
|
.unwrap_or_else(print_err_and_exit);
|
2018-09-18 11:53:16 -07:00
|
|
|
});
|
2018-06-16 01:43:23 +02:00
|
|
|
}
|