cmd/tsconnect: pre-compress main.wasm when building the NPM package

This way we can do that once (out of band, in the GitHub action),
instead of increasing the time of each deploy that uses the package.

.wasm is removed from the list of automatically pre-compressed
extensions, an OSS bump and small change on the corp side is needed to
make use of this change.

Signed-off-by: Mihai Parparita <mihai@tailscale.com>
pull/5950/head
Mihai Parparita 2 years ago committed by Mihai Parparita
parent 899b4cae10
commit 63ad49890f

@ -12,6 +12,7 @@ import (
"path" "path"
"github.com/tailscale/hujson" "github.com/tailscale/hujson"
"tailscale.com/util/precompress"
"tailscale.com/version" "tailscale.com/version"
) )
@ -37,6 +38,10 @@ func runBuildPkg() {
runEsbuild(*buildOptions) runEsbuild(*buildOptions)
if err := precompressWasm(); err != nil {
log.Fatalf("Could not pre-recompress wasm: %v", err)
}
log.Printf("Generating types...\n") log.Printf("Generating types...\n")
if err := runYarn("pkg-types"); err != nil { if err := runYarn("pkg-types"); err != nil {
log.Fatalf("Type generation failed: %v", err) log.Fatalf("Type generation failed: %v", err)
@ -49,6 +54,13 @@ func runBuildPkg() {
log.Printf("Built package version %s", version.Long) log.Printf("Built package version %s", version.Long)
} }
func precompressWasm() error {
log.Printf("Pre-compressing main.wasm...\n")
return precompress.Precompress(path.Join(*pkgDir, "main.wasm"), precompress.Options{
FastCompression: *fastCompression,
})
}
func updateVersion() error { func updateVersion() error {
packageJSONBytes, err := os.ReadFile("package.json.tmpl") packageJSONBytes, err := os.ReadFile("package.json.tmpl")
if err != nil { if err != nil {

@ -42,7 +42,7 @@ func PrecompressDir(dirPath string, options Options) error {
} }
eg.Go(func() error { eg.Go(func() error {
return precompress(p, options) return Precompress(p, options)
}) })
return nil return nil
}) })
@ -81,12 +81,11 @@ func OpenPrecompressedFile(w http.ResponseWriter, r *http.Request, path string,
} }
var compressibleExtensions = map[string]bool{ var compressibleExtensions = map[string]bool{
".js": true, ".js": true,
".css": true, ".css": true,
".wasm": true,
} }
func precompress(path string, options Options) error { func Precompress(path string, options Options) error {
contents, err := os.ReadFile(path) contents, err := os.ReadFile(path)
if err != nil { if err != nil {
return err return err

Loading…
Cancel
Save