-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mix): implement custom getRangeStrategy
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { RangeConfig } from '../types'; | ||
import { getRangeStrategy } from '.'; | ||
|
||
describe('modules/manager/mix/range', () => { | ||
it('returns same if not auto', () => { | ||
const config: RangeConfig = { rangeStrategy: 'pin' }; | ||
expect(getRangeStrategy(config)).toBe('pin'); | ||
|
||
config.rangeStrategy = 'widen'; | ||
expect(getRangeStrategy(config)).toBe('widen'); | ||
}); | ||
|
||
it('widens complex bump', () => { | ||
const config: RangeConfig = { | ||
rangeStrategy: 'bump', | ||
depType: 'prod', | ||
currentValue: '>= 1.6.0 and < 2.0.0', | ||
}; | ||
expect(getRangeStrategy(config)).toBe('widen'); | ||
}); | ||
|
||
it('bumps non-complex bump', () => { | ||
const config: RangeConfig = { | ||
rangeStrategy: 'bump', | ||
depType: 'prod', | ||
currentValue: '~>1.0.0', | ||
}; | ||
expect(getRangeStrategy(config)).toBe('bump'); | ||
}); | ||
|
||
it('widens complex auto', () => { | ||
const config: RangeConfig = { | ||
rangeStrategy: 'auto', | ||
depType: 'prod', | ||
currentValue: '<1.7.0 or ~>1.7.1', | ||
}; | ||
expect(getRangeStrategy(config)).toBe('widen'); | ||
}); | ||
|
||
it('defaults to update-lockfile', () => { | ||
const config: RangeConfig = { | ||
rangeStrategy: 'auto', | ||
depType: 'prod', | ||
}; | ||
expect(getRangeStrategy(config)).toBe('update-lockfile'); | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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 { currentValue, rangeStrategy } = config; | ||
const isComplexRange = currentValue | ||
? parseRange(currentValue).length > 1 | ||
: false; | ||
|
||
if (rangeStrategy === 'bump' && isComplexRange) { | ||
logger.debug( | ||
{ currentValue }, | ||
'Replacing bump strategy for complex range with widen', | ||
); | ||
return 'widen'; | ||
} | ||
if (rangeStrategy !== 'auto') { | ||
return rangeStrategy; | ||
} | ||
if (isComplexRange) { | ||
return 'widen'; | ||
} | ||
return 'update-lockfile'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters