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/lib/command.js b/lib/command.js index 3406926aa8..6ec4a4b463 100644 --- a/lib/command.js +++ b/lib/command.js @@ -22,6 +22,7 @@ contents = []; optionParser = null; exports.run = function() { + var oldModuleFilename, req, _i, _len, _ref; parseOptions(); if (opts.nodejs) { return forkNode(); @@ -32,6 +33,16 @@ if (opts.version) { return version(); } + if (opts.require) { + oldModuleFilename = module.filename; + module.filename = '.'; + _ref = opts.require; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + req = _ref[_i]; + require(req); + } + module.filename = oldModuleFilename; + } if (opts.interactive) { return require('./repl'); } @@ -95,16 +106,9 @@ return _results; }; compileScript = function(file, input, base) { - var o, options, req, t, task, _i, _len, _ref; + var o, options, t, task; o = opts; options = compileOptions(file); - if (o.require) { - _ref = o.require; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - req = _ref[_i]; - require(helpers.starts(req, '.') ? fs.realpathSync(req) : req); - } - } try { t = task = { file: file, 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 diff --git a/src/command.coffee b/src/command.coffee index b912c6cb6c..ca4b02fa58 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -59,6 +59,11 @@ exports.run = -> return forkNode() if opts.nodejs return usage() if opts.help return version() if opts.version + if opts.require + oldModuleFilename = module.filename + module.filename = '.' + require req for req in opts.require + module.filename = oldModuleFilename return require './repl' if opts.interactive return compileStdio() if opts.stdio return compileScript null, sources[0] if opts.eval @@ -98,8 +103,6 @@ compileScripts = -> compileScript = (file, input, base) -> o = opts options = compileOptions file - if o.require - require(if helpers.starts(req, '.') then fs.realpathSync(req) else req) for req in o.require try t = task = {file, input, options} CoffeeScript.emit 'compile', task