MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / parse

Method parse

src/packagedcode/npm.py:874–974  ·  view source on GitHub ↗

Parse a bew yarn.lock v2 YAML format which looks like this: "@algolia/cache-browser-local-storage@npm:4.2.0": version: 4.2.0 resolution: "@algolia/cache-browser-local-storage@npm:4.2.0" dependencies: "@algolia/cache-common": 4.2.0

(cls, location, package_only=False)

Source from the content-addressed store, hash-verified

872
873 @classmethod
874 def parse(cls, location, package_only=False):
875 """
876 Parse a bew yarn.lock v2 YAML format which looks like this:
877
878 "@algolia/cache-browser-local-storage@npm:4.2.0":
879 version: 4.2.0
880 resolution: "@algolia/cache-browser-local-storage@npm:4.2.0"
881 dependencies:
882 "@algolia/cache-common": 4.2.0
883 checksum: 72ac158925eb5a51e015aa22df5d2026fc0c0b6b58eb8c1290712e0
884 languageName: node
885 linkType: hard
886
887 Yield a single PackageData
888 """
889 with open(location) as yl:
890 lock_data = saneyaml.load(yl.read())
891 top_dependencies = []
892
893 for spec, details in lock_data.items():
894 if spec == '__metadata':
895 continue
896 version = details.get('version')
897 resolution = details.get('resolution')
898 ns_name, _, version = resolution.rpartition('@')
899 ns, _, name = ns_name.rpartition('/')
900 if version.startswith('npm:'):
901 _npm, _, version = version.partition(':')
902 purl = PackageURL(
903 type=cls.default_package_type,
904 namespace=ns,
905 name=name,
906 version=version,
907 )
908
909 # TODO: what type of checksum is this? ... this is a complex one
910 # See https://github.com/yarnpkg/berry/blob/f1edfae49d1bab7679ce3061e2749113dc3b80e8/packages/yarnpkg-core/sources/tgzUtils.ts
911 checksum = details.get('checksum')
912 dependencies = details.get('dependencies') or {}
913 peer_dependencies = details.get('peerDependencies') or {}
914 dependencies_meta = details.get('dependenciesMeta') or {}
915 # these are file references
916 bin = details.get('bin') or []
917
918 deps_for_resolved_by_purl = {}
919 cls.update_dependencies_by_purl(
920 dependencies=dependencies,
921 scope="dependencies",
922 dependencies_by_purl=deps_for_resolved_by_purl,
923 )
924 cls.update_dependencies_by_purl(
925 dependencies=peer_dependencies,
926 scope="peerDependencies",
927 dependencies_by_purl=deps_for_resolved_by_purl,
928 )
929 cls.update_dependencies_by_purl(
930 dependencies=dependencies_meta,
931 scope="dependenciesMeta",

Callers

nothing calls this directly

Calls 9

from_dataMethod · 0.80
getMethod · 0.65
loadMethod · 0.45
readMethod · 0.45
to_dictMethod · 0.45
valuesMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected