npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

npm version not creating git commits when in sub-directory

What I Wanted to Do

I have my npm library not in the root git folder but a subfolder.
I wanted to bump a version:

npm version minor

I expected it to commit the change to git and tag it.

What Happened Instead

When I ran npm version minor no git commit and no git tag were made.

Reproduction Steps

Create a git repository with an npm project in a subdirectory.
Then try to bump the version in the directory.

mkdir npm-version-no-git-commit
cd npm-version-no-git-commit
git init
mkdir test-package
cd test-package
npm init -y
git add .
git commit -m 'Initial commit'
npm version minor
git diff --quiet || echo 'dirty'


Platform Info

$ npm --versions
{ 'test-package': '1.1.0',
  npm: '6.10.1',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.8.0',
  icu: '64.2',
  modules: '64',
  napi: '4',
  nghttp2: '1.34.0',
  node: '10.16.0',
  openssl: '1.1.1b',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.28.0',
  v8: '',
  zlib: '1.2.11' }

$ node -p process.platform

Issue is probably this:

It doesn’t check properly if it’s in a git folder or not, it assumes the command cannot be run in a sub-folder.

Opened a PR for it, because it turns out it’s an easy fix.

Interesting. I see what you expected when your package was the only one in the repo.

The current behaviour may be deliberate for safety. In a repo with multiple packages, it would not make sense to tag the repo with an anonymous version number from a single package.

Still it should at least warn that it won’t create the commit even though its a Git repo. The current behaviour is quite unspecified, so even if it were deliberate, there’s no signs pointing to that.