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

Conversation

flimzy
Copy link
Member

@flimzy flimzy commented Oct 9, 2015

This simply copies the same functionality from ImportPackage(). Perhaps it
should be factored into a common function.

This appears to solve bug #306, but causes some test failures, which I will investigate later.

This simply copies the same functionality from ImportPackage(). Perhaps it
should be factored into a common function.
@neelance
Copy link
Member

neelance commented Oct 9, 2015

The code seems to be copied from ImportPackage. Would probably be good to put it into a new function.

@flimzy
Copy link
Member Author

flimzy commented Oct 10, 2015

(How) should this change be auto-tested?

Perhaps add gopherjs/jsbuiltin to the list of packages auto built/tested (since it includes a *.inc.js file)?

Should I also add a build/build_test.go to test my new function, or is unit testing in this sort of case not a priority for this project?

@flimzy
Copy link
Member Author

flimzy commented Oct 12, 2015

I've done as much as I know to do with tests. Is there anything else you'd like me to do on this before it's merged?

@@ -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.

@neelance
Copy link
Member

I think it is unlikely that the tests for jsFilesFromDir will ever catch a regression, since the function is very straightforward and unlikely to change in the future. It would be more interesting to test it on the BuildDir and ImportPackage layer.

If we want to keep the current test case, then the directory test-inc.js should be renamed or moved to testdata, because that's the usual way to do it and Go skips those directories when looking for files to build: Directory and file names that begin with "." or "_" are ignored by the go tool, as are directories named "testdata". Also foo.inc.js should at least contain a comment.

For now, I would also be okay with just dropping the test and merge the implementation. The build package still lacks tests in general. This needs to be improved at some point, but not necessarily now. The compiler itself has a much higher risk of regressions.

@flimzy
Copy link
Member Author

flimzy commented Oct 16, 2015

Dropping tests seems quite reasonable to me, so I'll just remove that commit from the PR.

@flimzy
Copy link
Member Author

flimzy commented Oct 16, 2015

Done... I think this is ready for merging then.

neelance added a commit that referenced this pull request Oct 17, 2015
Include *.inc.js files in `gopherjs build` mode.
@neelance neelance merged commit bc27ff3 into gopherjs:master Oct 17, 2015
@flimzy flimzy deleted the bug306 branch October 17, 2015 17:52
@theclapp
Copy link

theclapp commented May 4, 2016

Is the inclusion of *.inc.js documented anywhere? I didn't realize gopherjs did that, and spent awhile trying to figure out where it came from.

@dmitshur
Copy link
Member

dmitshur commented May 4, 2016

Is the inclusion of *.inc.js documented anywhere?

Yes, see https://github.com/gopherjs/gopherjs/wiki/Bundle-additional-JavaScript-with-Go-packages.

@theclapp
Copy link

theclapp commented May 4, 2016

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants