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

Set process.argv[0] to 'coffee' when using coffee foo.coffee #1303

Merged
merged 2 commits into from
Apr 30, 2011
Merged

Set process.argv[0] to 'coffee' when using coffee foo.coffee #1303

merged 2 commits into from
Apr 30, 2011

Conversation

TrevorBurnham
Copy link
Collaborator

As discussed at #1301 (and several other issues Michael linked to from there), the current behavior of process.argv is to preserve 'node' as the first array value. I wasn't convinced that this mattered when the issue was first raised, but I've since come around. The very purpose of argv is that it tells you how to run the current program; if you run

coffee foo.coffee

and process.argv is

['node', 'foo.coffee']

then you can't do that. It's internally inconsistent, and in practical terms, it means you can't use raw coffee files with libraries like multi-node (see #1283) and Cluster, which use process.argv to fork processes. Granted, it's a good practice to compile to JS before deployment in such an environment, but there are circumstances under which using coffee files directly is much more convenient. I see no advantage to the current behavior.

@jashkenas jashkenas merged commit fe889b8 into jashkenas:master Apr 30, 2011
@satyr
Copy link
Collaborator

satyr commented Apr 30, 2011

Is .run meant to be public as a module method? If so, this seems problematic:

$ cat 1303.js
console.log(process.argv[0])
require('coffee-script').run('', {})
console.log(process.argv[0])

$ node 1303.js
node
coffee

jashkenas added a commit that referenced this pull request Apr 30, 2011
@jashkenas
Copy link
Owner

As always, @satyr is right on the money. The above fix puts the coffee argv in the right place -- for anything that's run by the coffee command, and nowhere else.

@satyr
Copy link
Collaborator

satyr commented May 2, 2011

This fix seems leaky still:

$ /usr/local/bin/coffee -e 'console.log process.argv[0]'
node

$ /usr/local/bin/coffee -s <<_
> console.log process.argv[0]
> _
node

$ echo console.log process.argv[0] > t.coffee && \
> /usr/local/bin/coffee t.coffee
coffee

where:

$ /usr/local/bin/node -e 'process.argv[0]'
/usr/local/bin/node

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.

3 participants