Merge pull request #3113 from mklement0/make-repl-use-global-context

Make the REPL *CLI* use the global context to be consistent with the node REPL *CLI*.
This commit is contained in:
Jeremy Ashkenas 2013-10-20 09:17:07 -07:00
commit 465cffc675
2 changed files with 18 additions and 11 deletions

View File

@ -53,8 +53,11 @@
optionParser = null;
exports.run = function() {
var literals, source, _i, _len, _results;
var literals, replCliOpts, source, _i, _len, _results;
parseOptions();
replCliOpts = {
useGlobal: true
};
if (opts.nodejs) {
return forkNode();
}
@ -65,7 +68,7 @@
return version();
}
if (opts.interactive) {
return require('./repl').start();
return require('./repl').start(replCliOpts);
}
if (opts.watch && !fs.watch) {
return printWarn("The --watch feature depends on Node v0.6.0+. You are running " + process.version + ".");
@ -77,7 +80,7 @@
return compileScript(null, sources[0]);
}
if (!sources.length) {
return require('./repl').start();
return require('./repl').start(replCliOpts);
}
literals = opts.run ? sources.splice(1) : [];
process.argv = process.argv.slice(0, 2).concat(literals);

View File

@ -25,7 +25,7 @@ printWarn = (line) -> process.stderr.write line + '\n'
hidden = (file) -> /^\.|~$/.test file
# The help banner that is printed when `coffee` is called without arguments.
# The help banner that is printed in conjunction with `-h`/`--help`.
BANNER = '''
Usage: coffee [options] path/to/script.coffee -- [args]
@ -66,15 +66,19 @@ optionParser = null
# `--` will be passed verbatim to your script as arguments in `process.argv`
exports.run = ->
parseOptions()
return forkNode() if opts.nodejs
return usage() if opts.help
return version() if opts.version
return require('./repl').start() if opts.interactive
# Make the REPL *CLI* use the global context so as to (a) be consistent with the
# `node` REPL CLI and, therefore, (b) make packages that modify native prototypes
# (such as 'colors' and 'sugar') work as expected.
replCliOpts = useGlobal: yes
return forkNode() if opts.nodejs
return usage() if opts.help
return version() if opts.version
return require('./repl').start(replCliOpts) if opts.interactive
if opts.watch and not fs.watch
return printWarn "The --watch feature depends on Node v0.6.0+. You are running #{process.version}."
return compileStdio() if opts.stdio
return compileScript null, sources[0] if opts.eval
return require('./repl').start() unless sources.length
return compileStdio() if opts.stdio
return compileScript null, sources[0] if opts.eval
return require('./repl').start(replCliOpts) unless sources.length
literals = if opts.run then sources.splice 1 else []
process.argv = process.argv[0..1].concat literals
process.argv[0] = 'coffee'