Socket
Socket
Sign inDemoInstall

madge

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

madge - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

6

lib/analysis/circular.js

@@ -5,4 +5,3 @@ 'use strict';

* A circular dependency is occurring when we see a software package
* more than once, unless that software package has all its dependencies resolved
*
* more than once, unless that software package has all its dependencies resolved.
* @param {String} id

@@ -34,4 +33,3 @@ * @param {Object} modules

/**
* Finds all circular dependencies for the given modules
*
* Finds all circular dependencies for the given modules.
* @param {Object} modules

@@ -38,0 +36,0 @@ * @return {Object}

'use strict';
/**
* Finds all modules that depends on the given modules
*
* Finds all modules that depends on the given modules.
* @param {Object} modules

@@ -7,0 +6,0 @@ * @param {String} id

'use strict';
/**
* Module dependencies
* Module dependencies.
*/

@@ -9,4 +9,3 @@ var colors = require('colors');

/**
* Return colored string (or not)
*
* Return colored string (or not).
* @param {String} str

@@ -13,0 +12,0 @@ * @param {String} name

'use strict';
/**
* Module dependencies
* Module dependencies.
*/

@@ -11,4 +11,3 @@ var exec = require('child_process').exec,

/**
* Set color on a node
*
* Set color on a node.
* @param {Object} node

@@ -23,4 +22,3 @@ * @param {String} color

/**
* Set color for nodes without dependencies
*
* Set color for nodes without dependencies.
* @param {Object} node

@@ -34,8 +32,7 @@ * @param {String} [color]

/**
* Check if Graphviz is installed on the system
*
* Check if Graphviz is installed on the system.
* @throws Error
*/
function checkGraphvizInstalled() {
var child = exec('gvpr -V', function (error, stdout, stderr) {
exec('gvpr -V', function (error, stdout, stderr) {
if (error !== null) {

@@ -48,4 +45,3 @@ throw new Error('Graphviz could not be found. Ensure that "gvpr" is in your $PATH.\n' + error);

/**
* Creates a PNG image from the module dependency graph
*
* Creates a PNG image from the module dependency graph.
* @param {Object} modules

@@ -56,3 +52,2 @@ * @param {Object} opts

module.exports.image = function (modules, opts, callback) {
checkGraphvizInstalled();

@@ -104,4 +99,3 @@

/**
* Return the module dependency graph as DOT output
*
* Return the module dependency graph as DOT output.
* @param {Object} modules

@@ -111,7 +105,6 @@ * @return {String}

module.exports.dot = function (modules) {
var nodes = {};
checkGraphvizInstalled();
var nodes = {};
Object.keys(modules).forEach(function (id) {

@@ -118,0 +111,0 @@ var node = nodes[id] = nodes[id] || g.addNode(id);

@@ -8,4 +8,3 @@ 'use strict';

/**
* Expose factory function
*
* Expose factory function.
* @api public

@@ -21,4 +20,3 @@ * @param {String|Array|Object} src

/**
* Class constructor
*
* Class constructor.
* @constructor

@@ -30,3 +28,2 @@ * @api public

function Madge(src, opts) {
this.opts = opts || {};

@@ -53,4 +50,3 @@ this.opts.format = String(this.opts.format || 'cjs').toLowerCase();

/**
* Return the module dependency graph as an object
*
* Return the module dependency graph as an object.
* @api public

@@ -64,4 +60,3 @@ * @return {Object}

/**
* Return the modules that has circular dependencies
*
* Return the modules that has circular dependencies.
* @api public

@@ -75,4 +70,3 @@ * @return {Object}

/**
* Return a list of modules that depends on the given module
*
* Return a list of modules that depends on the given module.
* @api public

@@ -87,4 +81,3 @@ * @param {String} id

/**
* Return the module dependency graph as DOT output
*
* Return the module dependency graph as DOT output.
* @api public

@@ -98,4 +91,3 @@ * @return {String}

/**
* Return the module dependency graph as a PNG image
*
* Return the module dependency graph as a PNG image.
* @api public

@@ -102,0 +94,0 @@ * @param {Object} opts

'use strict';
/**
* Module dependencies
* Module dependencies.
*/

@@ -13,6 +13,4 @@ var fs = require('fs'),

/**
* This class will parse the AMD module format
*
* This class will parse the AMD module format.
* @see https://github.com/amdjs/amdjs-api/wiki/AMD

@@ -31,4 +29,3 @@ * @constructor

/**
* Normalize a module file path and return a proper identificator
*
* Normalize a module file path and return a proper identificator.
* @param {String} filename

@@ -38,3 +35,2 @@ * @return {String}

AMD.prototype.normalize = function (filename) {
var id = path.relative(this.baseDir, filename).replace(this.extRegEx, '');

@@ -45,3 +41,3 @@

if (fs.existsSync(filename)) {
var content = fs.readFileSync(filename, 'utf8'),
var content = this.getFileSource(filename),
def = parse(id, filename, content);

@@ -67,4 +63,3 @@ if (def) {

/**
* Parse the given file and return all found dependencies
*
* Parse the given file and return all found dependencies.
* @param {String} filename

@@ -74,7 +69,5 @@ * @return {Object}

AMD.prototype.parseFile = function (filename) {
try {
var dependencies = [],
src = fs.readFileSync(filename, 'utf8');
src = this.getFileSource(filename);

@@ -92,3 +85,2 @@ if (src.indexOf('define(') >= 0 || src.indexOf('require(') >= 0) {

}
} catch (e) {

@@ -95,0 +87,0 @@ if (this.opts.breakOnError) {

@@ -9,7 +9,7 @@ 'use strict';

commondir = require('commondir'),
finder = require('findit');
finder = require('findit'),
coffee = require('coffee-script');
/**
* Traversing `src` and fetches all dependencies
*
* Traversing `src` and fetches all dependencies.
* @constructor

@@ -22,3 +22,4 @@ * @param {Array} src

this.tree = {};
this.extRegEx = /\.js$/;
this.extRegEx = /\.(js|coffee)$/;
this.coffeeExtRegEx = /\.coffee$/;
src = this.resolveTargets(src);

@@ -32,4 +33,3 @@ this.excludeRegex = opts.exclude ? new RegExp(opts.exclude) : false;

/**
* Get the most common dir from the `src`
*
* Get the most common dir from the `src`.
* @param {Array} src

@@ -40,2 +40,3 @@ * @return {String}

var dir = commondir(src);
if (!fs.statSync(dir).isDirectory()) {

@@ -48,4 +49,3 @@ dir = path.dirname(dir);

/**
* Resolves all paths in `sources`and ensure we have a absolute path
*
* Resolves all paths in `sources`and ensure we have a absolute path.
* @param {Array} sources

@@ -61,4 +61,3 @@ * @return {Array}

/**
* Normalize a module file path and return a proper identificator
*
* Normalize a module file path and return a proper identificator.
* @param {String} filename

@@ -72,4 +71,3 @@ * @return {String}

/**
* Check if module should be excluded
*
* Check if module should be excluded.
* @param {String}

@@ -83,4 +81,3 @@ * @return {Boolean}

/**
* Parse the given `filename` and add it to the module tree
*
* Parse the given `filename` and add it to the module tree.
* @param {String} filename

@@ -90,2 +87,3 @@ */

var id = this.normalize(filename);
if (!this.isExcluded(id) && fs.existsSync(filename)) {

@@ -97,4 +95,3 @@ this.tree[id] = this.parseFile(filename);

/**
* Traverse `sources` and parse files found
*
* Traverse `sources` and parse files found.
* @param {Array} sources

@@ -117,6 +114,25 @@ */

/**
* Sort dependencies by name
* Read the given filename and compile it if necessary and return the content.
* @param {String} filename
* @return {String}
*/
Base.prototype.getFileSource = function (filename) {
var src = fs.readFileSync(filename, 'utf8');
if (filename.match(this.coffeeExtRegEx)) {
src = coffee.compile(src, {
header: false,
bare: true
});
}
return src;
};
/**
* Sort dependencies by name.
*/
Base.prototype.sortDependencies = function () {
var self = this;
this.tree = Object.keys(this.tree).sort().reduce(function (acc, id) {

@@ -123,0 +139,0 @@ (acc[id] = self.tree[id]).sort();

'use strict';
/**
* Module dependencies
* Module dependencies.
*/

@@ -15,4 +15,3 @@ var fs = require('fs'),

/**
* This class will parse the CommonJS module format
*
* This class will parse the CommonJS module format.
* @see http://nodejs.org/api/modules.html

@@ -26,3 +25,3 @@ * @constructor

/**
* Inherit from `Base`
* Inherit from `Base`.
*/

@@ -32,4 +31,3 @@ util.inherits(CJS, Base);

/**
* Resolve the given `id` to a filename
*
* Resolve the given `id` to a filename.
* @param {String} dir

@@ -54,4 +52,3 @@ * @param {String} id

/**
* Normalize a module file path and return a proper identificator
*
* Normalize a module file path and return a proper identificator.
* @param {String} filename

@@ -69,4 +66,3 @@ * @return {String}

/**
* Parse the given file and return all found dependencies
*
* Parse the given file and return all found dependencies.
* @param {String} filename

@@ -76,8 +72,6 @@ * @return {Object}

CJS.prototype.parseFile = function (filename) {
try {
if (fs.existsSync(filename)) {
var dependencies = [],
src = fs.readFileSync(filename, 'utf8');
src = this.getFileSource(filename);

@@ -98,5 +92,3 @@ if (src.indexOf('require(') >= 0) {

}
}
} catch (e) {

@@ -103,0 +95,0 @@ if (this.opts.breakOnError) {

@@ -17,3 +17,2 @@ 'use strict';

var uglify = require('uglify-js'),

@@ -20,0 +19,0 @@ parser = uglify.parser,

'use strict';
/**
* Module dependencies
* Module dependencies.
*/

@@ -9,4 +9,3 @@ var c = require('./color');

/**
* Return the given object as JSON
*
* Return the given object as JSON.
* @param {Object} obj

@@ -20,4 +19,3 @@ * @return {String}

/**
* Print module dependency graph as indented text (or JSON)
*
* Print module dependency graph as indented text (or JSON).
* @param {Object} modules

@@ -27,3 +25,2 @@ * @param {Object} opts

module.exports.list = function (modules, opts) {
opts = opts || {};

@@ -44,4 +41,3 @@

/**
* Print a summary of module dependencies
*
* Print a summary of module dependencies.
* @param {Object} modules

@@ -51,3 +47,2 @@ * @param {Object} opts

module.exports.summary = function (modules, opts) {
var o = {};

@@ -73,4 +68,3 @@

/**
* Print the result from Madge.circular()
*
* Print the result from Madge.circular().
* @param {Object} circular

@@ -80,3 +74,2 @@ * @param {Object} opts

module.exports.circular = function (modules, opts) {
if (opts.output === 'json') {

@@ -96,4 +89,3 @@ return process.stdout.write(toJSON(modules));

/**
* Print the result from Madge.depends()
*
* Print the result from Madge.depends().
* @param {Object} modules

@@ -103,3 +95,2 @@ * @param {Object} opts

module.exports.depends = function (modules, opts) {
if (opts.output === 'json') {

@@ -106,0 +97,0 @@ return process.stdout.write(toJSON(modules));

{
"name": "madge",
"version": "0.0.4",
"version": "0.0.5",
"author": "Patrik Henningsson <patrik.henningsson@gmail.com>",

@@ -37,6 +37,7 @@ "repository": "git://github.com/pahen/node-madge",

"uglify-js": "1.2.6",
"colors": "0.6.0-1"
"colors": "0.6.0-1",
"coffee-script": "1.3.3"
},
"devDependencies": {
"mocha": "1.2.x",
"mocha": "1.3.x",
"should": "*"

@@ -43,0 +44,0 @@ },

@@ -129,2 +129,19 @@ # MaDGe - Module Dependency Graph

# Release Notes
## v0.0.5 (August 8, 2012)
Added support for CoffeeScript. Files with extension .coffee will automatically be compiled on-the-fly.
## v0.0.4 (August 17, 2012)
Fixed dependency issues with Node.js v0.8.
## v0.0.3 (July 01, 2012)
Added support for Node.js v0.8 and dropped support for lower versions.
## v0.0.2 (May 21, 2012)
Added ability to read config file and customize colors.
## v0.0.1 (May 20, 2012)
Initial release.
# License

@@ -131,0 +148,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc