mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -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.
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
// Pure helper for the "Link to this card" popup (#5394): the Cards pull-down
|
|
// list should be sorted alphabetically by card title (case-insensitive) so a
|
|
// card can be found on boards with many cards. Extracted so the comparison is
|
|
// unit-testable in plain Node without Meteor (mirrors models/lib/cardSearch.js
|
|
// and models/lib/boardSortReorder.js).
|
|
//
|
|
// Only the link-card popup's Cards dropdown uses this; ordering of cards in
|
|
// board views / exports is intentionally left untouched.
|
|
|
|
// Locale-aware, case-insensitive title comparison. Missing/empty titles are
|
|
// treated as an empty string so undefined titles never throw and sort first.
|
|
function compareCardTitle(a, b) {
|
|
const at = String((a && a.title) || '');
|
|
const bt = String((b && b.title) || '');
|
|
return at.localeCompare(bt, undefined, { sensitivity: 'base', numeric: true });
|
|
}
|
|
|
|
// Return a new array of the given cards sorted alphabetically by title
|
|
// (case-insensitive). Does not mutate the input. Equal titles keep their input
|
|
// order (Array.prototype.sort is stable in modern V8/Node).
|
|
function sortCardsByTitle(cards) {
|
|
if (!Array.isArray(cards)) return cards;
|
|
return cards.slice().sort(compareCardTitle);
|
|
}
|
|
|
|
export {
|
|
compareCardTitle,
|
|
sortCardsByTitle,
|
|
};
|