np
np copied to clipboard
allow publishing current version without increment, to workaround issue with prerelease versions and --no-publish with CI/CD
Description
When using np in conjunction with a CI/CD environment, the recommended implementation is to use the --no-publish
flag and then have the actual publish handled on the CI/CD server (e.g. with npm publish
.)
Now, if one is using np to generate a prerelease SemVer release, when publishing locally np is smart enough to add the next
dist tag to the publication.
But if using with --no-publish
in a CI/CD setup like this, but the time this gets downstream to where the actual publish happens, you just have the version string. Unfortunately, since npm publish
is not really SemVer aware these days, a semantic version with a prerelease string will then still be published as latest
.
Rather than relying on npm publish
to adopt this logic, we propose adding a "publish only" style command to np, that could handle the publish to NPM using np's already quite smart logic about handling next
dist tags, so that prerelease versions are handled appropriately.
A CD flow could then look something like this:
Developer: `np --no-publish prerelease` -> updates package.json, git tags, pushes upstream to GitHub, drafts release on GitHub
CD system: detects new release -> runs `np --publish-current`
Is the feature request related to a problem?
For a user switching from running np locally on their workstation to integrating np into a CI workflow, it's highly likely they would encounter this same issue, and result in any prerelease
versions no longer being dist tagged as next
and impacting downstream package users who then npm install
it.
Possible implementation
Two ways I can see this being done with existing UI:
A) Add an counterpart for the --no-publish
flag that only does the publish stage with np's existing logic, e.g. --publish-only
or --publish-current-version
.
B) Add a current
version target. This could then be handled on the CI/CD server via something like np current --no-release-draft
. (Something similar appears to have previously discussed in #74, but with a different use case.)
Alternatives
We are currently hacking around this via usage of wrapping npm-publish-prerelease
on our CI, however the disadvantages are the behavior is slightly different than np locally (e.g. usage of prerelease
tag instead of next
, and discoverability for end users.
An alternative minimum thus could be to have np emit an informational warning to the user when doing a --no-publish
combined with a prerelease, and/or adding documentation to this effect in all places where --no-publish
and CI/CD systems are mentioned.
I have a somewhat different use case but having something like current
would work for me too.
I have other tooling in place that bumps my package.json versions in my monorepo packages. I then would like to use np
to actually do the release to npm, create tags, etc.
Same here -- other tools deal with the version number. Would be great to have an option like --publish-current-version
or --no-bump-version
What is the advantage of using np on CI? See https://github.com/sindresorhus/np/issues/619#issuecomment-994493179
Closing