imports: skip "node_modules" directories

Updates golang/go#16417

Change-Id: Ia4a5f997036274d09cca2ff10e500e403c1725ba
Reviewed-on: https://go-review.googlesource.com/25044
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Brad Fitzpatrick 2016-07-19 04:42:54 +00:00
parent edf8e6fef8
commit d4a8e583a1
2 changed files with 22 additions and 1 deletions

View File

@ -467,7 +467,8 @@ func scanGoDirs(goRoot bool) {
} }
if typ == os.ModeDir { if typ == os.ModeDir {
base := filepath.Base(path) base := filepath.Base(path)
if base == "" || base[0] == '.' || base[0] == '_' || base == "testdata" { if base == "" || base[0] == '.' || base[0] == '_' ||
base == "testdata" || base == "node_modules" {
return filepath.SkipDir return filepath.SkipDir
} }
fi, err := os.Lstat(path) fi, err := os.Lstat(path)

View File

@ -1346,6 +1346,26 @@ func TestIgnoreConfiguration(t *testing.T) {
}) })
} }
// Skip "node_modules" directory.
func TestSkipNodeModules(t *testing.T) {
testConfig{
gopathFiles: map[string]string{
"example.net/node_modules/pkg/a.go": "package pkg\nconst X = 1",
"otherwise-longer.net/not_modules/pkg/a.go": "package pkg\nconst X = 1",
},
}.test(t, func(t *goimportTest) {
const in = "package x\n\nconst _ = pkg.X\n"
const want = "package x\n\nimport \"otherwise-longer.net/not_modules/pkg\"\n\nconst _ = pkg.X\n"
buf, err := Process(t.gopath+"/src/x/x.go", []byte(in), nil)
if err != nil {
t.Fatal(err)
}
if string(buf) != want {
t.Errorf("wrong output.\ngot:\n%q\nwant:\n%q\n", buf, want)
}
})
}
func strSet(ss []string) map[string]bool { func strSet(ss []string) map[string]bool {
m := make(map[string]bool) m := make(map[string]bool)
for _, s := range ss { for _, s := range ss {