Skip to content

Commit fe13228

Browse files
committed
fix(pacmak): fail fast on OR conditions in Ruby version ranges
1 parent 18329e7 commit fe13228

3 files changed

Lines changed: 95 additions & 94 deletions

File tree

packages/jsii-pacmak/lib/targets/version-utils.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,27 @@ export function toPythonVersionRange(semverRange: string): string {
7676
*/
7777
export function toRubyVersionRange(semverRange: string): string {
7878
const range = new Range(semverRange);
79-
return range.set
80-
.map((set) =>
81-
set
82-
.map((comp) => {
83-
const versionId = toReleaseVersion(
84-
comp.semver.raw?.replace(/-0$/, '') ?? '0.0.0',
85-
TargetName.RUBY,
86-
);
87-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
88-
switch (comp.operator) {
89-
case '':
90-
return comp.value === '' ? "'>= 0.0.0'" : `'= ${versionId}'`;
91-
case '=':
92-
return `'= ${versionId}'`;
93-
default:
94-
return `'${comp.operator} ${versionId}'`;
95-
}
96-
})
97-
.join(', '),
98-
)
79+
if (range.set.length > 1) {
80+
throw new Error(
81+
`RubyGems does not support OR (||) requirements natively in a single dependency. Unsatisfiable constraint: ${semverRange}`,
82+
);
83+
}
84+
return range.set[0]
85+
.map((comp) => {
86+
const versionId = toReleaseVersion(
87+
comp.semver.raw?.replace(/-0$/, '') ?? '0.0.0',
88+
TargetName.RUBY,
89+
);
90+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
91+
switch (comp.operator) {
92+
case '':
93+
return comp.value === '' ? "'>= 0.0.0'" : `'= ${versionId}'`;
94+
case '=':
95+
return `'= ${versionId}'`;
96+
default:
97+
return `'${comp.operator} ${versionId}'`;
98+
}
99+
})
99100
.join(', ');
100101
}
101102

0 commit comments

Comments
 (0)