2024-02-13 16:22:30 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
// Allow unused code warnings because we share
|
|
|
|
// code between the two bin targets.
|
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_imports)]
|
|
|
|
|
|
|
|
mod standalone;
|
|
|
|
|
|
|
|
mod args;
|
|
|
|
mod auth_tokens;
|
|
|
|
mod cache;
|
|
|
|
mod emit;
|
|
|
|
mod errors;
|
|
|
|
mod file_fetcher;
|
|
|
|
mod http_util;
|
|
|
|
mod js;
|
|
|
|
mod node;
|
|
|
|
mod npm;
|
|
|
|
mod resolver;
|
2024-08-15 19:59:16 +00:00
|
|
|
mod shared;
|
2024-07-10 03:06:08 +00:00
|
|
|
mod task_runner;
|
2024-02-13 16:22:30 +00:00
|
|
|
mod util;
|
|
|
|
mod version;
|
|
|
|
mod worker;
|
|
|
|
|
|
|
|
use deno_core::error::generic_error;
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_core::error::JsError;
|
|
|
|
use deno_runtime::fmt_errors::format_js_error;
|
|
|
|
use deno_runtime::tokio_util::create_and_run_current_thread_with_maybe_metrics;
|
|
|
|
pub use deno_runtime::UNSTABLE_GRANULAR_FLAGS;
|
|
|
|
use deno_terminal::colors;
|
2024-08-19 16:41:11 +00:00
|
|
|
use indexmap::IndexMap;
|
2024-02-13 16:22:30 +00:00
|
|
|
|
2024-03-31 14:58:19 +00:00
|
|
|
use std::borrow::Cow;
|
2024-07-09 21:33:41 +00:00
|
|
|
use std::collections::HashMap;
|
2024-02-13 16:22:30 +00:00
|
|
|
use std::env;
|
|
|
|
use std::env::current_exe;
|
|
|
|
|
|
|
|
use crate::args::Flags;
|
|
|
|
|
2024-05-09 02:45:06 +00:00
|
|
|
#[allow(clippy::print_stderr)]
|
2024-02-13 16:22:30 +00:00
|
|
|
pub(crate) fn unstable_exit_cb(feature: &str, api_name: &str) {
|
|
|
|
eprintln!(
|
|
|
|
"Unstable API '{api_name}'. The `--unstable-{}` flag must be provided.",
|
|
|
|
feature
|
|
|
|
);
|
|
|
|
std::process::exit(70);
|
|
|
|
}
|
|
|
|
|
2024-05-09 02:45:06 +00:00
|
|
|
#[allow(clippy::print_stderr)]
|
2024-02-13 16:22:30 +00:00
|
|
|
fn exit_with_message(message: &str, code: i32) -> ! {
|
|
|
|
eprintln!(
|
|
|
|
"{}: {}",
|
|
|
|
colors::red_bold("error"),
|
|
|
|
message.trim_start_matches("error: ")
|
|
|
|
);
|
|
|
|
std::process::exit(code);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
|
|
|
|
match result {
|
|
|
|
Ok(value) => value,
|
|
|
|
Err(error) => {
|
2024-05-09 02:45:06 +00:00
|
|
|
let mut error_string = format!("{:?}", error);
|
2024-02-13 16:22:30 +00:00
|
|
|
|
|
|
|
if let Some(e) = error.downcast_ref::<JsError>() {
|
|
|
|
error_string = format_js_error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit_with_message(&error_string, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-19 16:41:11 +00:00
|
|
|
fn load_env_vars(env_vars: &IndexMap<String, String>) {
|
2024-07-09 21:33:41 +00:00
|
|
|
env_vars.iter().for_each(|env_var| {
|
|
|
|
if env::var(env_var.0).is_err() {
|
|
|
|
std::env::set_var(env_var.0, env_var.1);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-13 16:22:30 +00:00
|
|
|
fn main() {
|
2024-08-20 01:20:06 +00:00
|
|
|
deno_runtime::deno_permissions::mark_standalone();
|
2024-03-22 21:03:56 +00:00
|
|
|
let args: Vec<_> = env::args_os().collect();
|
2024-08-01 04:15:13 +00:00
|
|
|
let standalone = standalone::extract_standalone(Cow::Owned(args));
|
2024-02-13 16:22:30 +00:00
|
|
|
let future = async move {
|
2024-03-05 22:14:49 +00:00
|
|
|
match standalone {
|
|
|
|
Ok(Some(future)) => {
|
|
|
|
let (metadata, eszip) = future.await?;
|
2024-07-09 21:33:41 +00:00
|
|
|
util::logger::init(metadata.log_level);
|
|
|
|
load_env_vars(&metadata.env_vars_from_env_file);
|
2024-03-31 14:58:19 +00:00
|
|
|
let exit_code = standalone::run(eszip, metadata).await?;
|
|
|
|
std::process::exit(exit_code);
|
2024-03-05 22:14:49 +00:00
|
|
|
}
|
|
|
|
Ok(None) => Ok(()),
|
2024-02-13 16:22:30 +00:00
|
|
|
Err(err) => Err(err),
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
unwrap_or_exit(create_and_run_current_thread_with_maybe_metrics(future));
|
|
|
|
}
|