Skip to content

Commit ae94a07

Browse files
committed
chore: switch to guts for typescript types generation
1 parent bd8b702 commit ae94a07

File tree

9 files changed

+27
-2537
lines changed

9 files changed

+27
-2537
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ vpn/vpn.pb.go: vpn/vpn.proto
642642
site/src/api/typesGenerated.ts: $(wildcard scripts/apitypings/*) $(shell find ./codersdk $(FIND_EXCLUSIONS) -type f -name '*.go')
643643
# -C sets the directory for the go run command
644644
go run -C ./scripts/apitypings main.go > $@
645+
(cd ./site && npx biome format --write ./src/api/typesGenerated.ts)
645646
./scripts/pnpm_install.sh
646647

647648
site/e2e/provisionerGenerated.ts: provisionerd/proto/provisionerd.pb.go provisionersdk/proto/provisioner.pb.go

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,8 @@ require (
226226
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect
227227
github.com/charmbracelet/x/ansi v0.4.5 // indirect
228228
github.com/charmbracelet/x/term v0.2.0 // indirect
229-
github.com/coder/guts v0.0.0-20241127131903-b65758ff0bb6 // indirect
230-
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd // indirect
231229
github.com/eapache/queue/v2 v2.0.0-20230407133247-75960ed334e4 // indirect
232230
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
233-
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
234231
github.com/go-viper/mapstructure/v2 v2.0.0 // indirect
235232
github.com/googleapis/gax-go/v2 v2.14.0 // indirect
236233
github.com/hashicorp/go-plugin v1.6.1 // indirect

go.sum

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ github.com/coder/go-httpstat v0.0.0-20230801153223-321c88088322 h1:m0lPZjlQ7vdVp
217217
github.com/coder/go-httpstat v0.0.0-20230801153223-321c88088322/go.mod h1:rOLFDDVKVFiDqZFXoteXc97YXx7kFi9kYqR+2ETPkLQ=
218218
github.com/coder/go-scim/pkg/v2 v2.0.0-20230221055123-1d63c1222136 h1:0RgB61LcNs24WOxc3PBvygSNTQurm0PYPujJjLLOzs0=
219219
github.com/coder/go-scim/pkg/v2 v2.0.0-20230221055123-1d63c1222136/go.mod h1:VkD1P761nykiq75dz+4iFqIQIZka189tx1BQLOp0Skc=
220-
github.com/coder/guts v0.0.0-20241127131903-b65758ff0bb6 h1:kfue0W2wVPBtb7xUC8NDS+KQuYkysRiC7rRryYaumEc=
221-
github.com/coder/guts v0.0.0-20241127131903-b65758ff0bb6/go.mod h1:NpXPfboumDmFosCGHThTW2Ke4O4xn1hOSlKMD+TK4Oc=
222220
github.com/coder/pq v1.10.5-0.20240813183442-0c420cb5a048 h1:3jzYUlGH7ZELIH4XggXhnTnP05FCYiAFeQpoN+gNR5I=
223221
github.com/coder/pq v1.10.5-0.20240813183442-0c420cb5a048/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
224222
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx9n47SZOKOpgSE1bbJzlE4qPVs=
@@ -283,8 +281,6 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
283281
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
284282
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
285283
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
286-
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd h1:QMSNEh9uQkDjyPwu/J541GgSH+4hw+0skJDIj9HJ3mE=
287-
github.com/dop251/goja v0.0.0-20241024094426-79f3a7efcdbd/go.mod h1:MxLav0peU43GgvwVgNbLAj1s/bSGboKkhuULvq/7hx4=
288284
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
289285
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
290286
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
@@ -406,8 +402,6 @@ github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91
406402
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
407403
github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o=
408404
github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
409-
github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU=
410-
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
411405
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
412406
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
413407
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=

scripts/apitypings/go.mod

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module github.com/coder/coder/scripts/apitypings
22

3-
go 1.23.0
3+
go 1.23.1
4+
5+
toolchain go1.23.3
46

57
require (
8+
github.com/coder/coder/v2 v2.17.2
9+
github.com/coder/guts v0.0.0-20241209140041-d9cf060de89e
10+
github.com/coder/serpent v0.10.0
611
github.com/stretchr/testify v1.10.0
712
)
813

@@ -23,9 +28,7 @@ require (
2328
github.com/beorn7/perks v1.0.1 // indirect
2429
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
2530
github.com/cespare/xxhash/v2 v2.3.0 // indirect
26-
github.com/coder/coder/v2 v2.17.2 // indirect
2731
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 // indirect
28-
github.com/coder/serpent v0.10.0 // indirect
2932
github.com/coder/terraform-provider-coder v1.0.2 // indirect
3033
github.com/coreos/go-oidc/v3 v3.11.0 // indirect
3134
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
@@ -43,7 +46,7 @@ require (
4346
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
4447
github.com/golang/protobuf v1.5.4 // indirect
4548
github.com/google/go-cmp v0.6.0 // indirect
46-
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b // indirect
49+
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd // indirect
4750
github.com/google/uuid v1.6.0 // indirect
4851
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
4952
github.com/hashicorp/errwrap v1.1.0 // indirect
@@ -61,8 +64,7 @@ require (
6164
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
6265
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect
6366
github.com/hashicorp/yamux v0.1.1 // indirect
64-
github.com/klauspost/compress v1.17.9 // indirect
65-
github.com/kr/pretty v0.3.1 // indirect
67+
github.com/klauspost/compress v1.17.11 // indirect
6668
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
6769
github.com/mattn/go-colorable v0.1.13 // indirect
6870
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -87,7 +89,6 @@ require (
8789
github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect
8890
github.com/rivo/uniseg v0.4.7 // indirect
8991
github.com/robfig/cron/v3 v3.0.1 // indirect
90-
github.com/rogpeppe/go-internal v1.12.0 // indirect
9192
github.com/ryanuber/go-glob v1.0.0 // indirect
9293
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
9394
github.com/spaolacci/murmur3 v1.1.0 // indirect
@@ -100,12 +101,12 @@ require (
100101
github.com/zclconf/go-cty v1.15.0 // indirect
101102
github.com/zeebo/errs v1.3.0 // indirect
102103
go.nhat.io/otelsql v0.14.0 // indirect
103-
go.opentelemetry.io/otel v1.30.0 // indirect
104+
go.opentelemetry.io/otel v1.32.0 // indirect
104105
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
105106
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect
106-
go.opentelemetry.io/otel/metric v1.30.0 // indirect
107+
go.opentelemetry.io/otel/metric v1.32.0 // indirect
107108
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
108-
go.opentelemetry.io/otel/trace v1.30.0 // indirect
109+
go.opentelemetry.io/otel/trace v1.32.0 // indirect
109110
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
110111
go.uber.org/atomic v1.11.0 // indirect
111112
golang.org/x/crypto v0.29.0 // indirect

scripts/apitypings/main.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,22 @@ func main() {
2121
log.Fatalf("new convert: %v", err)
2222
}
2323

24-
generateDirectories := []string{
25-
"github.com/coder/coder/v2/codersdk",
26-
"github.com/coder/coder/v2/codersdk/health",
24+
generateDirectories := map[string]string{
25+
"github.com/coder/coder/v2/codersdk": "",
26+
"github.com/coder/coder/v2/coderd/healthcheck/health": "Health",
2727
}
28-
for _, dir := range generateDirectories {
29-
err = gen.Include(dir, true)
28+
for dir, prefix := range generateDirectories {
29+
err = gen.IncludeGenerateWithPrefix(dir, prefix)
3030
if err != nil {
3131
log.Fatalf("include generate package %q: %v", dir, err)
3232
}
3333
}
3434

35-
referencePackages := []string{
36-
"github.com/coder/serpent",
37-
"github.com/coder/coder/v2/coderd/healthcheck/health",
35+
referencePackages := map[string]string{
36+
"github.com/coder/serpent": "Serpent",
3837
}
39-
for _, pkg := range referencePackages {
40-
err = gen.Include(pkg, false)
38+
for pkg, prefix := range referencePackages {
39+
err = gen.IncludeReference(pkg, prefix)
4140
if err != nil {
4241
log.Fatalf("include reference package %q: %v", pkg, err)
4342
}
@@ -70,6 +69,8 @@ func TsMutations(ts *guts.Typescript) {
7069
config.ExportTypes,
7170
// Readonly interface fields
7271
config.ReadOnly,
72+
// Add ignore linter comments
73+
config.BiomeLintIgnoreAnyTypeParameters,
7374
)
7475
}
7576

@@ -89,6 +90,7 @@ func TypeMappings(gen *guts.GoParser) error {
8990
"github.com/coder/serpent.Bool": "bool",
9091
"github.com/coder/serpent.Duration": "int64",
9192
"github.com/coder/serpent.URL": "string",
93+
"github.com/coder/serpent.HostPort": "string",
9294
"encoding/json.RawMessage": "map[string]string",
9395
})
9496
if err != nil {

scripts/apitypings/main_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import (
1414
"strings"
1515
"testing"
1616

17+
"github.com/coder/guts"
1718
"github.com/stretchr/testify/require"
18-
19-
"github.com/coder/gots"
2019
)
2120

2221
// updateGoldenFiles is a flag that can be set to update golden files.
@@ -37,7 +36,7 @@ func TestGeneration(t *testing.T) {
3736
t.Parallel()
3837
dir := filepath.Join(".", "testdata", f.Name())
3938

40-
gen, err := gots.NewGolangParser()
39+
gen, err := guts.NewGolangParser()
4140
if err != nil {
4241
log.Fatalf("new convert: %v", err)
4342
}

scripts/apitypings/typesgenerated.ts

Whitespace-only changes.

site/biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"files": {
3-
"ignore": ["**/*Generated.ts"]
3+
"ignore": []
44
},
55
"linter": {
66
"rules": {

0 commit comments

Comments
 (0)