summaryrefslogtreecommitdiff
path: root/cli/tools/run/hmr.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-02-13 21:52:30 +0530
committerGitHub <noreply@github.com>2024-02-13 21:52:30 +0530
commita68eb3fcc3997fce8680f87edce46f6450e79635 (patch)
tree6839607033226fdfb2ce1be3187ef93791096507 /cli/tools/run/hmr.rs
parent492a9fbb9194a24a1f9223f797b4f4df9efde2bd (diff)
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.
Diffstat (limited to 'cli/tools/run/hmr.rs')
-rw-r--r--cli/tools/run/hmr.rs179
1 files changed, 91 insertions, 88 deletions
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<Emitter>,
}
-impl HmrRunner {
- pub fn new(
- emitter: Arc<Emitter>,
- session: LocalInspectorSession,
- watcher_communicator: Arc<WatcherCommunicator>,
- ) -> 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<cdp::SetScriptSourceResponse, AnyError> {
- let result = self
- .session
- .post_message(
- "Debugger.setScriptSource",
- Some(json!({
- "scriptId": script_id,
- "scriptSource": source,
- "allowTopFrameEditing": true,
- })),
- )
- .await?;
-
- Ok(serde_json::from_value::<cdp::SetScriptSourceResponse>(
- 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<Emitter>,
+ session: LocalInspectorSession,
+ watcher_communicator: Arc<WatcherCommunicator>,
+ ) -> 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<cdp::SetScriptSourceResponse, AnyError> {
+ let result = self
+ .session
+ .post_message(
+ "Debugger.setScriptSource",
+ Some(json!({
+ "scriptId": script_id,
+ "scriptSource": source,
+ "allowTopFrameEditing": true,
+ })),
+ )
+ .await?;
+
+ Ok(serde_json::from_value::<cdp::SetScriptSourceResponse>(
+ 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(())
+ }
+}