Skip to content

Commit

Permalink
Fixing require './foo' under --eval and REPL; issue 1035
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevor Burnham committed Jan 13, 2011
1 parent 47e4f4d commit 7815138
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/coffee-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
while (root.parent) {
root = root.parent;
}
root.filename = fs.realpathSync(options.fileName || '.');
root.filename = options.fileName ? fs.realpathSync(options.fileName) : '.';
if (root.moduleCache) {
root.moduleCache = {};
}
Expand All @@ -59,7 +59,7 @@
};
exports.eval = function(code, options) {
var __dirname, __filename;
__filename = options.fileName;
__filename = module.filename = options.fileName;
__dirname = path.dirname(__filename);
return eval(compile(code, options));
};
Expand Down
4 changes: 2 additions & 2 deletions src/coffee-script.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exports.run = (code, options) ->
while root.parent
root = root.parent
# Set the filename.
root.filename = fs.realpathSync options.fileName or '.'
root.filename = if options.fileName then fs.realpathSync(options.fileName) else '.'
# Clear the module cache.
root.moduleCache = {} if root.moduleCache
# Compile.
Expand All @@ -70,7 +70,7 @@ exports.run = (code, options) ->
# Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
# The CoffeeScript REPL uses this to run the input.
exports.eval = (code, options) ->
__filename = options.fileName
__filename = module.filename = options.fileName
__dirname = path.dirname __filename
eval compile code, options

Expand Down

0 comments on commit 7815138

Please sign in to comment.