mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -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.
55 lines
2.4 KiB
JavaScript
55 lines
2.4 KiB
JavaScript
'use strict';
|
|
|
|
// Pure helpers for a board's auto-created default swimlane. Extracted from
|
|
// models/boards.js so the idempotency guarantee behind the #6429 fix is
|
|
// unit-testable without Meteor.
|
|
//
|
|
// #6429: Board.getDefaultSwimline()/getDefaultSwimlineAsync() self-heal a
|
|
// missing default swimlane with a check-then-insert (read the board's
|
|
// swimlanes, insert one if none exist). That races: concurrent or repeated
|
|
// server calls for a swimlane-less board each saw zero swimlanes and each
|
|
// inserted a new one, so some boards accumulated 30 000+ empty "Default"
|
|
// swimlanes and became unloadable. The fix upserts on a DETERMINISTIC _id so
|
|
// the _id unique index caps auto-created default swimlanes at one per board.
|
|
|
|
// Deterministic _id for a board's auto-created default swimlane. A normal
|
|
// swimlane gets a Random.id() (17 chars, no hyphen), so this never collides
|
|
// with a user-created one.
|
|
function defaultSwimlaneId(boardId) {
|
|
return `${boardId}-default`;
|
|
}
|
|
|
|
// Fields for the upsert's $setOnInsert. archived/type are set explicitly: their
|
|
// schema autoValue/defaultValue only fire on insert, not on the upsert path used
|
|
// by the self-heal, so omitting them would fail required-field validation.
|
|
function defaultSwimlaneFields(boardId, title) {
|
|
return {
|
|
// Fall back to the string 'Default' when i18n is unavailable or returned a
|
|
// non-string (e.g. during migration, or the 'default (en)' object warning).
|
|
title: typeof title === 'string' && title.length > 0 ? title : 'Default',
|
|
boardId,
|
|
sort: 0,
|
|
archived: false,
|
|
type: 'swimlane',
|
|
};
|
|
}
|
|
|
|
// Choose a board's default swimlane from its list of swimlanes (#1971). Prefer
|
|
// the first NON-archived swimlane so a card added in List view never lands in an
|
|
// archived swimlane (which is invisible in Swimlane view — the reported bug).
|
|
// If every swimlane is archived, fall back to the first one (matching the old
|
|
// non-null behaviour, so callers that read `._id` never crash). Returns
|
|
// undefined only when the board has no swimlanes at all, which is the single
|
|
// case where the server self-heals a fresh default (#6382/#6429).
|
|
function pickDefaultSwimlane(swimlanes) {
|
|
if (!Array.isArray(swimlanes) || swimlanes.length === 0) return undefined;
|
|
const active = swimlanes.find(s => s && !s.archived);
|
|
return active || swimlanes[0];
|
|
}
|
|
|
|
export {
|
|
defaultSwimlaneId,
|
|
defaultSwimlaneFields,
|
|
pickDefaultSwimlane,
|
|
};
|