mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Plugin TOML support (-tags wazero): - manifest_toml.go: tryLoadPluginTOML using BurntSushi/toml v1.6.0 - manifest_nottoml.go: no-op stub for default build - loader.go: prefers plugin.toml, falls back to plugin.json Solid vitest preset: - vitest.config.ts: add vite-plugin-solid, expand include to src/components/solid/**/*.test.tsx — Badge.test.tsx now runs automatically as part of npm test (112 files / 3188 tests)
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
//go:build wazero
|
|
|
|
// TOML manifest support — compiled only with -tags wazero.
|
|
// Plugins may ship either plugin.json or plugin.toml; this file provides
|
|
// tryLoadPluginTOML which the loader calls before falling back to JSON.
|
|
package plugin
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
// tryLoadPluginTOML attempts to parse a plugin.toml from pluginDir.
|
|
// Returns the parsed Manifest and true on success.
|
|
// Returns nil, false if no plugin.toml exists (caller should try plugin.json).
|
|
// Returns nil, false plus logs if plugin.toml exists but is malformed — the
|
|
// caller will skip the plugin and log the error.
|
|
func tryLoadPluginTOML(pluginDir string) (*Manifest, bool, error) {
|
|
tomlPath := filepath.Join(pluginDir, "plugin.toml")
|
|
raw, err := os.ReadFile(tomlPath)
|
|
if os.IsNotExist(err) {
|
|
return nil, false, nil // not present; try JSON
|
|
}
|
|
if err != nil {
|
|
return nil, false, fmt.Errorf("read plugin.toml: %w", err)
|
|
}
|
|
|
|
var m Manifest
|
|
if _, err := toml.Decode(string(raw), &m); err != nil {
|
|
return nil, false, fmt.Errorf("parse plugin.toml: %w", err)
|
|
}
|
|
if err := m.Validate(); err != nil {
|
|
return nil, false, fmt.Errorf("invalid plugin.toml: %w", err)
|
|
}
|
|
return &m, true, nil
|
|
}
|