-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(groups): pin a version group to a specific version
- Loading branch information
1 parent
c64a109
commit 3de6f90
Showing
7 changed files
with
88 additions
and
8 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
57 changes: 57 additions & 0 deletions
57
src/bin-fix-mismatches/get-expected-version/get-expected-version.spec.ts
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,57 @@ | ||
import { getExpectedVersion } from '.'; | ||
import type { Instance } from '../../lib/get-input/get-instances'; | ||
|
||
it('applies pinned versions first', () => { | ||
expect( | ||
getExpectedVersion( | ||
'foo', | ||
{ instances: [], pinVersion: '2.2.2' }, | ||
{ wrappers: [] }, | ||
), | ||
).toEqual('2.2.2'); | ||
}); | ||
|
||
it('applies matching local package versions second', () => { | ||
expect( | ||
getExpectedVersion( | ||
'foo', | ||
{ instances: [] }, | ||
{ | ||
wrappers: [ | ||
{ | ||
contents: { name: 'bar', version: '0.1.0' }, | ||
filePath: '', | ||
json: '', | ||
}, | ||
{ | ||
contents: { name: 'foo', version: '1.2.3' }, | ||
filePath: '', | ||
json: '', | ||
}, | ||
], | ||
}, | ||
), | ||
).toEqual('1.2.3'); | ||
}); | ||
|
||
it('applies the highest installed version third', () => { | ||
expect( | ||
getExpectedVersion( | ||
'foo', | ||
{ | ||
instances: [ | ||
{ version: '2.0.0' }, | ||
{ version: '3.0.0' }, | ||
{ version: '1.0.0' }, | ||
] as Instance[], | ||
}, | ||
{ wrappers: [] }, | ||
), | ||
).toEqual('3.0.0'); | ||
}); | ||
|
||
it('returns an empty string if nothing matches', () => { | ||
expect( | ||
getExpectedVersion('foo', { instances: [] }, { wrappers: [] }), | ||
).toEqual(''); | ||
}); |
7 changes: 7 additions & 0 deletions
7
src/bin-fix-mismatches/get-expected-version/get-pinned-version.ts
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,7 @@ | ||
import type { IndexedVersionGroup } from '../../lib/get-input/get-instances'; | ||
|
||
export function getPinnedVersion( | ||
versionGroup: Pick<IndexedVersionGroup, 'pinVersion'>, | ||
): string { | ||
return versionGroup.pinVersion || ''; | ||
} |
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 |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import type { ProgramInput } from '../../lib/get-input'; | ||
import type { Instance } from '../../lib/get-input/get-instances'; | ||
import type { IndexedVersionGroup } from '../../lib/get-input/get-instances'; | ||
import { getHighestVersion } from './get-highest-version'; | ||
import { getPinnedVersion } from './get-pinned-version'; | ||
import { getWorkspaceVersion } from './get-workspace-version'; | ||
|
||
export function getExpectedVersion( | ||
input: ProgramInput, | ||
name: string, | ||
instances: Instance[], | ||
versionGroup: Pick<IndexedVersionGroup, 'instances' | 'pinVersion'>, | ||
input: Pick<ProgramInput, 'wrappers'>, | ||
): string { | ||
return ( | ||
getPinnedVersion(versionGroup) || | ||
getWorkspaceVersion(name, input.wrappers) || | ||
getHighestVersion(instances.map(({ version }) => version)) | ||
getHighestVersion(versionGroup.instances.map(({ version }) => version)) | ||
); | ||
} |
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
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