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

rejectVersionFunction gets the semver string as its first argument, not the name of the package #1442

Open
1 task done
MissingNoIOI opened this issue Aug 6, 2024 · 6 comments
Labels

Comments

@MissingNoIOI
Copy link

MissingNoIOI commented Aug 6, 2024


Steps to Reproduce

.ncurc.js:

module.exports = {
  rejectVersion: (name, semver) => {
    console.log(name)
    if (name == 'chai' && parseInt(semver[0]?.major) >= 5) {
      return true
    }
    if (name == 'sinon-chai' && parseInt(semver[0]?.major) >= 4) {
      return true
    }
    if (name == 'chai-exclude' && parseInt(semver[0]?.major) >= 3) {
      return true
    }
    if (name == 'sort-keys' && parseInt(semver[0]?.major) >= 5) {
      return true
    }
    if (name == '@typescript-eslint/parser' && parseInt(semver[0]?.major) >= 7) {
      return true
    }
    if (name == '@typescript-eslint/eslint-plugin' && parseInt(semver[0]?.major) >= 7) {
      return true
    }
    return false
  }
}

Steps:
Execute ncu with this configuration file

Current Behavior

The first argument that gets passed in is the string of the version, like "^4.3.16"

Expected Behavior

The first argument that gets passed in should be the name of the package, as described in the documentation. This way the rejectVersion function is not really useful

@raineorshine
Copy link
Owner

raineorshine commented Aug 6, 2024

Hi, thanks for reporting.

Yes, that's definitely not right. I'll work on cleaning that up. Any change in behavior will have to wait for a major version update, but in the mean time can you try switching to reject or filter instead of rejectVersion? I believe they pass (name, semver) as expected.

@MissingNoIOI
Copy link
Author

Yeah, with reject it inputs the name correctly, but the semver is now the current version, instead of the one to be upgraded to, so I cant filter the version either.

@raineorshine
Copy link
Owner

raineorshine commented Aug 9, 2024

filter and reject run before the latest versions are fetched, so you will not have access to the upgraded versions there. They are preferred when only filtering based on name or current version because they reduce the number of HTTP requests.

filterResults runs after the latest versions are fetched, allowing you to filter on the upgraded version.

@rubiesonthesky
Copy link

I have same problem with filterVersion, it's returning version instead of name so I can't filter out broken package version. Are there any way to some how reject or filter out this one version of certain package?

  filterVersion: (name, semver) => {
    if (name === 'codemirror' && semver[0]?.semver === '6.65.7') {
      return false
    }
    return true
  }

@rubiesonthesky
Copy link

^ I was able to achieve what I wanted with this code:

  filterResults: (packageName, {upgradedVersion}) => {
    console.log(packageName, upgradedVersion)
    if (packageName === 'codemirror' && upgradedVersion === '6.65.7') {
      return false
    }
    return true
  }

But the Readme is incorrect for filterResults. It says that the arguments are like packageName, { current, currentSemver, upgraded, upgradedSemver } when in practise the second object contains currentVersion, currentVersionSemver, upgradedVersion and upgradeVersionSemver.

@raineorshine
Copy link
Owner

raineorshine commented Nov 7, 2024

Thanks, I will update the README!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants