CoffeeScript support added #8

Closed
wants to merge 3 commits into from
View
9 lib/sandboxed_module.js
@@ -1,3 +1,4 @@
+var coffeeScript = require('coffee-script');
@felixge
Owner
felixge added a note Jun 3, 2012

So this will crash whenever coffee script is not installed?

One solution is to put coffee-script module in the dependencies. It's the way other modules like mocha go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
var requireLike = require('require-like');
var stackTrace = require('stack-trace');
var Module = require('module');
@@ -138,10 +139,16 @@ SandboxedModule.prototype._getCompileInfo = function() {
localValues.push(this.locals[localVariable]);
}
+ var sourceToWrap = fs.readFileSync(this.filename, 'utf8');
+
+ if (~this.filename.search('.coffee$')){
@felixge
Owner
felixge added a note Jun 3, 2012

Bitwise not? Seriously?

Didn't see the problem. Maybe use a RegEx?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ sourceToWrap = coffeeScript.compile(sourceToWrap, {bare:true});
+ }
+
var source =
'(function(' + localVariables.join(', ') + ') { ' +
'global = GLOBAL = root = (function() { return this; })();' +
- fs.readFileSync(this.filename, 'utf8') +
+ sourceToWrap +
'\n' +
'return global;\n' +
'});';
View
4 package.json
@@ -22,5 +22,7 @@
"devDependencies": {
"urun": "0.0.4"
},
- "optionalDependencies": {}
+ "optionalDependencies": {
+ "coffee-script": "1.2.0"
+ }
}
View
5 test/fixture/coffeeClass.coffee
@@ -0,0 +1,5 @@
+class coffeeClass
+ simpleData: ->
+ 1 + 1
+
+module.exports = coffeeClass
View
10 test/integration/test-coffee.js
@@ -0,0 +1,10 @@
+var common = require('../common');
+var assert = common.assert;
+var SandboxedModule = require(common.dir.lib + '/sandboxed_module');
+
+(function testRequire() {
+ var test = require('../fixture/coffeeClass');
+ console.log(new test().simpleData());
+ var coffeeClass = SandboxedModule.load('../fixture/coffeeClass').exports;
+ assert.strictEqual(new coffeeClass().simpleData(), 2);
+})();