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 version does not commit and tag without .git dir in cwd #3803

Closed
1 task done
trusktr opened this issue Sep 27, 2021 · 13 comments
Closed
1 task done

[BUG] npm version does not commit and tag without .git dir in cwd #3803

trusktr opened this issue Sep 27, 2021 · 13 comments
Labels
Bug thing that needs fixing cmd:version related to `npm version` Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release Release 8.x work is associated with a specific npm 8 release

Comments

@trusktr
Copy link

trusktr commented Sep 27, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I run npm version and no commit or tag is created. I am not using --no-git-tag-version. F.e. just npm version major -m "...".

Under what conditions does npm version avoid creating a commit and tag?

Expected Behavior

Always commit and tag unless I specify not to.

Steps To Reproduce

git clone https://github.com/lume/lume.git
cd lume/packages/lume
npm version major -m "v%s" --ignore-scripts

After this, you will see that package.json was updated, but no commit or tag was created.

Environment

  • OS: Linux
  • Node: 14.16
  • npm: 7.10
@trusktr trusktr added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Sep 27, 2021
@ljharb
Copy link
Collaborator

ljharb commented Sep 27, 2021

Do you have an .npmrc or any env vars that might be affecting npm’s config?

@ljharb
Copy link
Collaborator

ljharb commented Sep 27, 2021

Also, npm 7.10 is old, can you try with the latest v7?

@trusktr
Copy link
Author

trusktr commented Sep 27, 2021

Hello, I have an .npmrc in the project, but nothing suspicious (I avoid global configs):

package-lock=false
engine-strict=true

The package is not at the root of the repo. Does npm detect this and avoids committing/tagging if we're not at the root of the repo?

f.e. the repo is like this:

scripts/
dist-config/
the-actual-package/
  index.js
  package.json
  foo.js
  bar.js

and npm version is ran inside the-actual-package, and the-actual-package is what is actually published to npm.

@ljharb
Copy link
Collaborator

ljharb commented Sep 27, 2021

I doubt it - unless you're using npm workspaces, it should always find the closest package.json.

what does env | grep -i npm show? (don't forget to upgrade npm 7; there's been a lot of bug fixes since v7.10)

@trusktr
Copy link
Author

trusktr commented Sep 27, 2021

I edited my previous comment (in case you have to refresh) to show the repo layout.

I'm not using workspaces.

env | grep -i npm

PATH=/home/trusktr/.npm-packages/bin:/home/linuxbrew/.linuxbrew/bin:/home/trusktr/go/bin:/home/trusktr/.n-node-versions/bin:/home/trusktr/.local/bin:/usr/local/bin:/usr/bin:/var/lib/snapd/snap/bin:/usr/local/sbin:/opt/android-sdk/platform-tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/trusktr/.local/bin:/home/trusktr/.gem/ruby/1.9.1/bin:/home/trusktr/.gem/ruby/2.2.0/bin:/usr/local/bin:/home/trusktr/.vim/bundle/fzf/bin

(.npm-packages is just a location for rare global installs (npm, and few others) in my home folder instead of the normal location owned by root)

trusktr added a commit to lume/lume that referenced this issue Sep 28, 2021
We need to do this for now because while packages/lume/ is not at the
root of the repo, then `npm version` will not commit and tag like it
normally does. npm/cli#3803
@trusktr
Copy link
Author

trusktr commented Oct 1, 2021

Here is a reproduction:

git clone https://github.com/lume/lume.git
cd lume/packages/lume
npm version major -m "v%s" --ignore-scripts

After this, you will see that package.json was updated, but no commit or tag was created.

@trusktr
Copy link
Author

trusktr commented Oct 1, 2021

Is there a way to force it to commit and tag?

@ParadoxInfinite
Copy link

Hey @trusktr,
After creating a mock test of your use case I believe this is intended behaviour. Someone can correct me if I am wrong, but npm version command looks for a .git folder in the directory where you run the command, if no git folder is found, then it just leaves it be.
This can be seen from the code in the git module of npm which is what is used here.

And this makes sense to me, because if you increment the version of the subfolder, it isn't a bump in your package.json at the root of your project, correct? So it shouldn't tag/commit since the entire package/folder/repo wasn't versioned.

I would suggest to host your package lume as a separate repo and version that, use that as a submodule/dependency to your main project OR move up your main package to match up with the repo's root. I don't know how this would affect your codebase or if this is even feasible, but something to consider. Again, I might be entirely wrong, and if I am, someone please correct me.

@trusktr
Copy link
Author

trusktr commented Oct 6, 2021

Hmm. This issue makes working with postversion, or other hooks used for release processes, difficult because those scripts (which in this case come from a re-usable lib) use git stash, git add, npm publish, and other commands to manage releases.

This means I can't re-use this release process unless I move lume to the root, or to a new repo like you suggested (either of those options has a downside, like messing with how Lerna works, or moving code away from the main repo with all the original commit history, etc).

It would be great if an explicit passing of --git-tag-version would force the commit/tag attempt.

Longer term, I do believe that having the main package at the root of a repo would make most sense. This is just how things are at the moment.

@ParadoxInfinite
Copy link

Since you raised this bug on npm v7.10 and I've tried this with v7.24.1, has this worked before? On some previous version of npm maybe? If you could find that out, I'd be more than happy to take a look at what changed and see if it was an intended change.

@trusktr
Copy link
Author

trusktr commented Nov 18, 2021

I haven't had time to look at that, but I ended up moving the project to the top level of my repo, and luckily that worked out with Lerna, so the npm publish process works as expected now in that case.

@lukekarrys lukekarrys changed the title [BUG] npm version does not commit and tag [BUG] npm version does not commit and tag without .git dir in cwd Mar 1, 2022
@lukekarrys
Copy link
Contributor

I believe this is the same issue causing npm version patch -w <workspace> to not create commits and tags either

@lukekarrys lukekarrys added Release 8.x work is associated with a specific npm 8 release cmd:version related to `npm version` Priority 1 high priority issue and removed Needs Triage needs review for next steps labels Mar 1, 2022
@lukekarrys
Copy link
Contributor

Closing as a duplicate of #2010. Slightly difference cases to reproduce, but if #2010 is fixed, this will be fixed also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing cmd:version related to `npm version` Priority 1 high priority issue Release 7.x work is associated with a specific npm 7 release Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

4 participants