From fc6de859c741b1e8d260148d86feb95261654442 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 15 Jan 2025 17:11:56 -0500 Subject: [PATCH] Merging too --- .../create/src/mergers/mergeScripts.test.ts | 77 +++++++++++++++++++ packages/create/src/mergers/mergeScripts.ts | 13 +++- 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/packages/create/src/mergers/mergeScripts.test.ts b/packages/create/src/mergers/mergeScripts.test.ts index b8c72a1f..6162d96e 100644 --- a/packages/create/src/mergers/mergeScripts.test.ts +++ b/packages/create/src/mergers/mergeScripts.test.ts @@ -22,6 +22,83 @@ describe("mergeScripts", () => { [["a"], [], ["a"]], [["a"], ["a"], ["a"]], [["a"], ["b"], ["a", "b"]], + [ + [ + { + commands: ["pnpm build"], + }, + ], + [ + { + commands: ["pnpm build"], + }, + ], + [ + { + commands: ["pnpm build"], + }, + ], + ], + [ + [ + { + commands: ["pnpm build"], + silent: true, + }, + ], + [ + { + commands: ["pnpm build"], + }, + ], + [ + { + commands: ["pnpm build"], + }, + ], + ], + [ + [ + { + commands: ["pnpm build"], + silent: true, + }, + ], + [ + { + commands: ["pnpm build"], + silent: true, + }, + ], + [ + { + commands: ["pnpm build"], + silent: true, + }, + ], + ], + [ + [ + { + commands: ["pnpm build"], + phase: 0, + }, + ], + [ + { + commands: ["pnpm build"], + }, + ], + [ + { + commands: ["pnpm build"], + phase: 0, + }, + { + commands: ["pnpm build"], + }, + ], + ], [ [ { diff --git a/packages/create/src/mergers/mergeScripts.ts b/packages/create/src/mergers/mergeScripts.ts index 79d71406..44f62d96 100644 --- a/packages/create/src/mergers/mergeScripts.ts +++ b/packages/create/src/mergers/mergeScripts.ts @@ -6,8 +6,9 @@ export function mergeScripts( first: CreatedScript[], second: CreatedScript[], ): CreatedScript[] { - const commandsByPhase = new Map(); + const commandsByPhase = new Map(); const commandsWithoutPhase: string[] = []; + const nonSilentPhases = new Set(); for (const command of [...first, ...second]) { if (typeof command === "string") { @@ -15,6 +16,10 @@ export function mergeScripts( continue; } + if (!command.silent) { + nonSilentPhases.add(command.phase); + } + const byPhase = commandsByPhase.get(command.phase); if (!byPhase) { commandsByPhase.set(command.phase, [command.commands.slice()]); @@ -39,7 +44,11 @@ export function mergeScripts( return [ ...Array.from(commandsByPhase).flatMap(([phase, phaseCommands]) => phaseCommands - .map((commands) => ({ commands, phase })) + .map((commands) => ({ + commands, + phase, + ...(!nonSilentPhases.has(phase) && { silent: true }), + })) .filter((phaseCommand) => { const hash = hashObject(phaseCommand); if (seenPhaseCommands.has(hash)) {