diff --git a/readme.md b/readme.md index e0018599..de2d6736 100644 --- a/readme.md +++ b/readme.md @@ -243,6 +243,8 @@ To publish [scoped packages](https://docs.npmjs.com/misc/scope#publishing-public } ``` +If publishing a scoped package for the first time, `np` will prompt you to ask if you want to publish it publicly. + ### Private Org-scoped packages To publish a [private Org-scoped package](https://docs.npmjs.com/creating-and-publishing-an-org-scoped-package#publishing-a-private-org-scoped-package), you need to set the access level to `restricted`. You can do that by adding the following to your `package.json`: diff --git a/source/npm/handle-npm-error.js b/source/npm/handle-npm-error.js index 36586c93..fa191c51 100644 --- a/source/npm/handle-npm-error.js +++ b/source/npm/handle-npm-error.js @@ -25,6 +25,12 @@ const handleNpmError = (error, task, message, executor) => { ); } + // Attempting to privately publish a scoped package without the correct npm plan + // https://stackoverflow.com/a/44862841/10292952 + if (error.code === 402 || error.stderr.includes('npm ERR! 402 Payment Required')) { + throw new Error('You cannot publish a privately scoped package without a paid plan. Did you mean to publish publicly?'); + } + return throwError(error); }; diff --git a/source/ui.js b/source/ui.js index 5114986f..4d4001ba 100644 --- a/source/ui.js +++ b/source/ui.js @@ -284,6 +284,7 @@ module.exports = async (options, pkg) => { ...options, version: answers.version || answers.customVersion || options.version, tag: answers.tag || answers.customTag || options.tag, + publishScoped: answers.publishScoped, confirm: true, repoUrl, releaseNotes