Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions internal/pkgzip/pkgzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,33 @@ const (
)

// excludedDirs are directory names skipped anywhere in the tree. The platform
// rebuilds from source, so build output and dependencies must not be shipped.
// rebuilds from source, so VCS metadata, dependency installs, build output, and
// tooling caches must not be shipped — they bloat the bundle (a stray Python
// .venv alone added ~860 files / ~11 MiB to a Vite/TS block) and slow the
// review-repo push without ever being used by the server build recipe.
var excludedDirs = map[string]struct{}{
".git": {},
// VCS metadata
".git": {},
".hg": {},
".svn": {},
// dependency installs
"node_modules": {},
"dist": {},
".venv": {},
"venv": {},
".pnpm-store": {},
// build output
"dist": {},
"build": {},
"out": {},
".next": {},
// tooling / test caches
".vite": {},
".cache": {},
"coverage": {},
".pytest_cache": {},
".mypy_cache": {},
".ruff_cache": {},
".turbo": {},
}

// Result describes a produced package.
Expand Down
14 changes: 12 additions & 2 deletions internal/pkgzip/pkgzip_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ import (

func TestExcludedNamesAndJoin(t *testing.T) {
names := ExcludedNames()
if len(names) != 3 {
t.Fatalf("ExcludedNames = %v, want 3 entries", names)
if len(names) < 3 {
t.Fatalf("ExcludedNames = %v, want at least the core entries", names)
}
// Sorted.
for i := 1; i < len(names); i++ {
if names[i-1] > names[i] {
t.Errorf("ExcludedNames not sorted: %v", names)
}
}
// Must include the original core dirs.
have := map[string]bool{}
for _, n := range names {
have[n] = true
}
for _, core := range []string{".git", "node_modules", "dist"} {
if !have[core] {
t.Errorf("ExcludedNames missing core entry %q: %v", core, names)
}
}
if JoinExcluded() == "" {
t.Error("JoinExcluded should be non-empty")
}
Expand Down
48 changes: 45 additions & 3 deletions internal/pkgzip/pkgzip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,55 @@ func TestBuildDeterministicOrder(t *testing.T) {
}

func TestExcludedNames(t *testing.T) {
for _, n := range []string{".git", "node_modules", "dist"} {
for _, n := range []string{
".git", ".hg", ".svn",
"node_modules", ".venv", "venv", ".pnpm-store",
"dist", "build", "out", ".next",
".vite", ".cache", "coverage", ".pytest_cache", ".mypy_cache", ".ruff_cache", ".turbo",
} {
if !IsExcluded(n) {
t.Errorf("%q should be excluded", n)
}
}
if IsExcluded("src") {
t.Error("src should not be excluded")
for _, n := range []string{"src", "public", "assets", "lib"} {
if IsExcluded(n) {
t.Errorf("%q should NOT be excluded", n)
}
}
}

// TestBuildExcludesVenvAndCaches guards the regression that bloated the
// gen-matrix bundle to 888 files: a stray Python .venv plus build/test caches
// leaking into the SOURCE bundle. Only real source must survive.
func TestBuildExcludesVenvAndCaches(t *testing.T) {
dir := t.TempDir()
writeFile(t, dir, "block.manifest.json", `{"blockId":"x"}`)
writeFile(t, dir, "package.json", "{}")
writeFile(t, dir, "src/main.tsx", "export default 1")
// Junk that must all be excluded:
writeFile(t, dir, ".venv/lib/python3.12/site-packages/foo/__init__.py", "x")
writeFile(t, dir, "venv/bin/activate", "x")
writeFile(t, dir, "build/index.js", "x")
writeFile(t, dir, "out/page.html", "x")
writeFile(t, dir, ".next/server/app.js", "x")
writeFile(t, dir, ".vite/deps/chunk.js", "x")
writeFile(t, dir, "coverage/lcov.info", "x")
writeFile(t, dir, ".pytest_cache/v/cache/lastfailed", "x")

res, err := Build(dir)
if err != nil {
t.Fatalf("Build: %v", err)
}
got := namesInZip(t, res.Zip)
sort.Strings(got)
want := []string{"block.manifest.json", "package.json", "src/main.tsx"}
if len(got) != len(want) {
t.Fatalf("zip contents = %v, want %v", got, want)
}
for i := range want {
if got[i] != want[i] {
t.Errorf("zip[%d] = %q, want %q (all: %v)", i, got[i], want[i], got)
}
}
}

Expand Down
Loading