Files
accounted/lib/vat/vat-rate-unit.ts
T
Mattsson 281cb3989d fix(build): break Turbopack chunk-name hash collision from #1385's import edge (#1394)
Since the #1385 squash-merge every production build failed with 'Two or
more assets with different content were emitted to the same output path'
on [root-of-the-server]__1ge0sz5._.js: two distinct server chunk groups
(an AWS smithy helper chunk and the withRouteContext auth chunk) hash to
the same chunk name. The graph change that tipped the chunk layout into
the colliding state was entity-mapper.ts (arcim-migration extension
entry graph) importing lib/vat/supplier-invoice-line-checks, which
drags lib/money into the extension root.

Move normalizeVatRateToFraction into an import-free leaf module
(lib/vat/vat-rate-unit.ts), re-export it from
supplier-invoice-line-checks for all existing callers, and point
entity-mapper at the leaf. Behavior is unchanged (511 targeted tests
pass); the server chunk graph returns to the pre-#1385 shape that
builds cleanly. Verified: npm run build fails on ff864ad3d and passes
with this change.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-03 19:28:15 +02:00

22 lines
1.0 KiB
TypeScript

// Leaf module on purpose: imported by extension entry graphs (arcim-migration
// entity mapper) where pulling in supplier-invoice-line-checks' dependencies
// (lib/money) shifted the server chunk graph into a Turbopack chunk-name hash
// collision ("Two or more assets with different content were emitted to the
// same output path", first seen on the #1385 merge). Keep this file free of
// imports; supplier-invoice-line-checks re-exports it for all other callers.
/**
* Convert a supplier-invoice VAT rate to the database's decimal-fraction
* unit without changing the underlying rate. Values above 1 are interpreted
* as percentages, while values already between 0 and 1 pass through. This is
* intentionally a unit normalizer, not a Swedish-rate validator: imported
* foreign VAT such as 19 % must remain 0.19 instead of being rewritten.
*/
export function normalizeVatRateToFraction(rate: unknown): number {
const n = Number(rate)
if (!Number.isFinite(n) || n < 0) return 0
const fraction = n > 1 ? n / 100 : n
return fraction <= 1 ? fraction : 0
}