Skip to content
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

Require node modules from Opal #19

Open
wied03 opened this issue Apr 12, 2016 · 4 comments
Open

Require node modules from Opal #19

wied03 opened this issue Apr 12, 2016 · 4 comments
Milestone

Comments

@wied03
Copy link
Collaborator

wied03 commented Apr 12, 2016

Currently, you cannot require node modules from Opal without using back ticks or JS syntax. (see Requires under README).

What would also need to happen, is to monkey patch the Opal compiler to allow the following:

some_module = require_node 'something'
some_module.js_function

This would be a variant of the call node. That would under the hood become a webpack require that gets assigned to the some_module variable and Opal would not try to find it as an Opal module. It could even do the JS syntax under the hood so that you can call methods, etc. on it easily (see 2nd line above).

@wied03 wied03 changed the title Test requiring node modules Require node modules from Opal Apr 12, 2016
@wied03 wied03 added this to the 0.11.0 milestone Apr 12, 2016
@wied03
Copy link
Collaborator Author

wied03 commented Apr 14, 2016

@cj - This is already present in Opal's stdlib. See nodejs/kernel.rb and usage of it in nodejs/file.rb.

@wied03 wied03 closed this as completed Apr 14, 2016
@wied03 wied03 reopened this Apr 14, 2016
@wied03
Copy link
Collaborator Author

wied03 commented Apr 14, 2016

@cj - Never mind. 1) we can't load all the node stuff in there because it will throw off the phantomJS stuff in the test. 2) More importantly, the stdlib require is runtime. We need a compile time 'require' for webpack to pick up.

@cj
Copy link
Owner

cj commented Apr 14, 2016

Would there be a similar issue doing #2 or would it be simpler as you're just converting #= require foo to %x{require('foo')}? I'm using %x because it won't let me escape ` lol

@wied03
Copy link
Collaborator Author

wied03 commented Apr 14, 2016

I think this should be quite different than #2. #2 would scan source code to do that. This, to be robust, really needs to be compiler driven. Not hard though (probably 5-10 lines of code) + the tests. Just isn't as high on my individual priority list.

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

No branches or pull requests

2 participants