mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
refactor(run): use new module graph for run --watch (#8085)
This commit changes how "deno run --watch" is implemented by migrating to use ModuleGraph2.
This commit is contained in:
parent
dd952818bc
commit
95854b88ad
2 changed files with 24 additions and 16 deletions
24
cli/main.rs
24
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() {
|
||||
|
|
|
@ -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> {
|
||||
|
|
Loading…
Add table
Reference in a new issue