npm / npm/cli

[BUG] npm-version does not git-commit nor git-tag when package in subdirectory

Open
#2,010 27 comments 32 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug cmd:version Priority 2 Release 7.x Release 8.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

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:

If run in a git repo, it will also create a version commit and tag. This behavior is controlled by git-tag-version (see below), and can be disabled on the command line by running npm --no-git-tag-version version. It will fail if the working directory is not clean, unless the -f or --force flag is set.

Steps To Reproduce:
  1. initialize an npm package in the root of an initialized git repo
  2. npm version minor successfully bumps the version, commits and tags
  3. move the npm package into a subdirectory of the repo
  4. npm version minor still bumps the version in package.json and package-lock.json, but git is not committed nor tagged.
Environment:
  • macOS 10.15.7
  • node: v14.13.1
  • npm: 6.14.8
  • git: git version 2.28.0

This is apparently an existing bug going as far back as npm v3: https://github.com/npm/npm/issues/18795

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the documented steps with an npm package moved into a repository subdirectory, then trace the npm version command's handling of the package and repository roots. Done means npm version still updates package.json and package-lock.json while creating the expected git commit and tag.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.