taze
taze copied to clipboard
`npx taze major` and `npx taze minor` generate different minor outputs when major version is 0
Describe the bug
It looks like taze minor
and taze major
interpret minor changes differently when the major version is 0
; I think this is unexpected behavior, but let me know if it is meant to be this way!
In the repro:
❯ npx taze minor
success Install finished in 5.57s
dependencies are already up-to-date
~/projects/node-ugjrw2 7s
❯ npx taze major
success Install finished in 5.601s
node-starter - 1 minor
vitest dev ~2mo ^0.23.4 → ^0.25.3 ~6d
Add -w to write package.json
Reproduction
https://stackblitz.com/edit/node-ugjrw2?file=package.json&view=editor
System Info
❯ npx envinfo --system --binaries --browsers
success Install finished in 6.376s
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 7.17.0 - /usr/local/bin/npm
Used Package Manager
npm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guide.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- [X] The provided reproduction is a minimal reproducible of the bug.
Major version equal to zero is an exception
@ntnyq yep so perhaps the behavior is expected, but I would expect this:
❯ npx taze minor
success Install finished in 5.57
node-starter - 1 minor
vitest dev ~2mo ^0.23.4 → ^0.25.3 ~6d
Add -w to write package.json
~/projects/node-ugjrw2 7s
❯ npx taze major
success Install finished in 5.601s
node-starter - 1 minor
vitest dev ~2mo ^0.23.4 → ^0.25.3 ~6d
Add -w to write package.json
or this:
❯ npx taze minor
success Install finished in 5.57s
dependencies are already up-to-date
~/projects/node-ugjrw2 7s
❯ npx taze major
success Install finished in 5.601s
dependencies are already up-to-date
But instead there's nothing in taze minor
and a minor update visible in taze major
, which appears (to me) to be inconsistent, major version 0 or not.
The behavior is expected. Only the output for counters needs some improvements. PR welcome
@antfu which outputs need improvement? I might be able to work on that :)
could you help me understand why the behavior is expected? it seems counterintuitive that a minor
update would show up for taze major
but not taze minor
. unless vitest ^0.23.4 → ^0.27.1
is being misclassified as minor
?
❯ npx taze major
- node-starter - 1 minor
+ node-starter - 1 major
vitest dev ~2mo ^0.23.4 → ^0.25.3 ~6d
The counter is wrong. But it only shows up with taze major
so I consider it expected.
So seems like I'm entering a rabbit hole 😅
A minimal reproduction classifies 0.23.4 → 0.25.3
as a minor
change:
const semver = require('semver'); // "semver": "^7.3.8" in package.json
console.log(`${semver.diff('0.23.4', '0.25.3')}`); // outputs "minor"
What do you think about a minimal change like this?
// src/utils/versions.ts
export function changeVersionRange(version: string, mode: Exclude<RangeMode, 'latest' | 'newest'>) {
if (!semver.validRange(version))
return null
if (mode === 'default')
return version
const min = semver.minVersion(version)
if (!min)
return null
+ if (semver.major(min) === 0 && mode === 'minor')
+ return `>=${min} <1.x`
return {
major: '>=',
minor: '^',
patch: '~',
}[mode] + min
}
Isn't your change making it the opposite? 0.x
change should be considered as major. I feel it's something wrong with semver.diff
, maybe we should patch it instead?