npm-crawl.js
function(context, childPkg){
		var curAddress = childPkg.origFileUrl;
		var parentAddress = utils.path.parentNodeModuleAddress(childPkg.origFileUrl);
		while(parentAddress) {
			var packageAddress = parentAddress+"/"+childPkg.name+"/package.json";
			var parentPkg =	context.paths[packageAddress];
			if(parentPkg && SemVer.valid(parentPkg.version)) {
				if(SemVer.satisfies(parentPkg.version, childPkg.version)) {
					return parentPkg.fileUrl;
				} else {
					return curAddress;
				}
			}
			parentAddress = utils.path.parentNodeModuleAddress(packageAddress);
			curAddress = packageAddress;
		}
		return curAddress;
	}
function(context, childPkg){
		var curAddress = childPkg.origFileUrl;
		var parentAddress = utils.path.parentNodeModuleAddress(childPkg.origFileUrl);
		while(parentAddress) {
			var packageAddress = parentAddress+"/"+childPkg.name+"/package.json";
			var parentPkg =	context.paths[packageAddress];
			if(parentPkg && SemVer.valid(parentPkg.version)) {
				if(SemVer.satisfies(parentPkg.version, childPkg.version)) {
					return parentPkg.fileUrl;
				} else {
					return curAddress;
				}
			}
			parentAddress = utils.path.parentNodeModuleAddress(packageAddress);
			curAddress = packageAddress;
		}
		return curAddress;
	}
function ( context , childPkg ) { var curAddress = childPkg . origFileUrl ; var parentAddress = utils . path . parentNodeModuleAddress ( childPkg . origFileUrl ) ; while ( parentAddress ) { var packageAddress = parentAddress + "/" + childPkg . name + "/package.json" ; var parentPkg = context . paths [ packageAddress ] ; if ( parentPkg && SemVer . valid ( parentPkg . version ) ) { if ( SemVer . satisfies ( parentPkg . version , childPkg . version ) ) { return parentPkg . fileUrl ; } else { return curAddress ; } } parentAddress = utils . path . parentNodeModuleAddress ( packageAddress ) ; curAddress = packageAddress ; } return curAddress ; }
Walk up the parent addresses until you run into the root or a conflicting
package and return that as the address.
Walk up the parent addresses until you run into the root or a conflicting package and return that as the address .