@@ -408,23 +408,28 @@ def fetch_yarn_lock_relationships
408408 sig { params ( children : T ::Hash [ String , String ] , parsed : T ::Hash [ String , T . untyped ] ) . returns ( T ::Array [ String ] ) }
409409 def resolve_yarn_children ( children , parsed )
410410 children . filter_map do |child_name , child_req |
411- # Try exact key first
412- child_entry = parsed [ "#{ child_name } @#{ child_req } " ]
413- next "#{ child_name } @#{ child_entry [ 'version' ] } " if child_entry && child_entry [ "version" ]
414-
415- # Yarn groups multiple requirements into single keys like "foo@^1.0.0, foo@^1.2.0"
416- target_req = "#{ child_name } @#{ child_req } "
417- grouped_match = parsed . find { |k , _ | k . split ( ", " ) . include? ( target_req ) }
418- next "#{ child_name } @#{ grouped_match . last [ 'version' ] } " if grouped_match && grouped_match . last [ "version" ]
419-
420- # Fallback: find by name only if there's exactly one candidate
421- candidates = parsed . select { |k , _ | k . split ( /(?<=\w )\@ / ) . first == child_name }
422- if candidates . size == 1 && candidates . first . last [ "version" ]
423- "#{ child_name } @#{ candidates . first . last [ 'version' ] } "
424- end
411+ version = resolve_yarn_child_version ( child_name , child_req , parsed )
412+ "#{ child_name } @#{ version } " if version
425413 end
426414 end
427415
416+ sig { params ( child_name : String , child_req : String , parsed : T ::Hash [ String , T . untyped ] ) . returns ( T . nilable ( String ) ) }
417+ def resolve_yarn_child_version ( child_name , child_req , parsed )
418+ # Try exact key first
419+ child_entry = parsed [ "#{ child_name } @#{ child_req } " ]
420+ return child_entry [ "version" ] if child_entry && child_entry [ "version" ]
421+
422+ # Yarn groups multiple requirements into single keys like "foo@^1.0.0, foo@^1.2.0"
423+ target_req = "#{ child_name } @#{ child_req } "
424+ grouped_match = parsed . find { |k , _ | k . split ( ", " ) . include? ( target_req ) }
425+ return grouped_match . last [ "version" ] if grouped_match && grouped_match . last [ "version" ]
426+
427+ # Fallback: find by name only if there's exactly one candidate
428+ candidates = parsed . select { |k , _ | k . split ( /(?<=\w )\@ / ) . first == child_name }
429+ candidate = candidates . first
430+ candidate . last [ "version" ] if candidates . size == 1 && candidate
431+ end
432+
428433 sig { returns ( T ::Hash [ String , T ::Array [ String ] ] ) }
429434 def fetch_pnpm_lock_relationships
430435 parsed = YAML . safe_load ( T . must ( T . must ( pnpm_lockfile ) . content ) ) || { }
0 commit comments