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

Fix UI prompt for new publicly scoped packages #677

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

tommy-mitchell
Copy link
Collaborator

Fixes #660.

Needs test(s), but I'm not entirely sure how to test this.

@tommy-mitchell tommy-mitchell changed the title Fix UI prompt for publicly scoped packages Fix UI prompt for new publicly scoped packages Mar 19, 2023
@tommy-mitchell
Copy link
Collaborator Author

Related, maybe a CLI flag could be added to force this behavior? Something like --publish-scoped-public? Or perhaps just --access-public.

@tommy-mitchell
Copy link
Collaborator Author

tommy-mitchell commented Mar 19, 2023

If the user says no to publishing publicly, this could probably also catch the error from NPM about paying for private scoped packages and give a helpful message instead.


Edit - Added, but again needs tests:

// npm/handle-npm-error.js

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);
};

image

@sindresorhus
Copy link
Owner

I don't see how can test this without setting up a bunch of mocking or running a local npm server. Neither seem worth it.

@sindresorhus sindresorhus merged commit e71f691 into sindresorhus:main Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Newly publishing a public scoped package does not include the --access public flag
2 participants