From a0cdb595ec17fe1938ac5d338a602414d0de396c Mon Sep 17 00:00:00 2001 From: Stas Malolepszy Date: Wed, 12 Jun 2013 12:12:25 +0200 Subject: [PATCH] Support Simplified CommonJS Wrappers Add explicit support for CJS Wrappers which look like the following: define(function(require, exports, module){ var foo = require('foo'), bar = require('foo/bar'); exports.doSomething = function(){ console.log(foo + bar); }; }); A module is only treated as a CJS module if it doesn't contain a dependency array and the definition function contain at least one parameter. More information: http://requirejs.org/docs/api.html#cjsmodule https://github.com/jrburke/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define --- lib/dryice/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/dryice/index.js b/lib/dryice/index.js index b391558..d60cbb9 100644 --- a/lib/dryice/index.js +++ b/lib/dryice/index.js @@ -851,9 +851,20 @@ function findRequires(module) { else if (args[0][0] === 'string' && args[1][0] == 'array') { params = args[1][1]; } + // Check if it's a Simplified CommonJS Wrapper. A module is only + // treated as a CJS module if it doesn't contain a dependency array and + // the definition function contains at least one parameter. + // http://requirejs.org/docs/api.html#cjsmodule + else if ((args[0][0] === 'function' && args[0][2].length) || + (args[1][0] === 'function' && args[1][2].length && + args[0][0] === 'string')) { + // By definition there are no dependencies, so no more work is + // necessary. + return; + } else { console.log('- ' + module.path + ' has define(...) ' + - 'with non-array parameter. Ignoring requirement.'); + 'with unrecognized parameter. Ignoring requirement.'); return; }