-
Notifications
You must be signed in to change notification settings - Fork 2k
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
coffee dir
executes every coffee file, vs node dir
which executes index.js
only.
#2496
Comments
For example, with the following files.. # example/index.coffee
if require.main is module
console.log 'Index is the main file run! I was run directly by the user!'
exports.file1 = require './file1'
exports.file2 = require './file2'
exports.file3 = require './file3'
# example/file1.coffee
if require.main is module
console.log 'File1 is the main file run! I was run directly by the user!'
# example/file2.coffee
if require.main is module
console.log 'File2 is the main file run! I was run directly by the user!'
# example/file3.coffee
if require.main is module
console.log 'File3 is the main file run! I was run directly by the user!' And the actual output for this is...
Now, i would expect the output to simply be:
The reason for this is simply that interpreters such as Node and Python have the expected behavior to execute a directory by executing the index file only. Coffee, on the other hand, executes every file in the directory. I would think this would be counterintuitive to many of the new Coffee users coming from Nodejs. Not a huge issue either way. |
I've wondered about this for a long time, too, and agree that unless there's a good reason for this (which there may be; just not aware of any), it'd be great for The good news is that Node has the algorithm for this both documented and exposed: http://nodejs.org/api/modules.html#modules_all_together |
Yeah, I was thrown by this a little while back when I started playing with coffee-script. Definitely would be nice if it worked the same as |
I would imagine it's in there for tests - you can have all your tests in separate files in a "test" directory, and run them all by doing
Rather than having to write an index file that loads in and runs each test individually. |
You need helpers etc for test suites anyway, so I hardly see how that could be the case |
What do you mean? vows, for one, can run a file with tests in it straight through |
oh that's definitely nice |
Hrm... If we changed this, then the behavior of |
My CLI simply behaves as node's. The relevant issue is already linked above: michaelficarra/CoffeeScriptRedux#102 |
Calling
Is there a reliable way to tell whether the process was started by calling |
@ppvg Either way, this may be a none issue anymore, since Redux handles the issue properly. |
@leeolayvar that's what I thought, but I don't think that's true. The result is identical when Since I'm writing a library, I can't depend on the users using either regular CS or CS Redux. Edit: |
@ppvg No, i mean that in my opinion, |
I noted this in #3292, but noting here too: it'd still be worth getting to full |
Well as the title says, if you run
coffee directory
CoffeeScript will "execute" every coffee file found within that directory, as if they were all called directly (coffee dir/foo.coffee
,coffee dir/bar.coffee
, etc). This is very different behavior fromnode directory
which will look for, and only execute, anindex.js
file if found.Is this a bug? Or working as intended?
Note that the work-around is not hard, simply execute the index file explicitly, such as:
coffee directory/index.coffee
, it just seems more logical thatcoffee dir
andnode dir
should do the same things, as they do the same thing when used likecoffee file
andnode file
.The text was updated successfully, but these errors were encountered: