Merge pull request #27013 from backstage/blam/fix-yarn-plugin

yarn-plugin: Only throw if the version is not already bound
This commit is contained in:
Ben Lambert
2024-10-08 12:17:00 +02:00
committed by GitHub
2 changed files with 13 additions and 14 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,20 +44,14 @@ export class BackstageResolver implements Resolver {
* the version in backstage.json changes.
*/
bindDescriptor(descriptor: Descriptor): Descriptor {
if (descriptor.range !== '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;
}
/**