-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: simplify validate-addons logic & npm-exists (#67)
* hotfix: simplify validate-addons logic & npm-exists Simplifies the usage of validate-addons and replaces the manual mock of nom-exists with the actual. fix: refactor function convention and add jsdcos fix: rename validateAddons to npmPackagesExists Renames the validateAddons packages to npmPackagesExists. Synced with master to get latest changes from origin. Also added lint ignore to coverage folder. fix: remove coverage folder from commit fix: rename test header * fix: remove coverage from build fix: remove coverage folder
- Loading branch information
1 parent
fe62523
commit 68a2dfd
Showing
8 changed files
with
57 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
**/__testfixtures__/* | ||
coverage |
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 |
---|---|---|
|
@@ -11,3 +11,6 @@ npm-debug.* | |
|
||
# yarn log | ||
yarn-error.log | ||
|
||
# Jest Coverage | ||
coverage |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const npmExists = require('./npm-exists'); | ||
const resolvePackages = require('./resolve-packages'); | ||
|
||
|
||
/* | ||
* @function npmPackagesExists | ||
* | ||
* Loops through an array and checks if a package is registered | ||
* on npm and throws an error if it is not from @checkEachPackage | ||
* | ||
* @param { Array <String> } pkg - Array of packages to check existence of | ||
* @returns { Array } resolvePackages - Returns an process to install the pkg | ||
*/ | ||
|
||
module.exports = function npmPackagesExists(addons) { | ||
return addons.map( pkg => checkEachPackage(pkg)); | ||
}; | ||
|
||
/* | ||
* @function checkEachPackage | ||
* | ||
* Checks if a package is registered on npm and throws if it is not | ||
* | ||
* @param { Object } pkg - pkg to check existence of | ||
* @returns { <Function|Error> } resolvePackages - Returns an process to install the pkg | ||
*/ | ||
|
||
function checkEachPackage(pkg) { | ||
return npmExists(pkg).then( (moduleExists) => { | ||
if(!moduleExists) { | ||
Error.stackTraceLimit = 0; | ||
throw new TypeError('Package isn\'t registered on npm.'); | ||
} | ||
if (moduleExists) { | ||
return resolvePackages(pkg); | ||
} | ||
}).catch(err => { | ||
console.error(err.stack || err); | ||
process.exit(0); | ||
}); | ||
} |
6 changes: 3 additions & 3 deletions
6
lib/utils/validate-addons.spec.js → lib/utils/npm-packages-exists.spec.js
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 was deleted.
Oops, something went wrong.