Skip to content

Commit 94b0dfd

Browse files
authored
feat(tool/cmd/migrate): traverse system-test/ for nodejs keep files (#4827)
The nodejs migration previously only walked samples/ to discover files for the keep list. This meant files like system-test/.eslintrc.yml were not preserved during regeneration, causing unexpected deletions. The migration now walks both samples/ and system-test/, skipping generated/ directories. For #4413
1 parent 6f89d7f commit 94b0dfd

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

tool/cmd/migrate/nodejs.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ func buildNodejsLibraries(repoPath, googleapisDir string) ([]*config.Library, er
223223
library.Keep = append(library.Keep, name)
224224
}
225225
}
226-
samplesKeep, err := nodejsSamplesKeep(pkgDir)
227-
if err != nil {
228-
return nil, fmt.Errorf("collecting samples for %s: %w", libraryName, err)
226+
for _, dir := range []string{"samples", "system-test"} {
227+
dirKeep, err := nodejsSubdirKeep(pkgDir, dir)
228+
if err != nil {
229+
return nil, fmt.Errorf("collecting %s for %s: %w", dir, libraryName, err)
230+
}
231+
library.Keep = append(library.Keep, dirKeep...)
229232
}
230-
library.Keep = append(library.Keep, samplesKeep...)
231233

232234
libraries = append(libraries, library)
233235
}
@@ -361,24 +363,24 @@ func extractCopyrightYear(pkgDir string) string {
361363
return ""
362364
}
363365

364-
// nodejsSamplesKeep walks the samples/ directory under pkgDir and returns
365-
// all file paths relative to pkgDir, excluding anything under
366-
// samples/generated/. Returns nil if the samples/ directory does not exist.
367-
func nodejsSamplesKeep(pkgDir string) ([]string, error) {
368-
samplesDir := filepath.Join(pkgDir, "samples")
369-
if _, err := os.Stat(samplesDir); err != nil {
366+
// nodejsSubdirKeep walks the named subdirectory under pkgDir and returns all
367+
// file paths relative to pkgDir, excluding anything under a generated/
368+
// subdirectory. Returns nil if the subdirectory does not exist.
369+
func nodejsSubdirKeep(pkgDir, subdir string) ([]string, error) {
370+
dir := filepath.Join(pkgDir, subdir)
371+
if _, err := os.Stat(dir); err != nil {
370372
if os.IsNotExist(err) {
371373
return nil, nil
372374
}
373375
return nil, err
374376
}
375377
var paths []string
376-
err := filepath.WalkDir(samplesDir, func(path string, d os.DirEntry, err error) error {
378+
err := filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error {
377379
if err != nil {
378380
return err
379381
}
380382
if d.IsDir() {
381-
if filepath.Base(path) == "generated" && filepath.Dir(path) == samplesDir {
383+
if filepath.Base(path) == "generated" {
382384
return filepath.SkipDir
383385
}
384386
return nil

tool/cmd/migrate/nodejs_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestBuildNodejsLibraries(t *testing.T) {
4242
"samples/README.md",
4343
"samples/quickstart.js",
4444
"samples/test/quickstart.test.js",
45+
"system-test/.eslintrc.yml",
4546
},
4647
Nodejs: &config.NodejsPackage{
4748
ExtraProtocParameters: []string{"metadata"},
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
env:
2+
mocha: true

0 commit comments

Comments
 (0)