Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Include *.inc.js files in gopherjs build mode. #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ func (s *Session) BuildDir(packagePath string, importPath string, pkgObj string)
}
pkg := &PackageData{Package: buildPkg}
pkg.ImportPath = "main"
jsFiles, err := jsFilesFromDir(pkg.Dir)
if err != nil {
return err
}
pkg.JsFiles = jsFiles
if err := s.BuildPackage(pkg); err != nil {
return err
}
Expand Down Expand Up @@ -361,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
Expand Down Expand Up @@ -574,6 +575,20 @@ func NewMappingCallback(m *sourcemap.Map, goroot, gopath string) func(generatedL
}
}

func jsFilesFromDir(dir string) ([]string, error) {
files, err := ioutil.ReadDir(dir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to comment here. I realize it is not a regression since the code contained ioutil.ReadDir(pkg.Dir) previously.

But this looks like it won't work in environments where direct disk access isn't available (e.g., the Go playground, or when using GopherJS as a library to compile in-memory without writing to disk).

It'd be outside the scope of this PR, but are there plans to try to make this operate/support virtual filesystems and avoid having duplicate code/logic for building with gopherjs-the-binary vs. gopherjs-the-library?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, if there is a need for it then we'll improve it. I haven't checked the playground yet, but I think it should not be affected by this change.

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) {
Expand Down