Skip to content

Commit 49d15e3

Browse files
authored
fix(legacy_parser): update version resolution to use ctx.strategy (#17)
* fix(legacy_parser): update version resolution to use ctx.strategy Update the legacy version resolution to use the strategy from context instead of hardcoded "latest_installed". Also add the latest Node.js codename (jod) to the mapping table for version resolution. * docs: update nodejs documentation URL in comment Update the outdated Node.js documentation URL to the current one * fix(parse_legacy_file): improve LTS version resolution logic Replace static latest codename lookup with dynamic version number comparison to ensure correct LTS version is returned
1 parent 07d8c32 commit 49d15e3

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

hooks/parse_legacy_file.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function PLUGIN:ParseLegacyFile(ctx)
4343
end
4444
local query = resolve_version(content)
4545

46-
query = resolve_legacy_version("latest_installed", query)
46+
query = resolve_legacy_version(ctx.strategy, query)
4747

4848
return {
4949
version = query
@@ -57,6 +57,7 @@ function resolve_version(query)
5757
query = query:gsub("-", "/")
5858
end
5959

60+
-- https://nodejs.org/zh-cn/about/previous-releases
6061
local nodejs_codenames = {
6162
argon = 4,
6263
boron = 6,
@@ -66,7 +67,8 @@ function resolve_version(query)
6667
fermium = 14,
6768
gallium = 16,
6869
hydrogen = 18,
69-
iron = 20
70+
iron = 20,
71+
jod = 22
7072
}
7173

7274
for codename, version_number in pairs(nodejs_codenames) do
@@ -77,7 +79,14 @@ function resolve_version(query)
7779
end
7880

7981
if query == "lts" or query == "lts/*" then
80-
query = tostring(nodejs_codenames[#nodejs_codenames])
82+
-- Find the latest LTS version (highest version number)
83+
local latest_version = 0
84+
for codename, version_number in pairs(nodejs_codenames) do
85+
if version_number > latest_version then
86+
latest_version = version_number
87+
end
88+
end
89+
query = tostring(latest_version)
8190
end
8291

8392
return query

0 commit comments

Comments
 (0)