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

feature request: target that respects range grammar in package.json (~1.0.0, ^1.0.0, etc) #950

Closed
3 tasks done
ex-nerd opened this issue Sep 21, 2021 · 3 comments
Closed
3 tasks done

Comments

@ex-nerd
Copy link
Contributor

ex-nerd commented Sep 21, 2021

  • I have searched for similar issues
  • I am using the latest version of npm-check-updates
  • I am using node >= 10.17

Steps to Reproduce

The current --target options lack a way to say "upgrade to the latest values allowed by my package.json" (following semver range syntax). This would basically be the equivalent of rm -rf node_modules && npm install and then finding the versions that were installed to put them back in package.json.

This isn't simply a matter of using --target patch because I often have mixed requirements in package.json where I want to allow only patch updates to some packages, but want minor updates on others.

I thought this was an issue with how --minimal works (since I interpreted that as "the update the minimal amount" instead of "update a minimal number of packages"), but found #746 saying this is expected behavior. So instead of a bug, this is a feature request.

Current Behavior

package1 ~1.0.0~1.2.0
package2 ^1.0.0^2.0.0
package3 1.0.01.1.0

Expected Behavior

package1 ~1.0.0~1.0.1
package2 ^1.0.0^1.2.0
package3 1.0.01.0.0

@raineorshine
Copy link
Owner

Thanks for the suggestion! This is a great idea. For most users I would suggest using npm update as designed to achieve this behavior with semver. However, you are not the first to want greater control over the version numbers in the package.json.

The proposed addition would be a welcome contribution, it's just in need of a contributor. For historical discussion, see #581.

@raineorshine
Copy link
Owner

raineorshine commented Feb 28, 2022

As of v12.5.0, you can specify a custom target function in your .ncurc.js file, or when importing npm-check-updates as a module:

/** Custom target.
  @param dependencyName The name of the dependency.
  @param parsedVersion A parsed Semver object from semver-utils.
    (See https://git.coolaj86.com/coolaj86/semver-utils.js#semverutils-parse-semverstring)
  @returns One of the valid target values (specified in the table above).
*/
target: (dependencyName, [{ semver, version, operator, major, minor, patch, release, build }]) => {
  if (major === '0') return 'minor'
  return 'latest'
}

You can hack together your own semver-like target logic, but the intention is to eventually add a --semver option that handles this for you.

@raineorshine
Copy link
Owner

Closing as duplicate of #1054

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

No branches or pull requests

2 participants