From a235a0074ba9fb3ca7e6a02aedc6d96c40c8ad5b Mon Sep 17 00:00:00 2001 From: Patrik Henningsson Date: Wed, 25 Jun 2014 19:15:13 +0200 Subject: [PATCH] Code cleanup. --- README.md | 5 ++++- bin/madge | 2 +- lib/parse/amd.js | 27 ++++++++++++++------------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 4a4dc5ab..eac41307 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ Get an image representation of the module dependency graph. -C, --config provide a config file -R, --require-config include shim dependencies found in RequireJS config file -O, --optimized if given file is optimized with r.js - --main-require-module name of the primary RequireJS module, if it is included with `require()` + -M --main-require-module name of the primary RequireJS module, if it's included with `require()` -j --json output dependency tree in json @@ -228,6 +228,9 @@ minimize a global energy function, which is equivalent to statistical multi-dime # Release Notes +## v0.3.2 (June 25, 2014) +Handle anonymous require() as entry in the RequireJS optimized file (Thanks to Benjamin Horsleben). + ## v0.3.1 (June 03, 2014) Apply exclude to RequireJS shim dependencies (Thanks to Michael White). diff --git a/bin/madge b/bin/madge index f6574dc7..639f3d11 100755 --- a/bin/madge +++ b/bin/madge @@ -28,7 +28,7 @@ program .option('-C, --config ', 'provide a config file') .option('-R, --require-config ', 'include shim dependencies found in RequireJS config file') .option('-O, --optimized', 'if given file is optimized with r.js', false) - .option('--main-require-module', 'name of the primary RequireJS module, if it is included with `require()`', '') + .option('-M, --main-require-module', 'name of the primary RequireJS module, if it\'s included with `require()`', '') .option('-j --json', 'output dependency tree in json') .parse(process.argv); diff --git a/lib/parse/amd.js b/lib/parse/amd.js index b5bc3ce6..e9719e76 100644 --- a/lib/parse/amd.js +++ b/lib/parse/amd.js @@ -106,28 +106,29 @@ AMD.prototype.parseFile = function (filename) { * Get module dependencies from optimize file (r.js). */ AMD.prototype.addOptimizedModules = function (filename) { - var self = this; + var self = this, + anonymousRequire = []; - var anonymousRequire = []; amdetective(this.getFileSource(filename)) .filter(function(obj) { var id = obj.name || obj; return id !== 'require' && id !== 'exports' && id !== 'module' && !id.match(/\.?\w\!/) && !self.isExcluded(id); }) .forEach(function (obj) { - if (typeof(obj) === 'string') { - anonymousRequire.push(obj); - return; - } - if (!self.isExcluded(obj.name)) { - self.tree[obj.name] = obj.deps.filter(function(id) { - return id !== 'require' && id !== 'exports' && id !== 'module' && !id.match(/\.?\w\!/) && !self.isExcluded(id); - }); - } + if (typeof(obj) === 'string') { + anonymousRequire.push(obj); + return; + } + + if (!self.isExcluded(obj.name)) { + self.tree[obj.name] = obj.deps.filter(function(id) { + return id !== 'require' && id !== 'exports' && id !== 'module' && !id.match(/\.?\w\!/) && !self.isExcluded(id); + }); + } }); + if (anonymousRequire.length > 0) { - var anonymousName = self.opts.mainRequireModule || ''; - self.tree[anonymousName] = anonymousRequire; + this.tree[this.opts.mainRequireModule || ''] = anonymousRequire; } };