From b82b06c8ab19b63fd319f22b6ed4898728dddebe Mon Sep 17 00:00:00 2001 From: Gesa Stupperich Date: Fri, 4 Sep 2026 08:50:34 +0100 Subject: [PATCH] cmd/tsconnect: copy type declarations into package directory Once the pkg-types script has generated pkg.d.ts and checked them against the tsconfig.json and node_modules in cmd/tsconnect, copy them into the pkgDir so they get bundled into the package. Updates #19707 Signed-off-by: Gesa Stupperich --- cmd/tsconnect/build-pkg.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/tsconnect/build-pkg.go b/cmd/tsconnect/build-pkg.go index 0817c287d..20f6383ae 100644 --- a/cmd/tsconnect/build-pkg.go +++ b/cmd/tsconnect/build-pkg.go @@ -11,6 +11,7 @@ import ( "log" "os" "path" + "path/filepath" "github.com/tailscale/hujson" "tailscale.com/cmd/tsconnect/wasmbuild" @@ -52,6 +53,9 @@ func runBuildPkg() { if err := runYarn("pkg-types"); err != nil { log.Fatalf("Type generation failed: %v", err) } + if err := copyTypeDeclarations(); err != nil { + log.Fatalf("Cannot copy generated types: %v", err) + } if err := updateVersion(); err != nil { log.Fatalf("Cannot update version: %v", err) @@ -117,3 +121,18 @@ func copyReadme() error { } return os.WriteFile(path.Join(*pkgDir, "README.md"), readmeBytes, 0644) } + +// copyTypeDeclarations copies pkg.d.ts into pkgDir +// if pkgDir differs from the local default ./pkg. +func copyTypeDeclarations() error { + const src = "pkg/pkg.d.ts" + dst := path.Join(*pkgDir, "pkg.d.ts") + if filepath.Clean(src) == filepath.Clean(dst) { + return nil + } + data, err := os.ReadFile(src) + if err != nil { + return err + } + return os.WriteFile(dst, data, 0644) +}