mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
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.
36 lines
1.7 KiB
JavaScript
36 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
// Pure, isomorphic helper that builds a card's relative URL, matching the
|
|
// 'card' route '/b/:boardId/:slug/:cardId' (config/router.js).
|
|
//
|
|
// Why this is not just a template literal inline in Card.originRelativeUrl:
|
|
// on the server ReactiveCache.getBoard() (used by Card.board()) is async and
|
|
// returns a Promise, not a board document. Interpolating that Promise straight
|
|
// into the URL produced '/b/undefined/board/<cardId>' in card activity
|
|
// notification emails (issue #6427), because Promise._id / Promise.slug are
|
|
// undefined. This helper detects a Promise-shaped (thenable) board, ignores it,
|
|
// and falls back to the card's own boardId — which is always available
|
|
// synchronously — so the link stays valid even when the human-readable slug is
|
|
// unknown. Server callers should pass the already-awaited board to also get the
|
|
// correct slug.
|
|
|
|
function isThenable(value) {
|
|
return !!value && (typeof value === 'object' || typeof value === 'function')
|
|
&& typeof value.then === 'function';
|
|
}
|
|
|
|
function buildCardRelativeUrl(card, board) {
|
|
if (!card || !card._id) return undefined;
|
|
// A thenable is an unresolved Promise (server Card.board()); never read
|
|
// _id/slug off it — that is exactly what emitted '/b/undefined/board/...'.
|
|
const resolvedBoard = isThenable(board) ? undefined : board;
|
|
const boardId = (resolvedBoard && resolvedBoard._id) || card.boardId;
|
|
if (!boardId) return undefined;
|
|
const slug = (resolvedBoard && resolvedBoard.slug) || 'board';
|
|
// swimlaneId/listId were only ever appended as query params the route
|
|
// ignores, so they are dropped here.
|
|
return `/b/${boardId}/${slug}/${card._id}`;
|
|
}
|
|
|
|
export { isThenable, buildCardRelativeUrl };
|