10000 chore: switch to guts for typescript types generation · coder/coder@6305d44 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6305d44

Browse files
committed
chore: switch to guts for typescript types generation
1 parent fe9c7d1 commit 6305d44

File tree

8 files changed

+31
-2528
lines changed

8 files changed

+31
-2528
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

scripts/apitypings/go.mod

Lines changed: 10 additions & 8 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
@@ -87,7 +90,6 @@ require (
8790
github.com/richardartoul/molecule v1.0.1-0.20240531184615-7ca0df43c0b3 // indirect
8891
github.com/rivo/uniseg v0.4.7 // indirect
8992
github.com/robfig/cron/v3 v3.0.1 // indirect
90-
github.com/rogpeppe/go-internal v1.12.0 // indirect
9193
github.com/ryanuber/go-glob v1.0.0 // indirect
9294
github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect
9395
github.com/spaolacci/murmur3 v1.1.0 // indirect
@@ -100,12 +102,12 @@ require (
100102
github.com/zclconf/go-cty v1.15.0 // indirect
101103
github.com/zeebo/errs v1.3.0 // indirect
102104
go.nhat.io/otelsql v0.14.0 // indirect
103-
go.opentelemetry.io/otel v1.30.0 // indirect
105+
go.opentelemetry.io/otel v1.32.0 // indirect
104106
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
105107
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect
106-
go.opentelemetry.io/otel/metric v1.30.0 // indirect
108+
go.opentelemetry.io/otel/metric v1.32.0 // indirect
107109
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
108-
go.opentelemetry.io/otel/trace v1.30.0 // indirect
110+
go.opentelemetry.io/otel/trace v1.32.0 // indirect
109111
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
110112
go.uber.org/atomic v1.11.0 // indirect
111113
golang.org/x/crypto v0.30.0 // indirect

scripts/apitypings/go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ github.com/coder/gots v0.0.0-20241126221454-18fbabbd18c5 h1:f/mc6/A4owCKhJAjSGtW
6262
github.com/coder/gots v0.0.0-20241126221454-18fbabbd18c5/go.mod h1:zH5CGux/eew1rvjjoKKQloiiQMTu2qdx7xIgmPzCRbg=
6363
github.com/coder/gots v0.0.0-20241126222907-985a03a876f0 h1:0jxONsMRoXchCdCcfcXlaVm1ciLkF6LLBDa7OgF4HJw=
6464
github.com/coder/gots v0.0.0-20241126222907-985a03a876f0/go.mod h1:zH5CGux/eew1rvjjoKKQloiiQMTu2qdx7xIgmPzCRbg=
65+
github.com/coder/guts v0.0.0-20241209140041-d9cf060de89e/go.mod h1:NpXPfboumDmFosCGHThTW2Ke4O4xn1hOSlKMD+TK4Oc=
6566
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0 h1:3A0ES21Ke+FxEM8CXx9n47SZOKOpgSE1bbJzlE4qPVs=
6667
github.com/coder/pretty v0.0.0-20230908205945-e89ba86370e0/go.mod h1:5UuS2Ts+nTToAMeOjNlnHFkPahrtDkmpydBen/3wgZc=
6768
github.com/coder/serpent v0.8.0 h1:6OR+k6fekhSeEDmwwzBgnSjaa7FfGGrMlc3GoAEH9dg=
@@ -132,6 +133,7 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
132133
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
133134
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b h1:h9U78+dx9a4BKdQkBBos92HalKpaGKHrp+3Uo6yTodo=
134135
github.com/google/pprof v0.0.0-20230817174616-7a8ec2ada47b/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik=
136+
github.com/google/pprof v0.0.0-20240409012703-83162a5b38cd/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
135137
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
136138
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
137139
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@@ -307,16 +309,19 @@ go.nhat.io/otelsql v0.14.0 h1:Mz4xo+WVQLAOPZy6abxjVzZzNe8xoOUh/tOMJoxo3oo=
307309
go.nhat.io/otelsql v0.14.0/go.mod h1:iO9KfDBZO2WI6O7n+ippHe5OHdXQ5iiA2aIa3Kzywo8=
308310
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
309311
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
312+
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
310313
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 h1:dIIDULZJpgdiHz5tXrTgKIMLkus6jEFa7x5SOKcyR7E=
311314
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0/go.mod h1:jlRVBe7+Z1wyxFSUs48L6OBQZ5JwH2Hg/Vbl+t9rAgI=
312315
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 h1:R3X6ZXmNPRR8ul6i3WgFURCHzaXjHdm0karRG/+dj3s=
313316
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0/go.mod h1:QWFXnDavXWwMx2EEcZsf3yxgEKAqsxQ+Syjp+seyInw=
314317
go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4QIZs7+w=
315318
go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ=
319+
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
316320
go.opentelemetry.io/otel/sdk v1.30.0 h1:cHdik6irO49R5IysVhdn8oaiR9m8XluDaJAs4DfOrYE=
317321
go.opentelemetry.io/otel/sdk v1.30.0/go.mod h1:p14X4Ok8S+sygzblytT1nqG98QG2KYKv++HE0LY/mhg=
318322
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
319323
go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o=
324+
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
320325
go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0=
321326
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
322327
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=

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)
0