Skip to content

Commit

Permalink
Retrieve only host devDepencencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarchena committed May 24, 2015
1 parent 0369ccd commit 0b2ab08
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
66 changes: 37 additions & 29 deletions lib/search/search-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SearchEngine.prototype = (function () {
* @param {Dependency} current Dependency whose info will be completed
* @param {Dependency} dependent? Current dependency dependent (aka. parent)
*/
var scan = function scan(current, dependent) {
var deepScan = function deepScan(current, dependent) {

var currentDepBasePath,
isNotFirstScan = (dependent instanceof Dependency),
Expand All @@ -40,49 +40,57 @@ SearchEngine.prototype = (function () {
this.basePath;

if (isFilterDefined) {
doesntPassTheFilter = checkIf.
configJson(current.configJson, this.dependenciesManager).
doesntPassTheFilter(this.filterBy);
doesntPassTheFilter =
checkIf.
configJson(current.configJson, this.dependenciesManager).
doesntPassTheFilter(this.filterBy);
if (doesntPassTheFilter) {
return null;
}
}

if (isNotFirstScan && doesntPassTheFilter) {
return null;
}
dependent.addDependency(current);

if (current instanceof Dependency) {
if (isNotFirstScan) {
dependent.addDependency(current);
}
for (var i = 0, length = this.dependenciesType.length; i<length; i++) {
var t = this.dependenciesType[i];
if (typeof current.json[t] !== 'undefined') {
for (var k in current.json[t]) {
scan.call(this,
dependencyFactory.createDependency(
path.join(currentDepBasePath, this.dependenciesDirname, k), // Dependency path
this.dependenciesManager // Dependency type
),
current);
}
}
if (typeof current.json.dependencies !== 'undefined') {
for (var k in current.json.dependencies) {
deepScan.call(this,
dependencyFactory.createDependency(
path.join(currentDepBasePath, this.dependenciesDirname, k), // Dependency path
this.dependenciesManager // Dependency type
),
current);
}
}
};

/**
* Revealed function to search for dependencies
*
* @param {String} searchRootPath Path to module whose dependencies will be fetched
* @param {String} hostPath Path to module whose dependencies will be fetched
* @param {Function} callback Callback function if search is async
* @return {Array} Multidimensional array of Dependency objects
*/
var fetchDependencies = function fetchDependencies(searchRootPath, callback) {
var mainDependent = dependencyFactory.createDependency(searchRootPath, this.dependenciesManager);
scan.call(this, mainDependent);
var fetchDependencies = function fetchDependencies(hostPath, callback) {
var host = dependencyFactory.createDependency(hostPath, this.dependenciesManager);

for (var i = 0, length = this.dependenciesType.length; i<length; i++) {
var t = this.dependenciesType[i];
if (typeof host.json[t] !== 'undefined') {
for (var k in host.json[t]) {
deepScan.call(this,
dependencyFactory.createDependency(
path.join(this.basePath, this.dependenciesDirname, k), // Dependency path
this.dependenciesManager // Dependency type
),
host);
}
}
}

if(typeof callback === 'function') {
callback.call(this, mainDependent.dependencies);
callback.call(this, host.dependencies);
} else {
return mainDependent.dependencies;
return host.dependencies;
}
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dependency-info",
"version": "0.2.5",
"version": "0.2.6",
"description": "Get your project dependency tree from NPM as well as from bower",
"main": "lib/index.js",
"scripts": {
Expand Down Expand Up @@ -28,7 +28,7 @@
"gulp-jshint": "^1.10.0",
"gulp-mocha": "^2.0.1",
"istanbul": "^0.3.14",
"jshint-stylish": "^1.0.2",
"jshint-stylish": "^2.0.0",
"should": "^6.0.1"
}
}

0 comments on commit 0b2ab08

Please sign in to comment.