Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit 7861560

Browse files
Allow comments and trailing commas in hypermode.json (#173)
1 parent 715c5b9 commit 7861560

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Add CORS support to all endpoints [#171](https://github.com/gohypermode/runtime/pull/171)
66
- Replace hyphens with underscores in environment variables [#172](https://github.com/gohypermode/runtime/pull/172)
7+
- Allow comments and trailing commas in `hypermode.json` [#173](https://github.com/gohypermode/runtime/pull/173)
78

89
## 2024-05-02 - Version 0.6.3
910

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/rs/xid v1.5.0
2222
github.com/rs/zerolog v1.32.0
2323
github.com/stretchr/testify v1.9.0
24+
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a
2425
github.com/tetratelabs/wazero v1.7.1
2526
github.com/wundergraph/graphql-go-tools/execution v1.0.1
2627
github.com/wundergraph/graphql-go-tools/v2 v2.0.0-rc.31

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
182182
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
183183
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
184184
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
185+
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a h1:SJy1Pu0eH1C29XwJucQo73FrleVK6t4kYz4NVhp34Yw=
186+
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a/go.mod h1:DFSS3NAGHthKo1gTlmEcSBiZrRJXi28rLNd/1udP1c8=
185187
github.com/tetratelabs/wazero v1.7.1 h1:QtSfd6KLc41DIMpDYlJdoMc6k7QTN246DM2+n2Y/Dx8=
186188
github.com/tetratelabs/wazero v1.7.1/go.mod h1:ytl6Zuh20R/eROuyDaGPkp82O9C/DJfXAwJfQ3X6/7Y=
187189
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=

manifest/management.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"hmruntime/logger"
1212
"hmruntime/storage"
1313
"hmruntime/utils"
14+
15+
"github.com/tailscale/hujson"
1416
)
1517

1618
func MonitorAppDataFiles() {
@@ -49,6 +51,15 @@ func loadAppData(ctx context.Context, filename string) error {
4951

5052
_, ok := manifestFiles[filename]
5153
if ok {
54+
55+
// We allow comments and trailing commas in the JSON files.
56+
// This removes them, resulting in standard JSON.
57+
bytes, err := standardizeJSON(bytes)
58+
if err != nil {
59+
return err
60+
}
61+
62+
// Now parse the JSON
5263
err = json.Unmarshal(bytes, manifestFiles[filename])
5364
if err != nil {
5465
return err
@@ -57,3 +68,12 @@ func loadAppData(ctx context.Context, filename string) error {
5768

5869
return nil
5970
}
71+
72+
func standardizeJSON(b []byte) ([]byte, error) {
73+
ast, err := hujson.Parse(b)
74+
if err != nil {
75+
return b, err
76+
}
77+
ast.Standardize()
78+
return ast.Pack(), nil
79+
}

manifest/manifest.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ package manifest
66

77
var manifestFiles = map[string]Manifest{
88
"hypermode.json": &HypermodeData,
9-
"models.json": &ModelData,
109
}
1110

1211
var HypermodeData HypermodeManifest = HypermodeManifest{}
13-
var ModelData ModelsManifest = ModelsManifest{}
1412

1513
type Manifest any
1614

@@ -22,10 +20,6 @@ type HypermodeManifest struct {
2220
Manifest
2321
}
2422

25-
type ModelsManifest struct {
26-
Manifest
27-
}
28-
2923
type ModelTask string
3024

3125
const (

0 commit comments

Comments
 (0)