From bc75566d8ff408efd0b6d9d9ed3512d1a262a65f Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 2 Mar 2025 15:20:59 +0100 Subject: [PATCH 1/2] fix: addons executed in the wrong order in certain circumstances --- .changeset/tricky-icons-allow.md | 5 +++++ packages/cli/lib/install.ts | 19 ++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 .changeset/tricky-icons-allow.md diff --git a/.changeset/tricky-icons-allow.md b/.changeset/tricky-icons-allow.md new file mode 100644 index 000000000..7b28bf1bd --- /dev/null +++ b/.changeset/tricky-icons-allow.md @@ -0,0 +1,5 @@ +--- +'sv': patch +--- + +fix: addons executed in the wrong order in certain circumstances diff --git a/packages/cli/lib/install.ts b/packages/cli/lib/install.ts index 6f98ce43d..f388cb7db 100644 --- a/packages/cli/lib/install.ts +++ b/packages/cli/lib/install.ts @@ -180,19 +180,16 @@ async function runAddon({ addon, multiple, workspace }: RunAddon) { }; } -// sorts them to their execution order +// orders addons by putting addons that don't require any other addon in the front. +// This is a drastic simplification, as this could still cause some inconvenient cituations, +// but works for now in contrary to the previouse implementation function orderAddons(addons: Array>, setupResults: Record) { - return Array.from(addons).sort((a, b) => { - const aDeps = setupResults[a.id].dependsOn; - const bDeps = setupResults[b.id].dependsOn; - - if (!aDeps && !bDeps) return 0; - if (!aDeps) return -1; - if (!bDeps) return 1; - - if (aDeps.includes(b.id)) return 1; - if (bDeps.includes(a.id)) return -1; + return addons.sort((a, b) => { + const aDepends = setupResults[a.id]?.dependsOn?.length > 0; + const bDepends = setupResults[b.id]?.dependsOn?.length > 0; + if (aDepends && !bDepends) return 1; + if (!aDepends && bDepends) return -1; return 0; }); } From 97f67e570524dd473becfddd3f9787d026071ec5 Mon Sep 17 00:00:00 2001 From: Manuel Date: Sun, 2 Mar 2025 15:24:07 +0100 Subject: [PATCH 2/2] simplify --- packages/cli/lib/install.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/cli/lib/install.ts b/packages/cli/lib/install.ts index f388cb7db..b894bc07d 100644 --- a/packages/cli/lib/install.ts +++ b/packages/cli/lib/install.ts @@ -184,12 +184,7 @@ async function runAddon({ addon, multiple, workspace }: RunAddon) { // This is a drastic simplification, as this could still cause some inconvenient cituations, // but works for now in contrary to the previouse implementation function orderAddons(addons: Array>, setupResults: Record) { - return addons.sort((a, b) => { - const aDepends = setupResults[a.id]?.dependsOn?.length > 0; - const bDepends = setupResults[b.id]?.dependsOn?.length > 0; - - if (aDepends && !bDepends) return 1; - if (!aDepends && bDepends) return -1; - return 0; - }); + return addons.sort( + (a, b) => setupResults[a.id]?.dependsOn?.length - setupResults[b.id]?.dependsOn?.length + ); }