diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-06-14 18:29:19 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-14 22:29:19 +0000 |
commit | 84c793275b324c262dde02a432462565584c83f7 (patch) | |
tree | a5995a842fabb37b2ecdab794dbbce76b530ac3a /cli/watcher.rs | |
parent | 48c6f7178703d448da229a5baf19efb403416da0 (diff) |
fix: reload config files on watcher restarts (#19487)
Closes #19468
Diffstat (limited to 'cli/watcher.rs')
-rw-r--r-- | cli/watcher.rs | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/cli/watcher.rs b/cli/watcher.rs deleted file mode 100644 index f9c2c1b42..000000000 --- a/cli/watcher.rs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. - -use crate::args::CliOptions; -use crate::cache::ParsedSourceCache; -use crate::graph_util::ModuleGraphContainer; -use crate::module_loader::CjsResolutionStore; - -use deno_core::parking_lot::Mutex; -use deno_core::ModuleSpecifier; - -use std::path::PathBuf; -use std::sync::Arc; - -pub struct FileWatcher { - cli_options: Arc<CliOptions>, - cjs_resolutions: Arc<CjsResolutionStore>, - graph_container: Arc<ModuleGraphContainer>, - maybe_reporter: Option<FileWatcherReporter>, - parsed_source_cache: Arc<ParsedSourceCache>, -} - -impl FileWatcher { - pub fn new( - cli_options: Arc<CliOptions>, - cjs_resolutions: Arc<CjsResolutionStore>, - graph_container: Arc<ModuleGraphContainer>, - maybe_reporter: Option<FileWatcherReporter>, - parsed_source_cache: Arc<ParsedSourceCache>, - ) -> Self { - Self { - cli_options, - cjs_resolutions, - parsed_source_cache, - graph_container, - maybe_reporter, - } - } - /// Reset all runtime state to its default. This should be used on file - /// watcher restarts. - pub fn reset(&self) { - self.cjs_resolutions.clear(); - self.parsed_source_cache.clear(); - self.graph_container.clear(); - - self.init_watcher(); - } - - // Add invariant files like the import map and explicit watch flag list to - // the watcher. Dedup for build_for_file_watcher and reset_for_file_watcher. - pub fn init_watcher(&self) { - let files_to_watch_sender = match &self.maybe_reporter { - Some(reporter) => &reporter.sender, - None => return, - }; - if let Some(watch_paths) = self.cli_options.watch_paths() { - files_to_watch_sender.send(watch_paths.clone()).unwrap(); - } - if let Ok(Some(import_map_path)) = self - .cli_options - .resolve_import_map_specifier() - .map(|ms| ms.and_then(|ref s| s.to_file_path().ok())) - { - files_to_watch_sender.send(vec![import_map_path]).unwrap(); - } - } -} - -#[derive(Clone, Debug)] -pub struct FileWatcherReporter { - sender: tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>, - file_paths: Arc<Mutex<Vec<PathBuf>>>, -} - -impl FileWatcherReporter { - pub fn new(sender: tokio::sync::mpsc::UnboundedSender<Vec<PathBuf>>) -> Self { - Self { - sender, - file_paths: Default::default(), - } - } -} - -impl deno_graph::source::Reporter for FileWatcherReporter { - fn on_load( - &self, - specifier: &ModuleSpecifier, - modules_done: usize, - modules_total: usize, - ) { - let mut file_paths = self.file_paths.lock(); - if specifier.scheme() == "file" { - file_paths.push(specifier.to_file_path().unwrap()); - } - - if modules_done == modules_total { - self.sender.send(file_paths.drain(..).collect()).unwrap(); - } - } -} |