fix: only notify about unresolved import once (#1125)

This commit is contained in:
Matthias Seitz 2022-04-08 16:37:43 +02:00 committed by GitHub
parent e394f40e46
commit 69bf6ddd0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -367,9 +367,9 @@ impl Reporter for BasicStdoutReporter {
fn on_unresolved_import(&self, import: &Path, remappings: &[Remapping]) { fn on_unresolved_import(&self, import: &Path, remappings: &[Remapping]) {
println!( println!(
"Unable to resolve import: \"{}\" with remappings:\n {}", "Unable to resolve import: \"{}\" with remappings:\n {}",
import.display(), import.display(),
remappings.iter().map(|r| r.to_string()).collect::<Vec<_>>().join("\n ") remappings.iter().map(|r| r.to_string()).collect::<Vec<_>>().join("\n ")
); );
} }
} }

View File

@ -318,6 +318,11 @@ impl Graph {
// contains the files and their dependencies // contains the files and their dependencies
let mut nodes = Vec::with_capacity(unresolved.len()); let mut nodes = Vec::with_capacity(unresolved.len());
let mut edges = Vec::with_capacity(unresolved.len()); let mut edges = Vec::with_capacity(unresolved.len());
// keep track of all unique paths that we failed to resolve to not spam the reporter with
// the same path
let mut unresolved_paths = HashSet::new();
// now we need to resolve all imports for the source file and those imported from other // now we need to resolve all imports for the source file and those imported from other
// locations // locations
while let Some((path, node)) = unresolved.pop_front() { while let Some((path, node)) = unresolved.pop_front() {
@ -334,11 +339,18 @@ impl Graph {
add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?; add_node(&mut unresolved, &mut index, &mut resolved_imports, import)?;
} }
Err(err) => { Err(err) => {
crate::report::unresolved_import(import.data(), &paths.remappings); if unresolved_paths.insert(import.data().to_path_buf()) {
tracing::trace!("failed to resolve import component \"{:?}\"", err) crate::report::unresolved_import(import.data(), &paths.remappings);
}
tracing::trace!(
"failed to resolve import component \"{:?}\" for {:?}",
err,
node.path
)
} }
}; };
} }
nodes.push(node); nodes.push(node);
edges.push(resolved_imports); edges.push(resolved_imports);
} }