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

Target as a function #1052

Merged
merged 10 commits into from
Feb 28, 2022
Merged

Conversation

Primajin
Copy link
Contributor

@Primajin Primajin commented Feb 23, 2022

Closes #1034
Related: #958, #950, #581

The idea is to pass a function to target so that one can for example create a version of semver-like target:

  • return 'minor' for '^'
  • return 'patch' for '~'
target: (name, [{ operator }]) => operator === '^' ? 'minor' : operator === '~' ? 'patch' : 'latest'

(with the recent introduction in #1050 of filter as a function both can be combined to filter out pinned versions and versions that start with a 0 - re: #958) to fully achieve "safe" semver like versioning 🎉

target: (name, [{ operator }]) => operator === '^' ? 'minor' : operator === '~' ? 'patch' : 'latest',
filter: (_, [{ major, operator }]) => !(major === '0' || major === undefined || operator === undefined)

src/lib/queryVersions.ts Outdated Show resolved Hide resolved
test/index.test.ts Outdated Show resolved Hide resolved
@raineorshine
Copy link
Owner

So far I only pass version in as a string - could not yet wrap my head around SemVer utils though.

Use the same approach we used for filter:

filterFunction(name, semverutils.parseRange(version))
  1. The tests seem to run against live npm - how do we make sure that the expected latest version never changes other than choosing an old version and hope it doesn't get bumped? Can we not instead just mock the npm response?

I currently test against a package I control, https://github.com/raineorshine/ncu-test-v2, which will always have v2 as the latest. There is a suite of test packages used for testing other types of upgrades.

I think mocking the npm response would be a much better approach. I wish I had done that from the beginning. You're welcome to use either approach.

2. I couldn't reliably run the tests locally in test/index.test.ts without running everything - it always complained that pkgData is just a plain object and has no .should.have.stuff() - how do I run them locally as single tests?

I did some digging and turns out that was a bug! I was missing chai.should() from the test file. I added it in . It should work with that.

@Primajin
Copy link
Contributor Author

OK will bring in the changes in the coming week and then open up the PR for final review 🤞🏻

@Primajin Primajin marked this pull request as ready for review February 28, 2022 10:40
@Primajin
Copy link
Contributor Author

Alrighty ready for review 🤞🏻 🎉

@Primajin Primajin changed the title Draft: Target as a function Target as a function Feb 28, 2022
@Primajin
Copy link
Contributor Author

One last thing - should we somehow add the two filter + target as a new param/cli option?
As in semver = true sets both - so that people don't need to come up with the two functions I posted in the top?

target: (name, [{ operator }]) => operator === '^' ? 'minor' : operator === '~' ? 'patch' : 'latest',
filter: (_, [{ major, operator }]) => !(major === '0' || major === undefined || operator === undefined)

@raineorshine
Copy link
Owner

One last thing - should we somehow add the two filter + target as a new param/cli option?
As in semver = true sets both - so that people don't need to come up with the two functions I posted in the top?

Let's discuss in a separate issue. There's a bit more complexity to that.

@raineorshine raineorshine merged commit d335923 into raineorshine:main Feb 28, 2022
@raineorshine
Copy link
Owner

Published in v12.5.0

@Primajin Primajin deleted the target-as-a-function branch February 28, 2022 16:48
@Primajin
Copy link
Contributor Author

Primajin commented Mar 1, 2022

Oh by focusing only on the possible errors and tests etc. - I just realized we might want to tweak the success message 🤦🏻‍♂️

image

Maybe when it's a function we just call it "given" --> All dependencies match the given package versions :) ?

@raineorshine
Copy link
Owner

raineorshine commented Mar 1, 2022

Oops! Yes, I forgot target was used in a user message.

Let's say "target package versions":

All dependencies match the given package versions :)

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

Successfully merging this pull request may close these issues.

[FR] Introduce safe option
2 participants