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

[BUG] "npm publish" tags pre-versions as "latest" #7553

Closed
2 tasks done
kytta opened this issue May 22, 2024 · 8 comments
Closed
2 tasks done

[BUG] "npm publish" tags pre-versions as "latest" #7553

kytta opened this issue May 22, 2024 · 8 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps

Comments

@kytta
Copy link

kytta commented May 22, 2024

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

NOTE: This is rather a footgun than a bug

This was reported in npm/npm#13248 and has been ignored and never re-opened since, even though the problem clearly still exists. Following is the (adapted) description from the issues' original author. I have verified that this behaviour is still present.


Running npm version premajor && npm publish will tag the premajor version as latest by default. I confirmed this happens when running all pre-release options: premajor | preminor | prepatch | prerelease.

As pointed out in npm/npm#10189, there are valid reasons that authors would want to tag pre-release versions as latest. However, I think that this is not good default behaviour (though it is documented: "Publishing a package sets the latest tag to the published version unless the --tag option is used. For example, npm publish --tag=beta.")

Semver documentation states:

A pre-release version indicates that the version is unstable and might not satisfy the intended compatibility requirements as denoted by its associated normal version. Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.

Source: http://semver.org/#spec-item-9

Expected Behavior

I propose that the latest tag only be set if the version to be published is not a pre-release version. Or, at the very least, there should be a warning about this.

Steps To Reproduce

  1. While in any package directory...
  2. Run npm version prepatch or ... preminor or ... premajor or ... prerelease or set a pre-release version manually
  3. Run npm publish
  4. See that the package gets published to the latest tag without any fuss

Environment

  • npm: 10.5.2
  • Node.js: 20.13.0
  • OS Name: macOS Ventura 13.6.6
  • System Model Name: MacBook Pro 14-inch 2023 M2 Pro 32GB RAM
  • npm config:
; "project" config from /Users/nikitakaramov/Code/@kytta/npmtest/.npmrc

@kytta:registry = (redacted) 
//(redacted)/:_authToken = (protected) 

; "env" config from environment

userconfig = "/Users/nikitakaramov/.config/npm/npmrc" 

; node bin location = /Users/nikitakaramov/.local/share/mise/installs/node/20.13.0/bin/node
; node version = v20.13.0
; npm local prefix = /Users/nikitakaramov/Code/@kytta/npmtest
; npm version = 10.5.2
; cwd = /Users/nikitakaramov/Code/@kytta/npmtest
; HOME = /Users/nikitakaramov
; Run `npm config ls -l` to show all defaults.
@kytta kytta added Bug thing that needs fixing Needs Triage needs review for next steps labels May 22, 2024
@ljharb
Copy link
Contributor

ljharb commented May 22, 2024

Some tag must always be set - what tag would you expect as an alternative?

@kytta
Copy link
Author

kytta commented May 22, 2024

Some tag must always be set - what tag would you expect as an alternative?

If not failing for pre-release builds (which would force the user to set the tag), I'd choose either:

  • next for any semver-compliant pre-release version, or
  • the tag that matches the prerelease suffix, if there is any. For example, 2.0.0-alpha.1 would get the tag alpha, 2.0.0-rc.3 would get the tag rc

@ljharb
Copy link
Contributor

ljharb commented May 22, 2024

failing and forcing a tag seems nice. even better is if it implemented https://npmjs.com/safe-publish-latest, and failed to implicitly publish a latest whenever the version being published isn't a non-prerelease that is "later" than all existing versions.

@kytta
Copy link
Author

kytta commented May 23, 2024

So, this behaviour, then?

npm version 1.0.0
npm publish # no problem

npm version 1.0.1-alpha.1
npm publish
# npm ERR no tag set

npm publish --tag alpha # no problem

npm version 1.0.1-alpha.2
npm publish --tag latest # no problem; set implicitly

npm version 0.1.0 # assuming it's possible
npm publish
# npm ERR a newer 'latest' version is already published

Another question. What should we do about this behaviour:

  1. developer willingly publishes a pre-release to latest (Make latest default version for npm install package instead of * npm#10189 (comment))
    • say, 1.0.0-rc.1 => latest
  2. developer makes a new pre-release version with the same version number (major.minor.patch), and a different pre-release identifier combo
    • say, 1.0.0-rc.2
  3. developer runs npm publish

Should we allow this, because the developer "opted-in" to publishing pre-releases for 1.0.0 to latest (in other words, because the current latest is also a pre-release), or should we always require an explicit tag for pre-releases?

@ljharb
Copy link
Contributor

ljharb commented May 23, 2024

If they explicitly want something to be "latest" then it would be wildly improper for npm to prevent that, but it seems reasonable to me that implicit "latest" must always be a "later" non-prerelease.

(to be clear, this is something that'd have to be accepted by the npm team, and probably should be discussed in the RFC repo instead of here)

@kytta
Copy link
Author

kytta commented May 24, 2024

If they explicitly want something to be "latest" then it would be wildly improper for npm to prevent that, but it seems reasonable to me that implicit "latest" must always be a "later" non-prerelease.

Sounds good. It also matches the behaviour proposed in RFC 7

(to be clear, this is something that'd have to be accepted by the npm team, and probably should be discussed in the RFC repo instead of here)

Thanks for the heads-up! I've drafted one here: npm/rfcs#776

@wesleytodd
Copy link
Contributor

➕ 1 on failing when not passing an explicit --tag for prerelease versions. This has bitten me so many times over the years and has contributed to my beliefs automated publish workflows are superior (despite the tradeoffs). This would remove one of the rough edges around manual publish workflows and seems pretty clearly to be a good thing.

@wraithgar
Copy link
Member

wraithgar commented May 24, 2024

Because this is not a bug I am going to close this issue. The rfc issue is probably the best place to add more input. Personally I'm a huge fan of this idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps
Projects
None yet
Development

No branches or pull requests

4 participants