Skip to content

Commit 7ad7ad0

Browse files
committed
fix(fs): Ignore package.json files inside node_modules
1 parent 181c6cb commit 7ad7ad0

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

plugin/fixtures/node_modules/package.json

Whitespace-only changes.

plugin/fs.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ package plugin
22

33
import (
44
"encoding/json"
5+
"github.com/cocov-ci/go-plugin-kit/cocov"
6+
"go.uber.org/zap"
57
"io/fs"
68
"os"
79
"path/filepath"
8-
9-
"github.com/cocov-ci/go-plugin-kit/cocov"
10-
"go.uber.org/zap"
10+
"strings"
1111
)
1212

1313
func findRepositories(rootPath string) ([]string, error) {
@@ -19,9 +19,11 @@ func findRepositories(rootPath string) ([]string, error) {
1919
if err != nil {
2020
return err
2121
}
22-
if d.IsDir() {
22+
23+
if d.IsDir() || strings.Contains(path, "node_modules") {
2324
return nil
2425
}
26+
2527
if d.Name() == "package.json" {
2628
repos = append(repos, filepath.Dir(path))
2729
}

plugin/fs_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,25 @@ func TestFindRepositories(t *testing.T) {
1313
root := findRepositoryRoot(t)
1414
path := filepath.Join(root, "plugin", "fixtures")
1515

16+
entries, err := os.ReadDir(path)
17+
assert.NoError(t, err)
18+
19+
dirCount := 0
20+
for _, e := range entries {
21+
if e.IsDir() {
22+
dirCount++
23+
}
24+
}
25+
1626
repos, err := findRepositories(path)
1727
require.NoError(t, err)
1828
assert.NotNil(t, repos)
19-
assert.Len(t, repos, 3)
29+
30+
ignoredNodeModules := dirCount-len(repos) == 1
31+
assert.Truef(t, ignoredNodeModules,
32+
"Should ignore package.json files that are inside node_modules",
33+
)
34+
2035
}
2136

2237
func TestCheckDependencies(t *testing.T) {

0 commit comments

Comments
 (0)