lib/dependencyTools.js
function resolveDependencyGraph(module, resolved, unresolved, dependencies) {
	var moduleDependencies;
	if (module) {
		moduleDependencies = dependencies[module];
		if (!moduleDependencies) {
			throw new Error('Component ' + module + ' not installed. Try bower install --save ' + module);
		}
		unresolved.push(module);
	}
	else {
		moduleDependencies = Object.keys(dependencies);
	}

	moduleDependencies.forEach(function(moduleDependency) {
		if (resolved.indexOf(moduleDependency) === -1) {
			if (unresolved.indexOf(moduleDependency) !== -1) {
				throw new Error('Circular reference detected for ' + module + ' - ' + moduleDependency);
			}

			resolveDependencyGraph(moduleDependency, resolved, unresolved, dependencies);
		}
	});

	if (module) {
		resolved.push(module);
		unresolved = unresolved.splice(unresolved.indexOf(module), 1);
	}
}
function resolveDependencyGraph(module, resolved, unresolved, dependencies) {
	var moduleDependencies;
	if (module) {
		moduleDependencies = dependencies[module];
		if (!moduleDependencies) {
			throw new Error('Component ' + module + ' not installed. Try bower install --save ' + module);
		}
		unresolved.push(module);
	}
	else {
		moduleDependencies = Object.keys(dependencies);
	}

	moduleDependencies.forEach(function(moduleDependency) {
		if (resolved.indexOf(moduleDependency) === -1) {
			if (unresolved.indexOf(moduleDependency) !== -1) {
				throw new Error('Circular reference detected for ' + module + ' - ' + moduleDependency);
			}

			resolveDependencyGraph(moduleDependency, resolved, unresolved, dependencies);
		}
	});

	if (module) {
		resolved.push(module);
		unresolved = unresolved.splice(unresolved.indexOf(module), 1);
	}
}
function resolveDependencyGraph ( module , resolved , unresolved , dependencies ) { var moduleDependencies ; if ( module ) { moduleDependencies = dependencies [ module ] ; if ( ! moduleDependencies ) { throw new Error ( 'Component ' + module + ' not installed. Try bower install --save ' + module ) ; } unresolved . push ( module ) ; } else { moduleDependencies = Object . keys ( dependencies ) ; } moduleDependencies . forEach ( function ( moduleDependency ) { if ( resolved . indexOf ( moduleDependency ) === - 1 ) { if ( unresolved . indexOf ( moduleDependency ) !== - 1 ) { throw new Error ( 'Circular reference detected for ' + module + ' - ' + moduleDependency ) ; } resolveDependencyGraph ( moduleDependency , resolved , unresolved , dependencies ) ; } } ) ; if ( module ) { resolved . push ( module ) ; unresolved = unresolved . splice ( unresolved . indexOf ( module ) , 1 ) ; } }
Resolves a graph of dependencies into a flat, ordered array.

The arrays ordering ensures, that a dependecy of another module comes before the module itself.

This algorithem is adapted from the pseudo code example available here:
http://www.electricmonk.nl/log/2008/08/07/dependency-resolving-algorithm/
Resolves a graph of dependencies into a flat ordered array .