Skip to content

Commit 81c7351

Browse files
authored
fix(cli): Check existing conditions for specified options (#771)
1 parent 37b88e0 commit 81c7351

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

.changeset/petite-pandas-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
fix(cli): Check existing conditions for specified options

packages/cli/commands/add/index.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,38 @@ export async function runAddCommand(
231231
official[addonId] ??= {};
232232

233233
const optionEntries = Object.entries(details.options);
234+
const specifiedOptionsObject = Object.fromEntries(
235+
specifiedOptions.map((option) => option.split(':', 2))
236+
);
234237
for (const option of specifiedOptions) {
235238
let [optionId, optionValue] = option.split(':', 2);
236239

237240
// validates that the option exists
238-
const optionEntry = optionEntries.find(
239-
([id, question]) => id === optionId || question.group === optionId
240-
);
241+
const optionEntry = optionEntries.find(([id, question]) => {
242+
// simple ID match
243+
if (id === optionId) return true;
244+
245+
// group match - need to check conditions and value validity
246+
if (question.group === optionId) {
247+
// does the value exist for this option?
248+
if (question.type === 'select' || question.type === 'multiselect') {
249+
const isValidValue = question.options.some((opt) => opt.value === optionValue);
250+
if (!isValidValue) return false;
251+
}
252+
253+
// if there's a condition, does it pass?
254+
if (question.condition) {
255+
return question.condition(specifiedOptionsObject);
256+
}
257+
258+
// finally, unconditional
259+
return true;
260+
}
261+
262+
// unrecognized optionId
263+
return false;
264+
});
265+
241266
if (!optionEntry) {
242267
const { choices } = getOptionChoices(details);
243268
throw new Error(

0 commit comments

Comments
 (0)