diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-10-31 01:25:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-31 01:25:58 +0100 |
commit | 1713df13524ad20c6bd0413bcf4aa57adc3f9735 (patch) | |
tree | a558239a7f483cab10b83305b333d5ef9657bd3e /cli/emit.rs | |
parent | 48c5c3a3fb2f43716528db8915b36e55c411d94f (diff) |
feat: deno run --unstable-hmr (#20876)
This commit adds `--unstable-hmr` flag, that enabled Hot Module Replacement.
This flag works like `--watch` and accepts the same arguments. If
HMR is not possible the process will be restarted instead.
Currently HMR is only supported in `deno run` subcommand.
Upon HMR a `CustomEvent("hmr")` will be dispatched that contains
information which file was changed in its `details` property.
---------
Co-authored-by: Valentin Anger <syrupthinker@gryphno.de>
Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/emit.rs')
-rw-r--r-- | cli/emit.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/cli/emit.rs b/cli/emit.rs index e81d2e83c..8e51c4edd 100644 --- a/cli/emit.rs +++ b/cli/emit.rs @@ -101,6 +101,26 @@ impl Emitter { } } + /// Expects a file URL, panics otherwise. + pub async fn load_and_emit_for_hmr( + &self, + specifier: &ModuleSpecifier, + ) -> Result<String, AnyError> { + let media_type = MediaType::from_specifier(specifier); + let source_code = tokio::fs::read_to_string( + ModuleSpecifier::to_file_path(specifier).unwrap(), + ) + .await?; + let source_arc: Arc<str> = source_code.into(); + let parsed_source = self + .parsed_source_cache + .get_or_parse_module(specifier, source_arc, media_type)?; + let mut options = self.emit_options.clone(); + options.inline_source_map = false; + let transpiled_source = parsed_source.transpile(&options)?; + Ok(transpiled_source.text) + } + /// A hashing function that takes the source code and uses the global emit /// options then generates a string hash which can be stored to /// determine if the cached emit is valid or not. |