From 8feea70aae4b44b44a211b588e818be4fc06d8df Mon Sep 17 00:00:00 2001 From: Derek P Date: Mon, 18 Jul 2011 15:15:22 -0700 Subject: [PATCH] adds coffee-script precompilation support to node-webworkers. --- lib/webworker-child.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/webworker-child.js b/lib/webworker-child.js index 34b3c9f..4bd2f2a 100644 --- a/lib/webworker-child.js +++ b/lib/webworker-child.js @@ -28,6 +28,8 @@ try { ); } + + var writeError = process.binding('stdio').writeError; // Catch exceptions @@ -132,14 +134,25 @@ ws.addListener('open', function() { var scriptObj = undefined; switch (scriptLoc.protocol) { case 'file': + + + scriptSrc = fs.readFileSync(scriptLoc.pathname) + + // support coffeescript precompilation, if needed. + try { + if (scriptLoc.pathname.match(/.coffee/)) { + scriptSrc = require('coffee-script').compile(scriptSrc.toString()) + } + } catch (e) {} + scriptObj = new script.Script( - fs.readFileSync(scriptLoc.pathname), + scriptSrc, scriptLoc.href ); break; default: - writeError('Cannot load script from unknown protocol \'' + + writeError('Cannot load script from unknown protocol \'' + scriptLoc.protocol); process.exit(1); }