sindresorhus / np

A better `npm publish`
MIT License
7.56k stars 299 forks source link

Fixes #724

Closed mifi closed 11 months ago

mifi commented 11 months ago

This PR is best reviewed commit-by-commit

1. fix broken revert code after publish failure

it didn't work because of a missing await and .pkg

2. make boolean logic easier to understand

because pkg.publishConfig will often be undefined, canBePublishedPublicly would short circuit to undefined, but undefined means true in inquirer's when option. change this by always returning an explicit true or false. this should not bring any changes. also put isScoped(pkg.name) into the bool for consistency.

3 fix yarn npm publish for scoped packages

this will make yarn berry yarn npm publish behave like npm publish: npm publish on an already public scoped package will publish it gladly however for yarn npm publish, even if the scoped package is already published publicly we need to specify the --access public argument, or it will fail with 402 (Payment Required) here I add a check (currently only for yarn berry) for whether the published version of the package is public, and if so, set publishScoped to true (and don't ask for it)