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

debug #910

Closed
dvv opened this issue Dec 8, 2010 · 16 comments
Closed

debug #910

dvv opened this issue Dec 8, 2010 · 16 comments
Labels

Comments

@dvv
Copy link

dvv commented Dec 8, 2010

Hi!

How do I pass node executable options when running a coffee script with coffee binary or simply running a chmod a+x file with #!/usr/bin/env coffee?

In particular, I want to pass --debug-brk

TIA,
--Vladimir

@michaelficarra
Copy link
Collaborator

I believe you put -- after your coffee arguments and before your node arguments, but I have no way of testing it right now. -- usually signifies the end of a parameter list. Try that out and let me know if it worked for you.

@dvv
Copy link
Author

dvv commented Dec 8, 2010

Hmmm.

coffee --debug-brk script.coffee barks

Error: unrecognized option: --debug-brk
at OptionParser.parse (/home/dvv/NODE/coffee-script/lib/optparse.js:29:17)

coffee -- --debug-brk script.coffee simply does nothing

@michaelficarra
Copy link
Collaborator

What I was trying to convey was coffee script.coffee -- --debug. All the regular coffeescript arguments followed by -- followed by all of your node arguments.

@dvv
Copy link
Author

dvv commented Dec 8, 2010

script gets executed but options don't get honored.

Feasible would be to pass any options which coffee doesn't recognize to the node intact

@jashkenas
Copy link
Owner

I'm afraid that there isn't a way to pass arguments directly to the node interpreter from the coffee command ... because by the time that the coffee command has started running, Node has already been invoked. The complete source code for coffee is available here:

https://github.com/jashkenas/coffee-script/blob/master/bin/coffee

@michaelficarra
Copy link
Collaborator

I was going to write a nice, detailed message, but I'm lazy so I will just paste the related section of IRC chat:

  • <michaelficarra> Regarding vladimir's problem with not being able to pass arguments to node: I don't see why we can't
  • <michaelficarra> I know node is already running coffee, but can't we just execve or something similar and change the process to a new node instance with the given arguments?
  • <jashkenas> Sure, we could do that.
  • <michaelficarra> I'm not too familiar with node's process management capabilities, but it must have something like that
  • <jashkenas> We'd have to keep a list of all valid Node arguments.
  • <jashkenas> It'd be a bit ugly.
  • <jashkenas> Why not just compile the code and run it with Node?
  • <michaelficarra> why? just pass everything after -- to node
  • <michaelficarra> if node doesn't recognize it, it will give an appropriate error
  • <jashkenas> Things after -- are already for passing options to your own scripts.
  • <michaelficarra> ah, I see
  • <jashkenas> --help is CoffeeScript's help ... unless you pass it after --.
  • <michaelficarra> then it's your own script's argument, not node's
  • <jashkenas> right.
  • <michaelficarra> I guess we could just allow a --node argument that accepts a list of node arguments as a string
  • <jashkenas> and then exec...
  • <michaelficarra> for example: coffee --node "--debug --something-else" script.coffee
  • <michaelficarra> yeah
  • <michaelficarra> it wouldn't be the most elegant solution, but it wouldn't be a hack either
  • <jashkenas> sure.
  • <jashkenas> I'll reopen the ticket.
  • <michaelficarra> And I'll make a note about how I was mistaken about coffee's behaviour when given -- and describe its actual purpose

@dvv
Copy link
Author

dvv commented Dec 11, 2010

Excellent. Also an environment variable can hold node options

@dvv
Copy link
Author

dvv commented Dec 12, 2010

This is how a "fork" can be made in node. Hope this helps

#!/usr/bin/env node

if (process.env.coffeenodeargs) {
var args = process.argv.slice(1);
args.unshift(process.env.coffeenodeargs);
delete process.env.coffeenodeargs;
console.log('SPAWN');
console.log('ARGS:', args);
require('child_process').spawn(process.argv[0], args, process.env, [0,1,2]);
console.log('SPAWNED');
} else {
console.log('CHILD NODE');
// main script here
}

@michaelficarra
Copy link
Collaborator

I don't think a child process is the way to go with this. I see that you're passing the custom file descriptors to redirect stdin, stdout, and stderr, but is there no way to actually replace the current process with a new process (see man execl)?

@dvv
Copy link
Author

dvv commented Dec 13, 2010

I thought we'd want to stay in node infrastructure. There's no exec (in syscall sense) in node which i'm aware of.

If we could make coffee binary a shell script, things would be done easier.

@michaelficarra
Copy link
Collaborator

We do want to stay within node, I was just hoping they would have something comparable. Though after looking for a while, it seems that spawning the child process may be our best bet.

@dvv
Copy link
Author

dvv commented Dec 13, 2010

Right. And passing [0,1,2] as descriptors just delegates parent's channels to the child, so coffeenodeargs='--debug' coffee !.coffee >1 2>2 <3 should work as expected

@dvv
Copy link
Author

dvv commented Dec 16, 2010

$ node --debug /usr/local/bin/coffee index.coffee is the solution w/o touching anything. Think we can close the issue. Thanks to all participants.

--Vladimir

@michaelficarra
Copy link
Collaborator

@dvv: I still plan on adding the --node flag for passing through node arguments. Nice temporary fix, though.

@dvv
Copy link
Author

dvv commented Dec 16, 2010

Staying tuned,
--Vladimir

@michaelficarra
Copy link
Collaborator

@dvv: this is now fixed on a branch in my fork, waiting on pull request 945.

stephank pushed a commit to stephank/coffee-script that referenced this issue May 14, 2011
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants