-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: throw error when "name" key is missing in package.json #298
Conversation
src/lib/npm.js
Outdated
@@ -55,7 +55,7 @@ async function validateToken(otp, npm) { | |||
|
|||
function getRegistry(pkg, conf) { | |||
if (pkg.publishConfig && pkg.publishConfig.registry) return pkg.publishConfig.registry; | |||
|
|||
if (pkg.name === undefined) throw new Error(`Your package doesn't have name`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (pkg.name === undefined) throw new Error(`Your package doesn't have name`); | |
if (pkg.name === undefined) throw new Error(`package.json is missing "name" key`); |
I'm not sure if this is the right place to throw the error, I'd throw it as soon as we read out pkg
. The name property is not used in the getRegistry
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the next line is using the name property name[0]
, but I agree with you, it could be better if we placed it in the index.js
.
@@ -10,6 +10,7 @@ const ownPkg = require('../package.json'); | |||
const getLog = require('./lib/log'); | |||
|
|||
const pkg = JSON.parse(readFileSync('./package.json')); | |||
if (pkg.name === undefined) throw new Error(`"name" key is missing from your package.json`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @gr2m, I updated my PR and moved the validation from getRegistry method in npm.js in the index.js after reading the package.json directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍🏼
🎉 This PR is included in version 5.4.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
fixes #297