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

refactor: yarn constraint determination #27741

Closed
wants to merge 3 commits into from
Closed

Conversation

rarkins
Copy link
Collaborator

@rarkins rarkins commented Mar 6, 2024

Changes

Refactors and adds a test for yarn constraint determination.

Context

Preparing for #27656

Documentation (please check one with an [x])

  • I have updated the documentation, or
  • No documentation update is required

How I've tested my work (please select one)

I have verified these changes via:

  • Code inspection only, or
  • Newly added/modified unit tests, or
  • No unit tests but ran on a real repository, or
  • Both unit tests + ran on a real repository

@rarkins rarkins requested a review from viceice March 6, 2024 07:03
@rarkins rarkins enabled auto-merge March 6, 2024 07:04
@rarkins
Copy link
Collaborator Author

rarkins commented Mar 6, 2024

Apparently we fall back to Yarn 2 right now:

export function getYarnVersionFromLock(lockfile: LockFile): string {
const { lockfileVersion, isYarn1 } = lockfile;
if (isYarn1) {
return '^1.22.18';
}
if (lockfileVersion && lockfileVersion >= 8) {
// https://github.com/yarnpkg/berry/commit/9bcd27ae34aee77a567dd104947407532fa179b3
return '^3.0.0';
} else if (lockfileVersion && lockfileVersion >= 6) {
// https://github.com/yarnpkg/berry/commit/f753790380cbda5b55d028ea84b199445129f9ba
return '^2.2.0';
}
return '^2.0.0';
}

@rarkins rarkins marked this pull request as draft March 6, 2024 07:31
auto-merge was automatically disabled March 6, 2024 07:31

Pull request was converted to draft

@@ -409,6 +409,47 @@ describe('modules/manager/npm/post-update/yarn', () => {
expect(res.lockFile).toBe('package-lock-contents');
});

it('falls back to Yarn v1 for undefined constraint', async () => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apparently we default to Yarn v2 due to this:

export function getYarnVersionFromLock(lockfile: LockFile): string {
const { lockfileVersion, isYarn1 } = lockfile;
if (isYarn1) {
return '^1.22.18';
}
if (lockfileVersion && lockfileVersion >= 8) {
// https://github.com/yarnpkg/berry/commit/9bcd27ae34aee77a567dd104947407532fa179b3
return '^3.0.0';
} else if (lockfileVersion && lockfileVersion >= 6) {
// https://github.com/yarnpkg/berry/commit/f753790380cbda5b55d028ea84b199445129f9ba
return '^2.2.0';
}
return '^2.0.0';
}

Comment on lines +124 to +125
logger.debug('No yarn constraint found');
return undefined;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These lines are unreachable due to

export function getYarnVersionFromLock(lockfile: LockFile): string {
const { lockfileVersion, isYarn1 } = lockfile;
if (isYarn1) {
return '^1.22.18';
}
if (lockfileVersion && lockfileVersion >= 8) {
// https://github.com/yarnpkg/berry/commit/9bcd27ae34aee77a567dd104947407532fa179b3
return '^3.0.0';
} else if (lockfileVersion && lockfileVersion >= 6) {
// https://github.com/yarnpkg/berry/commit/f753790380cbda5b55d028ea84b199445129f9ba
return '^2.2.0';
}
return '^2.0.0';
}

Copy link
Member

Choose a reason for hiding this comment

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

so simply return lock constraint?

logger.debug('Using yarn update newValue as constraint');
return yarnUpdate.newValue;
}
if (config.constraints?.yarn) {
Copy link
Member

Choose a reason for hiding this comment

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

didn't we agree to use this first?

Comment on lines +124 to +125
logger.debug('No yarn constraint found');
return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

so simply return lock constraint?

@viceice
Copy link
Member

viceice commented Mar 10, 2024

we should latest yarn if no constraints can be found.

@rarkins rarkins closed this Mar 11, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2024
@rarkins rarkins deleted the refactor/yarn-constraint branch April 22, 2024 05:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants