From ff369cf0d9079b775b50e39f092c76b68a69b934 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 13:59:37 +0700 Subject: [PATCH 01/20] proposal for lite binary --- cli/main.rs | 5 -- cli/standalone.rs | 151 +++--------------------------------------- runtime/Cargo.toml | 4 ++ runtime/lib.rs | 1 + runtime/main.rs | 10 +++ runtime/standalone.rs | 139 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 163 insertions(+), 147 deletions(-) create mode 100644 runtime/main.rs create mode 100644 runtime/standalone.rs diff --git a/cli/main.rs b/cli/main.rs index ac0d2f59155b35..27c12210e7b298 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1219,11 +1219,6 @@ pub fn main() { colors::enable_ansi(); // For Windows 10 let args: Vec = env::args().collect(); - if let Err(err) = standalone::try_run_standalone_binary(args.clone()) { - eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); - std::process::exit(1); - } - let flags = flags::flags_from_vec(args); if !flags.v8_flags.is_empty() { init_v8_flags(&*flags.v8_flags); diff --git a/cli/standalone.rs b/cli/standalone.rs index fea42fc969b1c0..a072f59c51c681 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -1,159 +1,26 @@ -use crate::colors; -use crate::flags::Flags; -use crate::tokio_util; -use crate::version; use deno_core::error::bail; -use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::futures::FutureExt; -use deno_core::ModuleLoader; -use deno_core::ModuleSpecifier; -use deno_core::OpState; -use deno_runtime::permissions::Permissions; -use deno_runtime::worker::MainWorker; -use deno_runtime::worker::WorkerOptions; -use std::cell::RefCell; -use std::convert::TryInto; -use std::env::current_exe; use std::fs::File; use std::io::Read; use std::io::Seek; use std::io::SeekFrom; use std::io::Write; use std::path::PathBuf; -use std::pin::Pin; -use std::rc::Rc; -use std::sync::Arc; const MAGIC_TRAILER: &[u8; 8] = b"d3n0l4nd"; -/// This function will try to run this binary as a standalone binary -/// produced by `deno compile`. It determines if this is a stanalone -/// binary by checking for the magic trailer string `D3N0` at EOF-12. -/// After the magic trailer is a u64 pointer to the start of the JS -/// file embedded in the binary. This file is read, and run. If no -/// magic trailer is present, this function exits with Ok(()). -pub fn try_run_standalone_binary(args: Vec) -> Result<(), AnyError> { - let current_exe_path = current_exe()?; - - let mut current_exe = File::open(current_exe_path)?; - let trailer_pos = current_exe.seek(SeekFrom::End(-16))?; - let mut trailer = [0; 16]; - current_exe.read_exact(&mut trailer)?; - let (magic_trailer, bundle_pos_arr) = trailer.split_at(8); - if magic_trailer == MAGIC_TRAILER { - let bundle_pos_arr: &[u8; 8] = bundle_pos_arr.try_into()?; - let bundle_pos = u64::from_be_bytes(*bundle_pos_arr); - current_exe.seek(SeekFrom::Start(bundle_pos))?; - - let bundle_len = trailer_pos - bundle_pos; - let mut bundle = String::new(); - current_exe.take(bundle_len).read_to_string(&mut bundle)?; - // TODO: check amount of bytes read - - if let Err(err) = tokio_util::run_basic(run(bundle, args)) { - eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); - std::process::exit(1); - } - std::process::exit(0); - } else { - Ok(()) - } -} - -const SPECIFIER: &str = "file://$deno$/bundle.js"; - -struct EmbeddedModuleLoader(String); - -impl ModuleLoader for EmbeddedModuleLoader { - fn resolve( - &self, - _op_state: Rc>, - specifier: &str, - _referrer: &str, - _is_main: bool, - ) -> Result { - if specifier != SPECIFIER { - return Err(type_error( - "Self-contained binaries don't support module loading", - )); - } - Ok(ModuleSpecifier::resolve_url(specifier)?) - } - - fn load( - &self, - _op_state: Rc>, - module_specifier: &ModuleSpecifier, - _maybe_referrer: Option, - _is_dynamic: bool, - ) -> Pin> { - let module_specifier = module_specifier.clone(); - let code = self.0.to_string(); - async move { - if module_specifier.to_string() != SPECIFIER { - return Err(type_error( - "Self-contained binaries don't support module loading", - )); - } - Ok(deno_core::ModuleSource { - code, - module_url_specified: module_specifier.to_string(), - module_url_found: module_specifier.to_string(), - }) - } - .boxed_local() - } -} - -async fn run(source_code: String, args: Vec) -> Result<(), AnyError> { - let mut flags = Flags::default(); - flags.argv = args[1..].to_vec(); - // TODO(lucacasonato): remove once you can specify this correctly through embedded metadata - flags.unstable = true; - let main_module = ModuleSpecifier::resolve_url(SPECIFIER)?; - let permissions = Permissions::allow_all(); - let module_loader = Rc::new(EmbeddedModuleLoader(source_code)); - let create_web_worker_cb = Arc::new(|_| { - todo!("Worker are currently not supported in standalone binaries"); - }); - - let options = WorkerOptions { - apply_source_maps: false, - args: flags.argv.clone(), - debug_flag: false, - user_agent: crate::http_util::get_user_agent(), - unstable: true, - ca_filepath: None, - seed: None, - js_error_create_fn: None, - create_web_worker_cb, - attach_inspector: false, - maybe_inspector_server: None, - should_break_on_first_statement: false, - module_loader, - runtime_version: version::deno(), - ts_version: version::TYPESCRIPT.to_string(), - no_color: !colors::use_color(), - get_error_class_fn: Some(&crate::errors::get_error_class_name), - }; - let mut worker = - MainWorker::from_options(main_module.clone(), permissions, &options); - worker.bootstrap(&options); - worker.execute_module(&main_module).await?; - worker.execute("window.dispatchEvent(new Event('load'))")?; - worker.run_event_loop().await?; - worker.execute("window.dispatchEvent(new Event('unload'))")?; - Ok(()) -} - -/// This functions creates a standalone deno binary by appending a bundle -/// and magic trailer to the currently executing binary. pub async fn create_standalone_binary( mut source_code: Vec, output: PathBuf, ) -> Result<(), AnyError> { - let original_binary_path = std::env::current_exe()?; + + let binary_dir = match std::env::var("DENO_INSTALL") { + Ok(dir) => dir, + Err(_) => bail!("Cannot find $DENO_INSTALL in environment variables") + }; + let original_binary_path = PathBuf::from(binary_dir).join("/deno-rt"); + println!("original_binary_path: {:?}", original_binary_path); + let mut original_bin = tokio::fs::read(original_binary_path).await?; let mut trailer = MAGIC_TRAILER.to_vec(); @@ -198,4 +65,4 @@ pub async fn create_standalone_binary( } Ok(()) -} +} \ No newline at end of file diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 8632019b635c07..db72d9649ab875 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -9,6 +9,10 @@ edition = "2018" description = "Provides the deno runtime library" repository = "https://github.com/denoland/deno" +[[bin]] +name = "deno-rt" +path = "main.rs" + [lib] name = "deno_runtime" path = "lib.rs" diff --git a/runtime/lib.rs b/runtime/lib.rs index 6745f3ec81a16f..145ffcd6c8a8f9 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -20,6 +20,7 @@ pub mod js; pub mod metrics; pub mod ops; pub mod permissions; +pub mod standalone; pub mod resolve_addr; pub mod tokio_util; pub mod web_worker; diff --git a/runtime/main.rs b/runtime/main.rs new file mode 100644 index 00000000000000..1c37bebc969e7f --- /dev/null +++ b/runtime/main.rs @@ -0,0 +1,10 @@ +fn main() { + #[cfg(windows)] + colors::enable_ansi(); // For Windows 10 + + let args: Vec = std::env::args().collect(); + if let Err(err) = deno_runtime::standalone::try_run_standalone_binary(args) { + eprintln!("{}: {}", deno_runtime::colors::red_bold("error"), err.to_string()); + std::process::exit(1); + } +} \ No newline at end of file diff --git a/runtime/standalone.rs b/runtime/standalone.rs new file mode 100644 index 00000000000000..5a1f13f90ccee2 --- /dev/null +++ b/runtime/standalone.rs @@ -0,0 +1,139 @@ +use crate::colors; +use crate::tokio_util; +use crate::permissions::Permissions; +use crate::worker::MainWorker; +use crate::worker::WorkerOptions; +use deno_core::error::type_error; +use deno_core::error::AnyError; +use deno_core::futures::FutureExt; +use deno_core::ModuleLoader; +use deno_core::ModuleSpecifier; +use deno_core::OpState; +use std::cell::RefCell; +use std::convert::TryInto; +use std::fs::File; +use std::io::Read; +use std::io::Seek; +use std::io::SeekFrom; +use std::pin::Pin; +use std::rc::Rc; +use std::sync::Arc; + +const MAGIC_TRAILER: &[u8; 8] = b"d3n0l4nd"; +const SPECIFIER: &str = "file://$deno$/bundle.js"; + +pub fn try_run_standalone_binary(args: Vec) -> Result<(), AnyError> { + let current_exe_path = std::env::current_exe()?; + + let mut current_exe = File::open(current_exe_path)?; + let trailer_pos = current_exe.seek(SeekFrom::End(-16))?; + let mut trailer = [0; 16]; + current_exe.read_exact(&mut trailer)?; + let (magic_trailer, bundle_pos_arr) = trailer.split_at(8); + if magic_trailer == MAGIC_TRAILER { + let bundle_pos_arr: &[u8; 8] = bundle_pos_arr.try_into()?; + let bundle_pos = u64::from_be_bytes(*bundle_pos_arr); + current_exe.seek(SeekFrom::Start(bundle_pos))?; + + let bundle_len = trailer_pos - bundle_pos; + let mut bundle = String::new(); + current_exe.take(bundle_len).read_to_string(&mut bundle)?; + // TODO: check amount of bytes read + + if let Err(err) = tokio_util::run_basic(run(bundle, args)) { + eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); + std::process::exit(1); + } + std::process::exit(0); + } else { + Ok(()) + } +} + +async fn run(source_code: String, args: Vec) -> Result<(), AnyError> { + let main_module = ModuleSpecifier::resolve_url(SPECIFIER)?; + let permissions = Permissions::allow_all(); + let module_loader = Rc::new(EmbeddedModuleLoader(source_code)); + let create_web_worker_cb = Arc::new(|_| { + todo!("Worker are currently not supported in standalone binaries"); + }); + + let options = WorkerOptions { + apply_source_maps: false, + args, + debug_flag: false, + user_agent: "Deno/1.6.3".to_string(), // TODO (yos1p) Based on Deno version and user agent + unstable: true, + ca_filepath: None, + seed: None, + js_error_create_fn: None, + create_web_worker_cb, + attach_inspector: false, + maybe_inspector_server: None, + should_break_on_first_statement: false, + module_loader, + runtime_version: "1.6.3".to_string(), // TODO (yos1p) Deno version + ts_version: "4.1.3".to_string(), // TODO (yos1p) TS version + no_color: !colors::use_color(), + get_error_class_fn: Some(&get_error_class_name), + }; + let mut worker = + MainWorker::from_options(main_module.clone(), permissions, &options); + worker.bootstrap(&options); + worker.execute_module(&main_module).await?; + worker.execute("window.dispatchEvent(new Event('load'))")?; + worker.run_event_loop().await?; + worker.execute("window.dispatchEvent(new Event('unload'))")?; + Ok(()) +} + + +fn get_error_class_name(e: &AnyError) -> &'static str { + crate::errors::get_error_class_name(e) + .unwrap_or_else(|| { + panic!("Error '{}' contains boxed error of unknown type", e); + }) +} + +struct EmbeddedModuleLoader(String); + +impl ModuleLoader for EmbeddedModuleLoader { + fn resolve( + &self, + _op_state: Rc>, + specifier: &str, + _referrer: &str, + _is_main: bool, + ) -> Result { + if specifier != SPECIFIER { + return Err(type_error( + "Self-contained binaries don't support module loading", + )); + } + Ok(ModuleSpecifier::resolve_url(specifier)?) + } + + fn load( + &self, + _op_state: Rc>, + module_specifier: &ModuleSpecifier, + _maybe_referrer: Option, + _is_dynamic: bool, + ) -> Pin> { + let module_specifier = module_specifier.clone(); + let code = self.0.to_string(); + async move { + if module_specifier.to_string() != SPECIFIER { + return Err(type_error( + "Self-contained binaries don't support module loading", + )); + } + Ok(deno_core::ModuleSource { + code, + module_url_specified: module_specifier.to_string(), + module_url_found: module_specifier.to_string(), + }) + } + .boxed_local() + } +} From 443b67e28eb77a20045b31b410261ec5d72f00c0 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 14:02:23 +0700 Subject: [PATCH 02/20] fix formatting and lint --- cli/standalone.rs | 5 ++--- runtime/lib.rs | 2 +- runtime/main.rs | 20 ++++++++++++-------- runtime/standalone.rs | 12 +++++------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/cli/standalone.rs b/cli/standalone.rs index a072f59c51c681..566b8a1be3d2d2 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -13,10 +13,9 @@ pub async fn create_standalone_binary( mut source_code: Vec, output: PathBuf, ) -> Result<(), AnyError> { - let binary_dir = match std::env::var("DENO_INSTALL") { Ok(dir) => dir, - Err(_) => bail!("Cannot find $DENO_INSTALL in environment variables") + Err(_) => bail!("Cannot find $DENO_INSTALL in environment variables"), }; let original_binary_path = PathBuf::from(binary_dir).join("/deno-rt"); println!("original_binary_path: {:?}", original_binary_path); @@ -65,4 +64,4 @@ pub async fn create_standalone_binary( } Ok(()) -} \ No newline at end of file +} diff --git a/runtime/lib.rs b/runtime/lib.rs index 145ffcd6c8a8f9..96d54710c66a11 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -20,8 +20,8 @@ pub mod js; pub mod metrics; pub mod ops; pub mod permissions; -pub mod standalone; pub mod resolve_addr; +pub mod standalone; pub mod tokio_util; pub mod web_worker; pub mod worker; diff --git a/runtime/main.rs b/runtime/main.rs index 1c37bebc969e7f..ebcc5611fb8201 100644 --- a/runtime/main.rs +++ b/runtime/main.rs @@ -1,10 +1,14 @@ fn main() { - #[cfg(windows)] - colors::enable_ansi(); // For Windows 10 + #[cfg(windows)] + colors::enable_ansi(); // For Windows 10 - let args: Vec = std::env::args().collect(); - if let Err(err) = deno_runtime::standalone::try_run_standalone_binary(args) { - eprintln!("{}: {}", deno_runtime::colors::red_bold("error"), err.to_string()); - std::process::exit(1); - } -} \ No newline at end of file + let args: Vec = std::env::args().collect(); + if let Err(err) = deno_runtime::standalone::try_run_standalone_binary(args) { + eprintln!( + "{}: {}", + deno_runtime::colors::red_bold("error"), + err.to_string() + ); + std::process::exit(1); + } +} diff --git a/runtime/standalone.rs b/runtime/standalone.rs index 5a1f13f90ccee2..7dfe24908af461 100644 --- a/runtime/standalone.rs +++ b/runtime/standalone.rs @@ -1,6 +1,6 @@ use crate::colors; -use crate::tokio_util; use crate::permissions::Permissions; +use crate::tokio_util; use crate::worker::MainWorker; use crate::worker::WorkerOptions; use deno_core::error::type_error; @@ -73,7 +73,7 @@ async fn run(source_code: String, args: Vec) -> Result<(), AnyError> { should_break_on_first_statement: false, module_loader, runtime_version: "1.6.3".to_string(), // TODO (yos1p) Deno version - ts_version: "4.1.3".to_string(), // TODO (yos1p) TS version + ts_version: "4.1.3".to_string(), // TODO (yos1p) TS version no_color: !colors::use_color(), get_error_class_fn: Some(&get_error_class_name), }; @@ -87,12 +87,10 @@ async fn run(source_code: String, args: Vec) -> Result<(), AnyError> { Ok(()) } - fn get_error_class_name(e: &AnyError) -> &'static str { - crate::errors::get_error_class_name(e) - .unwrap_or_else(|| { - panic!("Error '{}' contains boxed error of unknown type", e); - }) + crate::errors::get_error_class_name(e).unwrap_or_else(|| { + panic!("Error '{}' contains boxed error of unknown type", e); + }) } struct EmbeddedModuleLoader(String); From b7bc053e647cf78dbb7b1663b54d6ce203d00cd8 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 14:35:20 +0700 Subject: [PATCH 03/20] fix deno-rt dir --- cli/standalone.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cli/standalone.rs b/cli/standalone.rs index 566b8a1be3d2d2..c95246b783c160 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -13,14 +13,10 @@ pub async fn create_standalone_binary( mut source_code: Vec, output: PathBuf, ) -> Result<(), AnyError> { - let binary_dir = match std::env::var("DENO_INSTALL") { - Ok(dir) => dir, - Err(_) => bail!("Cannot find $DENO_INSTALL in environment variables"), - }; - let original_binary_path = PathBuf::from(binary_dir).join("/deno-rt"); - println!("original_binary_path: {:?}", original_binary_path); + let cli_binary = std::env::current_exe()?; + let deno_rt_path = cli_binary.parent().unwrap().join("deno-rt"); - let mut original_bin = tokio::fs::read(original_binary_path).await?; + let mut original_bin = tokio::fs::read(deno_rt_path).await?; let mut trailer = MAGIC_TRAILER.to_vec(); trailer.write_all(&original_bin.len().to_be_bytes())?; From da1d8f8b3f54145544529759d78788a700823dc3 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 15:33:19 +0700 Subject: [PATCH 04/20] Fix standalone args --- runtime/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/main.rs b/runtime/main.rs index ebcc5611fb8201..b25df7aeea3600 100644 --- a/runtime/main.rs +++ b/runtime/main.rs @@ -2,7 +2,8 @@ fn main() { #[cfg(windows)] colors::enable_ansi(); // For Windows 10 - let args: Vec = std::env::args().collect(); + let args_raw: Vec = std::env::args().collect(); + let args: Vec = args_raw[1..].to_vec(); if let Err(err) = deno_runtime::standalone::try_run_standalone_binary(args) { eprintln!( "{}: {}", From 1a72ff428fdd1e0ee1929b14418bd517f50ad44b Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 17:02:01 +0700 Subject: [PATCH 05/20] fix runtime for windows release --- runtime/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/main.rs b/runtime/main.rs index b25df7aeea3600..9172874b6a3469 100644 --- a/runtime/main.rs +++ b/runtime/main.rs @@ -1,6 +1,6 @@ fn main() { #[cfg(windows)] - colors::enable_ansi(); // For Windows 10 + deno_runtime::colors::enable_ansi(); // For Windows 10 let args_raw: Vec = std::env::args().collect(); let args: Vec = args_raw[1..].to_vec(); From 5b8c15a33104946704a2d162eec723fd21e7868a Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 18:00:39 +0700 Subject: [PATCH 06/20] fix deno-rt extension for windows build --- cli/standalone.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli/standalone.rs b/cli/standalone.rs index c95246b783c160..fc7c682467f83d 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -14,7 +14,11 @@ pub async fn create_standalone_binary( output: PathBuf, ) -> Result<(), AnyError> { let cli_binary = std::env::current_exe()?; - let deno_rt_path = cli_binary.parent().unwrap().join("deno-rt"); + let deno_rt_path = if cfg!(windows) { + cli_binary.parent().unwrap().join("deno-rt.exe") + } else { + cli_binary.parent().unwrap().join("deno-rt") + }; let mut original_bin = tokio::fs::read(deno_rt_path).await?; From 4346d61aa60eb5f27d1ce6725d1c4aeb1f6e2615 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 18:44:11 +0700 Subject: [PATCH 07/20] Revert changes on Deno compile --- cli/standalone.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cli/standalone.rs b/cli/standalone.rs index fc7c682467f83d..16677f75522f47 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -13,14 +13,8 @@ pub async fn create_standalone_binary( mut source_code: Vec, output: PathBuf, ) -> Result<(), AnyError> { - let cli_binary = std::env::current_exe()?; - let deno_rt_path = if cfg!(windows) { - cli_binary.parent().unwrap().join("deno-rt.exe") - } else { - cli_binary.parent().unwrap().join("deno-rt") - }; - - let mut original_bin = tokio::fs::read(deno_rt_path).await?; + let original_binary_path = std::env::current_exe()?; + let mut original_bin = tokio::fs::read(original_binary_path).await?; let mut trailer = MAGIC_TRAILER.to_vec(); trailer.write_all(&original_bin.len().to_be_bytes())?; From c550e499f50b5a9a981da4c9a412253f1c1ec6d8 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 19:23:35 +0700 Subject: [PATCH 08/20] Fix standalone error --- cli/main.rs | 7 +++++++ runtime/main.rs | 3 +-- runtime/standalone.rs | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cli/main.rs b/cli/main.rs index 27c12210e7b298..895779cf3994ab 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1219,6 +1219,13 @@ pub fn main() { colors::enable_ansi(); // For Windows 10 let args: Vec = env::args().collect(); + if let Err(err) = + deno_runtime::standalone::try_run_standalone_binary(args.clone()) + { + eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); + std::process::exit(1); + } + let flags = flags::flags_from_vec(args); if !flags.v8_flags.is_empty() { init_v8_flags(&*flags.v8_flags); diff --git a/runtime/main.rs b/runtime/main.rs index 9172874b6a3469..c311de16a5e742 100644 --- a/runtime/main.rs +++ b/runtime/main.rs @@ -2,8 +2,7 @@ fn main() { #[cfg(windows)] deno_runtime::colors::enable_ansi(); // For Windows 10 - let args_raw: Vec = std::env::args().collect(); - let args: Vec = args_raw[1..].to_vec(); + let args: Vec = std::env::args().collect(); if let Err(err) = deno_runtime::standalone::try_run_standalone_binary(args) { eprintln!( "{}: {}", diff --git a/runtime/standalone.rs b/runtime/standalone.rs index 7dfe24908af461..8e50e9813260b2 100644 --- a/runtime/standalone.rs +++ b/runtime/standalone.rs @@ -40,7 +40,8 @@ pub fn try_run_standalone_binary(args: Vec) -> Result<(), AnyError> { current_exe.take(bundle_len).read_to_string(&mut bundle)?; // TODO: check amount of bytes read - if let Err(err) = tokio_util::run_basic(run(bundle, args)) { + let parsed_args: Vec = args[1..].to_vec(); + if let Err(err) = tokio_util::run_basic(run(bundle, parsed_args)) { eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); std::process::exit(1); } From b77ca714c1ada71172b02c51fd02a689e7f7833b Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 31 Dec 2020 23:50:28 +0700 Subject: [PATCH 09/20] move denort to cli crate --- cli/Cargo.toml | 4 ++++ cli/main.rs | 3 ++- cli/rt.rs | 5 +++++ cli/rt/main.rs | 19 +++++++++++++++++++ {runtime => cli/rt}/standalone.rs | 14 ++++++++------ runtime/Cargo.toml | 4 ---- runtime/lib.rs | 1 - runtime/main.rs | 14 -------------- 8 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 cli/rt.rs create mode 100644 cli/rt/main.rs rename {runtime => cli/rt}/standalone.rs (92%) delete mode 100644 runtime/main.rs diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 5b715ba9def213..f760f1ae269a8a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -14,6 +14,10 @@ default-run = "deno" name = "deno" path = "main.rs" +[[bin]] +name = "denort" +path = "rt/main.rs" + [[bench]] name = "deno_bench" harness = false diff --git a/cli/main.rs b/cli/main.rs index 895779cf3994ab..1caabf76e2f0c5 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -33,6 +33,7 @@ mod module_graph; mod module_loader; mod ops; mod program_state; +mod rt; mod source_maps; mod specifier_handler; mod standalone; @@ -1220,7 +1221,7 @@ pub fn main() { let args: Vec = env::args().collect(); if let Err(err) = - deno_runtime::standalone::try_run_standalone_binary(args.clone()) + crate::rt::try_run_standalone_binary(args.clone()) { eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); std::process::exit(1); diff --git a/cli/rt.rs b/cli/rt.rs new file mode 100644 index 00000000000000..c99bd79598c22e --- /dev/null +++ b/cli/rt.rs @@ -0,0 +1,5 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +mod standalone; + +pub use standalone::try_run_standalone_binary; \ No newline at end of file diff --git a/cli/rt/main.rs b/cli/rt/main.rs new file mode 100644 index 00000000000000..ecbdef86a258f6 --- /dev/null +++ b/cli/rt/main.rs @@ -0,0 +1,19 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +mod standalone; + +fn main() { + #[cfg(windows)] + deno_runtime::colors::enable_ansi(); // For Windows 10 + + let args: Vec = std::env::args().collect(); + if let Err(err) = standalone::try_run_standalone_binary(args) { + eprintln!( + "{}: {}", + deno_runtime::colors::red_bold("error"), + err.to_string() + ); + std::process::exit(1); + } + } + \ No newline at end of file diff --git a/runtime/standalone.rs b/cli/rt/standalone.rs similarity index 92% rename from runtime/standalone.rs rename to cli/rt/standalone.rs index 8e50e9813260b2..5811813c0011f0 100644 --- a/runtime/standalone.rs +++ b/cli/rt/standalone.rs @@ -1,14 +1,16 @@ -use crate::colors; -use crate::permissions::Permissions; -use crate::tokio_util; -use crate::worker::MainWorker; -use crate::worker::WorkerOptions; +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + use deno_core::error::type_error; use deno_core::error::AnyError; use deno_core::futures::FutureExt; use deno_core::ModuleLoader; use deno_core::ModuleSpecifier; use deno_core::OpState; +use deno_runtime::colors; +use deno_runtime::permissions::Permissions; +use deno_runtime::tokio_util; +use deno_runtime::worker::MainWorker; +use deno_runtime::worker::WorkerOptions; use std::cell::RefCell; use std::convert::TryInto; use std::fs::File; @@ -89,7 +91,7 @@ async fn run(source_code: String, args: Vec) -> Result<(), AnyError> { } fn get_error_class_name(e: &AnyError) -> &'static str { - crate::errors::get_error_class_name(e).unwrap_or_else(|| { + deno_runtime::errors::get_error_class_name(e).unwrap_or_else(|| { panic!("Error '{}' contains boxed error of unknown type", e); }) } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index db72d9649ab875..8632019b635c07 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -9,10 +9,6 @@ edition = "2018" description = "Provides the deno runtime library" repository = "https://github.com/denoland/deno" -[[bin]] -name = "deno-rt" -path = "main.rs" - [lib] name = "deno_runtime" path = "lib.rs" diff --git a/runtime/lib.rs b/runtime/lib.rs index 96d54710c66a11..6745f3ec81a16f 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -21,7 +21,6 @@ pub mod metrics; pub mod ops; pub mod permissions; pub mod resolve_addr; -pub mod standalone; pub mod tokio_util; pub mod web_worker; pub mod worker; diff --git a/runtime/main.rs b/runtime/main.rs deleted file mode 100644 index c311de16a5e742..00000000000000 --- a/runtime/main.rs +++ /dev/null @@ -1,14 +0,0 @@ -fn main() { - #[cfg(windows)] - deno_runtime::colors::enable_ansi(); // For Windows 10 - - let args: Vec = std::env::args().collect(); - if let Err(err) = deno_runtime::standalone::try_run_standalone_binary(args) { - eprintln!( - "{}: {}", - deno_runtime::colors::red_bold("error"), - err.to_string() - ); - std::process::exit(1); - } -} From 89c077527831a3a8a0956cf2f6546c4c2253e001 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Fri, 1 Jan 2021 00:35:50 +0700 Subject: [PATCH 10/20] Fix denort code and lint --- cli/Cargo.toml | 2 +- cli/denort.rs | 18 ++++++ cli/rt.rs | 146 ++++++++++++++++++++++++++++++++++++++++++- cli/rt/main.rs | 19 ------ cli/rt/standalone.rs | 140 ----------------------------------------- 5 files changed, 163 insertions(+), 162 deletions(-) create mode 100644 cli/denort.rs delete mode 100644 cli/rt/main.rs delete mode 100644 cli/rt/standalone.rs diff --git a/cli/Cargo.toml b/cli/Cargo.toml index f760f1ae269a8a..e2a2ff47ec7702 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -16,7 +16,7 @@ path = "main.rs" [[bin]] name = "denort" -path = "rt/main.rs" +path = "denort.rs" [[bench]] name = "deno_bench" diff --git a/cli/denort.rs b/cli/denort.rs new file mode 100644 index 00000000000000..6c9a06b581de6e --- /dev/null +++ b/cli/denort.rs @@ -0,0 +1,18 @@ +// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. + +mod rt; + +fn main() { + #[cfg(windows)] + deno_runtime::colors::enable_ansi(); // For Windows 10 + + let args: Vec = std::env::args().collect(); + if let Err(err) = rt::try_run_standalone_binary(args) { + eprintln!( + "{}: {}", + deno_runtime::colors::red_bold("error"), + err.to_string() + ); + std::process::exit(1); + } +} diff --git a/cli/rt.rs b/cli/rt.rs index c99bd79598c22e..23c0d960eefda8 100644 --- a/cli/rt.rs +++ b/cli/rt.rs @@ -1,5 +1,147 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -mod standalone; +use deno_core::error::type_error; +use deno_core::error::AnyError; +use deno_core::futures::FutureExt; +use deno_core::ModuleLoader; +use deno_core::ModuleSpecifier; +use deno_core::OpState; +use deno_runtime::colors; +use deno_runtime::permissions::Permissions; +use deno_runtime::tokio_util; +use deno_runtime::worker::MainWorker; +use deno_runtime::worker::WorkerOptions; +use std::cell::RefCell; +use std::convert::TryInto; +use std::fs::File; +use std::io::Read; +use std::io::Seek; +use std::io::SeekFrom; +use std::pin::Pin; +use std::rc::Rc; +use std::sync::Arc; -pub use standalone::try_run_standalone_binary; \ No newline at end of file +const MAGIC_TRAILER: &[u8; 8] = b"d3n0l4nd"; +const SPECIFIER: &str = "file://$deno$/bundle.js"; + +pub fn try_run_standalone_binary(args: Vec) -> Result<(), AnyError> { + let current_exe_path = std::env::current_exe()?; + + let mut current_exe = File::open(current_exe_path)?; + let trailer_pos = current_exe.seek(SeekFrom::End(-16))?; + let mut trailer = [0; 16]; + current_exe.read_exact(&mut trailer)?; + let (magic_trailer, bundle_pos_arr) = trailer.split_at(8); + if magic_trailer == MAGIC_TRAILER { + let bundle_pos_arr: &[u8; 8] = bundle_pos_arr.try_into()?; + let bundle_pos = u64::from_be_bytes(*bundle_pos_arr); + current_exe.seek(SeekFrom::Start(bundle_pos))?; + + let bundle_len = trailer_pos - bundle_pos; + let mut bundle = String::new(); + current_exe.take(bundle_len).read_to_string(&mut bundle)?; + // TODO: check amount of bytes read + + let parsed_args: Vec = args[1..].to_vec(); + if let Err(err) = tokio_util::run_basic(run(bundle, parsed_args)) { + eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); + std::process::exit(1); + } + std::process::exit(0); + } else { + Ok(()) + } +} + +async fn run(source_code: String, args: Vec) -> Result<(), AnyError> { + let main_module = ModuleSpecifier::resolve_url(SPECIFIER)?; + let permissions = Permissions::allow_all(); + let module_loader = Rc::new(EmbeddedModuleLoader(source_code)); + let create_web_worker_cb = Arc::new(|_| { + todo!("Worker are currently not supported in standalone binaries"); + }); + + let options = WorkerOptions { + apply_source_maps: false, + args, + debug_flag: false, + user_agent: format!("Deno/{}", deno_version()), + unstable: true, + ca_filepath: None, + seed: None, + js_error_create_fn: None, + create_web_worker_cb, + attach_inspector: false, + maybe_inspector_server: None, + should_break_on_first_statement: false, + module_loader, + runtime_version: deno_version(), + ts_version: env!("TS_VERSION").to_string(), + no_color: !colors::use_color(), + get_error_class_fn: Some(&get_error_class_name), + }; + let mut worker = + MainWorker::from_options(main_module.clone(), permissions, &options); + worker.bootstrap(&options); + worker.execute_module(&main_module).await?; + worker.execute("window.dispatchEvent(new Event('load'))")?; + worker.run_event_loop().await?; + worker.execute("window.dispatchEvent(new Event('unload'))")?; + Ok(()) +} + +fn get_error_class_name(e: &AnyError) -> &'static str { + deno_runtime::errors::get_error_class_name(e).unwrap_or_else(|| { + panic!("Error '{}' contains boxed error of unknown type", e); + }) +} + +fn deno_version() -> String { + let semver = env!("CARGO_PKG_VERSION"); + option_env!("DENO_CANARY").map_or(semver.to_string(), |_| { + format!("{}+{}", semver, env!("GIT_COMMIT_HASH")) + }) +} + +struct EmbeddedModuleLoader(String); + +impl ModuleLoader for EmbeddedModuleLoader { + fn resolve( + &self, + _op_state: Rc>, + specifier: &str, + _referrer: &str, + _is_main: bool, + ) -> Result { + if specifier != SPECIFIER { + return Err(type_error( + "Self-contained binaries don't support module loading", + )); + } + Ok(ModuleSpecifier::resolve_url(specifier)?) + } + + fn load( + &self, + _op_state: Rc>, + module_specifier: &ModuleSpecifier, + _maybe_referrer: Option, + _is_dynamic: bool, + ) -> Pin> { + let module_specifier = module_specifier.clone(); + let code = self.0.to_string(); + async move { + if module_specifier.to_string() != SPECIFIER { + return Err(type_error( + "Self-contained binaries don't support module loading", + )); + } + Ok(deno_core::ModuleSource { + code, + module_url_specified: module_specifier.to_string(), + module_url_found: module_specifier.to_string(), + }) + } + .boxed_local() + } +} diff --git a/cli/rt/main.rs b/cli/rt/main.rs deleted file mode 100644 index ecbdef86a258f6..00000000000000 --- a/cli/rt/main.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. - -mod standalone; - -fn main() { - #[cfg(windows)] - deno_runtime::colors::enable_ansi(); // For Windows 10 - - let args: Vec = std::env::args().collect(); - if let Err(err) = standalone::try_run_standalone_binary(args) { - eprintln!( - "{}: {}", - deno_runtime::colors::red_bold("error"), - err.to_string() - ); - std::process::exit(1); - } - } - \ No newline at end of file diff --git a/cli/rt/standalone.rs b/cli/rt/standalone.rs deleted file mode 100644 index 5811813c0011f0..00000000000000 --- a/cli/rt/standalone.rs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. - -use deno_core::error::type_error; -use deno_core::error::AnyError; -use deno_core::futures::FutureExt; -use deno_core::ModuleLoader; -use deno_core::ModuleSpecifier; -use deno_core::OpState; -use deno_runtime::colors; -use deno_runtime::permissions::Permissions; -use deno_runtime::tokio_util; -use deno_runtime::worker::MainWorker; -use deno_runtime::worker::WorkerOptions; -use std::cell::RefCell; -use std::convert::TryInto; -use std::fs::File; -use std::io::Read; -use std::io::Seek; -use std::io::SeekFrom; -use std::pin::Pin; -use std::rc::Rc; -use std::sync::Arc; - -const MAGIC_TRAILER: &[u8; 8] = b"d3n0l4nd"; -const SPECIFIER: &str = "file://$deno$/bundle.js"; - -pub fn try_run_standalone_binary(args: Vec) -> Result<(), AnyError> { - let current_exe_path = std::env::current_exe()?; - - let mut current_exe = File::open(current_exe_path)?; - let trailer_pos = current_exe.seek(SeekFrom::End(-16))?; - let mut trailer = [0; 16]; - current_exe.read_exact(&mut trailer)?; - let (magic_trailer, bundle_pos_arr) = trailer.split_at(8); - if magic_trailer == MAGIC_TRAILER { - let bundle_pos_arr: &[u8; 8] = bundle_pos_arr.try_into()?; - let bundle_pos = u64::from_be_bytes(*bundle_pos_arr); - current_exe.seek(SeekFrom::Start(bundle_pos))?; - - let bundle_len = trailer_pos - bundle_pos; - let mut bundle = String::new(); - current_exe.take(bundle_len).read_to_string(&mut bundle)?; - // TODO: check amount of bytes read - - let parsed_args: Vec = args[1..].to_vec(); - if let Err(err) = tokio_util::run_basic(run(bundle, parsed_args)) { - eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); - std::process::exit(1); - } - std::process::exit(0); - } else { - Ok(()) - } -} - -async fn run(source_code: String, args: Vec) -> Result<(), AnyError> { - let main_module = ModuleSpecifier::resolve_url(SPECIFIER)?; - let permissions = Permissions::allow_all(); - let module_loader = Rc::new(EmbeddedModuleLoader(source_code)); - let create_web_worker_cb = Arc::new(|_| { - todo!("Worker are currently not supported in standalone binaries"); - }); - - let options = WorkerOptions { - apply_source_maps: false, - args, - debug_flag: false, - user_agent: "Deno/1.6.3".to_string(), // TODO (yos1p) Based on Deno version and user agent - unstable: true, - ca_filepath: None, - seed: None, - js_error_create_fn: None, - create_web_worker_cb, - attach_inspector: false, - maybe_inspector_server: None, - should_break_on_first_statement: false, - module_loader, - runtime_version: "1.6.3".to_string(), // TODO (yos1p) Deno version - ts_version: "4.1.3".to_string(), // TODO (yos1p) TS version - no_color: !colors::use_color(), - get_error_class_fn: Some(&get_error_class_name), - }; - let mut worker = - MainWorker::from_options(main_module.clone(), permissions, &options); - worker.bootstrap(&options); - worker.execute_module(&main_module).await?; - worker.execute("window.dispatchEvent(new Event('load'))")?; - worker.run_event_loop().await?; - worker.execute("window.dispatchEvent(new Event('unload'))")?; - Ok(()) -} - -fn get_error_class_name(e: &AnyError) -> &'static str { - deno_runtime::errors::get_error_class_name(e).unwrap_or_else(|| { - panic!("Error '{}' contains boxed error of unknown type", e); - }) -} - -struct EmbeddedModuleLoader(String); - -impl ModuleLoader for EmbeddedModuleLoader { - fn resolve( - &self, - _op_state: Rc>, - specifier: &str, - _referrer: &str, - _is_main: bool, - ) -> Result { - if specifier != SPECIFIER { - return Err(type_error( - "Self-contained binaries don't support module loading", - )); - } - Ok(ModuleSpecifier::resolve_url(specifier)?) - } - - fn load( - &self, - _op_state: Rc>, - module_specifier: &ModuleSpecifier, - _maybe_referrer: Option, - _is_dynamic: bool, - ) -> Pin> { - let module_specifier = module_specifier.clone(); - let code = self.0.to_string(); - async move { - if module_specifier.to_string() != SPECIFIER { - return Err(type_error( - "Self-contained binaries don't support module loading", - )); - } - Ok(deno_core::ModuleSource { - code, - module_url_specified: module_specifier.to_string(), - module_url_found: module_specifier.to_string(), - }) - } - .boxed_local() - } -} From c444a4102598c9d9d46e129502952aa4e89db829 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Fri, 1 Jan 2021 00:42:49 +0700 Subject: [PATCH 11/20] rustfmt cli/main.rs --- cli/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cli/main.rs b/cli/main.rs index 1caabf76e2f0c5..d4abed59ebcecd 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1220,9 +1220,7 @@ pub fn main() { colors::enable_ansi(); // For Windows 10 let args: Vec = env::args().collect(); - if let Err(err) = - crate::rt::try_run_standalone_binary(args.clone()) - { + if let Err(err) = crate::rt::try_run_standalone_binary(args.clone()) { eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); std::process::exit(1); } From a4053e019e0f441c688fa4b2a318e27dec2ec04a Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Fri, 1 Jan 2021 00:53:22 +0700 Subject: [PATCH 12/20] track binary size of denort in benchmarks --- cli/bench/main.rs | 5 +++++ test_util/src/lib.rs | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/cli/bench/main.rs b/cli/bench/main.rs index de19ceda84dee0..1ddf7878c687e6 100644 --- a/cli/bench/main.rs +++ b/cli/bench/main.rs @@ -180,6 +180,11 @@ fn get_binary_sizes(target_dir: &PathBuf) -> Result { Value::Number(Number::from(test_util::deno_exe_path().metadata()?.len())), ); + sizes.insert( + "denort".to_string(), + Value::Number(Number::from(test_util::denort_exe_path().metadata()?.len())), + ); + // Because cargo's OUT_DIR is not predictable, search the build tree for // snapshot related files. for file in walkdir::WalkDir::new(target_dir) { diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 03b830783d0ee4..6199b2c97755e2 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -103,6 +103,15 @@ pub fn deno_exe_path() -> PathBuf { p } +pub fn denort_exe_path() -> PathBuf { + // Something like /Users/rld/src/deno/target/debug/deps/deno + let mut p = target_dir().join("denort"); + if cfg!(windows) { + p.set_extension("exe"); + } + p +} + pub fn prebuilt_tool_path(tool: &str) -> PathBuf { let mut exe = tool.to_string(); exe.push_str(if cfg!(windows) { ".exe" } else { "" }); From 580d3e4ad500c26d92206799659fa5732f034111 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Fri, 1 Jan 2021 09:52:28 +0700 Subject: [PATCH 13/20] add deny warning check for denort --- cli/denort.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/denort.rs b/cli/denort.rs index 6c9a06b581de6e..91652146f66cad 100644 --- a/cli/denort.rs +++ b/cli/denort.rs @@ -1,5 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +#![deny(warnings)] + mod rt; fn main() { From a518c2ee815d54c325ede6d822308b7461158ab2 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Fri, 1 Jan 2021 10:32:27 +0700 Subject: [PATCH 14/20] move args to run fn --- cli/rt.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cli/rt.rs b/cli/rt.rs index 23c0d960eefda8..ff53f4c92d9110 100644 --- a/cli/rt.rs +++ b/cli/rt.rs @@ -42,8 +42,7 @@ pub fn try_run_standalone_binary(args: Vec) -> Result<(), AnyError> { current_exe.take(bundle_len).read_to_string(&mut bundle)?; // TODO: check amount of bytes read - let parsed_args: Vec = args[1..].to_vec(); - if let Err(err) = tokio_util::run_basic(run(bundle, parsed_args)) { + if let Err(err) = tokio_util::run_basic(run(bundle, args)) { eprintln!("{}: {}", colors::red_bold("error"), err.to_string()); std::process::exit(1); } @@ -63,7 +62,7 @@ async fn run(source_code: String, args: Vec) -> Result<(), AnyError> { let options = WorkerOptions { apply_source_maps: false, - args, + args: args[1..].to_vec(), debug_flag: false, user_agent: format!("Deno/{}", deno_version()), unstable: true, From d84104acdcd37e79e6ec540da291c01e89d2cb47 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Tue, 5 Jan 2021 11:13:15 +0700 Subject: [PATCH 15/20] Fix lint and formatting --- cli/denort.rs | 2 +- cli/flags.rs | 2 +- cli/main.rs | 2 +- cli/standalone.rs | 2 +- cli/version.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/denort.rs b/cli/denort.rs index 811843ae278b0e..aa609ddba33fd6 100644 --- a/cli/denort.rs +++ b/cli/denort.rs @@ -3,8 +3,8 @@ #![deny(warnings)] mod flags_rt; -mod version; mod rt; +mod version; fn main() { #[cfg(windows)] diff --git a/cli/flags.rs b/cli/flags.rs index ef0fa15ff83a99..1457e89dfed110 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -12,8 +12,8 @@ use std::path::PathBuf; use std::str::FromStr; use tempfile::TempDir; -pub use crate::flags_rt::Flags; pub use crate::flags_rt::DenoSubcommand; +pub use crate::flags_rt::Flags; fn join_paths(allowlist: &[PathBuf], d: &str) -> String { allowlist diff --git a/cli/main.rs b/cli/main.rs index f2bfd39dfca6d6..e733a63f9da10f 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -48,8 +48,8 @@ mod version; use crate::file_fetcher::File; use crate::file_fetcher::FileFetcher; use crate::file_watcher::ModuleResolutionResult; -use crate::flags_rt::DenoSubcommand; use crate::flags::Flags; +use crate::flags_rt::DenoSubcommand; use crate::fmt_errors::PrettyJsError; use crate::import_map::ImportMap; use crate::media_type::MediaType; diff --git a/cli/standalone.rs b/cli/standalone.rs index 0fac4ae8589fb3..dccdb7cd0ea24d 100644 --- a/cli/standalone.rs +++ b/cli/standalone.rs @@ -1,7 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use crate::flags_rt::DenoSubcommand; use crate::flags::Flags; +use crate::flags_rt::DenoSubcommand; use crate::rt::Metadata; use deno_core::error::bail; use deno_core::error::AnyError; diff --git a/cli/version.rs b/cli/version.rs index b5369a688c8f56..21637f2500b07a 100644 --- a/cli/version.rs +++ b/cli/version.rs @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH"); -pub const TYPESCRIPT: &str = env!("TS_VERSION"); +pub const TYPESCRIPT: &str = env!("TS_VERSION"); pub fn deno() -> String { let semver = env!("CARGO_PKG_VERSION"); From 09ee2943f18fc6d2f0b979c9e4cef7c51c2dab15 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Tue, 5 Jan 2021 11:34:16 +0700 Subject: [PATCH 16/20] minor changes in main.rs --- cli/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/main.rs b/cli/main.rs index e733a63f9da10f..7e51814295a1b7 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -48,8 +48,8 @@ mod version; use crate::file_fetcher::File; use crate::file_fetcher::FileFetcher; use crate::file_watcher::ModuleResolutionResult; +use crate::flags::DenoSubcommand; use crate::flags::Flags; -use crate::flags_rt::DenoSubcommand; use crate::fmt_errors::PrettyJsError; use crate::import_map::ImportMap; use crate::media_type::MediaType; From 60460459e4f4cd564dbde1b91096fefb1a27f7a8 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Wed, 6 Jan 2021 19:40:18 +0700 Subject: [PATCH 17/20] Throw non-zero exit for denort --- cli/bench/main.rs | 2 +- cli/denort.rs | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cli/bench/main.rs b/cli/bench/main.rs index 5268d78e2696a3..d796237d1f6c4f 100644 --- a/cli/bench/main.rs +++ b/cli/bench/main.rs @@ -205,7 +205,7 @@ fn get_binary_sizes(target_dir: &PathBuf) -> Result { // add up size for denort sizes.insert( "denort".to_string(), - Value::Number(Number::from(test_util::denort_exe_path().metadata()?.len())) + Value::Number(Number::from(test_util::denort_exe_path().metadata()?.len())), ); // add up size for everything in target/release/deps/libswc* diff --git a/cli/denort.rs b/cli/denort.rs index aa609ddba33fd6..11202c3c2176c2 100644 --- a/cli/denort.rs +++ b/cli/denort.rs @@ -1,7 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -#![deny(warnings)] - mod flags_rt; mod rt; mod version; @@ -19,4 +17,11 @@ fn main() { ); std::process::exit(1); } + + // TODO (yos1p) Specify better error message + eprintln!( + "{}: Runtime Error.", + deno_runtime::colors::red_bold("error") + ); + std::process::exit(1); } From 73df12c1c131d7e25633d671547f25c3dfe859f8 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Wed, 6 Jan 2021 19:48:44 +0700 Subject: [PATCH 18/20] Fix fmt --- cli/denort.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/denort.rs b/cli/denort.rs index 11202c3c2176c2..a66489f40495ef 100644 --- a/cli/denort.rs +++ b/cli/denort.rs @@ -22,6 +22,6 @@ fn main() { eprintln!( "{}: Runtime Error.", deno_runtime::colors::red_bold("error") - ); + ); std::process::exit(1); } From 85806af83c0ad1c1ea30c2a7beef0e97bb2e0454 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Wed, 6 Jan 2021 22:48:07 +0700 Subject: [PATCH 19/20] Fix error message for denort --- cli/denort.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/denort.rs b/cli/denort.rs index a66489f40495ef..e59071743f5885 100644 --- a/cli/denort.rs +++ b/cli/denort.rs @@ -18,9 +18,8 @@ fn main() { std::process::exit(1); } - // TODO (yos1p) Specify better error message eprintln!( - "{}: Runtime Error.", + "{}: This executable is used internally by 'deno compile', it is not meant to be invoked directly.", deno_runtime::colors::red_bold("error") ); std::process::exit(1); From 339ff25e873ed87aad49716ee692f97f80387747 Mon Sep 17 00:00:00 2001 From: iamyaoxi Date: Thu, 7 Jan 2021 00:00:38 +0700 Subject: [PATCH 20/20] Trigger github actions