summaryrefslogtreecommitdiff
path: root/cli/graph_util.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-11-11 21:26:14 -0500
committerGitHub <noreply@github.com>2022-11-11 21:26:14 -0500
commitd81065cff9d2ac64f73ec29edeb6dae1fdf87f04 (patch)
tree90f5bf51422b0c39eed043c32f67ea1103a78a37 /cli/graph_util.rs
parent06bd9e9e1640150f98857a74fea0cc1a3b3386a7 (diff)
feat(unstable/npm): module graph derived npm specifier resolution order (#16602)
Diffstat (limited to 'cli/graph_util.rs')
-rw-r--r--cli/graph_util.rs34
1 files changed, 23 insertions, 11 deletions
diff --git a/cli/graph_util.rs b/cli/graph_util.rs
index e619f8a12..cfd79d491 100644
--- a/cli/graph_util.rs
+++ b/cli/graph_util.rs
@@ -3,6 +3,7 @@
use crate::colors;
use crate::emit::TsTypeLib;
use crate::errors::get_error_class_name;
+use crate::npm::resolve_npm_package_reqs;
use crate::npm::NpmPackageReference;
use crate::npm::NpmPackageReq;
@@ -50,7 +51,7 @@ pub enum ModuleEntry {
#[derive(Debug, Default)]
pub struct GraphData {
modules: HashMap<ModuleSpecifier, ModuleEntry>,
- npm_packages: HashSet<NpmPackageReq>,
+ npm_packages: Vec<NpmPackageReq>,
/// Map of first known referrer locations for each module. Used to enhance
/// error messages.
referrer_map: HashMap<ModuleSpecifier, Box<Range>>,
@@ -76,16 +77,20 @@ impl GraphData {
self.graph_imports.push(graph_import.clone())
}
+ let mut has_npm_specifier_in_graph = false;
+
for (specifier, result) in graph.specifiers() {
- if !reload && self.modules.contains_key(&specifier) {
+ if specifier.scheme() == "npm"
+ && NpmPackageReference::from_specifier(&specifier).is_ok()
+ {
+ has_npm_specifier_in_graph = true;
continue;
}
- if specifier.scheme() == "npm" {
- if let Ok(reference) = NpmPackageReference::from_specifier(&specifier) {
- self.npm_packages.insert(reference.req);
- continue;
- }
+
+ if !reload && self.modules.contains_key(&specifier) {
+ continue;
}
+
if let Some(found) = graph.redirects.get(&specifier) {
let module_entry = ModuleEntry::Redirect(found.clone());
self.modules.insert(specifier.clone(), module_entry);
@@ -139,6 +144,10 @@ impl GraphData {
}
}
}
+
+ if has_npm_specifier_in_graph {
+ self.npm_packages.extend(resolve_npm_package_reqs(graph));
+ }
}
pub fn entries(
@@ -147,9 +156,10 @@ impl GraphData {
self.modules.iter()
}
- /// Gets the unique npm package requirements from all the encountered graphs.
- pub fn npm_package_reqs(&self) -> Vec<NpmPackageReq> {
- self.npm_packages.iter().cloned().collect()
+ /// Gets the npm package requirements from all the encountered graphs
+ /// in the order that they should be resolved.
+ pub fn npm_package_reqs(&self) -> &Vec<NpmPackageReq> {
+ &self.npm_packages
}
/// Walk dependencies from `roots` and return every encountered specifier.
@@ -220,7 +230,9 @@ impl GraphData {
for (dep_specifier, dep) in dependencies.iter().rev() {
// todo(dsherret): ideally there would be a way to skip external dependencies
// in the graph here rather than specifically npm package references
- if NpmPackageReference::from_str(dep_specifier).is_ok() {
+ if dep_specifier.starts_with("npm:")
+ && NpmPackageReference::from_str(dep_specifier).is_ok()
+ {
continue;
}