Skip to content

gopherjs test does not include *.inc.js files. #306

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

Closed
flimzy opened this issue Sep 14, 2015 · 14 comments
Closed

gopherjs test does not include *.inc.js files. #306

flimzy opened this issue Sep 14, 2015 · 14 comments

Comments

@flimzy
Copy link
Member

flimzy commented Sep 14, 2015

The following description is inaccurate. Jump to here to see a proper explanation of the issue.

I don't know if this is a good idea, but I want to propose it for discussion, because it seems, at least at first glance, that it could make a few things easier for me.

I've read through issue #111 and the related commits. It appears (from reading 51e33b7, as well as the observed behavior in testing) that this feature is only applicable when compiling the main package.

Would it be reasonable to do the same for library packages?

At present I'm looking at this in respect to gopherjs/jsbuiltin#2. The current solution I'm using there (an eval(), triggers warnings in browsers with CSP enabled). So I was looking at including a simple jsbuiltin.inc.js that contained simply function typeoffunc(x) { return typeof x }. But, since this is the jsbuiltin package, and not main, that feature isn't enabled.

I can also see some potential benefits when writing wrappers/bindings for existing JavaScript functions--it might be handy (if/when licensing permits) to include the relevant JavaScript code in the bundled Go package.

I haven't thought this through entirely. I'm not 100% convinced it's all a good idea... But I imagine you guys have thought about many more of the underlying implications than I have to know if this is a good idea or not.

@dmitshur
Copy link
Member

I don't see why not.

In fact, I would be inclined to think the only reason it's not already the case is because of a bug or unintended omission.

Unless I'm missing something and there was a reason this .inc.js thing was added for main packages only?

That said, this is another feature I do not plan to use much myself, if at all. But if others want to, I think they should be able to. It should probably not be recommended unless appropriate for the situation.

@dmitshur
Copy link
Member

Unless I'm missing something and there was a reason this .inc.js thing was added for main packages only?

Now that I think about it more, it might be on purpose.

Adding additional JavaScript makes sense when building the final output, such as the case for a main Go package. But if it's done on a per-package level, it may cause conflicts between different packages, etc.

So, I probably take back what I said above.

@flimzy
Copy link
Member Author

flimzy commented Sep 14, 2015

Yes, that's true. For it to really work well, it would almost certainly have to be in some sort of a CommonJS-style closure. And trying to mix that with GopherJS doesn't sound fun.

@flimzy flimzy closed this as completed Sep 14, 2015
@flimzy flimzy reopened this Sep 14, 2015
@flimzy
Copy link
Member Author

flimzy commented Sep 14, 2015

(Oops, didn't mean to close it just yet... although that's probably going to be the eventual fate of this anyway).

@dmitshur
Copy link
Member

Yeah, let's wait to hear thoughts of @neelance (and maybe @dominikh) on this.

@neelance
Copy link
Member

I think it's reasonable to make it work with all packages. I don't know why it currently does not work, it was not on purpose. @flimzy Would you like to dig into that or should I take a look?

@flimzy
Copy link
Member Author

flimzy commented Sep 14, 2015

I'll take a crack at it.

What are your thoughts on @shurcooL's point about conflicts? I suppose just trust users not to let that happen?

@neelance
Copy link
Member

Yeah, bad things can be done in a lot of ways. This however does not seem like an explicit invitation to do so. ;-)

@flimzy
Copy link
Member Author

flimzy commented Sep 15, 2015

My investigation has lead me to the conclusion that the failure I observed is not specifically with non-main packages, but rather that gopherjs test fails to include *.inc.js files.

This also lead me to discover that gopherjs build only includes the *.inc.js files when they are explicitly mentioned on the command line:

gopherjs build jstest.go jstest.inc.js

But doing this with gopherjs test is not supported:

$ gopherjs test jstest.go jstest.inc.js 
cannot find package "jstest.go" in any of:
    /usr/local/go/src/jstest.go (from $GOROOT)
    /home/jonhall/go/src/jstest.go (from $GOPATH)

It appears that build accepts file names (even though gopherjs help build claims it needs package names--but go build seems to exhibit the same inconsistency). However, gopherjs test enforces the documented behavior of only allowing package names.

I'm willing to continue working toward a fix, but I think I need some guideance from you, @neelance, as to what the intended behavior for gopherjs build and gopherjs test are with respect to *.inc.js files.

@flimzy flimzy changed the title Include *.inc.js even for non-main packages? gopherjs test does not include *.inc.js files. Sep 15, 2015
@dmitshur
Copy link
Member

This also lead me to discover that gopherjs build only includes the *.inc.js files when they are explicitly mentioned on the command line:

gopherjs build jstest.go jstest.inc.js

Just want to confirm, do you mean that doing gopherjs build would not include .inc.js files?

@flimzy
Copy link
Member Author

flimzy commented Sep 17, 2015

That is correct. That is my observation.

@flimzy
Copy link
Member Author

flimzy commented Sep 17, 2015

I'm testing with this repo: https://github.com/flimzy/jstest

If I do gopherjs build, then gopherjs build jstest.go jstest.inc.js, the results differ as follows:

--- 1.js        2015-09-17 00:46:22.546548624 -0500
+++ jstest.js   2015-09-17 00:46:38.542719761 -0500
@@ -14947,6 +14947,10 @@
})();
$packages["main"] = (function() {
        var $pkg = {}, $init, fmt, sliceType, main;
+       (function() {
+console.log("Included the JS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
+
+       }).call($global);
        fmt = $packages["fmt"];
        sliceType = $sliceType($emptyInterface);
        main = function() {

@flimzy
Copy link
Member Author

flimzy commented Oct 9, 2015

I've been distracted the last several weeks by an international move. I'll finish investigating my fix in #322 over the next few days as time permits.

@dmitshur
Copy link
Member

Resolved with #322.

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

No branches or pull requests

3 participants