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.execPath correctly when running .coffee files #1307

Merged
merged 2 commits into from
May 1, 2011
Merged

Set process.execPath correctly when running .coffee files #1307

merged 2 commits into from
May 1, 2011

Conversation

TrevorBurnham
Copy link
Collaborator

Issue #1303 set process.argv[0] to coffee. However, process.execPath still gives the absolute path of node, not coffee. This patch corrects that by using the value of __filename from coffee as process.execPath when running a .coffee file.

Related: #1303 set `process.argv[0]` to `coffee`. This makes
`process.execPath` consistent with that change.
@michaelficarra
Copy link
Collaborator

I'm for fixing it, but I believe there are better fixes than changing run's signature. For example, we could instead add either process.execPath = process.mainModule.filename or process.execPath = process.argv[1] before process.ARGV = process.argv = process.argv.slice(0, 2).concat opts.literals (line 68).

@TrevorBurnham
Copy link
Collaborator Author

Great idea! I was unaware of process.mainModule. That makes it a simple 1-line addition in command.coffee.

@michaelficarra
Copy link
Collaborator

Before you commit to that, make sure process.mainModule is part of the public API. require.main.filename or module.filename or process.argv[1] may be a better choice.

@jashkenas
Copy link
Owner

None of those alternatives are documented in Node's public API, so I think this is fine for now.

@jashkenas jashkenas merged commit fc992ba into jashkenas:master May 1, 2011
@michaelficarra
Copy link
Collaborator

None of those alternatives are documented in Node's public API

process.argv[1]

@jashkenas
Copy link
Owner

process.argv[1] isn't the absolute path to the coffee executable.

@michaelficarra
Copy link
Collaborator

process.argv[1] isn't the absolute path to the coffee executable.

It is before we rewrite it. (test.coffee contains console.log process.argv and I added console.log process.argv to src/command.coffee right before we rewrite process.argv)

[ 'node',
  '/home/michael/projects/coffee-script/bin/coffee',
  '/home/michael/test.coffee' ]
[ 'coffee', '/home/michael/test.coffee' ]

which happens at the current line 68, the line I suggested we add the fix above... above.

edit: various inline edits

@TrevorBurnham
Copy link
Collaborator Author

That works too. For the record, require.main is part of Node's public API and should be equivalent to process.mainModule. (I asked here.)

@jashkenas
Copy link
Owner

Thanks for asking ... moved to require.main at 08294dc

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

Successfully merging this pull request may close these issues.

3 participants