mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-22 04:32:40 +09:00
Import yarn.lock into pnpm with the same supply-chain settings as cmd/tsconnect, plus overrides replacing yarn resolutions, two narrow trustPolicyExclude entries for packages published without provenance, and denied esbuild/@swc/core install scripts. Switch assets.go, cmd/build-webclient, release/dist and CI to tool/pnpm. release/dist now looks up pnpm only when building web client assets; Build.Yarn is deprecated. Updates tailscale/corp#51439 Change-Id: Ib472fc8439e916bfe41158e3952f9fa8c02f522d Signed-off-by: Jim Wright <jimw@tailscale.com>
94 lines
2.3 KiB
Go
94 lines
2.3 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// The build-webclient tool generates the static resources needed for the
|
|
// web client (code at client/web).
|
|
//
|
|
// # Running
|
|
//
|
|
// Meant to be invoked from the tailscale/web-client-prebuilt repo when
|
|
// updating the production built web client assets. To run it manually,
|
|
// you can use `./tool/go run ./cmd/build-webclient`
|
|
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
|
|
"tailscale.com/util/precompress"
|
|
)
|
|
|
|
var (
|
|
outDir = flag.String("outDir", "build/", "path to output directory")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
// The toolDir flag is relative to the current working directory,
|
|
// so we need to resolve it to an absolute path.
|
|
toolDir, err := filepath.Abs("./tool")
|
|
if err != nil {
|
|
log.Fatalf("Cannot resolve tool-dir: %v", err)
|
|
}
|
|
|
|
if err := build(toolDir, "client/web"); err != nil {
|
|
log.Fatalf("%v", err)
|
|
}
|
|
}
|
|
|
|
func build(toolDir, appDir string) error {
|
|
if err := os.Chdir(appDir); err != nil {
|
|
return fmt.Errorf("Cannot change cwd: %w", err)
|
|
}
|
|
|
|
// The lockfile is never modified (frozenLockfile is set in
|
|
// client/web/pnpm-workspace.yaml).
|
|
if err := pnpm(toolDir, "install"); err != nil {
|
|
return fmt.Errorf("install failed: %w", err)
|
|
}
|
|
|
|
if err := pnpm(toolDir, "--silent", "run", "lint"); err != nil {
|
|
return fmt.Errorf("lint failed: %w", err)
|
|
}
|
|
|
|
if err := pnpm(toolDir, "--silent", "run", "build", "--outDir="+*outDir, "--emptyOutDir"); err != nil {
|
|
return fmt.Errorf("build failed: %w", err)
|
|
}
|
|
|
|
var compressedFiles []string
|
|
if err := precompress.PrecompressDir(*outDir, precompress.Options{
|
|
ProgressFn: func(path string) {
|
|
log.Printf("Pre-compressing %v\n", path)
|
|
compressedFiles = append(compressedFiles, path)
|
|
},
|
|
}); err != nil {
|
|
return fmt.Errorf("Cannot precompress: %w", err)
|
|
}
|
|
|
|
// Cleanup: the original (uncompressed) files are not embedded; only the
|
|
// ".zst" variants are served.
|
|
for _, f := range compressedFiles {
|
|
if err := os.Remove(f); err != nil {
|
|
log.Printf("Failed to cleanup %q: %v", f, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func pnpm(toolDir string, args ...string) error {
|
|
return run(filepath.Join(toolDir, "pnpm"), args...)
|
|
}
|
|
|
|
func run(name string, args ...string) error {
|
|
cmd := exec.Command(name, args...)
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
return cmd.Run()
|
|
}
|