@@ -284,6 +284,7 @@ pub fn read_dependency(
284284/// registered for the parent packages. Especially relevant for peerDependencies.
285285/// 2. In parallel performs IO to read the dependencies config and
286286/// recursively continues operation for their dependencies as well.
287+ /// 3. Detects and warns about duplicate packages (same name, different paths).
287288fn read_dependencies (
288289 registered_dependencies_set : & mut AHashSet < String > ,
289290 project_context : & ProjectContext ,
@@ -302,6 +303,37 @@ fn read_dependencies(
302303 . iter ( )
303304 . filter_map ( |package_name| {
304305 if registered_dependencies_set. contains ( package_name) {
306+ // Package already registered - check for duplicate (different path)
307+ // Re-resolve from current package and from root to compare paths
308+ if let Ok ( current_path) = read_dependency ( package_name, package_config, project_context)
309+ && let Ok ( chosen_path) = read_dependency ( package_name, & project_context. current_config , project_context)
310+ && current_path != chosen_path
311+ {
312+ // Different paths - this is a duplicate
313+ let root_path = project_context. get_root_path ( ) ;
314+ let chosen_relative = chosen_path
315+ . strip_prefix ( root_path)
316+ . unwrap_or ( & chosen_path) ;
317+ let duplicate_relative = current_path
318+ . strip_prefix ( root_path)
319+ . unwrap_or ( & current_path) ;
320+ let current_package_path = package_config
321+ . path
322+ . parent ( )
323+ . map ( |p| p. to_path_buf ( ) )
324+ . unwrap_or_else ( || PathBuf :: from ( "." ) ) ;
325+ let parent_relative = current_package_path
326+ . strip_prefix ( root_path)
327+ . unwrap_or ( & current_package_path) ;
328+
329+ println ! (
330+ "Duplicated package: {} ./{} (chosen) vs ./{} in ./{}" ,
331+ package_name,
332+ chosen_relative. to_string_lossy( ) ,
333+ duplicate_relative. to_string_lossy( ) ,
334+ parent_relative. to_string_lossy( )
335+ ) ;
336+ }
305337 None
306338 } else {
307339 registered_dependencies_set. insert ( package_name. to_owned ( ) ) ;
@@ -481,6 +513,7 @@ This inconsistency will cause issues with package resolution.\n",
481513fn read_packages ( project_context : & ProjectContext , show_progress : bool ) -> Result < AHashMap < String , Package > > {
482514 // Store all packages and completely deduplicate them
483515 let mut map: AHashMap < String , Package > = AHashMap :: new ( ) ;
516+
484517 let current_package = {
485518 let config = & project_context. current_config ;
486519 let folder = config
@@ -500,6 +533,7 @@ fn read_packages(project_context: &ProjectContext, show_progress: bool) -> Resul
500533 show_progress,
501534 /* is local dep */ true ,
502535 ) ) ;
536+
503537 dependencies. iter ( ) . for_each ( |d| {
504538 if !map. contains_key ( & d. name ) {
505539 let package = make_package ( d. config . to_owned ( ) , & d. path , false , d. is_local_dep ) ;
0 commit comments