2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2019-09-03 22:12:21 -04:00
|
|
|
|
2022-06-27 16:54:09 -04:00
|
|
|
mod args;
|
2021-02-15 21:50:27 -05:00
|
|
|
mod auth_tokens;
|
2021-10-10 17:26:22 -04:00
|
|
|
mod cache;
|
2022-02-07 11:05:49 -05:00
|
|
|
mod cdp;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod checksum;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod deno_dir;
|
2022-08-29 14:19:54 -04:00
|
|
|
mod deno_std;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod diagnostics;
|
2020-05-23 09:22:08 -04:00
|
|
|
mod diff;
|
2022-03-08 18:19:02 -05:00
|
|
|
mod display;
|
2021-10-10 17:26:22 -04:00
|
|
|
mod emit;
|
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-11-16 14:48:50 -05:00
|
|
|
mod fs_util;
|
2021-12-16 05:45:41 -05:00
|
|
|
mod graph_util;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod http_cache;
|
2020-05-11 17:33:36 -04:00
|
|
|
mod http_util;
|
|
|
|
mod lockfile;
|
2021-05-11 00:54:10 -04:00
|
|
|
mod logger;
|
2020-12-07 05:46:39 -05:00
|
|
|
mod lsp;
|
2020-10-13 07:35:35 -04:00
|
|
|
mod module_loader;
|
2022-08-20 11:31:33 -04:00
|
|
|
mod node;
|
2022-08-10 15:23:58 -04:00
|
|
|
mod npm;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod ops;
|
2021-09-24 11:10:42 -04:00
|
|
|
mod proc_state;
|
2022-09-09 15:57:39 -04:00
|
|
|
mod progress_bar;
|
2021-10-10 17:26:22 -04:00
|
|
|
mod resolver;
|
2020-11-30 14:35:12 -05:00
|
|
|
mod standalone;
|
2020-08-03 17:39:48 -04:00
|
|
|
mod text_encoding;
|
2020-11-19 13:19:34 -05:00
|
|
|
mod tools;
|
2020-11-02 14:41:20 -05:00
|
|
|
mod tsc;
|
2021-04-13 10:24:45 -04:00
|
|
|
mod unix_util;
|
2020-10-12 07:25:25 -04:00
|
|
|
mod version;
|
2021-10-25 11:16:16 -04:00
|
|
|
mod windows_util;
|
2022-08-11 16:59:12 -04:00
|
|
|
mod worker;
|
2020-05-11 17:33:36 -04:00
|
|
|
|
2022-06-27 16:54:09 -04:00
|
|
|
use crate::args::flags_from_vec;
|
|
|
|
use crate::args::BenchFlags;
|
|
|
|
use crate::args::BundleFlags;
|
|
|
|
use crate::args::CacheFlags;
|
|
|
|
use crate::args::CheckFlags;
|
|
|
|
use crate::args::CompileFlags;
|
|
|
|
use crate::args::CompletionsFlags;
|
|
|
|
use crate::args::CoverageFlags;
|
|
|
|
use crate::args::DenoSubcommand;
|
|
|
|
use crate::args::DocFlags;
|
|
|
|
use crate::args::EvalFlags;
|
|
|
|
use crate::args::Flags;
|
|
|
|
use crate::args::FmtFlags;
|
|
|
|
use crate::args::InfoFlags;
|
2022-08-19 19:37:05 -04:00
|
|
|
use crate::args::InitFlags;
|
2022-06-27 16:54:09 -04:00
|
|
|
use crate::args::InstallFlags;
|
|
|
|
use crate::args::LintFlags;
|
|
|
|
use crate::args::ReplFlags;
|
|
|
|
use crate::args::RunFlags;
|
|
|
|
use crate::args::TaskFlags;
|
|
|
|
use crate::args::TestFlags;
|
|
|
|
use crate::args::TypeCheckMode;
|
|
|
|
use crate::args::UninstallFlags;
|
|
|
|
use crate::args::UpgradeFlags;
|
|
|
|
use crate::args::VendorFlags;
|
2022-07-12 18:58:39 -04:00
|
|
|
use crate::cache::TypeCheckCache;
|
2022-06-28 16:45:55 -04:00
|
|
|
use crate::emit::TsConfigType;
|
2020-11-05 19:38:21 -05:00
|
|
|
use crate::file_fetcher::File;
|
2021-05-10 02:06:13 -04:00
|
|
|
use crate::file_watcher::ResolutionResult;
|
2021-12-16 05:45:41 -05:00
|
|
|
use crate::graph_util::graph_lock_or_exit;
|
|
|
|
use crate::graph_util::graph_valid;
|
2021-09-24 11:10:42 -04:00
|
|
|
use crate::proc_state::ProcState;
|
2021-10-10 17:26:22 -04:00
|
|
|
use crate::resolver::ImportMapResolver;
|
2021-11-08 20:26:39 -05:00
|
|
|
use crate::resolver::JsxResolver;
|
2022-09-02 10:54:40 -04:00
|
|
|
use crate::tools::check;
|
2022-06-27 16:54:09 -04:00
|
|
|
|
2022-06-29 11:51:11 -04:00
|
|
|
use args::CliOptions;
|
2021-09-07 10:39:32 -04:00
|
|
|
use deno_ast::MediaType;
|
2020-10-23 07:05:41 -04:00
|
|
|
use deno_core::error::generic_error;
|
2020-09-14 12:48:57 -04:00
|
|
|
use deno_core::error::AnyError;
|
2022-04-26 19:06:10 -04:00
|
|
|
use deno_core::error::JsError;
|
2020-09-21 12:36:37 -04:00
|
|
|
use deno_core::futures::future::FutureExt;
|
|
|
|
use deno_core::futures::Future;
|
2021-12-16 05:45:41 -05:00
|
|
|
use deno_core::parking_lot::RwLock;
|
2021-02-17 13:47:18 -05:00
|
|
|
use deno_core::resolve_url_or_path;
|
2020-09-21 12:36:37 -04:00
|
|
|
use deno_core::serde_json;
|
|
|
|
use deno_core::serde_json::json;
|
2020-05-11 17:33:36 -04:00
|
|
|
use deno_core::v8_set_flags;
|
|
|
|
use deno_core::ModuleSpecifier;
|
2021-09-12 12:04:17 -04:00
|
|
|
use deno_runtime::colors;
|
2022-09-02 16:53:23 -04:00
|
|
|
use deno_runtime::fmt_errors::format_js_error;
|
2020-12-13 13:45:53 -05:00
|
|
|
use deno_runtime::permissions::Permissions;
|
2022-07-11 13:02:23 -04:00
|
|
|
use deno_runtime::tokio_util::run_local;
|
2021-03-26 12:34:25 -04:00
|
|
|
use log::debug;
|
|
|
|
use log::info;
|
2022-08-23 10:39:19 -04:00
|
|
|
use npm::NpmPackageReference;
|
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-08-18 12:30:13 -04:00
|
|
|
use std::sync::Arc;
|
2022-08-11 16:59:12 -04:00
|
|
|
use worker::create_main_worker;
|
2020-12-11 12:49:26 -05:00
|
|
|
|
2021-02-25 10:24:05 -05:00
|
|
|
pub fn write_to_stdout_ignore_sigpipe(
|
|
|
|
bytes: &[u8],
|
|
|
|
) -> Result<(), std::io::Error> {
|
2020-05-11 17:33:36 -04:00
|
|
|
use std::io::ErrorKind;
|
|
|
|
|
|
|
|
match std::io::stdout().write_all(bytes) {
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Err(e) => match e.kind() {
|
|
|
|
ErrorKind::BrokenPipe => Ok(()),
|
|
|
|
_ => Err(e),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-25 10:24:05 -05:00
|
|
|
pub fn write_json_to_stdout<T>(value: &T) -> Result<(), AnyError>
|
2020-07-08 10:50:12 -04:00
|
|
|
where
|
|
|
|
T: ?Sized + serde::ser::Serialize,
|
|
|
|
{
|
2021-06-03 14:49:02 -04:00
|
|
|
let mut writer = std::io::BufWriter::new(std::io::stdout());
|
|
|
|
serde_json::to_writer_pretty(&mut writer, value)?;
|
|
|
|
writeln!(&mut writer)?;
|
|
|
|
Ok(())
|
2020-07-08 10:50:12 -04:00
|
|
|
}
|
|
|
|
|
2020-08-18 12:30:13 -04:00
|
|
|
fn print_cache_info(
|
2021-09-24 11:10:42 -04:00
|
|
|
state: &ProcState,
|
2020-08-18 12:30:13 -04:00
|
|
|
json: bool,
|
2021-10-10 17:26:22 -04:00
|
|
|
location: Option<&deno_core::url::Url>,
|
2020-09-14 12:48:57 -04:00
|
|
|
) -> Result<(), AnyError> {
|
2020-07-08 10:50:12 -04:00
|
|
|
let deno_dir = &state.dir.root;
|
2020-11-05 19:38:21 -05:00
|
|
|
let modules_cache = &state.file_fetcher.get_http_cache_location();
|
2022-09-13 11:59:01 -04:00
|
|
|
let npm_cache = &state.npm_cache.as_readonly().get_cache_location();
|
2020-07-08 10:50:12 -04:00
|
|
|
let typescript_cache = &state.dir.gen_cache.location;
|
2021-04-08 21:27:27 -04:00
|
|
|
let registry_cache =
|
|
|
|
&state.dir.root.join(lsp::language_server::REGISTRIES_PATH);
|
2021-05-27 01:23:12 -04:00
|
|
|
let mut origin_dir = state.dir.root.join("location_data");
|
|
|
|
|
|
|
|
if let Some(location) = &location {
|
|
|
|
origin_dir =
|
|
|
|
origin_dir.join(&checksum::gen(&[location.to_string().as_bytes()]));
|
|
|
|
}
|
|
|
|
|
2022-03-10 19:57:57 -05:00
|
|
|
let local_storage_dir = origin_dir.join("local_storage");
|
|
|
|
|
2020-07-08 10:50:12 -04:00
|
|
|
if json {
|
2021-05-27 01:23:12 -04:00
|
|
|
let mut output = json!({
|
|
|
|
"denoDir": deno_dir,
|
|
|
|
"modulesCache": modules_cache,
|
2022-09-03 09:31:01 -04:00
|
|
|
"npmCache": npm_cache,
|
2021-05-27 01:23:12 -04:00
|
|
|
"typescriptCache": typescript_cache,
|
|
|
|
"registryCache": registry_cache,
|
|
|
|
"originStorage": origin_dir,
|
2020-07-08 10:50:12 -04:00
|
|
|
});
|
2021-05-27 01:23:12 -04:00
|
|
|
|
|
|
|
if location.is_some() {
|
2022-03-10 19:57:57 -05:00
|
|
|
output["localStorage"] = serde_json::to_value(local_storage_dir)?;
|
2021-05-27 01:23:12 -04:00
|
|
|
}
|
|
|
|
|
2020-07-08 10:50:12 -04:00
|
|
|
write_json_to_stdout(&output)
|
|
|
|
} else {
|
|
|
|
println!(
|
2022-03-10 19:57:57 -05:00
|
|
|
"{} {}",
|
|
|
|
colors::bold("DENO_DIR location:"),
|
|
|
|
deno_dir.display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"{} {}",
|
2020-07-08 10:50:12 -04:00
|
|
|
colors::bold("Remote modules cache:"),
|
2022-03-10 19:57:57 -05:00
|
|
|
modules_cache.display()
|
2020-07-08 10:50:12 -04:00
|
|
|
);
|
2022-09-03 09:31:01 -04:00
|
|
|
println!(
|
|
|
|
"{} {}",
|
|
|
|
colors::bold("npm modules cache:"),
|
|
|
|
npm_cache.display()
|
|
|
|
);
|
2020-07-08 10:50:12 -04:00
|
|
|
println!(
|
2022-03-10 19:57:57 -05:00
|
|
|
"{} {}",
|
2021-04-08 21:27:27 -04:00
|
|
|
colors::bold("Emitted modules cache:"),
|
2022-03-10 19:57:57 -05:00
|
|
|
typescript_cache.display()
|
2020-07-08 10:50:12 -04:00
|
|
|
);
|
2021-04-08 21:27:27 -04:00
|
|
|
println!(
|
2022-03-10 19:57:57 -05:00
|
|
|
"{} {}",
|
2021-04-08 21:27:27 -04:00
|
|
|
colors::bold("Language server registries cache:"),
|
2022-03-10 19:57:57 -05:00
|
|
|
registry_cache.display(),
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"{} {}",
|
|
|
|
colors::bold("Origin storage:"),
|
|
|
|
origin_dir.display()
|
2021-04-08 21:27:27 -04:00
|
|
|
);
|
2021-05-27 01:23:12 -04:00
|
|
|
if location.is_some() {
|
|
|
|
println!(
|
2022-03-10 19:57:57 -05:00
|
|
|
"{} {}",
|
2021-05-27 01:23:12 -04:00
|
|
|
colors::bold("Local Storage:"),
|
2022-03-10 19:57:57 -05:00
|
|
|
local_storage_dir.display(),
|
2021-05-27 01:23:12 -04:00
|
|
|
);
|
|
|
|
}
|
2020-07-08 10:50:12 -04:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-25 10:24:05 -05:00
|
|
|
pub fn get_types(unstable: bool) -> String {
|
2021-06-10 10:18:13 -04:00
|
|
|
let mut types = vec![
|
2022-07-14 17:52:44 -04:00
|
|
|
tsc::DENO_NS_LIB,
|
|
|
|
tsc::DENO_CONSOLE_LIB,
|
|
|
|
tsc::DENO_URL_LIB,
|
|
|
|
tsc::DENO_WEB_LIB,
|
|
|
|
tsc::DENO_FETCH_LIB,
|
|
|
|
tsc::DENO_WEBGPU_LIB,
|
|
|
|
tsc::DENO_WEBSOCKET_LIB,
|
|
|
|
tsc::DENO_WEBSTORAGE_LIB,
|
|
|
|
tsc::DENO_CRYPTO_LIB,
|
|
|
|
tsc::DENO_BROADCAST_CHANNEL_LIB,
|
|
|
|
tsc::DENO_NET_LIB,
|
|
|
|
tsc::SHARED_GLOBALS_LIB,
|
|
|
|
tsc::WINDOW_LIB,
|
2021-06-10 10:18:13 -04:00
|
|
|
];
|
2020-08-04 10:08:41 -04:00
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
if unstable {
|
2022-07-14 17:52:44 -04:00
|
|
|
types.push(tsc::UNSTABLE_NS_LIB);
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
2020-08-04 10:08:41 -04:00
|
|
|
|
2021-06-10 10:18:13 -04:00
|
|
|
types.join("\n")
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2020-11-30 14:35:12 -05:00
|
|
|
async fn compile_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
compile_flags: CompileFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2020-11-30 14:35:12 -05:00
|
|
|
let debug = flags.log_level == Some(log::Level::Debug);
|
|
|
|
|
2022-02-24 08:28:00 -05:00
|
|
|
let run_flags = tools::standalone::compile_to_runtime_flags(
|
|
|
|
&flags,
|
|
|
|
compile_flags.args.clone(),
|
|
|
|
)?;
|
2021-01-04 18:15:52 -05:00
|
|
|
|
2021-09-03 19:33:35 -04:00
|
|
|
let module_specifier = resolve_url_or_path(&compile_flags.source_file)?;
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps = ProcState::build(flags).await?;
|
2021-09-24 11:10:42 -04:00
|
|
|
let deno_dir = &ps.dir;
|
2020-11-30 14:35:12 -05:00
|
|
|
|
2022-03-28 14:38:15 -04:00
|
|
|
let output_path =
|
|
|
|
tools::standalone::resolve_compile_executable_output_path(&compile_flags)?;
|
2020-11-30 14:35:12 -05:00
|
|
|
|
2022-02-15 07:33:46 -05:00
|
|
|
let graph = Arc::try_unwrap(
|
|
|
|
create_graph_and_maybe_check(module_specifier.clone(), &ps, debug).await?,
|
|
|
|
)
|
|
|
|
.map_err(|_| {
|
|
|
|
generic_error("There should only be one reference to ModuleGraph")
|
|
|
|
})?;
|
|
|
|
|
2022-02-24 08:28:00 -05:00
|
|
|
graph.valid().unwrap();
|
|
|
|
|
2022-08-29 14:24:10 -04:00
|
|
|
let parser = ps.parsed_source_cache.as_capturing_parser();
|
|
|
|
let eszip = eszip::EszipV2::from_graph(graph, &parser, Default::default())?;
|
2020-11-30 14:35:12 -05:00
|
|
|
|
|
|
|
info!(
|
|
|
|
"{} {}",
|
|
|
|
colors::green("Compile"),
|
|
|
|
module_specifier.to_string()
|
|
|
|
);
|
2021-01-18 21:40:22 -05:00
|
|
|
|
2021-04-26 13:28:38 -04:00
|
|
|
// Select base binary based on target
|
2021-01-18 21:40:22 -05:00
|
|
|
let original_binary =
|
2021-09-03 19:33:35 -04:00
|
|
|
tools::standalone::get_base_binary(deno_dir, compile_flags.target.clone())
|
|
|
|
.await?;
|
2021-01-18 21:40:22 -05:00
|
|
|
|
|
|
|
let final_bin = tools::standalone::create_standalone_binary(
|
|
|
|
original_binary,
|
2022-02-15 07:33:46 -05:00
|
|
|
eszip,
|
|
|
|
module_specifier.clone(),
|
2021-01-07 21:08:51 -05:00
|
|
|
run_flags,
|
2022-02-24 08:28:00 -05:00
|
|
|
ps,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-11-30 14:35:12 -05:00
|
|
|
|
2022-03-28 14:38:15 -04:00
|
|
|
info!("{} {}", colors::green("Emit"), output_path.display());
|
2020-11-30 14:35:12 -05:00
|
|
|
|
2022-03-28 14:38:15 -04:00
|
|
|
tools::standalone::write_standalone_binary(output_path, final_bin).await?;
|
2021-01-18 21:40:22 -05:00
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-11-30 14:35:12 -05:00
|
|
|
}
|
|
|
|
|
2022-08-19 19:37:05 -04:00
|
|
|
async fn init_command(
|
|
|
|
_flags: Flags,
|
|
|
|
init_flags: InitFlags,
|
|
|
|
) -> Result<i32, AnyError> {
|
|
|
|
tools::init::init_project(init_flags).await?;
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
async fn info_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
info_flags: InfoFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps = ProcState::build(flags).await?;
|
2021-09-03 19:33:35 -04:00
|
|
|
if let Some(specifier) = info_flags.file {
|
2021-02-17 13:47:18 -05:00
|
|
|
let specifier = resolve_url_or_path(&specifier)?;
|
2022-07-01 11:50:16 -04:00
|
|
|
let graph = ps
|
|
|
|
.create_graph(vec![(specifier, deno_graph::ModuleKind::Esm)])
|
|
|
|
.await?;
|
2020-09-07 09:59:47 -04:00
|
|
|
|
2021-09-03 19:33:35 -04:00
|
|
|
if info_flags.json {
|
2021-12-11 09:56:45 -05:00
|
|
|
write_json_to_stdout(&json!(graph))?;
|
2020-09-07 09:59:47 -04:00
|
|
|
} else {
|
2021-12-11 09:56:45 -05:00
|
|
|
write_to_stdout_ignore_sigpipe(graph.to_string().as_bytes())?;
|
2020-09-07 09:59:47 -04:00
|
|
|
}
|
2020-10-11 22:25:27 -04:00
|
|
|
} else {
|
|
|
|
// If it was just "deno info" print location of caches and exit
|
2022-06-29 11:51:11 -04:00
|
|
|
print_cache_info(&ps, info_flags.json, ps.options.location_flag())?;
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn install_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
install_flags: InstallFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2020-10-19 15:19:20 -04:00
|
|
|
let mut preload_flags = flags.clone();
|
|
|
|
preload_flags.inspect = None;
|
|
|
|
preload_flags.inspect_brk = None;
|
2022-02-11 14:04:31 -05:00
|
|
|
let permissions =
|
2022-08-10 15:13:53 -04:00
|
|
|
Permissions::from_options(&preload_flags.permissions_options())?;
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps = ProcState::build(preload_flags).await?;
|
2021-09-03 19:33:35 -04:00
|
|
|
let main_module = resolve_url_or_path(&install_flags.module_url)?;
|
2022-04-26 19:00:04 -04:00
|
|
|
let mut worker = create_main_worker(
|
|
|
|
&ps,
|
2022-08-11 16:59:12 -04:00
|
|
|
main_module,
|
2022-04-26 19:00:04 -04:00
|
|
|
permissions,
|
|
|
|
vec![],
|
|
|
|
Default::default(),
|
2022-08-23 10:39:19 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2020-09-20 08:05:11 -04:00
|
|
|
// First, fetch and compile the module; this step ensures that the module exists.
|
2022-08-11 16:59:12 -04:00
|
|
|
worker.preload_main_module().await?;
|
2021-12-21 09:49:27 -05:00
|
|
|
tools::installer::install(flags, install_flags)?;
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2021-09-30 11:38:07 -04:00
|
|
|
async fn uninstall_command(
|
|
|
|
uninstall_flags: UninstallFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
|
|
|
tools::installer::uninstall(uninstall_flags.name, uninstall_flags.root)?;
|
|
|
|
Ok(0)
|
2021-09-30 11:38:07 -04:00
|
|
|
}
|
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
async fn lsp_command() -> Result<i32, AnyError> {
|
|
|
|
lsp::start().await?;
|
|
|
|
Ok(0)
|
2020-12-07 05:46:39 -05:00
|
|
|
}
|
|
|
|
|
2020-06-12 10:42:12 -04:00
|
|
|
async fn lint_command(
|
2021-09-03 11:01:58 -04:00
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
lint_flags: LintFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2021-09-03 19:33:35 -04:00
|
|
|
if lint_flags.rules {
|
|
|
|
tools::lint::print_rules_list(lint_flags.json);
|
2021-12-11 09:56:45 -05:00
|
|
|
return Ok(0);
|
2020-06-12 10:42:12 -04:00
|
|
|
}
|
|
|
|
|
2022-01-31 11:39:39 -05:00
|
|
|
tools::lint::lint(flags, lint_flags).await?;
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-06-08 08:06:20 -04:00
|
|
|
}
|
|
|
|
|
2020-09-14 12:48:57 -04:00
|
|
|
async fn cache_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
cache_flags: CacheFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps = ProcState::build(flags).await?;
|
2022-07-19 11:58:18 -04:00
|
|
|
load_and_type_check(&ps, &cache_flags.files).await?;
|
|
|
|
ps.cache_module_emits()?;
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn check_command(
|
|
|
|
flags: Flags,
|
|
|
|
check_flags: CheckFlags,
|
|
|
|
) -> Result<i32, AnyError> {
|
|
|
|
let ps = ProcState::build(flags).await?;
|
|
|
|
load_and_type_check(&ps, &check_flags.files).await?;
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn load_and_type_check(
|
|
|
|
ps: &ProcState,
|
|
|
|
files: &Vec<String>,
|
|
|
|
) -> Result<(), AnyError> {
|
2022-06-29 11:51:11 -04:00
|
|
|
let lib = ps.options.ts_type_lib_window();
|
2020-05-11 17:33:36 -04:00
|
|
|
|
2022-07-19 11:58:18 -04:00
|
|
|
for file in files {
|
|
|
|
let specifier = resolve_url_or_path(file)?;
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.prepare_module_load(
|
2022-03-10 20:33:02 -05:00
|
|
|
vec![specifier],
|
2021-10-10 17:26:22 -04:00
|
|
|
false,
|
2022-06-28 16:45:55 -04:00
|
|
|
lib,
|
2021-09-24 11:10:42 -04:00
|
|
|
Permissions::allow_all(),
|
|
|
|
Permissions::allow_all(),
|
2021-11-15 18:25:52 -05:00
|
|
|
false,
|
2021-09-24 11:10:42 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2022-07-19 11:58:18 -04:00
|
|
|
Ok(())
|
2022-04-10 19:12:51 -04:00
|
|
|
}
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
async fn eval_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
eval_flags: EvalFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2021-10-10 17:26:22 -04:00
|
|
|
// deno_graph works off of extensions for local files to determine the media
|
|
|
|
// type, and so our "fake" specifier needs to have the proper extension.
|
|
|
|
let main_module =
|
2022-06-24 23:51:58 -04:00
|
|
|
resolve_url_or_path(&format!("./$deno$eval.{}", eval_flags.ext))?;
|
2022-08-10 15:13:53 -04:00
|
|
|
let permissions = Permissions::from_options(&flags.permissions_options())?;
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps = ProcState::build(flags).await?;
|
2022-04-26 19:00:04 -04:00
|
|
|
let mut worker = create_main_worker(
|
|
|
|
&ps,
|
|
|
|
main_module.clone(),
|
|
|
|
permissions,
|
|
|
|
vec![],
|
|
|
|
Default::default(),
|
2022-08-23 10:39:19 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2020-05-11 17:33:36 -04:00
|
|
|
// Create a dummy source file.
|
2021-09-03 19:33:35 -04:00
|
|
|
let source_code = if eval_flags.print {
|
|
|
|
format!("console.log({})", eval_flags.code)
|
2020-05-21 10:35:36 -04:00
|
|
|
} else {
|
2021-09-03 19:33:35 -04:00
|
|
|
eval_flags.code
|
2020-05-21 10:35:36 -04:00
|
|
|
}
|
|
|
|
.into_bytes();
|
|
|
|
|
2020-11-05 19:38:21 -05:00
|
|
|
let file = File {
|
2021-02-17 13:47:18 -05:00
|
|
|
local: main_module.clone().to_file_path().unwrap(),
|
2020-11-05 19:38:21 -05:00
|
|
|
maybe_types: None,
|
2021-10-10 17:26:22 -04:00
|
|
|
media_type: MediaType::Unknown,
|
2022-05-20 16:40:55 -04:00
|
|
|
source: String::from_utf8(source_code)?.into(),
|
2021-02-17 13:47:18 -05:00
|
|
|
specifier: main_module.clone(),
|
2021-09-02 11:38:19 -04:00
|
|
|
maybe_headers: None,
|
2020-05-11 17:33:36 -04:00
|
|
|
};
|
2020-11-05 19:38:21 -05:00
|
|
|
|
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.
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.file_fetcher.insert_cached(file);
|
2022-08-11 16:59:12 -04:00
|
|
|
let exit_code = worker.run().await?;
|
|
|
|
Ok(exit_code)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
async fn create_graph_and_maybe_check(
|
|
|
|
root: ModuleSpecifier,
|
|
|
|
ps: &ProcState,
|
2020-11-30 14:35:12 -05:00
|
|
|
debug: bool,
|
2021-10-10 17:26:22 -04:00
|
|
|
) -> Result<Arc<deno_graph::ModuleGraph>, AnyError> {
|
|
|
|
let mut cache = cache::FetchCacher::new(
|
2022-07-19 11:58:18 -04:00
|
|
|
ps.emit_cache.clone(),
|
2021-10-10 17:26:22 -04:00
|
|
|
ps.file_fetcher.clone(),
|
2020-11-30 14:35:12 -05:00
|
|
|
Permissions::allow_all(),
|
2021-05-17 03:44:38 -04:00
|
|
|
Permissions::allow_all(),
|
2020-11-30 14:35:12 -05:00
|
|
|
);
|
2021-10-10 17:26:22 -04:00
|
|
|
let maybe_locker = lockfile::as_maybe_locker(ps.lockfile.clone());
|
2022-06-29 11:51:11 -04:00
|
|
|
let maybe_imports = ps.options.to_maybe_imports()?;
|
2021-11-08 20:26:39 -05:00
|
|
|
let maybe_import_map_resolver =
|
|
|
|
ps.maybe_import_map.clone().map(ImportMapResolver::new);
|
2022-06-28 16:45:55 -04:00
|
|
|
let maybe_jsx_resolver = ps
|
2022-06-29 11:51:11 -04:00
|
|
|
.options
|
2022-08-24 13:36:05 -04:00
|
|
|
.to_maybe_jsx_import_source_config()
|
|
|
|
.map(|cfg| JsxResolver::new(cfg, maybe_import_map_resolver.clone()));
|
2021-11-08 20:26:39 -05:00
|
|
|
let maybe_resolver = if maybe_jsx_resolver.is_some() {
|
|
|
|
maybe_jsx_resolver.as_ref().map(|jr| jr.as_resolver())
|
|
|
|
} else {
|
|
|
|
maybe_import_map_resolver
|
|
|
|
.as_ref()
|
|
|
|
.map(|im| im.as_resolver())
|
|
|
|
};
|
2022-08-22 12:14:59 -04:00
|
|
|
let analyzer = ps.parsed_source_cache.as_analyzer();
|
2021-10-10 17:26:22 -04:00
|
|
|
let graph = Arc::new(
|
|
|
|
deno_graph::create_graph(
|
2022-01-31 17:33:57 -05:00
|
|
|
vec![(root, deno_graph::ModuleKind::Esm)],
|
2021-10-10 17:26:22 -04:00
|
|
|
false,
|
|
|
|
maybe_imports,
|
|
|
|
&mut cache,
|
2021-11-08 20:26:39 -05:00
|
|
|
maybe_resolver,
|
2021-10-10 17:26:22 -04:00
|
|
|
maybe_locker,
|
2022-08-22 12:14:59 -04:00
|
|
|
Some(&*analyzer),
|
2022-01-13 11:58:00 -05:00
|
|
|
None,
|
2021-10-10 17:26:22 -04:00
|
|
|
)
|
|
|
|
.await,
|
|
|
|
);
|
|
|
|
|
2022-06-29 11:51:11 -04:00
|
|
|
let check_js = ps.options.check_js();
|
2022-03-28 21:48:29 -04:00
|
|
|
graph_valid(
|
|
|
|
&graph,
|
2022-06-29 11:51:11 -04:00
|
|
|
ps.options.type_check_mode() != TypeCheckMode::None,
|
2022-03-28 21:48:29 -04:00
|
|
|
check_js,
|
|
|
|
)?;
|
2021-12-16 05:45:41 -05:00
|
|
|
graph_lock_or_exit(&graph);
|
2020-11-30 14:35:12 -05:00
|
|
|
|
2022-06-29 11:51:11 -04:00
|
|
|
if ps.options.type_check_mode() != TypeCheckMode::None {
|
2022-06-28 16:45:55 -04:00
|
|
|
let ts_config_result =
|
2022-06-29 11:51:11 -04:00
|
|
|
ps.options.resolve_ts_config_for_emit(TsConfigType::Check {
|
|
|
|
lib: ps.options.ts_type_lib_window(),
|
2022-06-28 16:45:55 -04:00
|
|
|
})?;
|
|
|
|
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
2020-11-30 14:35:12 -05:00
|
|
|
eprintln!("{}", ignored_options);
|
|
|
|
}
|
2022-06-29 11:51:11 -04:00
|
|
|
let maybe_config_specifier = ps.options.maybe_config_file_specifier();
|
2022-07-12 22:44:15 -04:00
|
|
|
let cache = TypeCheckCache::new(&ps.dir.type_checking_cache_db_file_path());
|
2022-09-02 10:54:40 -04:00
|
|
|
let check_result = check::check(
|
2021-12-16 05:45:41 -05:00
|
|
|
&graph.roots,
|
|
|
|
Arc::new(RwLock::new(graph.as_ref().into())),
|
2022-07-12 18:58:39 -04:00
|
|
|
&cache,
|
2022-09-02 10:54:40 -04:00
|
|
|
check::CheckOptions {
|
2022-06-29 11:51:11 -04:00
|
|
|
type_check_mode: ps.options.type_check_mode(),
|
2021-10-10 17:26:22 -04:00
|
|
|
debug,
|
|
|
|
maybe_config_specifier,
|
2022-06-28 16:45:55 -04:00
|
|
|
ts_config: ts_config_result.ts_config,
|
2021-12-16 05:45:41 -05:00
|
|
|
log_checks: true,
|
2022-06-29 11:51:11 -04:00
|
|
|
reload: ps.options.reload_flag(),
|
2021-10-10 17:26:22 -04:00
|
|
|
},
|
|
|
|
)?;
|
|
|
|
debug!("{}", check_result.stats);
|
|
|
|
if !check_result.diagnostics.is_empty() {
|
|
|
|
return Err(check_result.diagnostics.into());
|
2020-11-30 14:35:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
Ok(graph)
|
2020-11-30 14:35:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn bundle_module_graph(
|
2021-10-10 17:26:22 -04:00
|
|
|
graph: &deno_graph::ModuleGraph,
|
|
|
|
ps: &ProcState,
|
2022-05-30 09:39:14 -04:00
|
|
|
) -> Result<deno_emit::BundleEmit, AnyError> {
|
2022-01-31 17:33:57 -05:00
|
|
|
info!("{} {}", colors::green("Bundle"), graph.roots[0].0);
|
2021-10-10 17:26:22 -04:00
|
|
|
|
2022-06-29 11:51:11 -04:00
|
|
|
let ts_config_result = ps
|
|
|
|
.options
|
|
|
|
.resolve_ts_config_for_emit(TsConfigType::Bundle)?;
|
|
|
|
if ps.options.type_check_mode() == TypeCheckMode::None {
|
2022-06-28 16:45:55 -04:00
|
|
|
if let Some(ignored_options) = ts_config_result.maybe_ignored_options {
|
2020-11-30 14:35:12 -05:00
|
|
|
eprintln!("{}", ignored_options);
|
|
|
|
}
|
|
|
|
}
|
2021-10-10 17:26:22 -04:00
|
|
|
|
2022-05-30 09:39:14 -04:00
|
|
|
deno_emit::bundle_graph(
|
2021-10-10 17:26:22 -04:00
|
|
|
graph,
|
2022-05-30 09:39:14 -04:00
|
|
|
deno_emit::BundleOptions {
|
|
|
|
bundle_type: deno_emit::BundleType::Module,
|
2022-06-28 16:45:55 -04:00
|
|
|
emit_options: ts_config_result.ts_config.into(),
|
2022-01-12 07:05:06 -05:00
|
|
|
emit_ignore_directives: true,
|
2021-10-10 17:26:22 -04:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
async fn bundle_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
bundle_flags: BundleFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2020-11-22 15:45:44 -05:00
|
|
|
let debug = flags.log_level == Some(log::Level::Debug);
|
2022-06-29 11:51:11 -04:00
|
|
|
let cli_options = Arc::new(CliOptions::from_flags(flags)?);
|
2021-05-10 02:06:13 -04:00
|
|
|
let resolver = |_| {
|
2022-06-29 11:51:11 -04:00
|
|
|
let cli_options = cli_options.clone();
|
2021-09-03 19:33:35 -04:00
|
|
|
let source_file1 = bundle_flags.source_file.clone();
|
|
|
|
let source_file2 = bundle_flags.source_file.clone();
|
2020-11-22 15:45:44 -05:00
|
|
|
async move {
|
2021-02-17 13:47:18 -05:00
|
|
|
let module_specifier = resolve_url_or_path(&source_file1)?;
|
2020-11-22 15:45:44 -05:00
|
|
|
|
|
|
|
debug!(">>>>> bundle START");
|
2022-06-29 11:51:11 -04:00
|
|
|
let ps = ProcState::from_options(cli_options).await?;
|
2021-10-10 17:26:22 -04:00
|
|
|
let graph =
|
|
|
|
create_graph_and_maybe_check(module_specifier, &ps, debug).await?;
|
2020-05-20 10:25:40 -04:00
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
let mut paths_to_watch: Vec<PathBuf> = graph
|
|
|
|
.specifiers()
|
2020-11-22 15:45:44 -05:00
|
|
|
.iter()
|
2021-10-10 17:26:22 -04:00
|
|
|
.filter_map(|(_, r)| {
|
2022-02-24 20:03:12 -05:00
|
|
|
r.as_ref().ok().and_then(|(s, _, _)| s.to_file_path().ok())
|
2021-10-10 17:26:22 -04:00
|
|
|
})
|
2020-11-22 15:45:44 -05:00
|
|
|
.collect();
|
2020-05-29 10:32:15 -04:00
|
|
|
|
2022-06-28 16:45:55 -04:00
|
|
|
if let Ok(Some(import_map_path)) = ps
|
2022-06-29 11:51:11 -04:00
|
|
|
.options
|
2022-06-29 20:41:48 -04:00
|
|
|
.resolve_import_map_specifier()
|
2022-06-28 16:45:55 -04:00
|
|
|
.map(|ms| ms.and_then(|ref s| s.to_file_path().ok()))
|
2022-02-22 18:51:14 -05:00
|
|
|
{
|
|
|
|
paths_to_watch.push(import_map_path);
|
2020-11-22 15:45:44 -05:00
|
|
|
}
|
2020-10-23 07:05:41 -04:00
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
Ok((paths_to_watch, graph, ps))
|
2020-10-19 23:10:42 -04:00
|
|
|
}
|
2020-11-28 09:18:13 -05:00
|
|
|
.map(move |result| match result {
|
2021-10-10 17:26:22 -04:00
|
|
|
Ok((paths_to_watch, graph, ps)) => ResolutionResult::Restart {
|
2021-09-24 11:10:42 -04:00
|
|
|
paths_to_watch,
|
2021-10-10 17:26:22 -04:00
|
|
|
result: Ok((ps, graph)),
|
2021-09-24 11:10:42 -04:00
|
|
|
},
|
2021-05-10 02:06:13 -04:00
|
|
|
Err(e) => ResolutionResult::Restart {
|
|
|
|
paths_to_watch: vec![PathBuf::from(source_file2)],
|
|
|
|
result: Err(e),
|
2020-11-28 09:18:13 -05:00
|
|
|
},
|
|
|
|
})
|
2020-11-22 15:45:44 -05:00
|
|
|
};
|
2020-10-19 23:10:42 -04:00
|
|
|
|
2021-10-10 17:26:22 -04:00
|
|
|
let operation = |(ps, graph): (ProcState, Arc<deno_graph::ModuleGraph>)| {
|
2021-09-03 19:33:35 -04:00
|
|
|
let out_file = bundle_flags.out_file.clone();
|
2020-11-22 15:45:44 -05:00
|
|
|
async move {
|
2022-06-28 16:45:55 -04:00
|
|
|
let bundle_output = bundle_module_graph(graph.as_ref(), &ps)?;
|
2020-11-22 15:45:44 -05:00
|
|
|
debug!(">>>>> bundle END");
|
|
|
|
|
|
|
|
if let Some(out_file) = out_file.as_ref() {
|
2022-05-30 09:39:14 -04:00
|
|
|
let output_bytes = bundle_output.code.as_bytes();
|
2020-11-22 15:45:44 -05:00
|
|
|
let output_len = output_bytes.len();
|
|
|
|
fs_util::write_file(out_file, output_bytes, 0o644)?;
|
|
|
|
info!(
|
|
|
|
"{} {:?} ({})",
|
|
|
|
colors::green("Emit"),
|
|
|
|
out_file,
|
2022-03-08 18:19:02 -05:00
|
|
|
colors::gray(display::human_size(output_len as f64))
|
2020-11-22 15:45:44 -05:00
|
|
|
);
|
2022-05-30 09:39:14 -04:00
|
|
|
if let Some(bundle_map) = bundle_output.maybe_map {
|
2021-10-10 17:26:22 -04:00
|
|
|
let map_bytes = bundle_map.as_bytes();
|
|
|
|
let map_len = map_bytes.len();
|
|
|
|
let ext = if let Some(curr_ext) = out_file.extension() {
|
|
|
|
format!("{}.map", curr_ext.to_string_lossy())
|
|
|
|
} else {
|
|
|
|
"map".to_string()
|
|
|
|
};
|
|
|
|
let map_out_file = out_file.with_extension(ext);
|
|
|
|
fs_util::write_file(&map_out_file, map_bytes, 0o644)?;
|
|
|
|
info!(
|
|
|
|
"{} {:?} ({})",
|
|
|
|
colors::green("Emit"),
|
|
|
|
map_out_file,
|
2022-03-08 18:19:02 -05:00
|
|
|
colors::gray(display::human_size(map_len as f64))
|
2021-10-10 17:26:22 -04:00
|
|
|
);
|
|
|
|
}
|
2020-11-22 15:45:44 -05:00
|
|
|
} else {
|
2022-05-30 09:39:14 -04:00
|
|
|
println!("{}", bundle_output.code);
|
2020-11-22 15:45:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-29 11:51:11 -04:00
|
|
|
if cli_options.watch_paths().is_some() {
|
2022-01-31 11:39:39 -05:00
|
|
|
file_watcher::watch_func(
|
|
|
|
resolver,
|
|
|
|
operation,
|
|
|
|
file_watcher::PrintConfig {
|
|
|
|
job_name: "Bundle".to_string(),
|
2022-06-29 11:51:11 -04:00
|
|
|
clear_screen: !cli_options.no_clear_screen(),
|
2022-01-31 11:39:39 -05:00
|
|
|
},
|
|
|
|
)
|
|
|
|
.await?;
|
2020-05-29 10:32:15 -04:00
|
|
|
} else {
|
2021-05-10 02:06:13 -04:00
|
|
|
let module_graph =
|
|
|
|
if let ResolutionResult::Restart { result, .. } = resolver(None).await {
|
|
|
|
result?
|
|
|
|
} else {
|
|
|
|
unreachable!();
|
|
|
|
};
|
2020-11-22 15:45:44 -05:00
|
|
|
operation(module_graph).await?;
|
2020-05-29 10:32:15 -04:00
|
|
|
}
|
2020-11-22 15:45:44 -05:00
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async fn doc_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
doc_flags: DocFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2021-12-20 16:29:02 -05:00
|
|
|
tools::doc::print_docs(flags, doc_flags).await?;
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2020-11-22 15:45:44 -05:00
|
|
|
async fn format_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
fmt_flags: FmtFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2022-06-29 11:51:11 -04:00
|
|
|
let config = CliOptions::from_flags(flags)?;
|
2021-09-13 14:19:10 -04:00
|
|
|
|
2021-09-03 19:33:35 -04:00
|
|
|
if fmt_flags.files.len() == 1 && fmt_flags.files[0].to_string_lossy() == "-" {
|
2022-06-28 16:45:55 -04:00
|
|
|
let maybe_fmt_config = config.to_fmt_config()?;
|
2021-12-11 09:56:45 -05:00
|
|
|
tools::fmt::format_stdin(
|
2021-09-13 16:06:45 -04:00
|
|
|
fmt_flags,
|
2021-09-13 14:19:10 -04:00
|
|
|
maybe_fmt_config.map(|c| c.options).unwrap_or_default(),
|
2021-12-11 09:56:45 -05:00
|
|
|
)?;
|
|
|
|
return Ok(0);
|
2020-11-22 15:45:44 -05:00
|
|
|
}
|
|
|
|
|
2022-06-28 16:45:55 -04:00
|
|
|
tools::fmt::format(&config, fmt_flags).await?;
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-11-22 15:45:44 -05:00
|
|
|
}
|
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
async fn repl_command(
|
|
|
|
flags: Flags,
|
|
|
|
repl_flags: ReplFlags,
|
|
|
|
) -> Result<i32, AnyError> {
|
2021-02-17 13:47:18 -05:00
|
|
|
let main_module = resolve_url_or_path("./$deno$repl.ts").unwrap();
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps = ProcState::build(flags).await?;
|
2022-04-26 19:00:04 -04:00
|
|
|
let mut worker = create_main_worker(
|
|
|
|
&ps,
|
|
|
|
main_module.clone(),
|
2022-08-10 15:13:53 -04:00
|
|
|
Permissions::from_options(&ps.options.permissions_options())?,
|
2022-04-26 19:00:04 -04:00
|
|
|
vec![],
|
|
|
|
Default::default(),
|
2022-08-23 10:39:19 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2022-08-11 16:59:12 -04:00
|
|
|
worker.setup_repl().await?;
|
|
|
|
tools::repl::run(
|
|
|
|
&ps,
|
|
|
|
worker.into_main_worker(),
|
|
|
|
repl_flags.eval_files,
|
|
|
|
repl_flags.eval,
|
|
|
|
)
|
|
|
|
.await
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> {
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps = ProcState::build(flags).await?;
|
2021-02-17 13:47:18 -05:00
|
|
|
let main_module = resolve_url_or_path("./$deno$stdin.ts").unwrap();
|
2022-04-26 19:00:04 -04:00
|
|
|
let mut worker = create_main_worker(
|
|
|
|
&ps.clone(),
|
|
|
|
main_module.clone(),
|
2022-08-10 15:13:53 -04:00
|
|
|
Permissions::from_options(&ps.options.permissions_options())?,
|
2022-04-26 19:00:04 -04:00
|
|
|
vec![],
|
|
|
|
Default::default(),
|
2022-08-23 10:39:19 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2020-09-11 12:19:49 -04:00
|
|
|
|
|
|
|
let mut source = Vec::new();
|
|
|
|
std::io::stdin().read_to_end(&mut source)?;
|
|
|
|
// Create a dummy source file.
|
2020-11-05 19:38:21 -05:00
|
|
|
let source_file = File {
|
2021-02-17 13:47:18 -05:00
|
|
|
local: main_module.clone().to_file_path().unwrap(),
|
2020-11-05 19:38:21 -05:00
|
|
|
maybe_types: None,
|
2020-09-11 12:19:49 -04:00
|
|
|
media_type: MediaType::TypeScript,
|
2022-05-20 16:40:55 -04:00
|
|
|
source: String::from_utf8(source)?.into(),
|
2020-11-05 19:38:21 -05:00
|
|
|
specifier: main_module.clone(),
|
2021-09-02 11:38:19 -04:00
|
|
|
maybe_headers: None,
|
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
|
2021-09-24 11:10:42 -04:00
|
|
|
ps.file_fetcher.insert_cached(source_file);
|
2020-09-11 12:19:49 -04:00
|
|
|
|
2022-08-11 16:59:12 -04:00
|
|
|
let exit_code = worker.run().await?;
|
|
|
|
Ok(exit_code)
|
2020-09-11 12:19:49 -04:00
|
|
|
}
|
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
// TODO(bartlomieju): this function is not handling `exit_code` set by the runtime
|
|
|
|
// code properly.
|
|
|
|
async fn run_with_watch(flags: Flags, script: String) -> Result<i32, AnyError> {
|
2022-06-08 06:07:25 -04:00
|
|
|
let flags = Arc::new(flags);
|
|
|
|
let main_module = resolve_url_or_path(&script)?;
|
|
|
|
let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
|
|
|
|
|
|
|
|
let operation = |(sender, main_module): (
|
|
|
|
tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>,
|
|
|
|
ModuleSpecifier,
|
|
|
|
)| {
|
2021-09-24 11:10:42 -04:00
|
|
|
let flags = flags.clone();
|
2022-08-10 15:13:53 -04:00
|
|
|
let permissions = Permissions::from_options(&flags.permissions_options())?;
|
|
|
|
Ok(async move {
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps =
|
|
|
|
ProcState::build_for_file_watcher((*flags).clone(), sender.clone())
|
|
|
|
.await?;
|
2022-08-11 16:59:12 -04:00
|
|
|
let worker = create_main_worker(
|
|
|
|
&ps,
|
|
|
|
main_module.clone(),
|
|
|
|
permissions,
|
|
|
|
vec![],
|
|
|
|
Default::default(),
|
2022-08-23 10:39:19 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2022-08-11 16:59:12 -04:00
|
|
|
worker.run_for_watcher().await?;
|
2021-09-24 11:10:42 -04:00
|
|
|
|
|
|
|
Ok(())
|
2022-08-10 15:13:53 -04:00
|
|
|
})
|
2021-09-24 11:10:42 -04:00
|
|
|
};
|
2020-11-22 15:45:44 -05:00
|
|
|
|
2022-06-08 06:07:25 -04:00
|
|
|
file_watcher::watch_func2(
|
|
|
|
receiver,
|
2022-01-31 11:39:39 -05:00
|
|
|
operation,
|
2022-06-08 06:07:25 -04:00
|
|
|
(sender, main_module),
|
2022-01-31 11:39:39 -05:00
|
|
|
file_watcher::PrintConfig {
|
|
|
|
job_name: "Process".to_string(),
|
|
|
|
clear_screen: !flags.no_clear_screen,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await?;
|
2022-06-08 06:07:25 -04:00
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-09-11 12:19:49 -04:00
|
|
|
}
|
|
|
|
|
2021-09-03 19:33:35 -04:00
|
|
|
async fn run_command(
|
|
|
|
flags: Flags,
|
|
|
|
run_flags: RunFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2020-09-11 12:19:49 -04:00
|
|
|
// Read script content from stdin
|
2022-08-12 15:21:17 -04:00
|
|
|
if run_flags.is_stdin() {
|
2020-09-11 12:19:49 -04:00
|
|
|
return run_from_stdin(flags).await;
|
|
|
|
}
|
|
|
|
|
2021-12-15 16:04:43 -05:00
|
|
|
if flags.watch.is_some() {
|
2021-09-03 19:33:35 -04:00
|
|
|
return run_with_watch(flags, run_flags.script).await;
|
2020-09-11 12:19:49 -04:00
|
|
|
}
|
2020-06-11 10:58:09 -04:00
|
|
|
|
2021-10-18 13:36:28 -04:00
|
|
|
// TODO(bartlomieju): actually I think it will also fail if there's an import
|
|
|
|
// map specified and bare specifier is used on the command line - this should
|
|
|
|
// probably call `ProcState::resolve` instead
|
2022-06-28 16:45:55 -04:00
|
|
|
let ps = ProcState::build(flags).await?;
|
2022-08-23 10:39:19 -04:00
|
|
|
let main_module = if NpmPackageReference::from_str(&run_flags.script).is_ok()
|
|
|
|
{
|
|
|
|
ModuleSpecifier::parse(&run_flags.script)?
|
|
|
|
} else {
|
|
|
|
resolve_url_or_path(&run_flags.script)?
|
|
|
|
};
|
2022-06-29 11:51:11 -04:00
|
|
|
let permissions =
|
2022-08-10 15:13:53 -04:00
|
|
|
Permissions::from_options(&ps.options.permissions_options())?;
|
2022-04-26 19:00:04 -04:00
|
|
|
let mut worker = create_main_worker(
|
|
|
|
&ps,
|
|
|
|
main_module.clone(),
|
|
|
|
permissions,
|
|
|
|
vec![],
|
|
|
|
Default::default(),
|
2022-08-23 10:39:19 -04:00
|
|
|
)
|
|
|
|
.await?;
|
2020-12-28 10:51:26 -05:00
|
|
|
|
2022-08-11 16:59:12 -04:00
|
|
|
let exit_code = worker.run().await?;
|
|
|
|
Ok(exit_code)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2022-03-10 20:56:14 -05:00
|
|
|
async fn task_command(
|
|
|
|
flags: Flags,
|
|
|
|
task_flags: TaskFlags,
|
|
|
|
) -> Result<i32, AnyError> {
|
|
|
|
tools::task::execute_script(flags, task_flags).await
|
|
|
|
}
|
|
|
|
|
2021-02-24 09:27:51 -05:00
|
|
|
async fn coverage_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
coverage_flags: CoverageFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2021-09-03 19:33:35 -04:00
|
|
|
if coverage_flags.files.is_empty() {
|
2021-07-15 12:28:14 -04:00
|
|
|
return Err(generic_error("No matching coverage profiles found"));
|
2021-02-24 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
2021-12-20 16:29:02 -05:00
|
|
|
tools::coverage::cover_files(flags, coverage_flags).await?;
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2021-02-24 09:27:51 -05:00
|
|
|
}
|
|
|
|
|
2022-03-11 17:07:02 -05:00
|
|
|
async fn bench_command(
|
|
|
|
flags: Flags,
|
|
|
|
bench_flags: BenchFlags,
|
|
|
|
) -> Result<i32, AnyError> {
|
|
|
|
if flags.watch.is_some() {
|
|
|
|
tools::bench::run_benchmarks_with_watch(flags, bench_flags).await?;
|
|
|
|
} else {
|
|
|
|
tools::bench::run_benchmarks(flags, bench_flags).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
2020-05-11 17:33:36 -04:00
|
|
|
async fn test_command(
|
|
|
|
flags: Flags,
|
2021-09-03 19:33:35 -04:00
|
|
|
test_flags: TestFlags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Result<i32, AnyError> {
|
2020-12-21 08:04:25 -05:00
|
|
|
if let Some(ref coverage_dir) = flags.coverage_dir {
|
2021-05-21 09:57:00 -04:00
|
|
|
std::fs::create_dir_all(&coverage_dir)?;
|
2021-05-19 09:33:22 -04:00
|
|
|
env::set_var(
|
|
|
|
"DENO_UNSTABLE_COVERAGE_DIR",
|
|
|
|
PathBuf::from(coverage_dir).canonicalize()?,
|
|
|
|
);
|
2020-12-21 08:04:25 -05:00
|
|
|
}
|
2020-09-13 09:01:30 -04:00
|
|
|
|
2021-12-15 16:04:43 -05:00
|
|
|
if flags.watch.is_some() {
|
2021-12-20 16:29:02 -05:00
|
|
|
tools::test::run_tests_with_watch(flags, test_flags).await?;
|
|
|
|
} else {
|
|
|
|
tools::test::run_tests(flags, test_flags).await?;
|
2021-05-10 02:06:13 -04:00
|
|
|
}
|
2020-09-13 09:01:30 -04:00
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
Ok(0)
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
|
|
|
|
2021-12-21 09:49:27 -05:00
|
|
|
async fn completions_command(
|
|
|
|
_flags: Flags,
|
|
|
|
completions_flags: CompletionsFlags,
|
|
|
|
) -> Result<i32, AnyError> {
|
|
|
|
write_to_stdout_ignore_sigpipe(&completions_flags.buf)?;
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn types_command(flags: Flags) -> Result<i32, AnyError> {
|
|
|
|
let types = get_types(flags.unstable);
|
|
|
|
write_to_stdout_ignore_sigpipe(types.as_bytes())?;
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn upgrade_command(
|
|
|
|
_flags: Flags,
|
|
|
|
upgrade_flags: UpgradeFlags,
|
|
|
|
) -> Result<i32, AnyError> {
|
|
|
|
tools::upgrade::upgrade(upgrade_flags).await?;
|
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
2022-02-16 13:14:19 -05:00
|
|
|
async fn vendor_command(
|
|
|
|
flags: Flags,
|
|
|
|
vendor_flags: VendorFlags,
|
|
|
|
) -> Result<i32, AnyError> {
|
2022-06-29 20:41:48 -04:00
|
|
|
tools::vendor::vendor(flags, vendor_flags).await?;
|
2022-02-16 13:14:19 -05:00
|
|
|
Ok(0)
|
|
|
|
}
|
|
|
|
|
2020-11-26 09:17:45 -05:00
|
|
|
fn init_v8_flags(v8_flags: &[String]) {
|
|
|
|
let v8_flags_includes_help = v8_flags
|
|
|
|
.iter()
|
|
|
|
.any(|flag| flag == "-help" || flag == "--help");
|
2021-01-04 18:15:52 -05:00
|
|
|
// Keep in sync with `standalone.rs`.
|
2020-11-26 09:17:45 -05:00
|
|
|
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);
|
2020-08-07 18:51:59 -04:00
|
|
|
}
|
2020-11-26 09:17:45 -05:00
|
|
|
eprintln!("\nFor 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
|
|
|
}
|
2020-11-26 09:17:45 -05:00
|
|
|
}
|
2020-05-11 17:33:36 -04:00
|
|
|
|
2020-11-26 09:17:45 -05:00
|
|
|
fn get_subcommand(
|
|
|
|
flags: Flags,
|
2021-12-11 09:56:45 -05:00
|
|
|
) -> Pin<Box<dyn Future<Output = Result<i32, AnyError>>>> {
|
2022-02-11 14:04:31 -05:00
|
|
|
match flags.subcommand.clone() {
|
2022-03-11 17:07:02 -05:00
|
|
|
DenoSubcommand::Bench(bench_flags) => {
|
|
|
|
bench_command(flags, bench_flags).boxed_local()
|
|
|
|
}
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Bundle(bundle_flags) => {
|
|
|
|
bundle_command(flags, bundle_flags).boxed_local()
|
|
|
|
}
|
|
|
|
DenoSubcommand::Doc(doc_flags) => {
|
|
|
|
doc_command(flags, doc_flags).boxed_local()
|
|
|
|
}
|
|
|
|
DenoSubcommand::Eval(eval_flags) => {
|
|
|
|
eval_command(flags, eval_flags).boxed_local()
|
2021-02-21 11:58:32 -05:00
|
|
|
}
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Cache(cache_flags) => {
|
|
|
|
cache_command(flags, cache_flags).boxed_local()
|
2020-10-23 10:56:25 -04:00
|
|
|
}
|
2022-04-10 19:12:51 -04:00
|
|
|
DenoSubcommand::Check(check_flags) => {
|
|
|
|
check_command(flags, check_flags).boxed_local()
|
|
|
|
}
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Compile(compile_flags) => {
|
|
|
|
compile_command(flags, compile_flags).boxed_local()
|
2021-04-26 13:28:38 -04:00
|
|
|
}
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Coverage(coverage_flags) => {
|
|
|
|
coverage_command(flags, coverage_flags).boxed_local()
|
2020-07-08 10:50:12 -04:00
|
|
|
}
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Fmt(fmt_flags) => {
|
|
|
|
format_command(flags, fmt_flags).boxed_local()
|
|
|
|
}
|
2022-08-19 19:37:05 -04:00
|
|
|
DenoSubcommand::Init(init_flags) => {
|
|
|
|
init_command(flags, init_flags).boxed_local()
|
|
|
|
}
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Info(info_flags) => {
|
|
|
|
info_command(flags, info_flags).boxed_local()
|
|
|
|
}
|
|
|
|
DenoSubcommand::Install(install_flags) => {
|
|
|
|
install_command(flags, install_flags).boxed_local()
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
2021-09-30 11:38:07 -04:00
|
|
|
DenoSubcommand::Uninstall(uninstall_flags) => {
|
|
|
|
uninstall_command(uninstall_flags).boxed_local()
|
|
|
|
}
|
2021-06-22 21:48:01 -04:00
|
|
|
DenoSubcommand::Lsp => lsp_command().boxed_local(),
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Lint(lint_flags) => {
|
|
|
|
lint_command(flags, lint_flags).boxed_local()
|
|
|
|
}
|
|
|
|
DenoSubcommand::Repl(repl_flags) => {
|
2021-12-11 09:56:45 -05:00
|
|
|
repl_command(flags, repl_flags).boxed_local()
|
2021-09-03 19:33:35 -04:00
|
|
|
}
|
|
|
|
DenoSubcommand::Run(run_flags) => {
|
|
|
|
run_command(flags, run_flags).boxed_local()
|
|
|
|
}
|
2022-03-10 20:56:14 -05:00
|
|
|
DenoSubcommand::Task(task_flags) => {
|
|
|
|
task_command(flags, task_flags).boxed_local()
|
|
|
|
}
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Test(test_flags) => {
|
|
|
|
test_command(flags, test_flags).boxed_local()
|
|
|
|
}
|
2021-12-21 09:49:27 -05:00
|
|
|
DenoSubcommand::Completions(completions_flags) => {
|
|
|
|
completions_command(flags, completions_flags).boxed_local()
|
2020-05-11 17:33:36 -04:00
|
|
|
}
|
2021-12-21 09:49:27 -05:00
|
|
|
DenoSubcommand::Types => types_command(flags).boxed_local(),
|
2021-09-03 19:33:35 -04:00
|
|
|
DenoSubcommand::Upgrade(upgrade_flags) => {
|
2021-12-21 09:49:27 -05:00
|
|
|
upgrade_command(flags, upgrade_flags).boxed_local()
|
2021-09-03 19:33:35 -04:00
|
|
|
}
|
2022-02-16 13:14:19 -05:00
|
|
|
DenoSubcommand::Vendor(vendor_flags) => {
|
|
|
|
vendor_command(flags, vendor_flags).boxed_local()
|
|
|
|
}
|
2020-11-26 09:17:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 08:49:05 -05:00
|
|
|
fn setup_panic_hook() {
|
|
|
|
// This function does two things inside of the panic hook:
|
|
|
|
// - Tokio does not exit the process when a task panics, so we define a custom
|
|
|
|
// panic hook to implement this behaviour.
|
|
|
|
// - We print a message to stderr to indicate that this is a bug in Deno, and
|
|
|
|
// should be reported to us.
|
2021-09-07 19:34:27 -04:00
|
|
|
let orig_hook = std::panic::take_hook();
|
|
|
|
std::panic::set_hook(Box::new(move |panic_info| {
|
2021-12-20 08:49:05 -05:00
|
|
|
eprintln!("\n============================================================");
|
|
|
|
eprintln!("Deno has panicked. This is a bug in Deno. Please report this");
|
|
|
|
eprintln!("at https://github.com/denoland/deno/issues/new.");
|
|
|
|
eprintln!("If you can reliably reproduce this panic, include the");
|
|
|
|
eprintln!("reproduction steps and re-run with the RUST_BACKTRACE=1 env");
|
|
|
|
eprintln!("var set and include the backtrace in your report.");
|
|
|
|
eprintln!();
|
2022-07-14 17:52:44 -04:00
|
|
|
eprintln!("Platform: {} {}", env::consts::OS, env::consts::ARCH);
|
2021-12-20 08:49:05 -05:00
|
|
|
eprintln!("Version: {}", version::deno());
|
2022-07-14 17:52:44 -04:00
|
|
|
eprintln!("Args: {:?}", env::args().collect::<Vec<_>>());
|
2021-12-20 08:49:05 -05:00
|
|
|
eprintln!();
|
2021-09-07 19:34:27 -04:00
|
|
|
orig_hook(panic_info);
|
|
|
|
std::process::exit(1);
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2021-01-07 13:06:08 -05:00
|
|
|
fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
|
|
|
|
match result {
|
|
|
|
Ok(value) => value,
|
|
|
|
Err(error) => {
|
2022-04-26 19:06:10 -04:00
|
|
|
let error_string = match error.downcast_ref::<JsError>() {
|
|
|
|
Some(e) => format_js_error(e),
|
|
|
|
None => format!("{:?}", error),
|
|
|
|
};
|
2022-01-14 11:38:17 -05:00
|
|
|
eprintln!(
|
|
|
|
"{}: {}",
|
|
|
|
colors::red_bold("error"),
|
2022-04-26 19:06:10 -04:00
|
|
|
error_string.trim_start_matches("error: ")
|
2022-01-14 11:38:17 -05:00
|
|
|
);
|
2021-01-07 13:06:08 -05:00
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-26 09:17:45 -05:00
|
|
|
pub fn main() {
|
2021-12-20 08:49:05 -05:00
|
|
|
setup_panic_hook();
|
2021-10-25 11:16:16 -04:00
|
|
|
|
|
|
|
unix_util::raise_fd_limit();
|
|
|
|
windows_util::ensure_stdio_open();
|
2020-11-26 09:17:45 -05:00
|
|
|
#[cfg(windows)]
|
|
|
|
colors::enable_ansi(); // For Windows 10
|
|
|
|
|
|
|
|
let args: Vec<String> = env::args().collect();
|
2022-02-15 07:33:46 -05:00
|
|
|
|
|
|
|
let exit_code = async move {
|
|
|
|
let standalone_res =
|
|
|
|
match standalone::extract_standalone(args.clone()).await {
|
|
|
|
Ok(Some((metadata, eszip))) => standalone::run(eszip, metadata).await,
|
|
|
|
Ok(None) => Ok(()),
|
|
|
|
Err(err) => Err(err),
|
|
|
|
};
|
|
|
|
// TODO(bartlomieju): doesn't handle exit code set by the runtime properly
|
|
|
|
unwrap_or_exit(standalone_res);
|
|
|
|
|
2022-06-27 16:54:09 -04:00
|
|
|
let flags = match flags_from_vec(args) {
|
2022-02-15 07:33:46 -05:00
|
|
|
Ok(flags) => flags,
|
|
|
|
Err(err @ clap::Error { .. })
|
2022-03-27 21:57:56 -04:00
|
|
|
if err.kind() == clap::ErrorKind::DisplayHelp
|
|
|
|
|| err.kind() == clap::ErrorKind::DisplayVersion =>
|
2022-02-15 07:33:46 -05:00
|
|
|
{
|
|
|
|
err.print().unwrap();
|
|
|
|
std::process::exit(0);
|
|
|
|
}
|
|
|
|
Err(err) => unwrap_or_exit(Err(AnyError::from(err))),
|
|
|
|
};
|
|
|
|
if !flags.v8_flags.is_empty() {
|
|
|
|
init_v8_flags(&*flags.v8_flags);
|
2021-01-09 07:08:03 -05:00
|
|
|
}
|
2021-05-11 00:54:10 -04:00
|
|
|
|
2022-02-15 07:33:46 -05:00
|
|
|
logger::init(flags.log_level);
|
|
|
|
|
2022-08-21 13:31:14 -04:00
|
|
|
get_subcommand(flags).await
|
2022-02-15 07:33:46 -05:00
|
|
|
};
|
2020-05-11 17:33:36 -04:00
|
|
|
|
2022-07-11 13:02:23 -04:00
|
|
|
let exit_code = unwrap_or_exit(run_local(exit_code));
|
2021-11-27 18:45:38 -05:00
|
|
|
|
2021-12-11 09:56:45 -05:00
|
|
|
std::process::exit(exit_code);
|
2018-06-15 19:43:23 -04:00
|
|
|
}
|