From 1fd80fb20175c28bc500e6d889594d1a5ebb6be7 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 12 Dec 2019 17:04:40 +0000 Subject: [PATCH] fix(external): Correctly set names for root packages Fixes the prefix trimming logic for package names and source files if the source files appear in the package root (which is, unsurprisingly, very common). --- external/main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/external/main.go b/external/main.go index 0c1d84d5b..028703e38 100644 --- a/external/main.go +++ b/external/main.go @@ -94,19 +94,27 @@ func analysePackage(root, source, importpath string, stdlib map[string]bool) (pk } prefix := strings.TrimPrefix(source, root+"/") + + name := []string{} + if len(prefix) != len(source) { + name = strings.Split(prefix, "/") + } else { + // Otherwise, the name is empty since its the root package and no + // prefix should be added to files. + prefix = "" + } + files := []string{} for _, f := range p.GoFiles { files = append(files, path.Join(prefix, f)) } - analysed := pkg{ - Name: strings.Split(prefix, "/"), + return pkg{ + Name: name, Files: files, LocalDeps: local, ForeignDeps: foreign, - } - - return analysed, nil + }, nil } func loadStdlibPkgs(from string) (pkgs map[string]bool, err error) {