diff --git a/dep/crawl/crawl.go b/dep/crawl/crawl.go index ddb7fb2..e39600a 100644 --- a/dep/crawl/crawl.go +++ b/dep/crawl/crawl.go @@ -106,7 +106,7 @@ func Crawl(repourl, dataDir string, l *log.Logger) <-chan Result { go func() { // queue the initial children to explore // we don't create a dep for the starting point - _, cdids := processRepo(repourl, l) + _, cdids := processRepo(repourl, true, l) push(cdids) // explore the graph concurrently until there are no more depnames queued @@ -150,16 +150,23 @@ func processDepID(id dep.ID, dataDir string, l *log.Logger) (r dep.Dep, childDep return dep.Dep{}, nil } - c, cdns := processRepo(dir, l) + c, cdns := processRepo(dir, false, l) return dep.Dep{ ID: id, Conf: c, }, cdns } -func processRepo(path string, l *log.Logger) (*conf.Config, []dep.ID) { +func processRepo(path string, isRoot bool, l *log.Logger) (*conf.Config, []dep.ID) { + opts := npm.Options{ + Dependencies: true, + } + if isRoot { + opts.DevDependencies = true + opts.PeerDependencies = true + } var r []dep.ID - ds := npm.Dependencies(path, l) + ds := npm.Dependencies(path, opts, l) r = append(r, ds...) ds, err := golang.Dependencies(path) if err != nil { diff --git a/dep/npm/npm.go b/dep/npm/npm.go index 0e12971..28338e8 100644 --- a/dep/npm/npm.go +++ b/dep/npm/npm.go @@ -31,9 +31,10 @@ type dist struct { } type pkg struct { - Name string `json:"name"` - Dependencies map[string]string `json:"dependencies"` - DevDependencies map[string]string `json:"devDependencies"` + Name string `json:"name"` + Dependencies map[string]string `json:"dependencies"` + DevDependencies map[string]string `json:"devDependencies"` + PeerDependencies map[string]string `json:"peerDependencies"` } func httpClient(l *log.Logger) *retryablehttp.Client { @@ -80,7 +81,13 @@ func Dir(name, dataDir string, l *log.Logger) string { return p } -func Dependencies(repoPath string, l *log.Logger) []dep.ID { +type Options struct { + Dependencies bool + DevDependencies bool + PeerDependencies bool +} + +func Dependencies(repoPath string, opts Options, l *log.Logger) []dep.ID { // parse the manifest pf, err := os.Open(path.Join(repoPath, "package.json")) if err != nil { @@ -99,8 +106,18 @@ func Dependencies(repoPath string, l *log.Logger) []dep.ID { } // return dependencies + depss := []map[string]string{} + if opts.Dependencies { + depss = append(depss, pj.Dependencies) + } + if opts.DevDependencies { + depss = append(depss, pj.DevDependencies) + } + if opts.PeerDependencies { + depss = append(depss, pj.PeerDependencies) + } var r []dep.ID - for _, deps := range []map[string]string{pj.Dependencies} { // TODO: add devDependencies, peerDependencies + for _, deps := range depss { for d := range deps { r = append(r, dep.ID{ Type: dep.NPM,