mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Patch child_process.fork to run .coffee files
This commit is contained in:
parent
5dea70b82e
commit
c98fae59fc
4 changed files with 47 additions and 7 deletions
|
@ -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');
|
||||
|
|
|
@ -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
14
test/cluster.coffee
Normal 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
|
|
@ -88,6 +88,7 @@
|
|||
'assignment'
|
||||
'booleans'
|
||||
'classes'
|
||||
'cluster'
|
||||
'comments'
|
||||
'compilation'
|
||||
'comprehensions'
|
||||
|
|
Loading…
Reference in a new issue