diff --git a/lib/cmd/vite/scripts.js b/lib/cmd/vite/scripts.js index 07f02ca..81ad805 100644 --- a/lib/cmd/vite/scripts.js +++ b/lib/cmd/vite/scripts.js @@ -57,19 +57,31 @@ exports.KILN_EDIT_ENTRY_KEY = KILN_EDIT_ENTRY_KEY; * @param {string|string[]} only * @returns {Set|null} */ -function normalizeRequestedSteps(only) { - if (!only || Array.isArray(only) && only.length === 0) return null; +/** + * Split a --only value into a deduped, trimmed array of entries. + * Accepts either repeated flags (--only js --only styles) or CSV + * (--only js,styles). + * + * @param {string|string[]} only + * @returns {string[]} + */ +function splitOnlyEntries(only) { + const values = Array.isArray(only) ? only : [only]; - // Accept either repeated flags (--only js --only styles) or CSV - // (--only js,styles), then normalize to one deduped Set. - const entries = (Array.isArray(only) ? only : [only]) + return values .flatMap(v => String(v).split(',')) .map(v => v.trim()) .filter(Boolean); +} - // "all" means "no filtering" so buildAll can reuse its normal path. - if (entries.includes('all')) return null; - +/** + * Partition --only entries into recognized build steps and anything + * unrecognized (a typo, most likely). + * + * @param {string[]} entries + * @returns {{ requested: Set, unrecognized: string[] }} + */ +function classifyOnlyEntries(entries) { const requested = new Set(); const unrecognized = []; @@ -81,6 +93,19 @@ function normalizeRequestedSteps(only) { } } + return { requested, unrecognized }; +} + +function normalizeRequestedSteps(only) { + if (!only || Array.isArray(only) && only.length === 0) return null; + + const entries = splitOnlyEntries(only); + + // "all" means "no filtering" so buildAll can reuse its normal path. + if (entries.includes('all')) return null; + + const { requested, unrecognized } = classifyOnlyEntries(entries); + if (unrecognized.length > 0) { throw new Error( `[clay vite] Unrecognized --only value(s): ${unrecognized.join(', ')}. ` +