Comparing version 0.14.10 to 0.14.11
0.14.11 / 2016-07-02 | ||
==================== | ||
* add support for recursively checking for dependency relationships | ||
0.14.10 / 2016-06-29 | ||
@@ -3,0 +8,0 @@ ==================== |
@@ -135,8 +135,15 @@ 'use strict' | ||
* | ||
* Available `options`: | ||
* - `recursive`: check for the dependency recursively | ||
* | ||
* @param {String|File} parent The parent file (or it's string ID). | ||
* @param {String|File} child The child file (or it's string ID). | ||
* @param {Object} [options] Additional options. | ||
* @return {Boolean} | ||
*/ | ||
hasDependency (parent, child) { | ||
return this.graph.hasEdge(id(child), id(parent)) | ||
hasDependency (parent, child, options) { | ||
let recursive = options ? !!options.recursive : false | ||
return recursive | ||
? this.graph.hasPath(id(child), id(parent)) | ||
: this.graph.hasEdge(id(child), id(parent)) | ||
} | ||
@@ -201,8 +208,12 @@ | ||
* | ||
* Available `options`: | ||
* - `recursive` looks for the dependant recursively. | ||
* | ||
* @param {String|File} child The child file (or it's string ID). | ||
* @param {String|File} parent The parent file (or it's string ID). | ||
* @param {Object} [options] Additional options. | ||
* @return {Boolean} | ||
*/ | ||
hasDependant (child, parent) { | ||
return this.graph.hasEdge(id(child), id(parent)) | ||
hasDependant (child, parent, options) { | ||
return this.hasDependency(parent, child, options) | ||
} | ||
@@ -209,0 +220,0 @@ |
{ | ||
"name": "mako-tree", | ||
"version": "0.14.10", | ||
"version": "0.14.11", | ||
"main": "./lib/tree", | ||
@@ -5,0 +5,0 @@ "description": "The build tree structure used internally by mako", |
@@ -62,3 +62,3 @@ # mako-tree | ||
### Tree#hasDependency(parent, child) | ||
### Tree#hasDependency(parent, child, [options]) | ||
@@ -68,2 +68,4 @@ Returns a `Boolean` reflecting if the dependency relationship between `parent` and `child` already | ||
If `options.recursive` is `true`, it will check the dependency tree recursively. | ||
### Tree#addDependency(parent, child) | ||
@@ -87,3 +89,3 @@ | ||
### Tree#hasDependant(child, parent) | ||
### Tree#hasDependant(child, parent, [options]) | ||
@@ -93,2 +95,4 @@ Returns a `Boolean` reflecting if the dependency relationship between `child` and `parent` already | ||
If `options.recursive` is `true`, it will check the dependency tree recursively. | ||
### Tree#addDependant(child, parent) | ||
@@ -95,0 +99,0 @@ |
@@ -190,8 +190,10 @@ /* eslint-env mocha */ | ||
describe('#hasDependency(parent, child)', function () { | ||
// index.html <- index.js | ||
describe('#hasDependency(parent, child, [options])', function () { | ||
// index.html <- index.js <- lib.js | ||
let tree = new Tree() | ||
let html = tree.addFile('index.html') | ||
let js = tree.addFile('index.js') | ||
let lib = tree.addFile('lib.js') | ||
tree.addDependency(html, js) | ||
tree.addDependency(js, lib) | ||
@@ -206,2 +208,6 @@ it('should return false for a missing dependency', function () { | ||
it('should return false if the dependency is deep', function () { | ||
assert.isFalse(tree.hasDependency(html, lib)) | ||
}) | ||
it('should return true for an existing dependency', function () { | ||
@@ -214,2 +220,10 @@ assert.isTrue(tree.hasDependency(html, js)) | ||
}) | ||
context('with options', function () { | ||
describe('.recursive', function () { | ||
it('should search the dependency tree recursively', function () { | ||
assert.isTrue(tree.hasDependency(html, lib, { recursive: true })) | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -313,8 +327,10 @@ | ||
describe('#hasDependant(child, parent)', function () { | ||
// a.js <- b.js | ||
describe('#hasDependant(child, parent, [options])', function () { | ||
// a.js <- b.js <- c.js | ||
let tree = new Tree() | ||
let a = tree.addFile('a.js') | ||
let b = tree.addFile('b.js') | ||
let c = tree.addFile('c.js') | ||
tree.addDependency(a, b) | ||
tree.addDependency(b, c) | ||
@@ -329,2 +345,6 @@ it('should return false for a missing dependency', function () { | ||
it('should return false when the depedency is deep', function () { | ||
assert.isFalse(tree.hasDependant(a, c)) | ||
}) | ||
it('should return true for an existing dependency', function () { | ||
@@ -337,2 +357,10 @@ assert.isTrue(tree.hasDependant(b, a)) | ||
}) | ||
context('with options', function () { | ||
describe('.recursive', function () { | ||
it('should return true when the dependant is deep', function () { | ||
assert.isTrue(tree.hasDependant(c, a, { recursive: true })) | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -339,0 +367,0 @@ |
65266
1507
222