From 5d54dd6c00c6856acc0657dfa55e5f89bb735818 Mon Sep 17 00:00:00 2001 From: Jordan Paulino Date: Tue, 15 Sep 2026 14:55:29 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=95=20Fix=20normalizeRequestedSteps=20?= =?UTF-8?q?complexity=20regression=20from=20#259?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `npx eslint lib cli index.js` -- the full lint command `npm test` actually runs -- currently fails on master: normalizeRequestedSteps has a cyclomatic complexity of 10 (max 8), introduced in #259 and missed there because that PR's own verification only linted the specific files it touched, not the full repo command. Master is broken for `npm test` right now as a result. Splits the function into splitOnlyEntries() (CSV/repeated-flag parsing) and classifyOnlyEntries() (recognized vs. unrecognized step names), leaving normalizeRequestedSteps as a thin orchestrator (complexity 7). No behavior change -- reverified the exact case #259 added: an unrecognized --only value still throws with the same message. Co-Authored-By: Claude Sonnet 5 --- lib/cmd/vite/scripts.js | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) 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(', ')}. ` +