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.
51 lines
2.1 KiB
JavaScript
51 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
// Pure helper: build the `meta` object stored on every card attachment
|
|
// (Attachments FilesCollection, ostrio:files). Kept side-effect free so it can
|
|
// be unit tested without a database or the Meteor client environment.
|
|
//
|
|
// This single builder is shared by ALL card attachment upload paths:
|
|
// - the card Attachments popup and clipboard upload
|
|
// (client/components/cards/attachments.js), and
|
|
// - images uploaded inside card COMMENTS / the card description through the
|
|
// rich text editor (client/components/main/editor.js, summernote
|
|
// onImageUpload), via Utils.getCommonAttachmentMetaFrom().
|
|
//
|
|
// Because comment uploads carry the exact same `meta.cardId` as direct card
|
|
// uploads, they are listed in the card's Attachments section, whose queries
|
|
// all key on `meta.cardId` (Template.attachmentGallery in
|
|
// client/components/cards/attachments.js and Cards.helpers.attachments in
|
|
// models/cards.js) with no `meta.source` filtering. That is the behaviour
|
|
// requested in https://github.com/wekan/wekan/issues/3843 — an attachment
|
|
// added in a card comment must stay linked to (and visible in) the card's
|
|
// global attachment list.
|
|
//
|
|
// For a linked card the attachment is attached to the REAL card (linkedId),
|
|
// so it shows up on the original card and on every linked copy.
|
|
//
|
|
// `getCardById` resolves the real card of a linked card (the client passes
|
|
// ReactiveCache.getCard). A missing/null card yields an empty meta rather
|
|
// than throwing, so a failed lookup cannot crash an upload handler.
|
|
function buildCardAttachmentMeta(card, getCardById) {
|
|
const meta = {};
|
|
if (!card) {
|
|
return meta;
|
|
}
|
|
if (typeof card.isLinkedCard === 'function' && card.isLinkedCard()) {
|
|
const realCard =
|
|
typeof getCardById === 'function' ? getCardById(card.linkedId) : null;
|
|
if (realCard) {
|
|
meta.boardId = realCard.boardId;
|
|
}
|
|
meta.cardId = card.linkedId;
|
|
} else {
|
|
meta.boardId = card.boardId;
|
|
meta.swimlaneId = card.swimlaneId;
|
|
meta.listId = card.listId;
|
|
meta.cardId = card._id;
|
|
}
|
|
return meta;
|
|
}
|
|
|
|
export { buildCardAttachmentMeta };
|