From db32446a74deced559c4ad322a641640b299ad1a Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 19 Dec 2023 08:19:09 +0100 Subject: [PATCH] feat(node): match lts versions resolves #4555 --- src/segments/node.go | 27 +++++++++++++++++++++++++++ src/segments/node_test.go | 25 ++++++++++++++----------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/src/segments/node.go b/src/segments/node.go index 168d09c5..24423eaa 100644 --- a/src/segments/node.go +++ b/src/segments/node.go @@ -69,6 +69,33 @@ func (n *Node) matchesVersionFile() (string, bool) { return "", true } + fileVersion = strings.TrimSpace(fileVersion) + + if strings.HasPrefix(fileVersion, "lts/") { + fileVersion = strings.ToLower(fileVersion) + codeName := strings.TrimPrefix(fileVersion, "lts/") + switch codeName { + case "argon": + fileVersion = "4.9.1" + case "boron": + fileVersion = "6.17.1" + case "carbon": + fileVersion = "8.17.0" + case "dubnium": + fileVersion = "10.24.1" + case "erbium": + fileVersion = "12.22.12" + case "fermium": + fileVersion = "14.21.3" + case "gallium": + fileVersion = "16.20.1" + case "hydrogen": + fileVersion = "18.19.0" + case "iron": + fileVersion = "20.10.0" + } + } + re := fmt.Sprintf( `(?im)^v?%s(\.?%s)?(\.?%s)?$`, n.language.version.Major, diff --git a/src/segments/node_test.go b/src/segments/node_test.go index 997fc5fb..355a2f80 100644 --- a/src/segments/node_test.go +++ b/src/segments/node_test.go @@ -11,10 +11,10 @@ import ( func TestNodeMatchesVersionFile(t *testing.T) { nodeVersion := version{ - Full: "1.2.3", - Major: "1", - Minor: "2", - Patch: "3", + Full: "20.10.0", + Major: "20", + Minor: "10", + Patch: "0", } cases := []struct { Case string @@ -23,14 +23,17 @@ func TestNodeMatchesVersionFile(t *testing.T) { RCVersion string }{ {Case: "no file context", Expected: true, RCVersion: ""}, - {Case: "version match", Expected: true, ExpectedVersion: "1.2.3", RCVersion: "1.2.3"}, - {Case: "version match with newline", Expected: true, ExpectedVersion: "1.2.3", RCVersion: "1.2.3\n"}, + {Case: "version match", Expected: true, ExpectedVersion: "20.10.0", RCVersion: "20.10.0"}, + {Case: "version match with newline", Expected: true, ExpectedVersion: "20.10.0", RCVersion: "20.10.0\n"}, {Case: "version mismatch", Expected: false, ExpectedVersion: "3.2.1", RCVersion: "3.2.1"}, - {Case: "version match in other format", Expected: true, ExpectedVersion: "1.2.3", RCVersion: "v1.2.3"}, - {Case: "version match without patch", Expected: true, ExpectedVersion: "1.2", RCVersion: "1.2"}, - {Case: "version match without patch in other format", Expected: true, ExpectedVersion: "1.2", RCVersion: "v1.2"}, - {Case: "version match without minor", Expected: true, ExpectedVersion: "1", RCVersion: "1"}, - {Case: "version match without minor in other format", Expected: true, ExpectedVersion: "1", RCVersion: "v1"}, + {Case: "version match in other format", Expected: true, ExpectedVersion: "20.10.0", RCVersion: "v20.10.0"}, + {Case: "version match without patch", Expected: true, ExpectedVersion: "20.10", RCVersion: "20.10"}, + {Case: "version match without patch in other format", Expected: true, ExpectedVersion: "20.10", RCVersion: "v20.10"}, + {Case: "version match without minor", Expected: true, ExpectedVersion: "20", RCVersion: "20"}, + {Case: "version match without minor in other format", Expected: true, ExpectedVersion: "20", RCVersion: "v20"}, + {Case: "lts match", Expected: true, ExpectedVersion: "20.10.0", RCVersion: "lts/iron"}, + {Case: "lts match upper case", Expected: true, ExpectedVersion: "20.10.0", RCVersion: "lts/Iron"}, + {Case: "lts mismatch", Expected: false, ExpectedVersion: "8.17.0", RCVersion: "lts/carbon"}, } for _, tc := range cases {