Parses and yields package dependencies for all lockfile versions present in the spec: https://github.com/pnpm/spec/blob/master/lockfile/
(cls, location, package_only=False)
| 1166 | |
| 1167 | @classmethod |
| 1168 | def parse(cls, location, package_only=False): |
| 1169 | """ |
| 1170 | Parses and yields package dependencies for all lockfile versions |
| 1171 | present in the spec: https://github.com/pnpm/spec/blob/master/lockfile/ |
| 1172 | """ |
| 1173 | |
| 1174 | with open(location) as yl: |
| 1175 | lock_data = saneyaml.load(yl.read()) |
| 1176 | |
| 1177 | lockfile_version = lock_data.get("lockfileVersion") |
| 1178 | is_shrinkwrap = False |
| 1179 | if not lockfile_version: |
| 1180 | lockfile_version = lock_data.get("shrinkwrapVersion") |
| 1181 | lockfile_minor_version = lock_data.get("shrinkwrapMinorVersion") |
| 1182 | if lockfile_minor_version: |
| 1183 | lockfile_version = f"{lockfile_version}.{lockfile_minor_version}" |
| 1184 | is_shrinkwrap = True |
| 1185 | |
| 1186 | extra_data = { |
| 1187 | "lockfileVersion": lockfile_version, |
| 1188 | } |
| 1189 | major_v, minor_v = lockfile_version.split(".") |
| 1190 | |
| 1191 | resolved_packages = lock_data.get("packages", {}) |
| 1192 | dependency_relations = lock_data.get("snapshots", {}) |
| 1193 | dependency_relations_by_purl = {} |
| 1194 | if dependency_relations: |
| 1195 | for purl_fields, relations in dependency_relations.items(): |
| 1196 | clean_purl_fields = purl_fields.split("(")[0] |
| 1197 | sections = clean_purl_fields.split("/") |
| 1198 | namespace = None |
| 1199 | if len(sections) == 2: |
| 1200 | namespace, name_version = sections |
| 1201 | elif len(sections) == 1: |
| 1202 | name_version, = sections |
| 1203 | name, version = name_version.split("@") |
| 1204 | |
| 1205 | purl = PackageURL( |
| 1206 | type=cls.default_package_type, |
| 1207 | name=name, |
| 1208 | namespace=namespace, |
| 1209 | version=version, |
| 1210 | ).to_string() |
| 1211 | dependency_relations_by_purl[purl] = relations |
| 1212 | |
| 1213 | dependencies_by_purl = {} |
| 1214 | |
| 1215 | for purl_fields, data in resolved_packages.items(): |
| 1216 | if major_v == "6": |
| 1217 | clean_purl_fields = purl_fields.split("(")[0] |
| 1218 | elif major_v == "5" or is_shrinkwrap: |
| 1219 | clean_purl_fields = purl_fields.split("_")[0] |
| 1220 | elif major_v == "9": |
| 1221 | clean_purl_fields = purl_fields |
| 1222 | else: |
| 1223 | message = f"Unknown pnpm lockfile format: {lockfile_version}" |
| 1224 | raise UnknownPnpmLockFormat(message, purl_fields) |
| 1225 |
nothing calls this directly
no test coverage detected