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.
39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
'use strict';
|
|
|
|
// Pure parsers for the due-date reminder configuration (NOTIFY_DUE_* env vars),
|
|
// extracted from models/cards.js so they are unit-testable without Meteor.
|
|
// Related to #3192 (due-date reminder mail).
|
|
|
|
// Parse NOTIFY_DUE_DAYS_BEFORE_AND_AFTER: a comma-separated list of day offsets
|
|
// (positive = days before due, 0 = due today, negative = days past due). Each is
|
|
// validated to the -14..14 window; invalid/out-of-range entries are dropped.
|
|
// Returns an array of integers (possibly empty).
|
|
function parseNotifyDueDays(envValue) {
|
|
if (!envValue || typeof envValue !== 'string') return [];
|
|
return envValue
|
|
.split(',')
|
|
.map(value => {
|
|
const iValue = parseInt(value, 10);
|
|
if (Number.isNaN(iValue) || iValue < -14 || iValue > 14) return false;
|
|
return iValue;
|
|
})
|
|
.filter(v => v !== false);
|
|
}
|
|
|
|
// Parse NOTIFY_DUE_AT_HOUR_OF_DAY: the hour of day (0..23) at which to send the
|
|
// reminders. Returns the parsed hour, or `defaultHour` when the value is missing,
|
|
// non-numeric, or out of range.
|
|
//
|
|
// #3192: the previous `parseInt(env, 10) || defaultHour` silently turned a valid
|
|
// hour of 0 (midnight) into the default (8), because 0 is falsy — so midnight
|
|
// reminders were impossible. It also accepted out-of-range hours (e.g. 25, -1).
|
|
// Number.isNaN + a 0..23 range check fixes both while keeping the "parse error ->
|
|
// default" behaviour.
|
|
function parseNotifyDueHour(envValue, defaultHour = 8) {
|
|
const hour = parseInt(envValue, 10);
|
|
if (Number.isNaN(hour) || hour < 0 || hour > 23) return defaultHour;
|
|
return hour;
|
|
}
|
|
|
|
export { parseNotifyDueDays, parseNotifyDueHour };
|