Patch child_process.fork to run .coffee files

This commit is contained in:
Michael Smith 2013-02-28 17:51:55 -08:00
parent 5dea70b82e
commit c98fae59fc
No known key found for this signature in database
GPG Key ID: 74223E91A6ACAFA2
4 changed files with 47 additions and 7 deletions

View File

@ -1,12 +1,14 @@
// Generated by CoffeeScript 1.5.0
(function() {
var Lexer, compile, ext, fs, helpers, lexer, loadFile, parser, path, vm, _i, _len, _ref,
var Lexer, child_process, compile, ext, fs, helpers, lexer, loadFile, parser, path, vm, _i, _len, _ref,
__hasProp = {}.hasOwnProperty;
fs = require('fs');
path = require('path');
child_process = require('child_process');
Lexer = require('./lexer').Lexer;
parser = require('./parser').parser;
@ -33,6 +35,19 @@
}
}
(function(fork) {
return child_process.fork = function(modulePath) {
var oldExecPath, output;
oldExecPath = process.execPath;
if (helpers.isCoffee(modulePath)) {
process.execPath = 'coffee';
}
output = fork.apply(this, arguments);
process.execPath = oldExecPath;
return output;
};
})(child_process.fork);
exports.VERSION = '1.5.0';
exports.helpers = require('./helpers');

View File

@ -6,12 +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'
helpers = require './helpers'
vm = require 'vm'
fs = require 'fs'
path = require 'path'
child_process = require 'child_process'
{Lexer} = require './lexer'
{parser} = require './parser'
helpers = require './helpers'
vm = require 'vm'
# Load and run a CoffeeScript file for Node, stripping any `BOM`s.
loadFile = (module, filename) ->
@ -23,6 +24,15 @@ if require.extensions
for ext in ['.coffee', '.litcoffee', '.md', '.coffee.md']
require.extensions[ext] = loadFile
# Patch child_process.fork to properly run .coffee files
do (fork = child_process.fork) ->
child_process.fork = (modulePath) ->
oldExecPath = process.execPath
process.execPath = 'coffee' if helpers.isCoffee modulePath
output = fork.apply this, arguments
process.execPath = oldExecPath
output
# The current CoffeeScript version number.
exports.VERSION = '1.5.0'

14
test/cluster.coffee Normal file
View File

@ -0,0 +1,14 @@
# Cluster Module
# ---------
unless window? or testingBrowser?
cluster = require('cluster')
if cluster.isMaster
test "#2737 - cluster module can spawn workers from a coffeescript process", ->
cluster.once 'exit', (worker, code) ->
eq code, 0
cluster.fork()
else
process.exit 0

View File

@ -88,6 +88,7 @@
'assignment'
'booleans'
'classes'
'cluster'
'comments'
'compilation'
'comprehensions'