From 9e9b3671661ee4b667e31a93eb5e7db3d92b6a8a Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Fri, 9 Oct 2015 17:19:08 +0200 Subject: [PATCH 1/2] Include *.inc.js files in `gopherjs build` mode. This simply copies the same functionality from ImportPackage(). Perhaps it should be factored into a common function. --- build/build.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build/build.go b/build/build.go index ba5285b58..2c8deaaa4 100644 --- a/build/build.go +++ b/build/build.go @@ -309,6 +309,15 @@ func (s *Session) BuildDir(packagePath string, importPath string, pkgObj string) } pkg := &PackageData{Package: buildPkg} pkg.ImportPath = "main" + files, err := ioutil.ReadDir(pkg.Dir) + if err != nil { + return err + } + for _, file := range files { + if strings.HasSuffix(file.Name(), ".inc.js") && file.Name()[0] != '_' { + pkg.JsFiles = append(pkg.JsFiles, file.Name()) + } + } if err := s.BuildPackage(pkg); err != nil { return err } From 113234f378141a513013c134385db1d2844fb921 Mon Sep 17 00:00:00 2001 From: Jonathan Hall Date: Sat, 10 Oct 2015 11:53:04 +0200 Subject: [PATCH 2/2] DRY: Factor common code into a function. --- build/build.go | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/build/build.go b/build/build.go index 2c8deaaa4..2263638d0 100644 --- a/build/build.go +++ b/build/build.go @@ -309,15 +309,11 @@ func (s *Session) BuildDir(packagePath string, importPath string, pkgObj string) } pkg := &PackageData{Package: buildPkg} pkg.ImportPath = "main" - files, err := ioutil.ReadDir(pkg.Dir) + jsFiles, err := jsFilesFromDir(pkg.Dir) if err != nil { return err } - for _, file := range files { - if strings.HasSuffix(file.Name(), ".inc.js") && file.Name()[0] != '_' { - pkg.JsFiles = append(pkg.JsFiles, file.Name()) - } - } + pkg.JsFiles = jsFiles if err := s.BuildPackage(pkg); err != nil { return err } @@ -370,15 +366,11 @@ func (s *Session) ImportPackage(path string) (*compiler.Archive, error) { } pkg := &PackageData{Package: buildPkg} - files, err := ioutil.ReadDir(pkg.Dir) + jsFiles, err := jsFilesFromDir(pkg.Dir) if err != nil { return nil, err } - for _, file := range files { - if strings.HasSuffix(file.Name(), ".inc.js") && file.Name()[0] != '_' { - pkg.JsFiles = append(pkg.JsFiles, file.Name()) - } - } + pkg.JsFiles = jsFiles if err := s.BuildPackage(pkg); err != nil { return nil, err @@ -583,6 +575,20 @@ func NewMappingCallback(m *sourcemap.Map, goroot, gopath string) func(generatedL } } +func jsFilesFromDir(dir string) ([]string, error) { + files, err := ioutil.ReadDir(dir) + if err != nil { + return nil, err + } + var jsFiles []string + for _, file := range files { + if strings.HasSuffix(file.Name(), ".inc.js") && file.Name()[0] != '_' { + jsFiles = append(jsFiles, file.Name()) + } + } + return jsFiles, nil +} + // hasGopathPrefix returns true and the length of the matched GOPATH workspace, // iff file has a prefix that matches one of the GOPATH workspaces. func hasGopathPrefix(file, gopath string) (hasGopathPrefix bool, prefixLen int) {