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.
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
// Bound a promise so a hung or stalled operation can never block forever. Resolves
|
|
// with the promise's value if it settles within `ms`; otherwise rejects with a timeout
|
|
// error (from `onTimeout()` if given, else a generic Error). The underlying promise is
|
|
// not cancelled — JavaScript cannot cancel a promise — but the caller is freed, so a
|
|
// method/handler returns an error to the client instead of spinning indefinitely.
|
|
//
|
|
// Pure and dependency-free so it can be unit-tested and reused anywhere a long
|
|
// operation needs a hard deadline (imports, migrations, external fetches, …).
|
|
//
|
|
// Usage:
|
|
// await withDeadline(doWork(), 120000, () => new Meteor.Error('op-timeout'));
|
|
|
|
function withDeadline(promise, ms, onTimeout) {
|
|
// A non-positive / invalid deadline means "no deadline": just await the promise.
|
|
if (!(ms > 0)) {
|
|
return Promise.resolve(promise);
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
let done = false;
|
|
|
|
const timer = setTimeout(() => {
|
|
if (done) return;
|
|
done = true;
|
|
const err =
|
|
typeof onTimeout === 'function' ? onTimeout() : new Error('operation-timeout');
|
|
reject(err);
|
|
}, ms);
|
|
|
|
// Do not keep the process alive just for this timer (Node only; harmless elsewhere).
|
|
if (timer && typeof timer.unref === 'function') {
|
|
timer.unref();
|
|
}
|
|
|
|
Promise.resolve(promise).then(
|
|
value => {
|
|
if (done) return;
|
|
done = true;
|
|
clearTimeout(timer);
|
|
resolve(value);
|
|
},
|
|
error => {
|
|
if (done) return;
|
|
done = true;
|
|
clearTimeout(timer);
|
|
reject(error);
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
export { withDeadline };
|