From a08dfff907e99d3c81648408e4b078950ecd7ee0 Mon Sep 17 00:00:00 2001 From: Alex MacCaw Date: Fri, 17 Aug 2012 09:32:55 -0700 Subject: [PATCH] allow CJS as a ext --- examples/example.js | 2 +- examples/modules/{program.module.js => program.cjs.js} | 0 lib/sprockets/commonjs.rb | 6 ++++-- 3 files changed, 5 insertions(+), 3 deletions(-) rename examples/modules/{program.module.js => program.cjs.js} (100%) diff --git a/examples/example.js b/examples/example.js index 7fad25b..be25fca 100644 --- a/examples/example.js +++ b/examples/example.js @@ -58,7 +58,7 @@ return this.require; }).call(this); -this.require.define({"modules/program":function(exports, require, module){module.exports = function(){ +this.require.define({"modules/program.cjs":function(exports, require, module){module.exports = function(){ alert('Long live the Programs!'); }; ;}}); diff --git a/examples/modules/program.module.js b/examples/modules/program.cjs.js similarity index 100% rename from examples/modules/program.module.js rename to examples/modules/program.cjs.js diff --git a/lib/sprockets/commonjs.rb b/lib/sprockets/commonjs.rb index 09e3509..ed73299 100644 --- a/lib/sprockets/commonjs.rb +++ b/lib/sprockets/commonjs.rb @@ -4,11 +4,13 @@ module Sprockets class CommonJS < Tilt::Template - DEFINE_WRAPPER = '%s.define({%s:' + + WRAPPER = '%s.define({%s:' + 'function(exports, require, module){' + '%s' + ";}});\n" + EXTENSIONS = %w{.module .cjs} + class << self attr_accessor :default_namespace end @@ -36,7 +38,7 @@ def evaluate(scope, locals, &block) attr_reader :namespace def commonjs_module?(scope) - File.extname(scope.logical_path) == '.module' + EXTENSIONS.include?(File.extname(scope.logical_path)) end def module_name(scope)