Skip to content

Commit

Permalink
chore(yarn): improve logging for version detection (#27629)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 29, 2024
1 parent f6fc128 commit 5c38694
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/modules/manager/npm/extract/yarn.ts
Expand Up @@ -21,6 +21,9 @@ export async function getYarnLock(filePath: string): Promise<LockFile> {
if (key === '__metadata') {
// yarn 2
lockfileVersion = parseInt(val.cacheKey, 10);
logger.once.debug(
`yarn.lock ${filePath} has __metadata.cacheKey=${lockfileVersion}`,
);
} else {
for (const entry of key.split(', ')) {
try {
Expand All @@ -39,8 +42,18 @@ export async function getYarnLock(filePath: string): Promise<LockFile> {
}
}
}
const isYarn1 = !('__metadata' in parsed);
if (isYarn1) {
logger.once.debug(
`yarn.lock ${filePath} is has no __metadata so is yarn 1`,
);
} else {
logger.once.debug(
`yarn.lock ${filePath} is has __metadata so is yarn 2+`,
);
}
return {
isYarn1: !('__metadata' in parsed),
isYarn1,
lockfileVersion,
lockedVersions,
};
Expand Down
13 changes: 11 additions & 2 deletions lib/modules/manager/npm/post-update/utils.ts
@@ -1,4 +1,5 @@
import upath from 'upath';
import { logger } from '../../../../logger';
import { readLocalFile } from '../../../../util/fs';
import { Lazy } from '../../../../util/lazy';
import { PackageJson, PackageJsonSchema } from '../schema';
Expand Down Expand Up @@ -30,10 +31,18 @@ export function getPackageManagerVersion(
pkg: PackageJsonSchema,
): string | null {
if (pkg.packageManager?.name === name) {
return pkg.packageManager.version;
const version = pkg.packageManager.version;
logger.debug(
`Found ${name} constraint in package.json packageManager: ${version}`,
);
return version;
}
if (pkg.engines?.[name]) {
return pkg.engines[name];
const version = pkg.engines[name];
logger.debug(
`Found ${name} constraint in package.json engines: ${version}`,
);
return version;
}
return null;
}

0 comments on commit 5c38694

Please sign in to comment.