Comparing version 0.4.1 to 0.5.0
@@ -11,2 +11,3 @@ 'use strict'; | ||
AMD = require('./parse/amd'), | ||
ES6 = require('./parse/es6'), | ||
graph = require('./graph'); | ||
@@ -128,9 +129,3 @@ | ||
if (src && src.length) { | ||
if (this.opts.format === 'cjs') { | ||
tree = new CJS(src, this.opts, this).tree; | ||
} else if (this.opts.format === 'amd') { | ||
tree = new AMD(src, this.opts, this).tree; | ||
} else { | ||
throw new Error('invalid module format "' + this.opts.format + '"'); | ||
} | ||
tree = this.parse(src); | ||
} | ||
@@ -149,2 +144,19 @@ | ||
/** | ||
* Parse the given source folder(s). | ||
* @param {Array|Object} src | ||
* @return {Object} | ||
*/ | ||
Madge.prototype.parse = function(src) { | ||
if (this.opts.format === 'cjs') { | ||
return new CJS(src, this.opts, this).tree; | ||
} else if (this.opts.format === 'amd') { | ||
return new AMD(src, this.opts, this).tree; | ||
} else if (this.opts.format === 'es6') { | ||
return new ES6(src, this.opts, this).tree; | ||
} else { | ||
throw new Error('invalid module format "' + this.opts.format + '"'); | ||
} | ||
}; | ||
/** | ||
* Return the module dependency graph as an object. | ||
@@ -151,0 +163,0 @@ * @api public |
@@ -44,8 +44,9 @@ 'use strict'; | ||
var dependencies = [], | ||
src = this.getFileSource(filename); | ||
src = this.getFileSource(filename), | ||
fileData = {filename: filename, src: src}; | ||
this.emit('parseFile', {filename: filename, src: src}); | ||
this.emit('parseFile', fileData); | ||
if (/define|require\s*\(/m.test(src)) { | ||
amdetective(src, {findNestedDependencies: this.opts.findNestedDependencies}).map(function (obj) { | ||
if (/define|require\s*\(/m.test(fileData.src)) { | ||
amdetective(fileData.src, {findNestedDependencies: this.opts.findNestedDependencies}).map(function (obj) { | ||
return typeof(obj) === 'string' ? [obj] : obj.deps; | ||
@@ -62,3 +63,3 @@ }).filter(function (deps) { | ||
var depFilename = path.resolve(path.dirname(filename), id); | ||
var depFilename = path.resolve(path.dirname(fileData.filename), id); | ||
@@ -65,0 +66,0 @@ if (depFilename) { |
@@ -33,4 +33,11 @@ 'use strict'; | ||
this.opts = opts; | ||
if (typeof this.opts.extensions === "undefined") { | ||
this.opts.extensions = ['.js']; | ||
} | ||
this.tree = {}; | ||
this.extRegEx = /\.(js|coffee|jsx)$/; | ||
this.extRegEx = new RegExp('\\.(coffee|jsx|' + this.opts.extensions.map(function(str) { | ||
return str.substring(1); | ||
}).join('|') + ')$', 'g'); | ||
this.coffeeExtRegEx = /\.coffee$/; | ||
@@ -57,3 +64,4 @@ this.jsxExtRegEx = /\.jsx$/; | ||
basedir: dir, | ||
paths: this.opts.paths | ||
paths: this.opts.paths, | ||
extensions: this.opts.extensions | ||
}); | ||
@@ -157,3 +165,3 @@ } catch (e) { | ||
} else if (filename.match(this.jsxExtRegEx)) { | ||
src = jsx.transform( src ); | ||
src = jsx.transform(src); | ||
} | ||
@@ -160,0 +168,0 @@ |
@@ -50,9 +50,10 @@ 'use strict'; | ||
var dependencies = [], | ||
src = this.getFileSource(filename); | ||
src = this.getFileSource(filename), | ||
fileData = {filename: filename, src: src}; | ||
this.emit('parseFile', {filename: filename, src: src}); | ||
this.emit('parseFile', fileData); | ||
if (/require\s*\(/m.test(src)) { | ||
detective(src).map(function (id) { | ||
var depFilename = this.resolve(path.dirname(filename), id); | ||
if (/require\s*\(/m.test(fileData.src)) { | ||
detective(fileData.src).map(function (id) { | ||
var depFilename = this.resolve(path.dirname(fileData.filename), id); | ||
if (depFilename) { | ||
@@ -59,0 +60,0 @@ return this.normalize(depFilename); |
{ | ||
"name": "madge", | ||
"version": "0.3.5", | ||
"version": "0.4.1", | ||
"npm-shrinkwrap-version": "5.2.0", | ||
"node-version": "v0.10.32", | ||
"dependencies": { | ||
"amdetective": { | ||
"version": "0.0.2", | ||
"from": "amdetective@0.0.2", | ||
"resolved": "https://registry.npmjs.org/amdetective/-/amdetective-0.0.2.tgz", | ||
@@ -12,3 +13,2 @@ "dependencies": { | ||
"version": "1.2.2", | ||
"from": "esprima@~1.2.2", | ||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.2.2.tgz" | ||
@@ -20,3 +20,2 @@ } | ||
"version": "1.3.3", | ||
"from": "coffee-script@1.3.3", | ||
"resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.3.3.tgz" | ||
@@ -26,3 +25,2 @@ }, | ||
"version": "0.6.0-1", | ||
"from": "colors@0.6.0-1", | ||
"resolved": "https://registry.npmjs.org/colors/-/colors-0.6.0-1.tgz" | ||
@@ -32,3 +30,2 @@ }, | ||
"version": "1.0.0", | ||
"from": "commander@1.0.0", | ||
"resolved": "https://registry.npmjs.org/commander/-/commander-1.0.0.tgz" | ||
@@ -38,3 +35,2 @@ }, | ||
"version": "0.0.1", | ||
"from": "commondir@0.0.1", | ||
"resolved": "https://registry.npmjs.org/commondir/-/commondir-0.0.1.tgz" | ||
@@ -44,8 +40,10 @@ }, | ||
"version": "0.1.1", | ||
"from": "detective@0.1.1", | ||
"resolved": "https://registry.npmjs.org/detective/-/detective-0.1.1.tgz" | ||
}, | ||
"detective-es6": { | ||
"version": "1.1.0", | ||
"resolved": "https://registry.npmjs.org/detective-es6/-/detective-es6-1.1.0.tgz" | ||
}, | ||
"graphviz": { | ||
"version": "0.0.7", | ||
"from": "graphviz@0.0.7", | ||
"resolved": "https://registry.npmjs.org/graphviz/-/graphviz-0.0.7.tgz", | ||
@@ -55,3 +53,2 @@ "dependencies": { | ||
"version": "0.4.0", | ||
"from": "temp@~0.4.0", | ||
"resolved": "https://registry.npmjs.org/temp/-/temp-0.4.0.tgz" | ||
@@ -63,3 +60,2 @@ } | ||
"version": "0.12.1", | ||
"from": "react-tools@0.12.1", | ||
"resolved": "https://registry.npmjs.org/react-tools/-/react-tools-0.12.1.tgz", | ||
@@ -69,52 +65,10 @@ "dependencies": { | ||
"version": "0.10.1", | ||
"from": "commoner@^0.10.0", | ||
"resolved": "https://registry.npmjs.org/commoner/-/commoner-0.10.1.tgz", | ||
"dependencies": { | ||
"q": { | ||
"version": "1.1.2", | ||
"from": "q@~1.1.2", | ||
"resolved": "https://registry.npmjs.org/q/-/q-1.1.2.tgz" | ||
}, | ||
"recast": { | ||
"version": "0.9.11", | ||
"from": "recast@~0.9.5", | ||
"resolved": "https://registry.npmjs.org/recast/-/recast-0.9.11.tgz", | ||
"dependencies": { | ||
"esprima-fb": { | ||
"version": "8001.1001.0-dev-harmony-fb", | ||
"from": "esprima-fb@~8001.1001.0-dev-harmony-fb", | ||
"resolved": "https://registry.npmjs.org/esprima-fb/-/esprima-fb-8001.1001.0-dev-harmony-fb.tgz" | ||
}, | ||
"source-map": { | ||
"version": "0.1.41", | ||
"from": "source-map@~0.1.40", | ||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.41.tgz", | ||
"dependencies": { | ||
"amdefine": { | ||
"version": "0.1.0", | ||
"from": "amdefine@>=0.0.4", | ||
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-0.1.0.tgz" | ||
} | ||
} | ||
}, | ||
"ast-types": { | ||
"version": "0.6.7", | ||
"from": "ast-types@~0.6.1", | ||
"resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.6.7.tgz" | ||
} | ||
} | ||
}, | ||
"commander": { | ||
"version": "2.5.1", | ||
"from": "commander@~2.5.0", | ||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.5.1.tgz" | ||
}, | ||
"graceful-fs": { | ||
"version": "3.0.5", | ||
"from": "graceful-fs@~3.0.4", | ||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-3.0.5.tgz" | ||
}, | ||
"glob": { | ||
"version": "4.2.2", | ||
"from": "glob@~4.2.1", | ||
"resolved": "https://registry.npmjs.org/glob/-/glob-4.2.2.tgz", | ||
@@ -124,3 +78,2 @@ "dependencies": { | ||
"version": "1.0.4", | ||
"from": "inflight@^1.0.4", | ||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.4.tgz", | ||
@@ -130,3 +83,2 @@ "dependencies": { | ||
"version": "1.0.1", | ||
"from": "wrappy@1", | ||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.1.tgz" | ||
@@ -138,3 +90,2 @@ } | ||
"version": "2.0.1", | ||
"from": "inherits@2", | ||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz" | ||
@@ -144,3 +95,2 @@ }, | ||
"version": "1.0.0", | ||
"from": "minimatch@^1.0.0", | ||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-1.0.0.tgz", | ||
@@ -150,3 +100,2 @@ "dependencies": { | ||
"version": "2.5.0", | ||
"from": "lru-cache@2", | ||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.0.tgz" | ||
@@ -156,3 +105,2 @@ }, | ||
"version": "1.0.0", | ||
"from": "sigmund@~1.0.0", | ||
"resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.0.tgz" | ||
@@ -164,3 +112,2 @@ } | ||
"version": "1.3.1", | ||
"from": "once@^1.3.0", | ||
"resolved": "https://registry.npmjs.org/once/-/once-1.3.1.tgz", | ||
@@ -170,3 +117,2 @@ "dependencies": { | ||
"version": "1.0.1", | ||
"from": "wrappy@1", | ||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.1.tgz" | ||
@@ -178,5 +124,16 @@ } | ||
}, | ||
"graceful-fs": { | ||
"version": "3.0.5", | ||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-3.0.5.tgz" | ||
}, | ||
"iconv-lite": { | ||
"version": "0.4.5", | ||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.5.tgz" | ||
}, | ||
"install": { | ||
"version": "0.1.8", | ||
"resolved": "https://registry.npmjs.org/install/-/install-0.1.8.tgz" | ||
}, | ||
"mkdirp": { | ||
"version": "0.5.0", | ||
"from": "mkdirp@~0.5.0", | ||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.0.tgz", | ||
@@ -186,3 +143,2 @@ "dependencies": { | ||
"version": "0.0.8", | ||
"from": "minimist@0.0.8", | ||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz" | ||
@@ -194,14 +150,31 @@ } | ||
"version": "0.1.6", | ||
"from": "private@~0.1.6", | ||
"resolved": "https://registry.npmjs.org/private/-/private-0.1.6.tgz" | ||
}, | ||
"install": { | ||
"version": "0.1.8", | ||
"from": "install@~0.1.7", | ||
"resolved": "https://registry.npmjs.org/install/-/install-0.1.8.tgz" | ||
"q": { | ||
"version": "1.1.2", | ||
"resolved": "https://registry.npmjs.org/q/-/q-1.1.2.tgz" | ||
}, | ||
"iconv-lite": { | ||
"version": "0.4.5", | ||
"from": "iconv-lite@~0.4.5", | ||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.5.tgz" | ||
"recast": { | ||
"version": "0.9.11", | ||
"resolved": "https://registry.npmjs.org/recast/-/recast-0.9.11.tgz", | ||
"dependencies": { | ||
"ast-types": { | ||
"version": "0.6.7", | ||
"resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.6.7.tgz" | ||
}, | ||
"esprima-fb": { | ||
"version": "8001.1001.0-dev-harmony-fb", | ||
"resolved": "https://registry.npmjs.org/esprima-fb/-/esprima-fb-8001.1001.0-dev-harmony-fb.tgz" | ||
}, | ||
"source-map": { | ||
"version": "0.1.41", | ||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.41.tgz", | ||
"dependencies": { | ||
"amdefine": { | ||
"version": "0.1.0", | ||
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-0.1.0.tgz" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
@@ -212,3 +185,2 @@ } | ||
"version": "8.2.0", | ||
"from": "jstransform@^8.2.0", | ||
"resolved": "https://registry.npmjs.org/jstransform/-/jstransform-8.2.0.tgz", | ||
@@ -218,3 +190,2 @@ "dependencies": { | ||
"version": "0.1.1", | ||
"from": "base62@0.1.1", | ||
"resolved": "https://registry.npmjs.org/base62/-/base62-0.1.1.tgz" | ||
@@ -224,3 +195,2 @@ }, | ||
"version": "8001.1001.0-dev-harmony-fb", | ||
"from": "esprima-fb@8001.1001.0-dev-harmony-fb", | ||
"resolved": "https://registry.npmjs.org/esprima-fb/-/esprima-fb-8001.1001.0-dev-harmony-fb.tgz" | ||
@@ -230,3 +200,2 @@ }, | ||
"version": "0.1.31", | ||
"from": "source-map@0.1.31", | ||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.31.tgz", | ||
@@ -236,3 +205,2 @@ "dependencies": { | ||
"version": "0.1.0", | ||
"from": "amdefine@>=0.0.4", | ||
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-0.1.0.tgz" | ||
@@ -248,3 +216,2 @@ } | ||
"version": "0.2.3", | ||
"from": "resolve@0.2.3", | ||
"resolved": "https://registry.npmjs.org/resolve/-/resolve-0.2.3.tgz" | ||
@@ -254,3 +221,2 @@ }, | ||
"version": "1.2.6", | ||
"from": "https://registry.npmjs.org/uglify-js/-/uglify-js-1.2.6.tgz", | ||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-1.2.6.tgz" | ||
@@ -260,6 +226,5 @@ }, | ||
"version": "0.0.5", | ||
"from": "walkdir@0.0.5", | ||
"resolved": "https://registry.npmjs.org/walkdir/-/walkdir-0.0.5.tgz" | ||
} | ||
} | ||
} | ||
} |
{ | ||
"name": "madge", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"author": "Patrik Henningsson <patrik.henningsson@gmail.com>", | ||
@@ -29,3 +29,4 @@ "repository": "git://github.com/pahen/node-madge", | ||
"scripts": { | ||
"test": "grunt" | ||
"test": "grunt", | ||
"shrinkwrap": "npm-shrinkwrap" | ||
}, | ||
@@ -39,2 +40,3 @@ "dependencies": { | ||
"detective": "0.1.1", | ||
"detective-es6": "1.1.0", | ||
"graphviz": "0.0.7", | ||
@@ -52,2 +54,3 @@ "react-tools": "0.12.1", | ||
"grunt-release": "0.7.0", | ||
"npm-shrinkwrap": "5.2.0", | ||
"should": "*" | ||
@@ -54,0 +57,0 @@ }, |
@@ -5,3 +5,3 @@ # MaDGe - Module Dependency Graph | ||
Create graphs from your [CommonJS](http://nodejs.org/api/modules.html) or [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) module dependencies. Could also be useful for finding circular dependencies in your code. Tested on [Node.js](http://nodejs.org/) and [RequireJS](http://requirejs.org/) projects. Dependencies are calculated using static code analysis. CommonJS dependencies are found using James Halliday's [detective](https://github.com/substack/node-detective) and for AMD I'm using [amdetective](https://www.npmjs.org/package/amdetective). Modules written in [CoffeeScript](http://coffeescript.org/) with extension .coffee are supported and will automatically be compiled on-the-fly. | ||
Create graphs from your [CommonJS](http://nodejs.org/api/modules.html), [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) or [ES6](https://people.mozilla.org/~jorendorff/es6-draft.html) module dependencies. Could also be useful for finding circular dependencies in your code. Tested on [Node.js](http://nodejs.org/) and [RequireJS](http://requirejs.org/) projects. Dependencies are calculated using static code analysis. CommonJS dependencies are found using James Halliday's [detective](https://github.com/substack/node-detective), for AMD I'm using [amdetective](https://www.npmjs.org/package/amdetective) and for ES6 [detective-es6](https://www.npmjs.com/package/detective-es6) is used. Modules written in [CoffeeScript](http://coffeescript.org/) with extension .coffee are supported and will automatically be compiled on-the-fly. | ||
@@ -63,3 +63,3 @@ ## Examples | ||
- {String} **format**. The module format to expect, 'cjs' or 'amd'. Commonjs (cjs) is the default format. | ||
- {String} **format**. The module format to expect, 'cjs', 'amd' or 'es6'. Commonjs (cjs) is the default format. | ||
- {String} **exclude**. String from which a regex will be constructed for excluding files from the scan. | ||
@@ -73,2 +73,3 @@ - {Boolean} **breakOnError**. True if the parser should stop on parse errors and when modules are missing, false otherwise. Defaults to false. | ||
- {Function} **onAddModule** . Function to be called when adding a module to the module tree (argument will be an object with "id" and "dependencies" property set). | ||
- {Array} **extensions**. List of file extensions which are considered. Defaults to `['.js']`. | ||
@@ -128,3 +129,3 @@ ## dependency object (returned from madge) | ||
-V, --version output the version number | ||
-f, --format <name> format to parse (amd/cjs) | ||
-f, --format <name> format to parse (amd/cjs/es6) | ||
-s, --summary show summary of all dependencies | ||
@@ -157,2 +158,6 @@ -c, --circular show circular dependencies | ||
### List all module dependencies (ES6) | ||
$ madge --format es6 /path/src | ||
### Finding circular dependencies | ||
@@ -237,2 +242,6 @@ | ||
## v0.5.0 (April 2, 2015) | ||
Added support for ES6 modules (Thanks to Marc Laval). | ||
Added support for setting custom file extension name (Thanks to Marc Laval). | ||
## v0.4.1 (December 19, 2014) | ||
@@ -239,0 +248,0 @@ Fixed issues with absolute paths for modules IDs in Windows (all tests should now pass on Windows too). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131505
24
1878
342
12
7
6
+ Addeddetective-es6@1.1.0
+ Addedacorn@1.2.2(transitive)
+ Addeddetective-es6@1.1.0(transitive)
+ Addednode-source-walk@1.4.2(transitive)