renovate/lib/modules/manager/npm/range.ts
Michael Kriese e5c6f38d75
refactor: enable strict checks (#16168)
* refactor:  enable strict checks

* chore: revert changes

* chore: fix tsconfig
2022-06-21 13:00:21 +02:00

40 lines
1.2 KiB
TypeScript

import { parseRange } from 'semver-utils';
import { logger } from '../../../logger';
import type { RangeStrategy } from '../../../types';
import type { RangeConfig } from '../types';
export function getRangeStrategy(config: RangeConfig): RangeStrategy {
const { depType, depName, packageJsonType, currentValue, rangeStrategy } =
config;
// TODO #7154
const isComplexRange = parseRange(currentValue!).length > 1;
if (rangeStrategy === 'bump' && isComplexRange) {
logger.debug(
{ currentValue },
'Replacing bump strategy for complex range with widen'
);
return 'widen';
}
if (rangeStrategy !== 'auto') {
return rangeStrategy;
}
if (depType === 'devDependencies') {
// Always pin devDependencies
logger.trace({ dependency: depName }, 'Pinning devDependency');
return 'pin';
}
if (depType === 'dependencies' && packageJsonType === 'app') {
// Pin dependencies if we're pretty sure it's not a browser library
logger.trace({ dependency: depName }, 'Pinning app dependency');
return 'pin';
}
if (depType === 'peerDependencies') {
// Widen peer dependencies
logger.debug('Widening peer dependencies');
return 'widen';
}
if (isComplexRange) {
return 'widen';
}
return 'replace';
}