File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ def fetch_npm_versions(url: ParseResult) -> list[Version]:
1111 if url .netloc != "registry.npmjs.org" :
1212 return []
1313 parts = url .path .split ("/" )
14- package = parts [1 ]
14+ # Handle scoped packages like @myorg/mypackage
15+ package = f"{ parts [1 ]} /{ parts [2 ]} " if parts [1 ].startswith ("@" ) else parts [1 ]
1516 npm_url = f"https://registry.npmjs.org/{ package } /latest"
1617 info (f"fetch { npm_url } " )
1718 resp = urllib .request .urlopen (npm_url )
Original file line number Diff line number Diff line change 1+ import io
2+ import unittest .mock
3+ from urllib .parse import urlparse
4+
5+ from nix_update .version import fetch_latest_version
6+ from nix_update .version .version import VersionPreference
7+ from tests import conftest
8+
9+
10+ def fake_npm_urlopen (url : str ) -> io .BytesIO :
11+ if url == "https://registry.npmjs.org/@anthropic-ai/claude-code/latest" :
12+ return io .BytesIO (b'{"version": "1.0.43"}' )
13+
14+ if url == "https://registry.npmjs.org/express/latest" :
15+ return io .BytesIO (b'{"version": "4.21.2"}' )
16+
17+ raise ValueError (f"Unexpected URL in test: { url } " ) # noqa: EM102, TRY003
18+
19+
20+ def test_scoped_npm (helpers : conftest .Helpers ) -> None :
21+ del helpers
22+ with unittest .mock .patch ("urllib.request.urlopen" , fake_npm_urlopen ):
23+ assert (
24+ fetch_latest_version (
25+ urlparse (
26+ "https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-1.0.42.tgz" ,
27+ ),
28+ VersionPreference .STABLE ,
29+ "(.*)" ,
30+ ).number
31+ == "1.0.43"
32+ )
33+
34+
35+ def test_regular_npm (helpers : conftest .Helpers ) -> None :
36+ del helpers
37+ with unittest .mock .patch ("urllib.request.urlopen" , fake_npm_urlopen ):
38+ assert (
39+ fetch_latest_version (
40+ urlparse ("https://registry.npmjs.org/express/-/express-4.21.1.tgz" ),
41+ VersionPreference .STABLE ,
42+ "(.*)" ,
43+ ).number
44+ == "4.21.2"
45+ )
You can’t perform that action at this time.
0 commit comments