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

npx taze major and npx taze minor generate different minor outputs when major version is 0 #54

Open
5 tasks done
runofthemill opened this issue Nov 28, 2022 · 7 comments

Comments

@runofthemill
Copy link

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

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@ntnyq
Copy link
Contributor

ntnyq commented Jan 12, 2023

Major version equal to zero is an exception

@runofthemill
Copy link
Author

@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.

@antfu
Copy link
Member

antfu commented Jan 13, 2023

The behavior is expected. Only the output for counters needs some improvements. PR welcome

@runofthemill
Copy link
Author

@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?

@antfu
Copy link
Member

antfu commented Jan 17, 2023

❯ 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.

@runofthemill
Copy link
Author

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
}

@antfu
Copy link
Member

antfu commented Jan 23, 2023

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?

a1mersnow added a commit to a1mersnow/taze that referenced this issue Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants