Skip to content

Commit 6f390d7

Browse files
committed
node: Raise an error unless yarn lockfile is v1
Helps #361 v2 is WIP #252
1 parent 2cc8dd0 commit 6f390d7

File tree

1 file changed

+16
-0
lines changed
  • node/flatpak_node_generator/providers

1 file changed

+16
-0
lines changed

node/flatpak_node_generator/providers/yarn.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,23 @@ def is_git_version(version: str) -> bool:
4444
return len([p for p in url.path.split('/') if p]) == 2
4545
return False
4646

47+
@staticmethod
48+
def is_yarn_v1_lockfile(path: Path) -> bool:
49+
if path.exists():
50+
with open(path, encoding='utf-8') as f:
51+
for i, line in enumerate(f):
52+
if i > 10:
53+
break
54+
if '# yarn lockfile v1' in line.strip():
55+
return True
56+
return False
57+
4758
def parse_lockfile(self, lockfile: Path) -> Dict[str, Any]:
59+
if not self.is_yarn_v1_lockfile(lockfile):
60+
raise NotImplementedError(
61+
'Only yarn v1 lockfiles are supported. See https://classic.yarnpkg.com/'
62+
)
63+
4864
def _iter_lines() -> Iterator[Tuple[int, str]]:
4965
indent = ' '
5066
for line in lockfile.open():

0 commit comments

Comments
 (0)