Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
pahen committed Jun 25, 2014
1 parent b5d9d1e commit a235a00
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Get an image representation of the module dependency graph.
-C, --config <filename> provide a config file
-R, --require-config <filename> 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


Expand Down Expand Up @@ -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).

Expand Down
2 changes: 1 addition & 1 deletion bin/madge
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ program
.option('-C, --config <filename>', 'provide a config file')
.option('-R, --require-config <filename>', '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);

Expand Down
27 changes: 14 additions & 13 deletions lib/parse/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down

0 comments on commit a235a00

Please sign in to comment.