Skip to content
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

Merged
merged 5 commits into from
Jul 26, 2020

Conversation

abdelrahmanahmed
Copy link
Contributor

@abdelrahmanahmed abdelrahmanahmed commented Aug 17, 2019

fixes #297

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`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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.

@pvdlg pvdlg added the cli label Aug 19, 2019
@@ -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`);
Copy link
Contributor Author

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

@gr2m gr2m changed the title refactor: 💡 added error message feat: throw error when "name" key is missing in package.json Jul 26, 2020
Copy link
Member

@gr2m gr2m left a 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 👍🏼

@gr2m gr2m merged commit 8083cc0 into semantic-release:master Jul 26, 2020
@semantic-release-bot
Copy link
Collaborator

🎉 This PR is included in version 5.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhance error message when setup CLI
4 participants