Skip to content
Snippets Groups Projects
Unverified Commit 0f238918 authored by Jamie Magee's avatar Jamie Magee Committed by GitHub
Browse files

fix(yarn): incorrect logic around caching of locked versions (#7330)

The issue is that the compatibility was only being set for the first `package.json` that was detected, due to how this if/else statement was constructed.

https://github.com/renovatebot/renovate/blob/1b99f4f0f7011f48b90250540c2b60cf2b1c9d20/lib/manager/npm/extract/locked-versions.ts#L16-L30

`isYarn1`, and the following logic, was only being executed if the lockfile was _not_ found in the cache.
parent 1b99f4f0
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ import { getYarnLock } from './yarn'; ...@@ -7,7 +7,7 @@ import { getYarnLock } from './yarn';
export async function getLockedVersions( export async function getLockedVersions(
packageFiles: PackageFile[] packageFiles: PackageFile[]
): Promise<void> { ): Promise<void> {
const lockFileCache: Record<string, Record<string, string>> = {}; const lockFileCache: Record<string, YarnLockCache> = {};
logger.debug('Finding locked versions'); logger.debug('Finding locked versions');
for (const packageFile of packageFiles) { for (const packageFile of packageFiles) {
const { yarnLock, npmLock, pnpmShrinkwrap } = packageFile; const { yarnLock, npmLock, pnpmShrinkwrap } = packageFile;
...@@ -15,34 +15,42 @@ export async function getLockedVersions( ...@@ -15,34 +15,42 @@ export async function getLockedVersions(
logger.trace('Found yarnLock'); logger.trace('Found yarnLock');
if (!lockFileCache[yarnLock]) { if (!lockFileCache[yarnLock]) {
logger.trace('Retrieving/parsing ' + yarnLock); logger.trace('Retrieving/parsing ' + yarnLock);
const { lockedVersions, cacheVersion, isYarn1 } = await getYarnLock( lockFileCache[yarnLock] = await getYarnLock(yarnLock);
yarnLock }
); const { cacheVersion, isYarn1 } = lockFileCache[yarnLock];
lockFileCache[yarnLock] = lockedVersions; if (!isYarn1) {
if (!isYarn1) { if (cacheVersion >= 6) {
if (cacheVersion >= 6) { // https://github.com/yarnpkg/berry/commit/f753790380cbda5b55d028ea84b199445129f9ba
// https://github.com/yarnpkg/berry/commit/f753790380cbda5b55d028ea84b199445129f9ba packageFile.compatibility.yarn = '>= 2.2.0';
packageFile.compatibility.yarn = '>= 2.2.0'; } else {
} else { packageFile.compatibility.yarn = '>= 2.0.0';
packageFile.compatibility.yarn = '>= 2.0.0';
}
} }
} }
for (const dep of packageFile.deps) { for (const dep of packageFile.deps) {
dep.lockedVersion = dep.lockedVersion =
lockFileCache[yarnLock][`${dep.depName}@${dep.currentValue}`]; lockFileCache[yarnLock].lockedVersions[
`${dep.depName}@${dep.currentValue}`
];
} }
} else if (npmLock) { } else if (npmLock) {
logger.debug('Found ' + npmLock + ' for ' + packageFile.packageFile); logger.debug('Found ' + npmLock + ' for ' + packageFile.packageFile);
if (!lockFileCache[npmLock]) { if (!lockFileCache[npmLock]) {
logger.trace('Retrieving/parsing ' + npmLock); logger.trace('Retrieving/parsing ' + npmLock);
lockFileCache[npmLock] = await getNpmLock(npmLock); lockFileCache[npmLock] = { lockedVersions: await getNpmLock(npmLock) };
} }
for (const dep of packageFile.deps) { for (const dep of packageFile.deps) {
dep.lockedVersion = valid(lockFileCache[npmLock][dep.depName]); dep.lockedVersion = valid(
lockFileCache[npmLock].lockedVersions[dep.depName]
);
} }
} else if (pnpmShrinkwrap) { } else if (pnpmShrinkwrap) {
logger.debug('TODO: implement pnpm-lock.yaml parsing of lockVersion'); logger.debug('TODO: implement pnpm-lock.yaml parsing of lockVersion');
} }
} }
} }
interface YarnLockCache {
lockedVersions: Record<string, string>;
cacheVersion?: number;
isYarn1?: boolean;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment