Skip to content

Commit 8dd83e6

Browse files
authored
feat(internal/librarian): identify nodejs veneer libraries (#4802)
isVeneer function is updated to return true for Node.js libraries that have an output path specified but no APIs defined. This ensures that Librarian can correctly categorize handwritten Node.js libraries that do not contain generated GAPIC surfaces.
1 parent b48cbae commit 8dd83e6

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

internal/librarian/library.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,14 @@ func mergePackageDependencies(defaults, lib []*config.RustPackageDependency) []*
164164
// isVeneer reports whether the library has handwritten code wrapping generated
165165
// code.
166166
func isVeneer(language string, lib *config.Library) bool {
167-
if language == config.LanguageRust {
167+
switch language {
168+
case config.LanguageRust:
168169
return rust.IsVeneer(lib)
170+
case config.LanguageNodejs:
171+
return lib.Output != "" && len(lib.APIs) == 0
172+
default:
173+
return false
169174
}
170-
return false
171175
}
172176

173177
// libraryOutput returns the output path for a library. If the library has an

internal/librarian/library_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,53 @@ func TestCanDeriveAPIPath(t *testing.T) {
591591
})
592592
}
593593
}
594+
595+
func TestIsVeneer(t *testing.T) {
596+
for _, test := range []struct {
597+
name string
598+
language string
599+
lib *config.Library
600+
want bool
601+
}{
602+
{
603+
name: "rust is veneer",
604+
language: config.LanguageRust,
605+
lib: &config.Library{
606+
Rust: &config.RustCrate{
607+
Modules: []*config.RustModule{{APIPath: "google/storage/v2"}},
608+
},
609+
},
610+
want: true,
611+
},
612+
{
613+
name: "rust is not veneer",
614+
language: config.LanguageRust,
615+
lib: &config.Library{},
616+
want: false,
617+
},
618+
{
619+
name: "nodejs handwritten tool is veneer",
620+
language: config.LanguageNodejs,
621+
lib: &config.Library{
622+
Output: "packages/typeless-sample-bot",
623+
APIs: nil,
624+
},
625+
want: true,
626+
},
627+
{
628+
name: "nodejs gapic lib is not veneer",
629+
language: config.LanguageNodejs,
630+
lib: &config.Library{
631+
Output: "packages/gapic-lib",
632+
APIs: []*config.API{{Path: "google/example/v1"}},
633+
},
634+
want: false,
635+
},
636+
} {
637+
t.Run(test.name, func(t *testing.T) {
638+
if got := isVeneer(test.language, test.lib); got != test.want {
639+
t.Errorf("isVeneer(%q, %+v) = %v, want %v", test.language, test.lib, got, test.want)
640+
}
641+
})
642+
}
643+
}

0 commit comments

Comments
 (0)