Comparing version 0.1.1 to 0.1.2
@@ -10,2 +10,3 @@ 'use strict'; | ||
parse = require('./parse'), | ||
resolve = require('resolve'), | ||
colors = require('colors'), | ||
@@ -29,2 +30,22 @@ Base = require('./base'); | ||
/** | ||
* Resolve the given `id` to a filename. | ||
* @param {String} dir | ||
* @param {String} id | ||
* @return {String} | ||
*/ | ||
AMD.prototype.resolve = function (dir, id) { | ||
try { | ||
return resolve.sync(id, { | ||
basedir: dir | ||
}); | ||
} catch (e) { | ||
if (this.opts.breakOnError) { | ||
console.log(String('\nError while resolving module from: ' + id).red); | ||
throw e; | ||
} | ||
return id; | ||
} | ||
}; | ||
/** | ||
* Normalize a module file path and return a proper identificator. | ||
@@ -72,4 +93,15 @@ * @param {String} filename | ||
parse.findDependencies(filename, src).filter(function (id) { | ||
return id !== 'require'; | ||
}).filter(function (id) { | ||
return id !== 'require' && id !== 'exports' && id !== 'module'; | ||
}).map(function (id) { | ||
// Only resolve relative module identifiers (if the first term is "." or "..") | ||
if (id.charAt(0) !== '.') { | ||
return id; | ||
} | ||
var depFilename = this.resolve(path.dirname(filename), id); | ||
if (depFilename) { | ||
return this.normalize(depFilename); | ||
} | ||
}, this).filter(function (id) { | ||
if (!this.isExcluded(id) && dependencies.indexOf(id) < 0) { | ||
@@ -76,0 +108,0 @@ dependencies.push(id); |
@@ -45,3 +45,3 @@ 'use strict'; | ||
/** | ||
* 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 | ||
@@ -118,3 +118,3 @@ * @return {Array} | ||
} | ||
return src; | ||
@@ -121,0 +121,0 @@ }; |
{ | ||
"name": "madge", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Patrik Henningsson <patrik.henningsson@gmail.com>", | ||
@@ -5,0 +5,0 @@ "repository": "git://github.com/pahen/node-madge", |
@@ -135,2 +135,5 @@ # MaDGe - Module Dependency Graph | ||
## v0.1.2 (November 15, 2012) | ||
Relative AMD module identifiers (if the first term is "." or "..") are now resolved. | ||
## v0.1.1 (September 3, 2012) | ||
@@ -137,0 +140,0 @@ Tweaked circular dependency path output. |
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
56390
20
1414
182