Comparing version 0.4.1 to 0.4.2
@@ -95,3 +95,2 @@ /* | ||
name: '', | ||
dependents: 0, | ||
dependencies: {} | ||
@@ -111,3 +110,2 @@ }; | ||
dep.name = componentConfigFile.name; | ||
dep.dependents += 1; | ||
@@ -140,12 +138,31 @@ if (dep.main.length === 0) { | ||
* | ||
* @param {object} dependency dependency a | ||
* @param {object} lastDependency dependency b | ||
* @param {object} a dependency a | ||
* @param {object} b dependency b | ||
* @return {number} the priority of dependency a in comparison to dependency b | ||
*/ | ||
var dependencyComparator = function (dependency, lastDependency) { | ||
return Object. | ||
keys(dependency.dependencies). | ||
filter(function (dependency) { | ||
return dependency === lastDependency.name; | ||
}).length ? 1 : 0; | ||
var dependencyComparator = function (a, b) { | ||
var aNeedsB = false; | ||
var bNeedsA = false; | ||
aNeedsB = Object. | ||
keys(a.dependencies). | ||
some(function (dependency) { | ||
return dependency === b.name; | ||
}); | ||
if (aNeedsB) { | ||
return 1; | ||
} | ||
bNeedsA = Object. | ||
keys(b.dependencies). | ||
some(function (dependency) { | ||
return dependency === a.name; | ||
}); | ||
if (bNeedsA) { | ||
return -1; | ||
} | ||
return 0; | ||
}; | ||
@@ -155,2 +172,49 @@ | ||
/** | ||
* Take two arrays, sort based on their dependency relationship, then merge them | ||
* together. | ||
* | ||
* @param {array} left | ||
* @param {array} right | ||
* @return {array} the sorted, merged array | ||
*/ | ||
var merge = function (left, right) { | ||
var result = []; | ||
var leftIndex = 0; | ||
var rightIndex = 0; | ||
while (leftIndex < left.length && rightIndex < right.length) { | ||
if (dependencyComparator(left[leftIndex], right[rightIndex]) < 1) { | ||
result.push(left[leftIndex++]); | ||
} else { | ||
result.push(right[rightIndex++]); | ||
} | ||
} | ||
return result. | ||
concat(left.slice(leftIndex)). | ||
concat(right.slice(rightIndex)); | ||
}; | ||
/** | ||
* Take an array and slice it in halves, sorting each half along the way. | ||
* | ||
* @param {array} items | ||
* @return {array} the sorted array | ||
*/ | ||
var mergeSort = function (items) { | ||
if (items.length < 2) { | ||
return items; | ||
} | ||
var middle = Math.floor(items.length / 2); | ||
return merge( | ||
mergeSort(items.slice(0, middle)), | ||
mergeSort(items.slice(middle)) | ||
); | ||
}; | ||
/** | ||
* Some dependencies which we know should always come first. | ||
@@ -176,3 +240,3 @@ */ | ||
var dependencies = | ||
var dependencies = mergeSort( | ||
_.toArray(config.get('global-dependencies').get()). | ||
@@ -182,5 +246,2 @@ filter(function (dependency) { | ||
}). | ||
reduce(function (grouped, dependency) { | ||
return grouped.push(dependency) && grouped.sort(dependencyComparator); | ||
}, []). | ||
filter(function (dependency) { | ||
@@ -192,4 +253,4 @@ if (_.contains(eliteDependencies, dependency.name)) { | ||
} | ||
}). | ||
map(prop('main')); | ||
}) | ||
).map(prop('main')); | ||
@@ -196,0 +257,0 @@ eliteDependenciesCaught. |
{ | ||
"name": "wiredep", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"description": "Wire dependencies to your source code.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/stephenplusplus/wiredep", |
@@ -10,3 +10,3 @@ # wiredep | ||
```js | ||
var wiredep = require('wiredep')({ | ||
require('wiredep')({ | ||
directory: 'the directory of your Bower packages.', | ||
@@ -13,0 +13,0 @@ bowerJson: 'your bower.json file contents.', |
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
16343
435