Files
wekan/models/lib/linkedCardCover.js
T
Lauri Ojansivu 8d1fae4f7d Convert client-reachable models/lib helpers from CommonJS to ES modules (1/2).
The rspack client build treats a `module.exports` file imported into the
client bundle as an ES module and throws
"ES Modules may not assign module.exports" at evaluation time, aborting
the whole client module chain (No such template: swimlane / notifications
/ boardButtons, blank board, missing top bar). This is not an rspack
version regression (the lockfile has pinned ~1.7.x since v8.40); it is
that WeKan added CommonJS helpers to the client bundle.

Convert the 42 client-reachable pure-logic models/lib helpers from
`module.exports = { ... }` to `export { ... }`, and calendarFilter's
internal require('./swimlaneFilter') to an import with a .js extension
(node ESM needs it; rspack/reify tolerate it). Server-only helpers that
use node built-ins (fs/path/child_process) stay CommonJS. The plain-Node
.cjs unit tests for these helpers now use `await import(...js)` (wrapped
in an async IIFE); a source-guard in importVirtualMembers was updated
from module.exports to export. Verified: the full tests/*.test.cjs suite
has the SAME 7 pre-existing failures as before this change and no new
ones.
2026-07-23 18:55:30 +03:00

38 lines
1.7 KiB
JavaScript

'use strict';
// Pure helper for resolving a (possibly linked) card's cover attachment id.
// Extracted so the resolution is unit-testable without Meteor.
//
// #5666 ("Minicard connection without images"): a linked card
// (type 'cardType-linkedCard') is a placeholder on the linking board — its real
// content, including the cover image, lives on the card it points at (`linkedId`)
// on the other board. Every other minicard field resolves through the real card
// (getTitle/getReceived/getDue/... all do `getCard(this.linkedId)`), but the
// cover helpers read `this.coverId` directly. A linked card has no coverId of its
// own, so the cover never showed on the linking board's minicard even though the
// real card's attachment is published there. Resolve the cover id through the
// real card, mirroring the other linked-card getters.
const TYPE_LINKED_CARD = 'cardType-linkedCard';
// The card whose cover applies to `card`: the real card behind a link, otherwise
// the card itself. `getCard(id)` returns the card doc for an id (used to hop a
// linked card to its real card). Returns null when it can't be resolved.
function coverSourceCard(card, getCard) {
if (!card) return null;
if (card.type === TYPE_LINKED_CARD && card.linkedId) {
return typeof getCard === 'function' ? getCard(card.linkedId) || null : null;
}
return card;
}
// The cover attachment id to display for `card`, resolved through the real card
// for linked cards. Returns null when there is none (or the real card isn't
// loaded yet), so the caller renders no cover instead of throwing.
function resolveCoverId(card, getCard) {
const source = coverSourceCard(card, getCard);
return source && source.coverId ? source.coverId : null;
}
export { coverSourceCard, resolveCoverId };