From 8e99c93d146d05b49deefacf3034ffc0a8f2a8d3 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Sun, 19 Oct 2025 17:13:00 +0300 Subject: [PATCH] refactor: use yaml.v3 everywhere and remove dependency on yaml.v2 --- go.mod | 3 +-- tracker/gioui/keybindings.go | 7 +++++-- tracker/gioui/preferences.go | 7 +++++-- tracker/list.go | 2 +- tracker/presets.go | 8 ++++++-- vm/compiler/bridge/native_synth_test.go | 2 +- vm/go_synth_test.go | 2 +- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 0ffd699..eb0d25b 100644 --- a/go.mod +++ b/go.mod @@ -12,8 +12,7 @@ require ( github.com/viterin/vek v0.4.2 gitlab.com/gomidi/midi/v2 v2.2.10 golang.org/x/exp/shiny v0.0.0-20250408133849-7e4ce0ab07d0 - golang.org/x/text v0.24.0 - gopkg.in/yaml.v2 v2.3.0 + golang.org/x/text v0.24.0 gopkg.in/yaml.v3 v3.0.1 pipelined.dev/audio/vst2 v0.10.1-0.20240223162706-41e9b65fb5c2 ) diff --git a/tracker/gioui/keybindings.go b/tracker/gioui/keybindings.go index 52aefda..97f2069 100644 --- a/tracker/gioui/keybindings.go +++ b/tracker/gioui/keybindings.go @@ -1,6 +1,7 @@ package gioui import ( + "bytes" _ "embed" "fmt" "strconv" @@ -10,7 +11,7 @@ import ( "gioui.org/io/event" "gioui.org/io/key" "github.com/vsariola/sointu/tracker" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) type ( @@ -31,7 +32,9 @@ var defaultKeyBindings []byte func init() { var keyBindings, userKeybindings []KeyBinding - if err := yaml.UnmarshalStrict(defaultKeyBindings, &keyBindings); err != nil { + dec := yaml.NewDecoder(bytes.NewReader(defaultKeyBindings)) + dec.KnownFields(true) + if err := dec.Decode(&keyBindings); err != nil { panic(fmt.Errorf("failed to unmarshal default keybindings: %w", err)) } if err := ReadCustomConfig("keybindings.yml", &userKeybindings); err == nil { diff --git a/tracker/gioui/preferences.go b/tracker/gioui/preferences.go index 19a5b07..18fe1c6 100644 --- a/tracker/gioui/preferences.go +++ b/tracker/gioui/preferences.go @@ -1,12 +1,13 @@ package gioui import ( + "bytes" _ "embed" "fmt" "os" "path/filepath" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" "gioui.org/unit" ) @@ -53,7 +54,9 @@ func ReadCustomConfig(filename string, target any) error { // return at least the default config, and the warning will just tell if there // was a problem parsing the custom config. func ReadConfig(defaultConfig []byte, path string, target any) (warn error) { - if err := yaml.UnmarshalStrict(defaultConfig, target); err != nil { + dec := yaml.NewDecoder(bytes.NewReader(defaultConfig)) + dec.KnownFields(true) + if err := dec.Decode(target); err != nil { panic(fmt.Errorf("ReadConfig %v failed to unmarshal the embedded default config: %w", path, err)) } return ReadCustomConfig(path, target) diff --git a/tracker/list.go b/tracker/list.go index 9f9a3ac..5eb3a1e 100644 --- a/tracker/list.go +++ b/tracker/list.go @@ -10,7 +10,7 @@ import ( "github.com/vsariola/sointu" "github.com/vsariola/sointu/vm" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) type ( diff --git a/tracker/presets.go b/tracker/presets.go index 46ba2e0..11ed1bc 100644 --- a/tracker/presets.go +++ b/tracker/presets.go @@ -1,6 +1,7 @@ package tracker import ( + "bytes" "embed" "io/fs" "os" @@ -12,7 +13,7 @@ import ( "github.com/vsariola/sointu" "github.com/vsariola/sointu/vm" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) //go:generate go run generate/gmdls_entries.go @@ -169,7 +170,10 @@ func (m *Presets) loadPresetsFromFs(fsys fs.FS, userDefined bool, seenDir map[st return nil } var instr sointu.Instrument - if yaml.UnmarshalStrict(data, &instr) == nil { + + dec := yaml.NewDecoder(bytes.NewReader(data)) + dec.KnownFields(true) + if dec.Decode(&instr) == nil { noExt := path[:len(path)-len(filepath.Ext(path))] splitted := splitPath(noExt) splitted = splitted[1:] // remove "presets" from the path diff --git a/vm/compiler/bridge/native_synth_test.go b/vm/compiler/bridge/native_synth_test.go index 1410bca..c1398c5 100644 --- a/vm/compiler/bridge/native_synth_test.go +++ b/vm/compiler/bridge/native_synth_test.go @@ -15,7 +15,7 @@ import ( "github.com/vsariola/sointu" "github.com/vsariola/sointu/vm/compiler/bridge" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" // TODO: test the song using a mocks instead ) diff --git a/vm/go_synth_test.go b/vm/go_synth_test.go index 04d62f8..49ddd55 100644 --- a/vm/go_synth_test.go +++ b/vm/go_synth_test.go @@ -16,7 +16,7 @@ import ( "github.com/vsariola/sointu" "github.com/vsariola/sointu/vm" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) const errorThreshold = 1e-2