mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -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.
43 lines
1.9 KiB
JavaScript
43 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
// Pure helper for the "@" member autocomplete (issue #5116 follow-up): typing
|
|
// "@ann" should suggest the board member "Anna" / username "anna.smith". The
|
|
// add-card-title strategy in client/components/lists/listBody.js used a
|
|
// case-SENSITIVE, prefix-only, username-only match
|
|
// (user.username.indexOf(term) === 0), so "@ann" did not match "Anna", "@Anna"
|
|
// did not match username "anna", and a full-name-only search never matched. It
|
|
// also threw if ReactiveCache.getUser() returned null. The card description /
|
|
// comment editor (client/components/main/editor.js) already matched
|
|
// case-insensitively on username OR full name, but shared no code and had the
|
|
// same null hazard.
|
|
//
|
|
// Extracted here (mirrors models/lib/labelAutocomplete.js and the other
|
|
// models/lib pure helpers) so both call sites match members the same way and it
|
|
// is unit-testable in plain Node without Meteor.
|
|
|
|
// Does `user` match the typed `term`? Case-insensitive substring match against
|
|
// the username and the profile full name. A null/undefined user, or a missing
|
|
// username/fullname, is treated safely (no throw). An empty term matches every
|
|
// user (the menu shows all members before anything is typed).
|
|
function memberMatchesTerm(user, term) {
|
|
if (!user) return false;
|
|
const needle = String(term == null ? '' : term).toLowerCase();
|
|
const username = String(user.username == null ? '' : user.username).toLowerCase();
|
|
const fullname = String(
|
|
(user.profile && user.profile.fullname) == null ? '' : user.profile.fullname,
|
|
).toLowerCase();
|
|
return username.indexOf(needle) > -1 || fullname.indexOf(needle) > -1;
|
|
}
|
|
|
|
// Filter a list of user documents by the typed term, preserving input order.
|
|
// Does not mutate the input; skips null/undefined entries.
|
|
function filterMembersByTerm(users, term) {
|
|
if (!Array.isArray(users)) return [];
|
|
return users.filter(user => memberMatchesTerm(user, term));
|
|
}
|
|
|
|
export {
|
|
memberMatchesTerm,
|
|
filterMembersByTerm,
|
|
};
|