Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/petite-pandas-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix(cli): Check existing conditions for specified options
31 changes: 28 additions & 3 deletions packages/cli/commands/add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,38 @@ export async function runAddCommand(
official[addonId] ??= {};

const optionEntries = Object.entries(details.options);
const specifiedOptionsObject = Object.fromEntries(
specifiedOptions.map((option) => option.split(':', 2))
);
for (const option of specifiedOptions) {
let [optionId, optionValue] = option.split(':', 2);
Copy link
Member Author

@GrygrFlzr GrygrFlzr Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could instead do

for (const option of Object.entries(specifiedOptionsObject)) {
    let [optionId, optionValue] = option;

But I'm not sure that's clearer intent.


// validates that the option exists
const optionEntry = optionEntries.find(
([id, question]) => id === optionId || question.group === optionId
);
const optionEntry = optionEntries.find(([id, question]) => {
// simple ID match
if (id === optionId) return true;

// group match - need to check conditions and value validity
if (question.group === optionId) {
// does the value exist for this option?
if (question.type === 'select' || question.type === 'multiselect') {
const isValidValue = question.options.some((opt) => opt.value === optionValue);
if (!isValidValue) return false;
}

// if there's a condition, does it pass?
if (question.condition) {
return question.condition(specifiedOptionsObject);
}

// finally, unconditional
return true;
}

// unrecognized optionId
return false;
});

if (!optionEntry) {
const { choices } = getOptionChoices(details);
throw new Error(
Expand Down
Loading