mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-15 09:06:25 +00:00
e5c6f38d75
* refactor: enable strict checks * chore: revert changes * chore: fix tsconfig
40 lines
1.2 KiB
TypeScript
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';
|
|
}
|