add CoffeeScript.register method for require.extensions registration

This commit is contained in:
Michael Ficarra
2013-12-08 14:21:18 -06:00
parent ba4743cc83
commit 08a57898a7
7 changed files with 11 additions and 5 deletions

View File

@@ -161,7 +161,7 @@ task 'bench', 'quick benchmark of compilation time', ->
# Run the CoffeeScript test suite.
runTests = (CoffeeScript) ->
require './lib/coffee-script/register'
CoffeeScript.register()
startTime = Date.now()
currentFile = null
passedTests = 0

View File

@@ -182,6 +182,10 @@
}
};
exports.register = function() {
return require('./register');
};
exports._compileFile = function(filename, sourceMap) {
var answer, err, raw, stripped;
if (sourceMap == null) {

View File

@@ -178,7 +178,7 @@
} else if (o.nodes) {
return printLine(CoffeeScript.nodes(t.input, t.options).toString().trim());
} else if (o.run) {
require('./register');
CoffeeScript.register();
return CoffeeScript.run(t.input, t.options);
} else if (o.join && t.file !== o.join) {
if (helpers.isLiterate(file)) {

View File

@@ -145,7 +145,7 @@
console.warn("Node 0.8.0+ required for CoffeeScript REPL");
process.exit(1);
}
require('./register');
CoffeeScript.register();
process.argv = ['coffee'].concat(process.argv.slice(2));
opts = merge(replDefaults, opts);
repl = nodeREPL.start(opts);

View File

@@ -156,6 +156,8 @@ exports.eval = (code, options = {}) ->
else
vm.runInContext js, sandbox
exports.register = -> require './register'
exports._compileFile = (filename, sourceMap = no) ->
raw = fs.readFileSync filename, 'utf8'
stripped = if raw.charCodeAt(0) is 0xFEFF then raw.substring 1 else raw

View File

@@ -138,7 +138,7 @@ compileScript = (file, input, base = null) ->
else if o.nodes
printLine CoffeeScript.nodes(t.input, t.options).toString().trim()
else if o.run
require './register'
CoffeeScript.register()
CoffeeScript.run t.input, t.options
else if o.join and t.file isnt o.join
t.input = helpers.invertLiterate t.input if helpers.isLiterate file

View File

@@ -131,7 +131,7 @@ module.exports =
console.warn "Node 0.8.0+ required for CoffeeScript REPL"
process.exit 1
require './register'
CoffeeScript.register()
process.argv = ['coffee'].concat process.argv[2..]
opts = merge replDefaults, opts
repl = nodeREPL.start opts