Skip to content

Commit

Permalink
Merging too
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Jan 15, 2025
1 parent ef3e5e4 commit fc6de85
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
77 changes: 77 additions & 0 deletions packages/create/src/mergers/mergeScripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
},
],
],
[
[
{
Expand Down
13 changes: 11 additions & 2 deletions packages/create/src/mergers/mergeScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ export function mergeScripts(
first: CreatedScript[],
second: CreatedScript[],
): CreatedScript[] {
const commandsByPhase = new Map<number, string[][]>();
const commandsByPhase = new Map<number | undefined, string[][]>();
const commandsWithoutPhase: string[] = [];
const nonSilentPhases = new Set<number | undefined>();

for (const command of [...first, ...second]) {
if (typeof command === "string") {
commandsWithoutPhase.push(command);
continue;
}

if (!command.silent) {
nonSilentPhases.add(command.phase);
}

const byPhase = commandsByPhase.get(command.phase);
if (!byPhase) {
commandsByPhase.set(command.phase, [command.commands.slice()]);
Expand All @@ -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)) {
Expand Down

0 comments on commit fc6de85

Please sign in to comment.