Comparing version 1.3.1 to 1.4.0
1.4.0 / 2016-11-02 | ||
================== | ||
* feat(tree): improve error messages | ||
1.3.1 / 2016-10-23 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -5,2 +5,3 @@ 'use strict' | ||
let assert = require('assert') | ||
let bytes = require('bytes') | ||
@@ -135,6 +136,13 @@ let debug = require('debug')('mako-tree') | ||
let file = this.getFile(id(node)) | ||
debug('removing file %s: (force: %j)', utils.relative(file.path), force) | ||
assert(file, `cannot find file ${node} in this tree`) | ||
const relative = utils.relative(file.path) | ||
debug('removing file %s: (force: %j)', relative, force) | ||
if (force) { | ||
this.graph.destroyVertex(file.id) | ||
} else { | ||
if (this.graph.degree(file.id) > 0) { | ||
throw new Error(`cannot remove ${relative} while it still has dependencies in the tree (use force: true to override this)`) | ||
} | ||
this.graph.removeVertex(file.id) | ||
@@ -169,8 +177,9 @@ } | ||
addDependency (parent, child) { | ||
let childId = id(child) | ||
let parentId = id(parent) | ||
this.graph.addEdge(childId, parentId) | ||
let childPath = utils.relative(this.getFile(childId).path) | ||
let parentPath = utils.relative(this.getFile(parentId).path) | ||
debug('added dependency %s -> %s', childPath, parentPath) | ||
let childFile = this.getFile(id(child)) | ||
assert(childFile, `cannot add dependency because ${child} is not in the tree`) | ||
let parentFile = this.getFile(id(parent)) | ||
assert(parentFile, `cannot add dependency because ${parent} is not in the tree`) | ||
this.graph.addEdge(childFile.id, parentFile.id) | ||
debug('added dependency %s -> %s', utils.relative(childFile.path), utils.relative(parentFile.path)) | ||
} | ||
@@ -185,8 +194,9 @@ | ||
removeDependency (parent, child) { | ||
let childId = id(child) | ||
let parentId = id(parent) | ||
this.graph.removeEdge(childId, parentId) | ||
let childPath = utils.relative(this.getFile(childId).path) | ||
let parentPath = utils.relative(this.getFile(parentId).path) | ||
debug('removed dependency %s -> %s', childPath, parentPath) | ||
let childFile = this.getFile(id(child)) | ||
assert(childFile, `cannot remove dependency because ${child} is not in the tree`) | ||
let parentFile = this.getFile(id(parent)) | ||
assert(parentFile, `cannot remove dependency because ${parent} is not in the tree`) | ||
this.graph.removeEdge(childFile.id, parentFile.id) | ||
debug('removed dependency %s -> %s', utils.relative(childFile.path), utils.relative(parentFile.path)) | ||
} | ||
@@ -241,8 +251,9 @@ | ||
addDependant (child, parent) { | ||
let childId = id(child) | ||
let parentId = id(parent) | ||
this.graph.addEdge(childId, parentId) | ||
let childPath = utils.relative(this.getFile(childId).path) | ||
let parentPath = utils.relative(this.getFile(parentId).path) | ||
debug('added dependant %s <- %s', childPath, parentPath) | ||
let childFile = this.getFile(id(child)) | ||
assert(childFile, `cannot add dependant because ${child} is not in the tree`) | ||
let parentFile = this.getFile(id(parent)) | ||
assert(parentFile, `cannot add dependant because ${parent} is not in the tree`) | ||
this.graph.addEdge(childFile.id, parentFile.id) | ||
debug('added dependant %s <- %s', utils.relative(childFile.path), utils.relative(parentFile.path)) | ||
} | ||
@@ -257,8 +268,9 @@ | ||
removeDependant (child, parent) { | ||
let childId = id(child) | ||
let parentId = id(parent) | ||
this.graph.removeEdge(childId, parentId) | ||
let childPath = utils.relative(this.getFile(childId).path) | ||
let parentPath = utils.relative(this.getFile(parentId).path) | ||
debug('removed dependant %s <- %s', childPath, parentPath) | ||
let childFile = this.getFile(id(child)) | ||
assert(childFile, `cannot remove dependant because ${child} is not in the tree`) | ||
let parentFile = this.getFile(id(parent)) | ||
assert(parentFile, `cannot remove dependant because ${parent} is not in the tree`) | ||
this.graph.removeEdge(childFile.id, parentFile.id) | ||
debug('removed dependant %s <- %s', utils.relative(childFile.path), utils.relative(parentFile.path)) | ||
} | ||
@@ -265,0 +277,0 @@ |
{ | ||
"name": "mako-tree", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"main": "./lib/tree", | ||
@@ -5,0 +5,0 @@ "description": "The build tree structure used internally by mako", |
@@ -192,5 +192,3 @@ /* eslint-env mocha */ | ||
assert.throws(function () { | ||
tree.removeFile(html) | ||
}) | ||
assert.throws(() => tree.removeFile(html), 'cannot remove index.html while it still has dependencies in the tree (use force: true to override this)') | ||
}) | ||
@@ -206,2 +204,8 @@ | ||
it('should fail when the given id is not present in the tree', function () { | ||
let tree = new Tree() | ||
assert.throws(() => tree.removeFile('does not exist'), 'cannot find file does not exist in this tree') | ||
}) | ||
context('with options', function () { | ||
@@ -298,2 +302,18 @@ context('.force', function () { | ||
}) | ||
it('should fail when the parent file is not in the tree', function () { | ||
let tree = new Tree() | ||
let parent = 'does not exist' | ||
let child = tree.addFile('index.html') | ||
assert.throws(() => tree.addDependency(parent, child), `cannot add dependency because ${parent} is not in the tree`) | ||
}) | ||
it('should fail when the child file is not in the tree', function () { | ||
let tree = new Tree() | ||
let parent = tree.addFile('index.html') | ||
let child = 'does not exist' | ||
assert.throws(() => tree.addDependency(parent, child), `cannot add dependency because ${child} is not in the tree`) | ||
}) | ||
}) | ||
@@ -323,2 +343,20 @@ | ||
}) | ||
it('should fail when the parent file is not in the tree', function () { | ||
let tree = new Tree() | ||
let html = tree.addFile('index.html') | ||
let js = tree.addFile('index.js') | ||
tree.addDependency(html, js) | ||
assert.throws(() => tree.removeDependency('does not exist', js.id), 'cannot remove dependency because does not exist is not in the tree') | ||
}) | ||
it('should fail when the child file is not in the tree', function () { | ||
let tree = new Tree() | ||
let html = tree.addFile('index.html') | ||
let js = tree.addFile('index.js') | ||
tree.addDependency(html, js) | ||
assert.throws(() => tree.removeDependency(html.id, 'does not exist'), 'cannot remove dependency because does not exist is not in the tree') | ||
}) | ||
}) | ||
@@ -434,2 +472,18 @@ | ||
}) | ||
it('should fail when the child file is not in the tree', function () { | ||
let tree = new Tree() | ||
let child = 'does not exist' | ||
let parent = tree.addFile('b.js') | ||
assert.throws(() => tree.addDependant(child, parent), `cannot add dependant because ${child} is not in the tree`) | ||
}) | ||
it('should fail when the parent file is not in the tree', function () { | ||
let tree = new Tree() | ||
let child = tree.addFile('a.js') | ||
let parent = 'does not exist' | ||
assert.throws(() => tree.addDependant(child, parent), `cannot add dependant because ${parent} is not in the tree`) | ||
}) | ||
}) | ||
@@ -459,2 +513,22 @@ | ||
}) | ||
it('should fail when the child file is not in the tree', function () { | ||
// a.js <- b.js | ||
let tree = new Tree() | ||
let a = tree.addFile('a.js') | ||
let b = tree.addFile('b.js') | ||
tree.addDependant(b, a) | ||
assert.throws(() => tree.removeDependant('does not exist', a), 'cannot remove dependant because does not exist is not in the tree') | ||
}) | ||
it('should fail when the parent file is not in the tree', function () { | ||
// a.js <- b.js | ||
let tree = new Tree() | ||
let a = tree.addFile('a.js') | ||
let b = tree.addFile('b.js') | ||
tree.addDependant(b, a) | ||
assert.throws(() => tree.removeDependant(b, 'does not exist'), 'cannot remove dependant because does not exist is not in the tree') | ||
}) | ||
}) | ||
@@ -461,0 +535,0 @@ |
Sorry, the diff of this file is not supported yet
76559
1651