@@ -107,6 +107,10 @@ def assemble(cls, package_data, resource, codebase, package_adder):
107
107
yield from yield_dependencies_from_package_resource (resource )
108
108
return
109
109
110
+ if codebase .has_single_resource :
111
+ yield from models .DatafileHandler .assemble (package_data , resource , codebase , package_adder )
112
+ return
113
+
110
114
assert len (package_resource .package_data ) == 1 , f'Invalid package.json for { package_resource .path } '
111
115
pkg_data = package_resource .package_data [0 ]
112
116
pkg_data = models .PackageData .from_dict (pkg_data )
@@ -204,6 +208,7 @@ def update_dependencies_by_purl(
204
208
is_runtime = False ,
205
209
is_optional = False ,
206
210
is_resolved = False ,
211
+ is_direct = True ,
207
212
):
208
213
209
214
metadata_deps = ['peerDependenciesMeta' , 'dependenciesMeta' ]
@@ -221,6 +226,7 @@ def update_dependencies_by_purl(
221
226
is_runtime = is_runtime ,
222
227
is_optional = is_optional ,
223
228
is_resolved = is_resolved ,
229
+ is_direct = is_direct ,
224
230
)
225
231
dependecies_by_purl [dep_purl ] = dep_package
226
232
@@ -244,6 +250,7 @@ def update_dependencies_by_purl(
244
250
is_runtime = is_runtime ,
245
251
is_optional = metadata .get ("optional" ),
246
252
is_resolved = is_resolved ,
253
+ is_direct = is_direct ,
247
254
)
248
255
dependecies_by_purl [dep_purl ] = dep_package
249
256
continue
@@ -264,6 +271,7 @@ def update_dependencies_by_purl(
264
271
is_runtime = is_runtime ,
265
272
is_optional = is_optional ,
266
273
is_resolved = is_resolved ,
274
+ is_direct = is_direct ,
267
275
)
268
276
dependecies_by_purl [dep_purl ] = dep_package
269
277
@@ -476,6 +484,10 @@ def parse(cls, location, package_only=False):
476
484
477
485
class BaseNpmLockHandler (BaseNpmHandler ):
478
486
487
+ @classmethod
488
+ def is_lockfile (cls ):
489
+ return True
490
+
479
491
@classmethod
480
492
def parse (cls , location , package_only = False ):
481
493
@@ -590,6 +602,7 @@ def parse(cls, location, package_only=False):
590
602
is_runtime = is_runtime ,
591
603
is_optional = is_optional ,
592
604
is_resolved = True ,
605
+ is_direct = False ,
593
606
)
594
607
595
608
# URLs and checksums
@@ -638,6 +651,7 @@ def parse(cls, location, package_only=False):
638
651
is_runtime = is_runtime ,
639
652
is_optional = is_optional ,
640
653
is_resolved = False ,
654
+ is_direct = True ,
641
655
)
642
656
643
657
resolved_package .dependencies = [
@@ -723,6 +737,10 @@ class YarnLockV2Handler(BaseNpmHandler):
723
737
def is_datafile (cls , location , filetypes = tuple ()):
724
738
return super ().is_datafile (location , filetypes = filetypes ) and is_yarn_v2 (location )
725
739
740
+ @classmethod
741
+ def is_lockfile (cls ):
742
+ return True
743
+
726
744
@classmethod
727
745
def parse (cls , location , package_only = False ):
728
746
"""
@@ -833,6 +851,10 @@ class YarnLockV1Handler(BaseNpmHandler):
833
851
description = 'yarn.lock lockfile v1 format'
834
852
documentation_url = 'https://classic.yarnpkg.com/lang/en/docs/yarn-lock/'
835
853
854
+ @classmethod
855
+ def is_lockfile (cls ):
856
+ return True
857
+
836
858
@classmethod
837
859
def is_datafile (cls , location , filetypes = tuple ()):
838
860
return super ().is_datafile (location , filetypes = filetypes ) and not is_yarn_v2 (location )
@@ -953,6 +975,7 @@ def parse(cls, location, package_only=False):
953
975
scope = 'dependencies' ,
954
976
is_optional = False ,
955
977
is_runtime = True ,
978
+ is_direct = True ,
956
979
)
957
980
resolved_package_data .dependencies .append (subdep )
958
981
@@ -972,6 +995,7 @@ def parse(cls, location, package_only=False):
972
995
scope = 'dependencies' ,
973
996
is_optional = False ,
974
997
is_runtime = True ,
998
+ is_direct = False ,
975
999
resolved_package = resolved_package_data .to_dict (),
976
1000
)
977
1001
dependencies .append (dep .to_dict ())
@@ -988,6 +1012,10 @@ def parse(cls, location, package_only=False):
988
1012
989
1013
class BasePnpmLockHandler (BaseNpmHandler ):
990
1014
1015
+ @classmethod
1016
+ def is_lockfile (cls ):
1017
+ return True
1018
+
991
1019
@classmethod
992
1020
def parse (cls , location , package_only = False ):
993
1021
"""
@@ -1063,19 +1091,22 @@ def parse(cls, location, package_only=False):
1063
1091
scope = 'dependencies' ,
1064
1092
dependecies_by_purl = deps_for_resolved_by_purl ,
1065
1093
is_resolved = True ,
1094
+ is_direct = False ,
1066
1095
)
1067
1096
cls .update_dependencies_by_purl (
1068
1097
dependencies = peer_dependencies ,
1069
1098
scope = 'peerDependencies' ,
1070
1099
dependecies_by_purl = deps_for_resolved_by_purl ,
1071
1100
is_optional = True ,
1101
+ is_direct = False ,
1072
1102
)
1073
1103
cls .update_dependencies_by_purl (
1074
1104
dependencies = optional_dependencies ,
1075
1105
scope = 'optionalDependencies' ,
1076
1106
dependecies_by_purl = deps_for_resolved_by_purl ,
1077
1107
is_resolved = True ,
1078
1108
is_optional = True ,
1109
+ is_direct = False ,
1079
1110
)
1080
1111
cls .update_dependencies_by_purl (
1081
1112
dependencies = peer_dependencies_meta ,
@@ -1122,6 +1153,7 @@ def parse(cls, location, package_only=False):
1122
1153
is_optional = is_optional ,
1123
1154
is_runtime = is_runtime ,
1124
1155
is_resolved = True ,
1156
+ is_direct = True ,
1125
1157
resolved_package = resolved_package .to_dict (),
1126
1158
extra_data = extra_data_deps ,
1127
1159
)
@@ -1577,7 +1609,7 @@ def bundle_deps_mapper(bundle_deps, package):
1577
1609
return package
1578
1610
1579
1611
1580
- def deps_mapper (deps , package , field_name ):
1612
+ def deps_mapper (deps , package , field_name , is_direct = True ):
1581
1613
"""
1582
1614
Handle deps such as dependencies, devDependencies, peerDependencies, optionalDependencies
1583
1615
return a tuple of (dep type, list of deps)
@@ -1630,6 +1662,7 @@ def deps_mapper(deps, package, field_name):
1630
1662
purl = purl ,
1631
1663
scope = field_name ,
1632
1664
extracted_requirement = requirement ,
1665
+ is_direct = is_direct ,
1633
1666
** dependency_attributes
1634
1667
)
1635
1668
dependencies .append (dep )
0 commit comments