From 7815138386ee1fbbcc3c6cfd3d904658ff8a2b10 Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Thu, 13 Jan 2011 14:20:11 -0500 Subject: [PATCH] Fixing require './foo' under --eval and REPL; issue 1035 --- lib/coffee-script.js | 4 ++-- src/coffee-script.coffee | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/coffee-script.js b/lib/coffee-script.js index 12ca09e211..d67b745c21 100755 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -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 = {}; } @@ -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)); }; diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 01710cd59d..6c3b9c4687 100755 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -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. @@ -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