[Pkg-javascript-commits] [node-deps-sort] 33/79: sameDeps
Bastien Roucariès
rouca at moszumanska.debian.org
Wed Sep 6 09:41:54 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-deps-sort.
commit e5a98626c3c64bf278c2c02a79a749496ceeb828
Author: James Halliday <mail at substack.net>
Date: Mon Jul 21 17:23:36 2014 -0700
sameDeps
---
index.js | 39 ++++++++++++++++++++++++++++++++++++---
test/dedupe.js | 2 +-
test/dedupe_index.js | 3 ++-
3 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/index.js b/index.js
index ce63202..758e865 100644
--- a/index.js
+++ b/index.js
@@ -26,15 +26,20 @@ function sorter (rows, tr, opts) {
}
var hashes = {}, deduped = {};
+ var sameDeps = depCmp();
+
if (opts.dedupe) {
rows.forEach(function (row) {
var h = shasum(row.source);
+ sameDeps.add(row, h);
+
if (hashes[h]) {
- row.dedupe = hashes[h];
- deduped[row.id] = hashes[h];
+ row.dedupe = hashes[h].id;
+ row.sameDeps = sameDeps.cmp(row.deps, hashes[h].deps);
+ deduped[row.id] = hashes[h].id;
}
else {
- hashes[h] = row.id;
+ hashes[h] = row;
}
});
}
@@ -80,3 +85,31 @@ function cmp (a, b) {
function has (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
}
+
+function depCmp (hashes) {
+ var deps = {}, hashes = {};
+ return { add: add, cmp: cmp }
+
+ function add (row, hash) {
+ deps[row.id] = row.deps;
+ hashes[row.id] = hash;
+ }
+ function cmp (a, b, limit) {
+ var keys = Object.keys(a);
+ if (keys.length !== Object.keys(b).length) return false;
+
+ for (var i = 0; i < keys.length; i++) {
+ var k = keys[i], ka = a[k], kb = b[k];
+ var ha = hashes[ka];
+ var hb = hashes[kb];
+ var da = deps[ka];
+ var db = deps[kb];
+
+ if (ka === kb) continue;
+ if (ha !== hb || (!limit && !sameDeps(da, db, 1))) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/test/dedupe.js b/test/dedupe.js
index e1806fc..221f499 100644
--- a/test/dedupe.js
+++ b/test/dedupe.js
@@ -10,7 +10,7 @@ test('dedupe', function (t) {
function end () {
t.deepEqual(rows, [
{ id: '/bar.js', deps: {}, source: 'TWO' },
- { id: '/foo.js', deps: {}, source: 'TWO', dedupe: '/bar.js' },
+ { id: '/foo.js', deps: {}, source: 'TWO', dedupe: '/bar.js', sameDeps: true },
{
id: '/main.js',
deps: { './foo': '/foo.js', './bar': '/bar.js' },
diff --git a/test/dedupe_index.js b/test/dedupe_index.js
index fb6348a..dc8bea3 100644
--- a/test/dedupe_index.js
+++ b/test/dedupe_index.js
@@ -23,7 +23,8 @@ test('dedupe index', function (t) {
dedupe: '/bar.js',
index: 2,
indexDeps: {},
- dedupeIndex: 1
+ dedupeIndex: 1,
+ sameDeps: true
},
{
id: '/main.js',
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-deps-sort.git
More information about the Pkg-javascript-commits
mailing list