diff options
-rw-r--r-- | cli/main.rs | 24 | ||||
-rw-r--r-- | cli/module_graph2.rs | 16 |
2 files changed, 24 insertions, 16 deletions
diff --git a/cli/main.rs b/cli/main.rs index f89d344c0..382e76f23 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -550,22 +550,24 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<(), AnyError> { let main_module = ModuleSpecifier::resolve_url_or_path(&script)?; let program_state = ProgramState::new(flags.clone())?; - let mut module_graph_loader = module_graph::ModuleGraphLoader::new( - program_state.file_fetcher.clone(), - program_state.maybe_import_map.clone(), + let handler = Rc::new(RefCell::new(FetchHandler::new( + &program_state, Permissions::allow_all(), - false, - false, + )?)); + let mut builder = module_graph2::GraphBuilder2::new( + handler, + program_state.maybe_import_map.clone(), + program_state.lockfile.clone(), ); - module_graph_loader.add_to_graph(&main_module, None).await?; - let module_graph = module_graph_loader.get_graph(); + builder.add(&main_module, false).await?; + let module_graph = builder.get_graph(); // Find all local files in graph let mut paths_to_watch: Vec<PathBuf> = module_graph - .values() - .map(|f| Url::parse(&f.url).unwrap()) - .filter(|url| url.scheme() == "file") - .map(|url| url.to_file_path().unwrap()) + .get_modules() + .iter() + .filter(|specifier| specifier.as_url().scheme() == "file") + .map(|specifier| specifier.as_url().to_file_path().unwrap()) .collect(); if let Some(import_map) = program_state.flags.import_map_path.clone() { diff --git a/cli/module_graph2.rs b/cli/module_graph2.rs index ceb507b01..05bd40783 100644 --- a/cli/module_graph2.rs +++ b/cli/module_graph2.rs @@ -694,11 +694,6 @@ impl Graph2 { Ok((s, stats, maybe_ignored_options)) } - fn contains_module(&self, specifier: &ModuleSpecifier) -> bool { - let s = self.resolve_specifier(specifier); - self.modules.contains_key(s) - } - /// Type check the module graph, corresponding to the options provided. pub fn check( self, @@ -831,6 +826,11 @@ impl Graph2 { Ok((response.stats, response.diagnostics, maybe_ignored_options)) } + fn contains_module(&self, specifier: &ModuleSpecifier) -> bool { + let s = self.resolve_specifier(specifier); + self.modules.contains_key(s) + } + /// Update the handler with any modules that are marked as _dirty_ and update /// any build info if present. fn flush(&mut self) -> Result<(), AnyError> { @@ -949,6 +949,12 @@ impl Graph2 { self.modules.get(s) } + /// Consume graph and return list of all module specifiers + /// contained in the graph. + pub fn get_modules(&self) -> Vec<ModuleSpecifier> { + self.modules.keys().map(|s| s.to_owned()).collect() + } + /// Get the source for a given module specifier. If the module is not part /// of the graph, the result will be `None`. pub fn get_source(&self, specifier: &ModuleSpecifier) -> Option<String> { |