Comparing version 0.1.1 to 0.2.0
0.2.0 / 2015-10-22 | ||
================== | ||
* internal: flipping edge direction (deps now flow to entries) | ||
* renamed: `tree.getSources()` to `tree.getEntries()` | ||
* renamed: `tree.isSource()` to `tree.isEntry()` | ||
* renamed: `file.isSource()` to `file.isEntry()` | ||
* added: `tree.topologicalOrder()` | ||
0.1.1 / 2015-10-19 | ||
@@ -3,0 +12,0 @@ ================== |
@@ -16,4 +16,4 @@ | ||
isSource() { | ||
return this.tree.isSource(this.path); | ||
isEntry() { | ||
return this.tree.isEntry(this.path); | ||
} | ||
@@ -20,0 +20,0 @@ |
@@ -7,2 +7,3 @@ | ||
let File = require('./file'); | ||
let toposort = require('graph-toposort'); | ||
@@ -36,9 +37,9 @@ | ||
isSource(location) { | ||
return this.graph.inDegree(location) === 0; | ||
isEntry(location) { | ||
return this.graph.outDegree(location) === 0; | ||
} | ||
getSources() { | ||
debug('listing sources'); | ||
return Array.from(this.graph.sources()).map(function (vertex) { | ||
getEntries() { | ||
debug('listing entry files'); | ||
return Array.from(this.graph.sinks()).map(function (vertex) { | ||
debug('found source %s', vertex[0]); | ||
@@ -50,9 +51,9 @@ return vertex[0]; | ||
hasDependency(parent, child) { | ||
return this.graph.hasEdge(parent, child); | ||
return this.graph.hasEdge(child, parent); | ||
} | ||
addDependency(parent, child) { | ||
debug('adding dependency %s > %s', parent, child); | ||
debug('adding dependency %s to %s', child, parent); | ||
if (!this.hasFile(child)) this.addFile(child); | ||
this.graph.addEdge(parent, child); | ||
this.graph.addEdge(child, parent); | ||
return this.getFile(child); | ||
@@ -62,7 +63,7 @@ } | ||
removeDependency(parent, child) { | ||
debug('removing dependency %s > %s', parent, child); | ||
this.graph.removeEdge(parent, child); | ||
debug('removing dependency %s from %s', child, parent); | ||
this.graph.removeEdge(child, parent); | ||
// if nothing else depends on this node, let's remove it | ||
if (this.graph.inDegree(child) === 0) { | ||
if (this.graph.outDegree(child) === 0) { | ||
debug('node %s no longer depended on, removing from tree', child); | ||
@@ -81,4 +82,4 @@ this.removeFile(child); | ||
let deps = recursive | ||
? this.graph.verticesWithPathFrom(node) | ||
: this.graph.verticesFrom(node); | ||
? this.graph.verticesWithPathTo(node) | ||
: this.graph.verticesTo(node); | ||
@@ -92,4 +93,4 @@ return Array.from(deps).map(function (vertex) { | ||
let deps = recursive | ||
? this.graph.verticesWithPathTo(node) | ||
: this.graph.verticesTo(node); | ||
? this.graph.verticesWithPathFrom(node) | ||
: this.graph.verticesFrom(node); | ||
@@ -101,2 +102,6 @@ return Array.from(deps).map(function (vertex) { | ||
topologicalOrder() { | ||
return toposort(this.graph); | ||
} | ||
size() { | ||
@@ -103,0 +108,0 @@ return this.graph.vertexCount(); |
{ | ||
"name": "mako-tree", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "The build tree structure used internally by mako", | ||
@@ -9,2 +9,3 @@ "repository": "makojs/tree", | ||
"file-extension": "^1.1.4", | ||
"graph-toposort": "0.0.1", | ||
"graph.js": "^1.20.1" | ||
@@ -11,0 +12,0 @@ }, |
@@ -64,6 +64,11 @@ # mako-tree | ||
### Tree#getSources() | ||
### Tree#isSource(location) | ||
Returns a `Boolean` telling whether or not the file at `location` is an entry file. (in other | ||
words, is not a dependency) | ||
### Tree#getEntries() | ||
Returns an `Array` of all the entry files in this graph. (in other words, files that are at the | ||
top of the dependency chains) | ||
end of the dependency chains) | ||
@@ -113,2 +118,6 @@ ### Tree#hasDependency(parent, child) | ||
### Tree#topologicalOrder() | ||
Returns an `Array` of files that can be processed in an order that respects all the dependencies. | ||
### File(location) *(constructor)* | ||
@@ -136,5 +145,5 @@ | ||
### File#isSource() | ||
### File#isEntry() | ||
Short-hand for `tree.isSource(file.path)`. | ||
Short-hand for `tree.isEntry(file.path)`. | ||
@@ -141,0 +150,0 @@ ### File#hasDependency(child) |
@@ -24,3 +24,3 @@ | ||
describe('#isSource()', function () { | ||
describe('#isEntry()', function () { | ||
// a -> b | ||
@@ -32,8 +32,8 @@ let tree = new Tree(); | ||
it('should return true if the file is a source', function () { | ||
assert.isTrue(a.isSource()); | ||
it('should return true if the file is a Entry', function () { | ||
assert.isTrue(a.isEntry()); | ||
}); | ||
it('should return false if the file is not a source', function () { | ||
assert.isFalse(b.isSource()); | ||
it('should return false if the file is not a Entry', function () { | ||
assert.isFalse(b.isEntry()); | ||
}); | ||
@@ -40,0 +40,0 @@ }); |
@@ -73,3 +73,3 @@ | ||
it('should fail if there are still dependencies defined', function () { | ||
// a -> b | ||
// a <- b | ||
let tree = new Tree(); | ||
@@ -86,11 +86,11 @@ tree.addFile('a'); | ||
describe('#getSources()', function () { | ||
describe('#getEntries()', function () { | ||
it('should return an empty list', function () { | ||
let tree = new Tree(); | ||
assert.deepEqual(tree.getSources(), []); | ||
assert.deepEqual(tree.getEntries(), []); | ||
}); | ||
it('should return only the top-level entry', function () { | ||
// a -> b -> c | ||
// -> d | ||
// a <- b <- c | ||
// <- d | ||
let tree = new Tree(); | ||
@@ -102,11 +102,11 @@ tree.addFile('a'); | ||
tree.addDependency('a', 'b'); | ||
tree.addDependency('a', 'd'); | ||
tree.addDependency('b', 'c'); | ||
tree.addDependency('a', 'd'); | ||
assert.deepEqual(tree.getSources(), [ 'a' ]); | ||
assert.deepEqual(tree.getEntries(), [ 'a' ]); | ||
}); | ||
it('should return all the top-level entries', function () { | ||
// a -> b | ||
// c -> d -> e | ||
// a <- b | ||
// c <- d <- e | ||
let tree = new Tree(); | ||
@@ -122,8 +122,8 @@ tree.addFile('a'); | ||
assert.deepEqual(tree.getSources(), [ 'a', 'c' ]); | ||
assert.deepEqual(tree.getEntries(), [ 'a', 'c' ]); | ||
}); | ||
}); | ||
describe('#isSource(location)', function () { | ||
// a -> b | ||
describe('#isEntry(location)', function () { | ||
// a <- b | ||
let tree = new Tree(); | ||
@@ -135,7 +135,7 @@ tree.addFile('a'); | ||
it('should return true when the file has no dependants', function () { | ||
assert.isTrue(tree.isSource('a')); | ||
assert.isTrue(tree.isEntry('a')); | ||
}); | ||
it('should return false when the file is depended upon', function () { | ||
assert.isFalse(tree.isSource('b')); | ||
assert.isFalse(tree.isEntry('b')); | ||
}); | ||
@@ -145,3 +145,3 @@ }); | ||
describe('#hasDependency(parent, child)', function () { | ||
// a -> b | ||
// a <- b | ||
let tree = new Tree(); | ||
@@ -207,3 +207,3 @@ tree.addFile('a'); | ||
it('should remove the edge from the graph', function () { | ||
// a -> b | ||
// a <- b | ||
let tree = new Tree(); | ||
@@ -221,4 +221,4 @@ tree.addFile('a'); | ||
it('should remove the unused nodes', function () { | ||
// a -> b | ||
// -> c | ||
// a <- b | ||
// <- c | ||
let tree = new Tree(); | ||
@@ -231,3 +231,3 @@ tree.addFile('a'); | ||
// a -> b | ||
// a <- b | ||
tree.removeDependency('a', 'c'); | ||
@@ -241,4 +241,4 @@ | ||
it('should not remove nodes that are still depended upon', function () { | ||
// a -> c | ||
// b -> | ||
// a <- c | ||
// b <- | ||
let tree = new Tree(); | ||
@@ -251,3 +251,3 @@ tree.addFile('a'); | ||
// a -> c | ||
// a <- c | ||
// b | ||
@@ -263,4 +263,4 @@ tree.removeDependency('b', 'c'); | ||
describe('#moveDependency(from, to, child)', function () { | ||
it('should transfer the dependency from -> to', function () { | ||
// a -> b -> c | ||
it('should transfer the dependency from <- to', function () { | ||
// a <- b <- c | ||
let tree = new Tree(); | ||
@@ -274,4 +274,4 @@ tree.addFile('a'); | ||
// a -> b | ||
// -> c | ||
// a <- b | ||
// <- c | ||
assert.isTrue(tree.hasDependency('a', 'b')); | ||
@@ -284,3 +284,3 @@ assert.isTrue(tree.hasDependency('a', 'c')); | ||
describe('#dependenciesOf(node, [recursive])', function () { | ||
// a -> b -> c -> d | ||
// a <- b <- c <- d | ||
let tree = new Tree(); | ||
@@ -307,3 +307,3 @@ tree.addFile('a'); | ||
describe('#dependantsOf(node, [recursive])', function () { | ||
// a -> b -> c -> d | ||
// a <- b <- c <- d | ||
let tree = new Tree(); | ||
@@ -328,2 +328,20 @@ tree.addFile('a'); | ||
}); | ||
describe('#topologicalOrder()', function () { | ||
// a <- b <- c <- d | ||
// <- e | ||
let tree = new Tree(); | ||
tree.addFile('a'); | ||
tree.addFile('b'); | ||
tree.addFile('c'); | ||
tree.addFile('d'); | ||
tree.addDependency('a', 'b'); | ||
tree.addDependency('a', 'e'); | ||
tree.addDependency('b', 'c'); | ||
tree.addDependency('c', 'd'); | ||
it('should return a topolically sorted list', function () { | ||
assert.deepEqual(tree.topologicalOrder(), [ 'd', 'e', 'c', 'b', 'a' ]); | ||
}); | ||
}); | ||
}); |
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
25729
485
166
4
+ Addedgraph-toposort@0.0.1
+ Addedgraph-toposort@0.0.1(transitive)