diff options
Diffstat (limited to 'cli/npm/resolution')
-rw-r--r-- | cli/npm/resolution/graph.rs | 2 | ||||
-rw-r--r-- | cli/npm/resolution/mod.rs | 2 | ||||
-rw-r--r-- | cli/npm/resolution/specifier.rs | 43 |
3 files changed, 38 insertions, 9 deletions
diff --git a/cli/npm/resolution/graph.rs b/cli/npm/resolution/graph.rs index 81ff58546..e21048149 100644 --- a/cli/npm/resolution/graph.rs +++ b/cli/npm/resolution/graph.rs @@ -1081,7 +1081,7 @@ fn tag_to_version_info<'a>( // explicit version. if tag == "latest" && info.name == "@types/node" { return get_resolved_package_version_and_info( - &NpmVersionReq::parse("18.0.0 - 18.8.2").unwrap(), + &NpmVersionReq::parse("18.0.0 - 18.11.18").unwrap(), info, parent, ); diff --git a/cli/npm/resolution/mod.rs b/cli/npm/resolution/mod.rs index f10678cbe..ed194bbac 100644 --- a/cli/npm/resolution/mod.rs +++ b/cli/npm/resolution/mod.rs @@ -28,7 +28,7 @@ mod specifier; use graph::Graph; pub use snapshot::NpmResolutionSnapshot; -pub use specifier::resolve_npm_package_reqs; +pub use specifier::resolve_graph_npm_info; pub use specifier::NpmPackageReference; pub use specifier::NpmPackageReq; diff --git a/cli/npm/resolution/specifier.rs b/cli/npm/resolution/specifier.rs index 9a7f67cf8..6667c60dd 100644 --- a/cli/npm/resolution/specifier.rs +++ b/cli/npm/resolution/specifier.rs @@ -168,8 +168,15 @@ impl NpmVersionMatcher for NpmPackageReq { } } -/// Resolves the npm package requirements from the graph attempting. The order -/// returned is the order they should be resolved in. +pub struct GraphNpmInfo { + /// The order of these package requirements is the order they + /// should be resolved in. + pub package_reqs: Vec<NpmPackageReq>, + /// Gets if the graph had a built-in node specifier (ex. `node:fs`). + pub has_node_builtin_specifier: bool, +} + +/// Resolves npm specific information from the graph. /// /// This function will analyze the module graph for parent-most folder /// specifiers of all modules, then group npm specifiers together as found in @@ -211,7 +218,7 @@ impl NpmVersionMatcher for NpmPackageReq { /// /// Then it would resolve the npm specifiers in each of those groups according /// to that tree going by tree depth. -pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec<NpmPackageReq> { +pub fn resolve_graph_npm_info(graph: &ModuleGraph) -> GraphNpmInfo { fn collect_specifiers<'a>( graph: &'a ModuleGraph, module: &'a deno_graph::Module, @@ -248,6 +255,7 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec<NpmPackageReq> { graph: &ModuleGraph, specifier_graph: &mut SpecifierTree, seen: &mut HashSet<ModuleSpecifier>, + has_node_builtin_specifier: &mut bool, ) { if !seen.insert(module.specifier.clone()) { return; // already visited @@ -267,12 +275,22 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec<NpmPackageReq> { .dependencies .insert(get_folder_path_specifier(specifier)); } + + if !*has_node_builtin_specifier && specifier.scheme() == "node" { + *has_node_builtin_specifier = true; + } } // now visit all the dependencies for specifier in &specifiers { if let Some(module) = graph.get(specifier) { - analyze_module(module, graph, specifier_graph, seen); + analyze_module( + module, + graph, + specifier_graph, + seen, + has_node_builtin_specifier, + ); } } } @@ -284,9 +302,16 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec<NpmPackageReq> { .collect::<Vec<_>>(); let mut seen = HashSet::new(); let mut specifier_graph = SpecifierTree::default(); + let mut has_node_builtin_specifier = false; for root in &root_specifiers { if let Some(module) = graph.get(root) { - analyze_module(module, graph, &mut specifier_graph, &mut seen); + analyze_module( + module, + graph, + &mut specifier_graph, + &mut seen, + &mut has_node_builtin_specifier, + ); } } @@ -324,7 +349,10 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec<NpmPackageReq> { } } - result + GraphNpmInfo { + has_node_builtin_specifier, + package_reqs: result, + } } fn get_folder_path_specifier(specifier: &ModuleSpecifier) -> ModuleSpecifier { @@ -979,7 +1007,8 @@ mod tests { }, ) .await; - let reqs = resolve_npm_package_reqs(&graph) + let reqs = resolve_graph_npm_info(&graph) + .package_reqs .into_iter() .map(|r| r.to_string()) .collect::<Vec<_>>(); |