Skip to content

Commit bc27ff3

Browse files
committed
Merge pull request #322 from flimzy/bug306
Include *.inc.js files in `gopherjs build` mode.
2 parents a40ce0a + 113234f commit bc27ff3

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

build/build.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ func (s *Session) BuildDir(packagePath string, importPath string, pkgObj string)
309309
}
310310
pkg := &PackageData{Package: buildPkg}
311311
pkg.ImportPath = "main"
312+
jsFiles, err := jsFilesFromDir(pkg.Dir)
313+
if err != nil {
314+
return err
315+
}
316+
pkg.JsFiles = jsFiles
312317
if err := s.BuildPackage(pkg); err != nil {
313318
return err
314319
}
@@ -361,15 +366,11 @@ func (s *Session) ImportPackage(path string) (*compiler.Archive, error) {
361366
}
362367
pkg := &PackageData{Package: buildPkg}
363368

364-
files, err := ioutil.ReadDir(pkg.Dir)
369+
jsFiles, err := jsFilesFromDir(pkg.Dir)
365370
if err != nil {
366371
return nil, err
367372
}
368-
for _, file := range files {
369-
if strings.HasSuffix(file.Name(), ".inc.js") && file.Name()[0] != '_' {
370-
pkg.JsFiles = append(pkg.JsFiles, file.Name())
371-
}
372-
}
373+
pkg.JsFiles = jsFiles
373374

374375
if err := s.BuildPackage(pkg); err != nil {
375376
return nil, err
@@ -574,6 +575,20 @@ func NewMappingCallback(m *sourcemap.Map, goroot, gopath string) func(generatedL
574575
}
575576
}
576577

578+
func jsFilesFromDir(dir string) ([]string, error) {
579+
files, err := ioutil.ReadDir(dir)
580+
if err != nil {
581+
return nil, err
582+
}
583+
var jsFiles []string
584+
for _, file := range files {
585+
if strings.HasSuffix(file.Name(), ".inc.js") && file.Name()[0] != '_' {
586+
jsFiles = append(jsFiles, file.Name())
587+
}
588+
}
589+
return jsFiles, nil
590+
}
591+
577592
// hasGopathPrefix returns true and the length of the matched GOPATH workspace,
578593
// iff file has a prefix that matches one of the GOPATH workspaces.
579594
func hasGopathPrefix(file, gopath string) (hasGopathPrefix bool, prefixLen int) {

0 commit comments

Comments
 (0)