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 <[email protected]>
This commit is contained in:
Gesa Stupperich authored and Gesa Stupperich committed 2026-09-04 11:51:56 +01:00
1 parent 31d8badb3b
commit b82b06c8ab
1 file changed
+19
+19
View File
@@ -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)
}