Skip to content

Commit b70ce06

Browse files
committed
fix: deduplicate tap formulae from CLI list on snapshot import
When importing a snapshot, formulae provided by a third-party tap (e.g. argoproj/tap/kubectl-argo-rollouts) appeared both in TAPS and CLI sections because the same package existed in both snapshot.packages.formulae and snapshot.packages.taps. Filter out formulae whose name matches the last segment of a three-segment tap entry, keeping only the more specific tap version.
1 parent 5ee1a89 commit b70ce06

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/routes/api/configs/from-snapshot/+server.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,26 @@ export const POST: RequestHandler = async ({ platform, cookies, request }) => {
5656
const snapshotNpm: string[] = snapshot.packages?.npm || [];
5757
const snapshotTaps: string[] = snapshot.packages?.taps || [];
5858

59+
// Build a set of formula names that are already covered by a tap entry
60+
// (e.g. "argoproj/tap/kubectl-argo-rollouts" covers "kubectl-argo-rollouts")
61+
// so they don't appear in both CLI and TAPS sections.
62+
// Only consider three-segment tap entries (owner/tap/formula) to avoid
63+
// false-positive collisions with two-segment tap names like "homebrew/cask".
64+
const tapFormulaNames = new Set<string>();
65+
for (const t of snapshotTaps) {
66+
const parts = t.split('/');
67+
if (parts.length === 3) {
68+
tapFormulaNames.add(parts[2]);
69+
}
70+
}
71+
5972
const packages = [
60-
...snapshotFormulae.map((name: string) => ({ name, type: 'formula' })),
61-
...snapshotCasks.map((name: string) => ({ name, type: 'cask' })),
62-
...snapshotNpm.map((name: string) => ({ name, type: 'npm' })),
63-
...snapshotTaps.map((name: string) => ({ name, type: 'tap' })),
73+
...snapshotFormulae
74+
.filter((name) => !tapFormulaNames.has(name))
75+
.map((name) => ({ name, type: 'formula' })),
76+
...snapshotCasks.map((name) => ({ name, type: 'cask' })),
77+
...snapshotNpm.map((name) => ({ name, type: 'npm' })),
78+
...snapshotTaps.map((name) => ({ name, type: 'tap' })),
6479
];
6580

6681
const pv = validatePackages(packages);

0 commit comments

Comments
 (0)