From a68eb3fcc3997fce8680f87edce46f6450e79635 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 13 Feb 2024 21:52:30 +0530 Subject: feat: denort binary for `deno compile` (#22205) This introduces the `denort` binary - a slim version of deno without tooling. The binary is used as the default for `deno compile`. Improves `deno compile` final size by ~2.5x (141 MB -> 61 MB) on Linux x86_64. --- cli/tools/run/hmr.rs | 179 ++++++++++++++++++++++++++------------------------- 1 file changed, 91 insertions(+), 88 deletions(-) (limited to 'cli/tools/run') diff --git a/cli/tools/run/hmr.rs b/cli/tools/run/hmr.rs index 88f90f680..4ca9ee8b9 100644 --- a/cli/tools/run/hmr.rs +++ b/cli/tools/run/hmr.rs @@ -61,105 +61,22 @@ pub struct HmrRunner { emitter: Arc, } -impl HmrRunner { - pub fn new( - emitter: Arc, - session: LocalInspectorSession, - watcher_communicator: Arc, - ) -> Self { - Self { - session, - emitter, - watcher_communicator, - script_ids: HashMap::new(), - } - } - +#[async_trait::async_trait(?Send)] +impl crate::worker::HmrRunner for HmrRunner { // TODO(bartlomieju): this code is duplicated in `cli/tools/coverage/mod.rs` - pub async fn start(&mut self) -> Result<(), AnyError> { + async fn start(&mut self) -> Result<(), AnyError> { self.enable_debugger().await } // TODO(bartlomieju): this code is duplicated in `cli/tools/coverage/mod.rs` - pub async fn stop(&mut self) -> Result<(), AnyError> { + async fn stop(&mut self) -> Result<(), AnyError> { self .watcher_communicator .change_restart_mode(WatcherRestartMode::Automatic); self.disable_debugger().await } - // TODO(bartlomieju): this code is duplicated in `cli/tools/coverage/mod.rs` - async fn enable_debugger(&mut self) -> Result<(), AnyError> { - self - .session - .post_message::<()>("Debugger.enable", None) - .await?; - self - .session - .post_message::<()>("Runtime.enable", None) - .await?; - Ok(()) - } - - // TODO(bartlomieju): this code is duplicated in `cli/tools/coverage/mod.rs` - async fn disable_debugger(&mut self) -> Result<(), AnyError> { - self - .session - .post_message::<()>("Debugger.disable", None) - .await?; - self - .session - .post_message::<()>("Runtime.disable", None) - .await?; - Ok(()) - } - - async fn set_script_source( - &mut self, - script_id: &str, - source: &str, - ) -> Result { - let result = self - .session - .post_message( - "Debugger.setScriptSource", - Some(json!({ - "scriptId": script_id, - "scriptSource": source, - "allowTopFrameEditing": true, - })), - ) - .await?; - - Ok(serde_json::from_value::( - result, - )?) - } - - async fn dispatch_hmr_event( - &mut self, - script_id: &str, - ) -> Result<(), AnyError> { - let expr = format!( - "dispatchEvent(new CustomEvent(\"hmr\", {{ detail: {{ path: \"{}\" }} }}));", - script_id - ); - - let _result = self - .session - .post_message( - "Runtime.evaluate", - Some(json!({ - "expression": expr, - "contextId": Some(1), - })), - ) - .await?; - - Ok(()) - } - - pub async fn run(&mut self) -> Result<(), AnyError> { + async fn run(&mut self) -> Result<(), AnyError> { self .watcher_communicator .change_restart_mode(WatcherRestartMode::Manual); @@ -252,3 +169,89 @@ impl HmrRunner { } } } + +impl HmrRunner { + pub fn new( + emitter: Arc, + session: LocalInspectorSession, + watcher_communicator: Arc, + ) -> Self { + Self { + session, + emitter, + watcher_communicator, + script_ids: HashMap::new(), + } + } + + // TODO(bartlomieju): this code is duplicated in `cli/tools/coverage/mod.rs` + async fn enable_debugger(&mut self) -> Result<(), AnyError> { + self + .session + .post_message::<()>("Debugger.enable", None) + .await?; + self + .session + .post_message::<()>("Runtime.enable", None) + .await?; + Ok(()) + } + + // TODO(bartlomieju): this code is duplicated in `cli/tools/coverage/mod.rs` + async fn disable_debugger(&mut self) -> Result<(), AnyError> { + self + .session + .post_message::<()>("Debugger.disable", None) + .await?; + self + .session + .post_message::<()>("Runtime.disable", None) + .await?; + Ok(()) + } + + async fn set_script_source( + &mut self, + script_id: &str, + source: &str, + ) -> Result { + let result = self + .session + .post_message( + "Debugger.setScriptSource", + Some(json!({ + "scriptId": script_id, + "scriptSource": source, + "allowTopFrameEditing": true, + })), + ) + .await?; + + Ok(serde_json::from_value::( + result, + )?) + } + + async fn dispatch_hmr_event( + &mut self, + script_id: &str, + ) -> Result<(), AnyError> { + let expr = format!( + "dispatchEvent(new CustomEvent(\"hmr\", {{ detail: {{ path: \"{}\" }} }}));", + script_id + ); + + let _result = self + .session + .post_message( + "Runtime.evaluate", + Some(json!({ + "expression": expr, + "contextId": Some(1), + })), + ) + .await?; + + Ok(()) + } +} -- cgit v1.2.3