-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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-version does not git-commit nor git-tag when package in subdirectory #2010
Comments
I just hit this issue using NPM workspaces on Node v15.2.1 / NPM v7.0.8 for Ubuntu. The problem may become more popular with workspaces containing independently versioned packages as they tend to use subdirectories. |
@niedzielski does it still occur with v7.0.15? |
@ljharb, yes. I can repro on NPM v7.0.15. Using a local installation of NPM: ../node_modules/.bin/npm version prerelease --preid=foo Changes the package version in my repo to |
This still occours in 7.5.4 |
npm If your bug is preproducible on If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo Closing: This is an automated message. |
Reopening; latest comment suggests it's still an issue in npm 7. |
This should be really easy to solve by using |
Workaround:
Edit.: My bad, the above tags the commit before "Bump version". This works: NEW_VERSION=$(npm version patch) \
&& add package.json package-lock.json \
&& git commit -m 'Bump version' \
&& git tag $NEW_VERSION I ended up putting everything into a #!/usr/bin/env bash
if [ "$1" != "major" ] && [ "$1" != "minor" ] && [ "$1" != "patch" ];
then
echo "Could not release!"
echo "Usage: 'npm run release -- (major|minor|patch)'"
echo ""
exit 1
fi
NEW_VERSION=$(npm version $1)
git add package.json package-lock.json
git commit -m 'Bump version'
git tag $NEW_VERSION
echo "Bumped version to $NEW_VERSION"
# Prompt for pushing
read -p "Push HEAD and tags to $NEW_VERSION? y/n " PUSH
if [ $PUSH = "y" ]
then
git push && git push --tags
else
echo "Not pushing."
fi Edit: Our new version of the release script. |
How can I point tagged version in commit message in this case? |
@Yegorich555 Sorry, I found out myself that my workaround does not work as intended, but I forgot to update my post. I edited the above post and added my current solution. 🙂 |
I think this will be fixed by replacing this call of git.is with git.find
I'm happy to create a PR if a maintaner is happy with this approach |
I've tested this actually with workspaces as I'm interested in what's going on in npm/rfcs#570 |
This is also in npm 8 |
Sorry to ping you directly @ljharb (you helped me in the past) but do you think my approach acceptable? |
@fernandopasik i have no idea; i'm not an npm maintainer |
Still a problem... |
Could we at least update the really misleading documentation about this? The work arounds are easy enough to implement, but its frustrating to follow the docs exactly and see unexpected behaviors. |
I was facing the same issue, However, I noticed I was not in the root folder. I moved to the project root folder run |
same issue on 8.12, came up with a work around for windows using cmd.exe as shell for npm scripts:
|
I replaced my yarn implementation with npm using a workspace. And I'm getting the following error when not in de root folder:
|
this is still present in NPM v9.5.0 It also silently killed my build, my build continued until I tried to push the tag created by npm version, which didn't exist... - task: Npm@1
displayName: 'NPM Version'
inputs:
command: 'custom'
workingDir: '$(Build.SourcesDirectory)/webapp'
customCommand: 'version --allow-same-version $(GitVersion.SemVer)'
verbose: true Yields:
I think that the
-- I'd merge it. |
Any progress on this being fixed - just encountered after upgrading from npm@6.14.16 to npm@8.19.4? I also agree with @ncook-hxgn suggestion to upgrade to a warning. @ncook-hxgn did you figure a solution or workaround to this problem? |
Indeedy I do, @dmcweeney - task: CmdLine@2
displayName: 'Git Tag'
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
inputs:
script: |
echo "##[command]https://github.com/npm/cli/issues/2010"
echo "##[group]workaround [BUG] npm-version does not git-commit nor git-tag when package in subdirectory #2010"
git add package.json package-lock.json
git commit -m "CI: bump package to v$(GitVersion.Semver)"
git tag -a v$(GitVersion.SemVer) -m v$(GitVersion.SemVer)
echo "##[endgroup]"
git push origin v$(GitVersion.SemVer)
workingDirectory: '$(Build.SourcesDirectory)/webapp' |
Thanks @ncook-hxgn ! |
I worked around this similarly in my npm scripts as: "scripts": {
...
"bump": "mkdir .git && npm version patch",
"version": "npm run build && git add -A .",
"postversion": "git push && git push --tags && rmdir .git"
} |
yikes |
Current Behavior:
npm version <version>
is not committing the modified package.json or package-lock.json; nor git-tagging.We were using
npm version {major|minor|patch}
extensively (and successfully). It stopped working once the package was moved out of the root of the repo and into a subdirectory.Expected Behavior:
npm version <version>
should continue to create a git-commit and git-tag as indicated in the docs:Steps To Reproduce:
npm version minor
successfully bumps the version, commits and tagsnpm version minor
still bumps the version in package.json and package-lock.json, but git is not committed nor tagged.Environment:
This is apparently an existing bug going as far back as npm v3: npm/npm#18795
The text was updated successfully, but these errors were encountered: