fix(npm): better logs when transitive remediation is prevented

This commit is contained in:
Rhys Arkins 2021-05-14 12:44:02 +02:00
parent c482661cf5
commit 570ce0ccee
2 changed files with 24 additions and 10 deletions

View file

@ -1,4 +1,5 @@
import type { PackageJson } from 'type-fest'; import type { PackageJson } from 'type-fest';
import { logger } from '../../../../logger';
import { api as semver } from '../../../../versioning/npm'; import { api as semver } from '../../../../versioning/npm';
import type { PackageLockOrEntry, ParentDependency } from './types'; import type { PackageLockOrEntry, ParentDependency } from './types';
@ -29,7 +30,10 @@ export function findDepConstraints(
const { dependencies, requires, version } = lockEntry; const { dependencies, requires, version } = lockEntry;
if (parentDepName && requires) { if (parentDepName && requires) {
const constraint = requires[depName]; const constraint = requires[depName];
if (constraint && semver.matches(currentVersion, constraint)) { if (constraint) {
// istanbul ignore else
if (semver.isValid(constraint)) {
if (semver.matches(currentVersion, constraint)) {
if (constraint === currentVersion) { if (constraint === currentVersion) {
// Workaround for old versions of npm which wrote the exact version in requires instead of the constraint // Workaround for old versions of npm which wrote the exact version in requires instead of the constraint
requires[depName] = newVersion; requires[depName] = newVersion;
@ -40,6 +44,13 @@ export function findDepConstraints(
constraint, constraint,
}); });
} }
} else {
logger.warn(
{ parentDepName, depName, currentVersion, constraint },
'Parent constraint is invalid'
);
}
}
} }
if (dependencies) { if (dependencies) {
for (const [packageName, dependency] of Object.entries(dependencies)) { for (const [packageName, dependency] of Object.entries(dependencies)) {

View file

@ -89,7 +89,10 @@ export async function updateLockedDependency(
); );
logger.trace({ deps: lockedDeps, constraints }, 'Matching details'); logger.trace({ deps: lockedDeps, constraints }, 'Matching details');
if (!constraints.length) { if (!constraints.length) {
logger.warn('Could not find constraints for the locked dependency'); logger.info(
{ depName, currentVersion, newVersion },
'Could not find constraints for the locked dependency - cannot remediate'
);
return null; return null;
} }
const parentUpdates: UpdateLockedConfig[] = []; const parentUpdates: UpdateLockedConfig[] = [];