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

fix: yarn getPeerDependencies doesnt work on private reporsitories wh… #1471

Merged
merged 1 commit into from
Oct 27, 2024

Conversation

rbnayax
Copy link
Contributor

@rbnayax rbnayax commented Oct 27, 2024

…en credentials are only set for yarn and not npm

fix: #1470

@@ -26,8 +26,8 @@ describe('npm', function () {
})

it('getPeerDependencies', async () => {
await npm.getPeerDependencies('ncu-test-return-version', '1.0').should.eventually.deep.equal({})
await npm.getPeerDependencies('ncu-test-peer', '1.0').should.eventually.deep.equal({
await npm.getPeerDependencies('ncu-test-return-version', '1.0.0').should.eventually.deep.equal({})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raineorshine as far as I understand, this method will only be called with specific versions.
If that is not the case, please let me know as the yarn version doesn't support specs currently

Copy link
Owner

@raineorshine raineorshine Oct 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPeerDependenciesFromRegistry is presumed to only get exact versions numbers:

async function getPeerDependenciesFromRegistry(packageMap: Index<Version>, options: Options) {

However, runLocal incorrectly passes a version spec:

Object.entries(current).map(([packageName, versionSpec]) => {

I'm not actually sure what npm's behavior is when given a spec. Does it get the peer dependencies at the bottom of the range? Top of the range?

Open to your suggestion of how to best handle this. There is some risk of regression if we change runLocal to pass an exact version. If just limited the conversion to just yarn that would limit the surface area of the change, at the expense of some consistency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From docs at https://docs.npmjs.com/cli/v7/commands/npm-view

If the version range matches multiple versions then each printed value will be prefixed with the version it applies to.

Running this locally with the json flag returns many json objects, for each version in the spec.
Running it in the code, this returns an array.
In case the sepc is only resolved to a single version (like in the test) this will work as it will not return an array.
So seems like this should not work at all if it is given a spec that resolves to multiple versions (but it will not fail)
I think that we need to fix the runLocal behaviour, thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn v2 works by giving latest version of the spec
we can make the same behavior for npm where we take the last element from the array, if such exists
the issue lies with yarn v1 which doesn't support spec at all. Let me check if that can be handled

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, never mind. It was staring me right in the face; it already converts to minVersion of the range, that's why it works. We don't need to change anything.

? (nodeSemver.minVersion(versionSpec)?.version ?? versionSpec)

The behavior is indeterminate of the spec is not a valid version range, but there's no need to address that at this point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see but we have that in another place:

const upgradedPeerDependenciesLatest = await getPeerDependenciesFromRegistry(upgradedLatestVersions, options)

Which as far as I understand does provide a spec. Should I fix that with same mechanism of minVersion?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Good catch.

I jumped the gun. Was trying to get it merged before my lunch break 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha Ok on it in another PR

@rbnayax
Copy link
Contributor Author

rbnayax commented Oct 27, 2024

@raineorshine would appreciate your review :-)

@raineorshine raineorshine merged commit 9d38d58 into raineorshine:main Oct 27, 2024
7 checks passed
@rbnayax rbnayax deleted the #1470 branch October 27, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants