lerna / lerna/lerna

Version command fails when literal version contains leading zeros

Open
#2,840 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stale
Dominant language
TypeScript
Stars
36.1k
Forks
2.3k
Avg merge
1d 4h
Merged PRs (30d)
50

Description

Expected Behavior

lerna version 1.1.0124

Should set the version to 1.1.124 (or even 1.1.0124 since NPM doesn't seem to care).

Current Behavior

Fails with "ERR! lerna bump must be an explicit version string or one of: 'major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', or 'prerelease'."

Possible Solution

Normalize the version number.

My current solution in our CI bash script is this:

# Remove leading zeros in version number parts (Lerna doesn't like them).
shopt -s extglob # Turn on extended globs for the following pattern matching
VERSION=${VERSION##+(0)} # Remove all leading zeros
VERSION=${VERSION/#./0.} # Add a leading zero if only a leading dot (.) remains
VERSION=${VERSION//.+(0)/.} # Remove leading zeros from minor and patch numbers

Steps to Reproduce (for bugs)

lerna.json

{
  "version": "0.0.0",
  "npmClient": "yarn",
  "useWorkspaces": true
}

lerna-debug.log

<!-- If you have a `lerna-debug.log` available, please paste it here -->
<!-- Otherwise, feel free to delete this <details> block -->

Context

Our CI pipeline isn't very strict about putting together version numbers. The patch version frequently has leading zeros. This is the only tool that complains about that.

Your Environment

Executable Version
lerna --version 4.0.0
npm --version 6.14.5
yarn --version 1.22.10
node --version 12.18.1
OS Version
macOS Big Sur 11.2.2

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 with the lerna version command and the version argument handling; the issue demonstrates the failing input 1.1.0124 and includes a sample lerna.json. Verify the command accepts the literal version and produces the expected normalized version without the explicit-version error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.