Skip to content
Merged
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
41 changes: 33 additions & 8 deletions lib/cmd/vite/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,31 @@ exports.KILN_EDIT_ENTRY_KEY = KILN_EDIT_ENTRY_KEY;
* @param {string|string[]} only
* @returns {Set<string>|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<string>, unrecognized: string[] }}
*/
function classifyOnlyEntries(entries) {
const requested = new Set();
const unrecognized = [];

Expand All @@ -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(', ')}. ` +
Expand Down
Loading