From 709f17c2786e2d720dbd491649c83ea36ab44699 Mon Sep 17 00:00:00 2001 From: matehat Date: Fri, 12 Mar 2010 14:22:01 -0500 Subject: [PATCH] Added an extension on node's 'require' module so it can import .coffee module and added some tests to make sure it works. --- Cakefile | 2 ++ lib/coffee-script.js | 3 +++ src/coffee-script.coffee | 3 +++ test/test_importing.coffee | 2 ++ test/test_module.coffee | 1 + 5 files changed, 11 insertions(+) create mode 100644 test/test_importing.coffee create mode 100644 test/test_module.coffee diff --git a/Cakefile b/Cakefile index bf12f6aa..b1e365b4 100644 --- a/Cakefile +++ b/Cakefile @@ -68,6 +68,8 @@ task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', -> task 'test', 'run the CoffeeScript language test suite', -> process.mixin require 'assert' + require.paths.unshift './test' + test_count: 0 start_time: new Date() [original_ok, original_throws]: [ok, throws] diff --git a/lib/coffee-script.js b/lib/coffee-script.js index 016917b8..438dba3d 100644 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -17,6 +17,9 @@ Lexer = this.Lexer; parser = this.parser; } + require.registerExtension('.coffee', function(content) { + return require('coffee-script').compile(content); + }); // The current CoffeeScript version number. exports.VERSION = '0.5.5'; // Instantiate a Lexer for our use here. diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 9a8639a7..1434323b 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -17,6 +17,9 @@ else Lexer: this.Lexer parser: this.parser +require.registerExtension '.coffee', (content) -> + require('coffee-script').compile content + # The current CoffeeScript version number. exports.VERSION: '0.5.5' diff --git a/test/test_importing.coffee b/test/test_importing.coffee new file mode 100644 index 00000000..6ae62e0b --- /dev/null +++ b/test/test_importing.coffee @@ -0,0 +1,2 @@ +# Check if it can import a coffeescript-only module and check its output +ok (require 'test_module').foo is "bar" \ No newline at end of file diff --git a/test/test_module.coffee b/test/test_module.coffee new file mode 100644 index 00000000..7c3b08df --- /dev/null +++ b/test/test_module.coffee @@ -0,0 +1 @@ +exports.foo: "bar" \ No newline at end of file