Skip to content

Commit 560f8c0

Browse files
committed
fix(snippets): always descend into the entrypoint root
skipDirNames prunes well-known noise (node_modules, dist, build, …) under each entrypoint, but filepath.WalkDir invokes the callback for the root itself first. If a consumer pointed `--entrypoint=./build` at a project that emits TSX there, the root's basename matched the skip-list and the walk silently produced zero files. Guard the skip check so it only fires beneath the root, and add a regression test.
1 parent 3d17dd6 commit 560f8c0

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

snippets/internal/adapters/ldapplication/ldapplication.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,16 @@ func discoverFilesUnder(entrypoints []string) ([]string, error) {
109109
return walkErr
110110
}
111111
if d.IsDir() {
112-
if _, skip := skipDirNames[d.Name()]; skip {
113-
return filepath.SkipDir
112+
// Always descend into the entrypoint root, even if its
113+
// basename happens to be in skipDirNames (e.g.
114+
// `--entrypoint=./build` for a project that lays its
115+
// generated TSX out there). The skip-list is meant to prune
116+
// well-known noise *under* the root, not to silently turn
117+
// the entire walk into a no-op.
118+
if p != abs {
119+
if _, skip := skipDirNames[d.Name()]; skip {
120+
return filepath.SkipDir
121+
}
114122
}
115123
return nil
116124
}

snippets/internal/adapters/ldapplication/ldapplication_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ func TestDiscoverFilesUnder_DedupsOverlappingEntrypoints(t *testing.T) {
8080
}
8181
}
8282

83+
// The skip-list (node_modules, build, dist, …) prunes noise *under* the
84+
// entrypoint root. If the user passes one of those names *as* the
85+
// entrypoint (e.g. a project that emits its TSX into ./build), the walk
86+
// must still descend — otherwise discovery silently produces zero files.
87+
func TestDiscoverFilesUnder_RootMatchingSkipNameStillDescends(t *testing.T) {
88+
tmp := t.TempDir()
89+
root := filepath.Join(tmp, "build")
90+
writeAppFile(t, root, "marker.tsx",
91+
"// SDK_SNIPPET:RENDER:x/cmd hash=0 version=0.1.0\n<Snippet>x</Snippet>\n")
92+
93+
files, err := discoverFilesUnder([]string{root})
94+
if err != nil {
95+
t.Fatal(err)
96+
}
97+
if len(files) != 1 || filepath.Base(files[0]) != "marker.tsx" {
98+
t.Fatalf("expected marker.tsx under skip-named root, got %v", files)
99+
}
100+
}
101+
83102
// A non-directory entrypoint is rejected loudly rather than silently no-op'd.
84103
func TestDiscoverFilesUnder_RejectsNonDirectory(t *testing.T) {
85104
tmp := t.TempDir()

0 commit comments

Comments
 (0)