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
added support Node's --require and -r flags in babel-node #7471
Conversation
stuneak
commented
Mar 2, 2018
•
edited
edited
Q | A |
---|---|
Fixed Issues? | #7465 |
Patch: Bug Fix? | n |
Major: Breaking Change? | n |
Minor: New Feature? | y |
Tests Added + Pass? | n |
Documentation PR | |
Any Dependency Changes? | n |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7238/ |
@@ -50,6 +50,11 @@ getV8Flags(function(err, v8Flags) { | |||
args.unshift(arg); | |||
break; | |||
|
|||
case "-r": | |||
case "--require": | |||
args.unshift(flag); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--require
has an option according to the docu: https://nodejs.org/api/cli.html#cli_r_require_module
So using flag
here is probably wrong and should be arg
instead, but I haven't tested it, so correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it seems I missed that the module is not separated by equal sign but with space in this case, so flag
and arg
are the same. Still I think this will not work as the preceding module name will be pushed to args (in the switch-default) whereas this here gets unshifted.
Hi guys, can you push forward a little with this task? I am very looking forward it. |
Okay I checked it and it wasn't working. I pushed a commit now it is working |
Guys, when do you plan, include this awesome feature in a release? |
Hi all! Thanks for adding this feature! At the moment though it looks like the
because it's not resolving
|
I see so we should change this line https://github.com/babel/babel/pull/7471/files#diff-bd092c1aa1f13cc3b620707dc4fc8a1eR153 to check if the path starts with dot and only then append cwd. In the other cases (absolute paths starting with / or modules starting with [a-zA-Z]) we can simply require them. Not sure about Windows though. |
@danez Node has an API, const Module = require('module')
const fakeParent = new Module('', null)
fakeParent.paths = Module._nodeModulePaths('.')
const paths = ['.', ...Module._resolveLookupPaths(request, fakeParent, true)]
const filename = Module._findPath(request, paths, false) |
My vote would be to use |
The idea wouldn't be to use Node internals for all-the-things. It would be to fork and only use the internals for Node < 8. Though an external package is cool too. |