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)
| 827 | |
| 828 | |
| 829 | def 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 | |
| 857 | class YarnLockV2Handler(BaseNpmHandler): |
no test coverage detected