From de5c099b47bd1d2e528f1a10179f130a02f26f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 31 Jan 2020 00:42:39 +0100 Subject: feat: deno install in Rust (#3806) //std/installer couldn't be removed due to bug, but it's now deprecated. --- cli/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'cli/lib.rs') diff --git a/cli/lib.rs b/cli/lib.rs index 655bd2413..3a894e0da 100644 --- a/cli/lib.rs +++ b/cli/lib.rs @@ -35,6 +35,7 @@ mod global_state; mod global_timer; mod http_util; mod import_map; +mod installer; mod js; mod lockfile; mod metrics; @@ -280,6 +281,27 @@ async fn info_command(flags: DenoFlags) { js_check(result); } +async fn install_command( + flags: DenoFlags, + dir: Option, + exe_name: String, + module_url: String, + args: Vec, +) { + // Firstly fetch and compile module, this + // ensures the module exists. + let mut fetch_flags = flags.clone(); + fetch_flags.argv.push(module_url.to_string()); + fetch_flags.reload = true; + fetch_command(fetch_flags).await; + + let install_result = + installer::install(flags, dir, &exe_name, &module_url, args); + if let Err(e) = install_result { + print_msg_and_exit(&e.to_string()); + } +} + async fn fetch_command(flags: DenoFlags) { let (mut worker, state) = create_worker_and_state(flags); @@ -428,6 +450,12 @@ pub async fn main() { DenoSubcommand::Fetch => fetch_command(flags).await, DenoSubcommand::Format { check, files } => fmt_command(files, check).await, DenoSubcommand::Info => info_command(flags).await, + DenoSubcommand::Install { + dir, + exe_name, + module_url, + args, + } => install_command(flags, dir, exe_name, module_url, args).await, DenoSubcommand::Repl => run_repl(flags).await, DenoSubcommand::Run => run_script(flags).await, DenoSubcommand::Types => types_command(), -- cgit v1.2.3