Skip to content

Commit 6adcaba

Browse files
committed
refactor: simplify skill batching flow
1 parent cb18072 commit 6adcaba

1 file changed

Lines changed: 23 additions & 23 deletions

File tree

src/index.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -461,22 +461,6 @@ async function runSkillCommand(
461461
installationTaskLog.success(`Installed ${skillNoun} ${skillLabel}`);
462462
}
463463

464-
function groupContiguousSkillsBySource(skills: ExtraSkill[]) {
465-
const skillGroups: ExtraSkill[][] = [];
466-
467-
for (const skill of skills) {
468-
const lastGroup = skillGroups.at(-1);
469-
if (lastGroup?.[0]?.source === skill.source) {
470-
lastGroup.push(skill);
471-
continue;
472-
}
473-
474-
skillGroups.push([skill]);
475-
}
476-
477-
return skillGroups;
478-
}
479-
480464
export async function create({
481465
name,
482466
root,
@@ -613,15 +597,31 @@ export async function create({
613597
skipFiles,
614598
});
615599

616-
const selectedExtraSkills = skills
617-
.map((skillValue) =>
618-
filteredExtraSkills?.find((extraSkill) => extraSkill.value === skillValue),
619-
)
620-
.filter((skill): skill is ExtraSkill => Boolean(skill));
600+
const skillsByValue = new Map(
601+
(filteredExtraSkills ?? []).map((extraSkill) => [extraSkill.value, extraSkill]),
602+
);
603+
let currentSkillBatch: ExtraSkill[] = [];
621604

622605
// Batch only contiguous skills from the same source to preserve install order.
623-
for (const groupedSkills of groupContiguousSkillsBySource(selectedExtraSkills)) {
624-
await runSkillCommand(groupedSkills, distFolder);
606+
for (const skillValue of skills) {
607+
const matchedSkill = skillsByValue.get(skillValue);
608+
if (!matchedSkill) {
609+
continue;
610+
}
611+
612+
if (
613+
currentSkillBatch.length > 0 &&
614+
currentSkillBatch[0].source !== matchedSkill.source
615+
) {
616+
await runSkillCommand(currentSkillBatch, distFolder);
617+
currentSkillBatch = [];
618+
}
619+
620+
currentSkillBatch.push(matchedSkill);
621+
}
622+
623+
if (currentSkillBatch.length > 0) {
624+
await runSkillCommand(currentSkillBatch, distFolder);
625625
}
626626

627627
const packageRoot = path.resolve(__dirname, '..');

0 commit comments

Comments
 (0)