From c7ff35fabebcbe5fa01d43912196f53eb1ccbb0d Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 16 Aug 2026 10:03:37 +0300 Subject: [PATCH] Migrate invariant --- packages/tournament-engine/package.json | 1 + packages/tournament-engine/src/create/seeding.ts | 2 +- packages/tournament-engine/src/create/swiss.ts | 2 +- .../src/propagation/report-result.ts | 2 +- packages/tournament-engine/src/propagation/set.ts | 2 +- packages/tournament-engine/src/swiss/pairing.ts | 3 ++- packages/tournament-engine/src/utils/invariant.ts | 12 ------------ pnpm-lock.yaml | 3 +++ 8 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 packages/tournament-engine/src/utils/invariant.ts diff --git a/packages/tournament-engine/package.json b/packages/tournament-engine/package.json index 35401153a..6d2670625 100644 --- a/packages/tournament-engine/package.json +++ b/packages/tournament-engine/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "@sendou/in-game-lists": "workspace:*", + "@sendou/utils": "workspace:*", "edmonds-blossom-fixed": "1.0.1", "remeda": "2.39.0" }, diff --git a/packages/tournament-engine/src/create/seeding.ts b/packages/tournament-engine/src/create/seeding.ts index 350c657c1..e75593200 100644 --- a/packages/tournament-engine/src/create/seeding.ts +++ b/packages/tournament-engine/src/create/seeding.ts @@ -1,7 +1,7 @@ // https://web.archive.org/web/20200601102344/https://tl.net/forum/sc2-tournaments/202139-superior-double-elimination-losers-bracket-seeding +import invariant from "@sendou/utils/invariant"; import type { OrderingMap, Seeding, SeedOrdering } from "../types"; -import invariant from "../utils/invariant"; export const ordering: OrderingMap = { natural: (array: T[]) => [...array], diff --git a/packages/tournament-engine/src/create/swiss.ts b/packages/tournament-engine/src/create/swiss.ts index 95f0c2b31..d26f7c0df 100644 --- a/packages/tournament-engine/src/create/swiss.ts +++ b/packages/tournament-engine/src/create/swiss.ts @@ -1,3 +1,4 @@ +import invariant from "@sendou/utils/invariant"; import { ENGINE_DEFAULTS } from "../constants"; import type { BracketData, @@ -5,7 +6,6 @@ import type { ResolvedCreateBracketInput, } from "../types"; import { nullFilledArray } from "../utils/arrays"; -import invariant from "../utils/invariant"; /** * Creates a Swiss bracket data set: all rounds up front, matches for round 1 only. diff --git a/packages/tournament-engine/src/propagation/report-result.ts b/packages/tournament-engine/src/propagation/report-result.ts index 20d3710cb..f4aac0fa4 100644 --- a/packages/tournament-engine/src/propagation/report-result.ts +++ b/packages/tournament-engine/src/propagation/report-result.ts @@ -1,5 +1,5 @@ +import invariant from "@sendou/utils/invariant"; import type { BracketData, EngineResult, ReportResultInput } from "../types"; -import invariant from "../utils/invariant"; import { Store } from "./store"; import { Propagator } from "./traversal"; diff --git a/packages/tournament-engine/src/propagation/set.ts b/packages/tournament-engine/src/propagation/set.ts index 70b1f73ef..0e4104659 100644 --- a/packages/tournament-engine/src/propagation/set.ts +++ b/packages/tournament-engine/src/propagation/set.ts @@ -1,6 +1,6 @@ +import invariant from "@sendou/utils/invariant"; import { isSetOverByScore, matchEndedEarly } from "../status"; import type { BracketData, EngineResult, MatchData, Side } from "../types"; -import invariant from "../utils/invariant"; import { reportResult } from "./report-result"; import { resetMatchResults } from "./reset-result"; diff --git a/packages/tournament-engine/src/swiss/pairing.ts b/packages/tournament-engine/src/swiss/pairing.ts index d5b1e0a6f..4541a9df1 100644 --- a/packages/tournament-engine/src/swiss/pairing.ts +++ b/packages/tournament-engine/src/swiss/pairing.ts @@ -1,4 +1,6 @@ /// + +import invariant from "@sendou/utils/invariant"; import blossom from "edmonds-blossom-fixed"; import * as R from "remeda"; import { swissRoundCount } from "../create/settings"; @@ -8,7 +10,6 @@ import type { MatchData, SwissStanding, } from "../types"; -import invariant from "../utils/invariant"; import { err, ok, type Result } from "../utils/result"; import { calculateTeamStatus } from "./team-status"; diff --git a/packages/tournament-engine/src/utils/invariant.ts b/packages/tournament-engine/src/utils/invariant.ts deleted file mode 100644 index f321a91b7..000000000 --- a/packages/tournament-engine/src/utils/invariant.ts +++ /dev/null @@ -1,12 +0,0 @@ -// adapted from https://github.com/alexreardon/tiny-invariant, changed to show errors in production as well - -export default function invariant( - condition: any, - message?: string, -): asserts condition { - if (condition) return; - - const addition = message ? `: ${message}` : ""; - - throw new Error(`Invariant failed${addition}`); -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 06d032876..4db13a38d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -353,6 +353,9 @@ importers: '@sendou/in-game-lists': specifier: workspace:* version: link:../in-game-lists + '@sendou/utils': + specifier: workspace:* + version: link:../utils edmonds-blossom-fixed: specifier: 1.0.1 version: 1.0.1