cli
cli copied to clipboard
[BUG] `npm version` command does not respect `config set tag-version-prefix ""` since >= v9.6.5
Is there an existing issue for this?
- [X] I have searched the existing issues
This issue exists in the latest npm version
- [X] I am using the latest npm
Current Behavior
Despite explicitly using npm config set tag-version-prefix ""
before npm version <patch|minor|major>
, the created git tag and resulting function output are still prefixed with v
.
This behavior occurs in NPM v9.6.5 -> v9.8.1
Expected Behavior
Up until npm v9.6.5, when using npm config set tag-version-prefix ""
, the created git tag, git commit message and command output would all result in the new version without the v
prefix.
Steps To Reproduce
- Create a new empty NPM project with
npm init -y && git init
- Run
npm config set tag-version-prefix ""
- Run
npm version
with eithermajor
,minor
orpatch
- Observe command output with
v
prefix - Check git tags with
git tag --list
and observe created tag withv
prefix - Check git commit logs with
git log
and observe commit message of new version, withoutv
prefix
Environment
- npm: >= v9.6.5
- Node.js: >= 18.16.0
- OS Name: MacOS Ventura 13.4/Ubuntu 22.04.3
- System Model Name: Macbook Pro 2019/GitHub Actions Runner 2.308.0
- npm config:
; "user" config from /Users/calem.roelofs/.npmrc
//npm.pkg.github.com/:_authToken = (protected)
; node bin location = /Users/calem.roelofs/.nvm/versions/node/v18.16.0/bin/node
; node version = v18.16.0
; npm local prefix = /Users/calem.roelofs/Code/CalemRoelofs/testversion
; npm version = 9.6.5
; cwd = /Users/calem.roelofs/Code/CalemRoelofs/testversion
; HOME = /Users/calem.roelofs
; Run `npm config ls -l` to show all defaults.
I've just stumbled on the problem myself. I can confirm it also affects 10.2.0
263260e7c03d:/tmp/node_tu# npm --version
10.2.0
263260e7c03d:/tmp/node_tu# npm config get tag-version-prefix
x
263260e7c03d:/tmp/node_tu# npm config set tag-version-prefix 't'
263260e7c03d:/tmp/node_tu# npm config get tag-version-prefix
t
263260e7c03d:/tmp/node_tu# npm config set tag-version-prefix ''
263260e7c03d:/tmp/node_tu# npm config get tag-version-prefix
v # should have been empty
263260e7c03d:/tmp/node_tu#
263260e7c03d:/tmp/node_tu# npm --version
9.9.0
263260e7c03d:/tmp/node_tu# npm config get tag-version-prefix
v
263260e7c03d:/tmp/node_tu# npm config set tag-version-prefix 't'
263260e7c03d:/tmp/node_tu# npm config get tag-version-prefix
t
263260e7c03d:/tmp/node_tu# npm config set tag-version-prefix ''
263260e7c03d:/tmp/node_tu# npm config get tag-version-prefix
v # should have been empty
263260e7c03d:/tmp/node_tu#
263260e7c03d:/tmp/node_tu# npm --version
8.19.4
263260e7c03d:/tmp/node_tu# npm config set tag-version-prefix 't'
263260e7c03d:/tmp/node_tu# npm config get tag-version-prefix
t
263260e7c03d:/tmp/node_tu# npm config set tag-version-prefix ''
263260e7c03d:/tmp/node_tu# npm config get tag-version-prefix
263260e7c03d:/tmp/node_tu#
I tried to workaround the problem by setting the environment variable NPM_CONFIG_TAG_VERSION_PREFIX
It does not work either
263260e7c03d:/tmp/node_tu# npm config set "tag-version-prefix=u" ; npm config get tag-version-prefix
u
263260e7c03d:/tmp/node_tu# export NPM_CONFIG_TAG_VERSION_PREFIX=tag
263260e7c03d:/tmp/node_tu# npm config set "tag-version-prefix=u" ; npm config get tag-version-prefix
tag
263260e7c03d:/tmp/node_tu# export NPM_CONFIG_TAG_VERSION_PREFIX=
263260e7c03d:/tmp/node_tu# npm config set "tag-version-prefix=u" ; npm config get tag-version-prefix
u # should have been empty
The only workaround I found was to set tag-version-prefix
directly in a .npmrc
file.
This behaviour is not consistent with the current documentation:
tag-version-prefix
Default: "v" Type: String
If set, alters the prefix used when tagging a new version when performing a version increment using npm version. To remove the prefix altogether, set it to the empty string: "".
Because other tools may rely on the convention that npm version tags look like v1.0.0, only use this property if it is absolutely necessary. In particular, use care when overriding this setting for public packages.
Any news about this ?
It's great that there's a work-around, though we've upgraded a number of projects to later versions of node that include this version of npm and we're now getting broken builds because we're extracting the version number from this function and need the tag prefix removed.