mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Expanding __filename and __dirname when running with the coffee command -- Issue #771
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
(function() {
|
||||
var Lexer, compile, fs, lexer, parser, path;
|
||||
fs = require('fs');
|
||||
path = require('path');
|
||||
Lexer = require('./lexer').Lexer;
|
||||
parser = require('./parser').parser;
|
||||
if (require.extensions) {
|
||||
fs = require('fs');
|
||||
require.extensions['.coffee'] = function(module, filename) {
|
||||
var content;
|
||||
content = compile(fs.readFileSync(filename, 'utf8'));
|
||||
@@ -40,7 +40,7 @@
|
||||
while (root.parent) {
|
||||
root = root.parent;
|
||||
}
|
||||
root.filename = options.fileName;
|
||||
root.filename = fs.realpathSync(options.fileName);
|
||||
if (root.moduleCache) {
|
||||
root.moduleCache = {};
|
||||
}
|
||||
@@ -48,7 +48,7 @@
|
||||
};
|
||||
exports.eval = function(code, options) {
|
||||
var __dirname, __filename;
|
||||
__filename = options.fileName;
|
||||
__filename = fs.realpathSync(options.fileName);
|
||||
__dirname = path.dirname(__filename);
|
||||
return eval(exports.compile(code, options));
|
||||
};
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
# If included on a webpage, it will automatically sniff out, compile, and
|
||||
# execute all scripts present in `text/coffeescript` tags.
|
||||
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
{Lexer} = require './lexer'
|
||||
{parser} = require './parser'
|
||||
|
||||
# TODO: Remove registerExtension when fully deprecated
|
||||
if require.extensions
|
||||
fs = require 'fs'
|
||||
require.extensions['.coffee'] = (module, filename) ->
|
||||
content = compile fs.readFileSync filename, 'utf8'
|
||||
module._compile content, filename
|
||||
@@ -53,7 +53,7 @@ exports.run = (code, options) ->
|
||||
while root.parent
|
||||
root = root.parent
|
||||
# Set the filename
|
||||
root.filename = options.fileName
|
||||
root.filename = fs.realpathSync options.fileName
|
||||
# Clear the module cache
|
||||
root.moduleCache = {} if root.moduleCache
|
||||
# Compile
|
||||
@@ -65,7 +65,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 = fs.realpathSync options.fileName
|
||||
__dirname = path.dirname __filename
|
||||
eval exports.compile(code, options)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user