chore: support fixed versions of backstage version in resolver

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2024-10-08 11:57:32 +02:00
parent d5f254f8e4
commit aba538db72
2 changed files with 13 additions and 17 deletions
@@ -114,15 +114,20 @@ describe('BackstageResolver', () => {
});
describe('with range "backstage:1.23.45"', () => {
it('throws an error', () => {
expect(() =>
it('returns the correct descriptor', () => {
expect(
backstageResolver.bindDescriptor(
structUtils.makeDescriptor(
structUtils.makeIdent('backstage', 'core'),
'backstage:1.23.45',
),
),
).toThrow(/unsupported version range/i);
).toEqual(
structUtils.makeDescriptor(
structUtils.makeIdent('backstage', 'core'),
'backstage:1.23.45',
),
);
});
});
});
@@ -44,23 +44,14 @@ export class BackstageResolver implements Resolver {
* the version in backstage.json changes.
*/
bindDescriptor(descriptor: Descriptor): Descriptor {
if (
descriptor.range !== 'backstage:^' &&
!descriptor.range.startsWith('backstage:')
) {
throw new Error(
`Unsupported version range "${
descriptor.range
}" for package ${structUtils.stringifyIdent(
descriptor,
)}. The backstage protocol only supports the range "backstage:^".`,
if (descriptor.range === 'backstage:^') {
return structUtils.makeDescriptor(
descriptor,
`${PROTOCOL}${getCurrentBackstageVersion()}`,
);
}
return structUtils.makeDescriptor(
descriptor,
`${PROTOCOL}${getCurrentBackstageVersion()}`,
);
return descriptor;
}
/**