From cdd45a3ad80b0be2aa69142b3c8d7e763c18497f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E5=B7=9D=E7=99=BD=E6=B5=AA?= <1679659@qq.com> Date: Wed, 2 Dec 2026 08:16:22 -0700 Subject: [PATCH] feat(plugin): support REIMS_GO_PLATFORM override for cross-platform market checks --- internal/plugin/package.go | 9 +++++++++ internal/plugin/platform_test.go | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 internal/plugin/platform_test.go diff --git a/internal/plugin/package.go b/internal/plugin/package.go index 6be8ae3..1bdf297 100644 --- a/internal/plugin/package.go +++ b/internal/plugin/package.go @@ -519,6 +519,9 @@ func parseLocaleMessagesJSON(raw []byte) (map[string]string, error) { } func currentPlatformTag() string { + if override := strings.TrimSpace(os.Getenv("REIMS_GO_PLATFORM")); override != "" { + return strings.ToLower(strings.ReplaceAll(override, "/", "-")) + } arch := runtime.GOARCH if arch == "amd64" { arch = "x64" @@ -692,6 +695,12 @@ func matchesCurrentPlatform(platforms []string) bool { } curTag := currentPlatformTag() curPair := runtime.GOOS + "/" + runtime.GOARCH + if override := strings.TrimSpace(os.Getenv("REIMS_GO_PLATFORM")); override != "" { + curPair = strings.ToLower(strings.ReplaceAll(override, "-", "/")) + if curPair == "windows/x64" { + curPair = "windows/amd64" + } + } for _, p := range platforms { p = strings.TrimSpace(p) if p == "*" || strings.EqualFold(p, "any") || strings.EqualFold(p, curTag) || strings.EqualFold(p, curPair) { diff --git a/internal/plugin/platform_test.go b/internal/plugin/platform_test.go new file mode 100644 index 0000000..7bd0eb1 --- /dev/null +++ b/internal/plugin/platform_test.go @@ -0,0 +1,13 @@ +package plugin + +import "testing" + +func TestPlatformOverrideEnv(t *testing.T) { + t.Setenv("REIMS_GO_PLATFORM", "windows-x64") + if !matchesCurrentPlatform([]string{"windows-x64"}) || !matchesCurrentPlatform([]string{"windows/amd64"}) { + t.Fatal("expected windows-x64 override to match windows-x64 and windows/amd64") + } + if matchesCurrentPlatform([]string{"linux-x64"}) { + t.Fatal("expected windows-x64 override to reject linux-x64") + } +}