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

Function is_yarn_v2

src/packagedcode/npm.py:829–854  ·  view source on GitHub ↗

Return True if this is a yarn.lock format version 2 and False if this is version 1. Raise an UnknownYarnLockFormat exception if neither v1 or v2. v1 is a custom, almost-like-YAMl format. v2 is a proper subset of YAML. The start of v1 file has this: # THIS IS AN AUTOGENERAT

(location)

Source from the content-addressed store, hash-verified

827
828
829def is_yarn_v2(location):
830 """
831 Return True if this is a yarn.lock format version 2 and False if this is
832 version 1. Raise an UnknownYarnLockFormat exception if neither v1 or v2.
833
834 v1 is a custom, almost-like-YAMl format. v2 is a proper subset of YAML.
835
836 The start of v1 file has this:
837 # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
838 # yarn lockfile v1
839
840 The start of v2 file has this:
841 # This file is generated by running "yarn install" inside your project.
842 # Manual changes might be lost - proceed with caution!
843
844 __metadata:
845 """
846 with open(location) as ylf:
847 # check only in the first 10 lines
848 for line in islice(ylf, 0, 10):
849 if '__metadata:' in line:
850 return True
851 if 'yarn lockfile v1' in line:
852 return False
853
854 raise UnknownYarnLockFormat(location)
855
856
857class YarnLockV2Handler(BaseNpmHandler):

Callers 2

is_datafileMethod · 0.85
is_datafileMethod · 0.85

Calls 1

Tested by

no test coverage detected