2929from scanpipe import pipes
3030from scanpipe .models import CodebaseRelation
3131from scanpipe .models import CodebaseResource
32- from scanpipe .models import DiscoveredPackage
3332from scanpipe .pipes import flag
3433from scanpipe .pipes import get_resource_diff_ratio
3534from scanpipe .pipes import js
@@ -910,19 +909,21 @@ def _map_javascript_npm_lookup_resource(
910909 """Map unmatched ``node_modules`` files."""
911910 purl = js .get_purl_from_node_module (to_directory .path )
912911 matched = to_resources .filter (path__startswith = to_directory .path )
912+ matched_count = matched .count ()
913+
913914 if not matched :
914915 return 0
915916
916- try :
917- package = project .discoveredpackages .get (
918- type = purl .type ,
919- namespace = "" if not purl .namespace else purl .namespace ,
920- name = purl .name ,
921- version = purl .version ,
922- )
923- package .add_resources (matched )
917+ package = project .discoveredpackages .filter (
918+ type = purl .type ,
919+ namespace = "" if not purl .namespace else purl .namespace ,
920+ name = purl .name ,
921+ version = purl .version ,
922+ ).first ()
924923
925- except DiscoveredPackage .DoesNotExist :
924+ if package :
925+ package .add_resources (matched )
926+ else :
926927 if results := purldb .fetch_package (purl = str (purl )):
927928 package_data = results [0 ]
928929 package_data .pop ("uuid" , None )
@@ -937,4 +938,4 @@ def _map_javascript_npm_lookup_resource(
937938 return 0
938939
939940 matched .update (status = flag .NPM_LOOKUP )
940- return len ( matched )
941+ return matched_count
0 commit comments