-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Promises for async operations
This helps some of the async code easier to read
- Loading branch information
1 parent
f74e5bf
commit 525dbba
Showing
7 changed files
with
42 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
var path = require('path'); | ||
var findup = require('findup'); | ||
var Promise = require('bluebird'); | ||
|
||
/** | ||
* @param {string} importOriginPath Path of file that made @import reference | ||
*/ | ||
module.exports = function nearestPackageRoot(packageName, importOriginPath, callback) { | ||
module.exports = function nearestPackageRoot(packageName, importOriginPath) { | ||
var pathToFind = path.join('node_modules', packageName, 'package.json'); | ||
var dirnameOfImportOrigin = path.dirname(importOriginPath); | ||
var promise, handleFoundPath; | ||
|
||
findup(path.dirname(importOriginPath), pathToFind, function (err, nearestPackageParent) { | ||
if(err) { | ||
callback(err); | ||
} | ||
promise = new Promise(function (resolve, reject) { | ||
handleFoundPath = function (err, nearestPackageParent) { | ||
if(err) { | ||
reject(err); | ||
return; | ||
} | ||
|
||
var packageJSONLocation = path.join( | ||
nearestPackageParent, | ||
'node_modules', | ||
packageName | ||
); | ||
var packageJSONLocation = path.join( nearestPackageParent, 'node_modules', packageName); | ||
|
||
callback(null, packageJSONLocation); | ||
resolve(packageJSONLocation); | ||
}; | ||
}); | ||
|
||
findup(dirnameOfImportOrigin, pathToFind, handleFoundPath); | ||
|
||
return promise; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters