Skip to content
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

Decouple --require from individual file compilations #1045

Merged
2 commits merged into from
Jan 15, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 12 additions & 8 deletions lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
7 changes: 5 additions & 2 deletions src/command.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down