mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Found by following every import, re-export and require from client/main.js and server/main.js (meteor.mainModule: only what that reaches is loaded) and each local package's package.js: - packages/wekan-fullcalendar/fullcalendar/ (88 files) and update.sh: the vendored FullCalendar v3 and the script that updated it as a git submodule; the package takes FullCalendar 5 from npm (Npm.depends). - packages/wekan-fontawesome/fontawesome-free: js/, sprites/, metadata/, attribution.js and the .min.css copies; package.js adds only the plain CSS and the webfonts. Its package.json no longer names the removed files. - models/lib/propagateMembers.js and models/lib/teamBoardMemberSync.js: replaced on 2026-10-14 by models/lib/groupBoardMembership.js (memberships that record their team or org, #4178), which the server uses. Their tests exercised the old modules; the same scenarios now run against planGain / groupChanges, and the wiring checks are kept. - models/lib/recoveryPlan.js and its test: a model of the SQLite recovery policy that nothing ran; releases/ferretdb/sqlite-recovery.mjs carries it out and tests/sqliteVerifiedRecovery.test.cjs tests that. The Recovery design page says so. - packages/wekan-ldap/server/configResolver.js: a vendored copy nothing imported - the LDAP package reads its settings through the app's accessor. Its sync test is now a check that no package carries such a copy; three comments that sent readers to it explain the reason instead. docs/Design/TeamsOrganizations.md also said losing a team removes nothing; since #4178 a team takes back what it gave. Thanks to xet7 !
81 lines
3.4 KiB
JavaScript
81 lines
3.4 KiB
JavaScript
'use strict';
|
|
|
|
// Every server module that does its work by being loaded - registering a login
|
|
// handler, a cron job, a startup observer - is reached from server/main.js.
|
|
//
|
|
// package.json sets meteor.mainModule, so Meteor loads ONLY what an import
|
|
// chain from server/main.js reaches; a file that is not imported never runs.
|
|
// Three finished features sat like that for months, each with a passing test
|
|
// that read the file but never asked whether the app loads it:
|
|
// server/loginTimingNormalization.js LockoutBleed's DDP login half (GHSA-2g94-9x3m-hv37)
|
|
// server/cardRecurrenceSchedule.js the card Recurrence setting's cron job
|
|
// server/productNameCache.js the product name for the snap's outage pages
|
|
// Run: node tests/serverModulesLoaded.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
// import ... from, export ... from (a re-export loads the module too), require, import()
|
|
const SPEC = /(?:import\s+(?:[^'"]*?\s+from\s+)?|export\s+(?:\*|\{[^}]*\})(?:\s+as\s+\w+)?\s+from\s+|require\(\s*|import\(\s*)['"]([^'"]+)['"]/g;
|
|
const EXTS = ['', '.js', '.mjs', '.cjs', '.jade', '.css', '.html', '.json', '/index.js'];
|
|
|
|
function resolve(from, spec) {
|
|
let base;
|
|
if (spec.startsWith('/')) base = path.join(ROOT, spec);
|
|
else if (spec.startsWith('.')) base = path.resolve(path.dirname(from), spec);
|
|
else return null;
|
|
for (const ext of EXTS) {
|
|
const file = base + ext;
|
|
if (fs.existsSync(file) && fs.statSync(file).isFile()) return file;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function reachable(entries) {
|
|
const seen = new Set();
|
|
const stack = [...entries];
|
|
while (stack.length) {
|
|
const file = stack.pop();
|
|
if (seen.has(file)) continue;
|
|
seen.add(file);
|
|
const text = fs.readFileSync(file, 'utf8');
|
|
for (const m of text.matchAll(SPEC)) {
|
|
const next = resolve(file, m[1]);
|
|
if (next) stack.push(next);
|
|
}
|
|
}
|
|
return seen;
|
|
}
|
|
|
|
const loaded = reachable([path.join(ROOT, 'server/main.js')]);
|
|
|
|
// A module that runs by being loaded: it registers something at startup.
|
|
const SIDE_EFFECT = /Meteor\.startup\(|Meteor\.methods\(|Meteor\.publish\(|publishComposite\(|SyncedCron\.add\(|registerLoginHandler\(|WebApp\.(handlers|connectHandlers)\./;
|
|
|
|
let passed = 0;
|
|
const test = (name, fn) => { fn(); passed += 1; console.log(`ok - ${name}`); };
|
|
|
|
test('the three features that were never loaded are loaded now', () => {
|
|
for (const file of ['server/loginTimingNormalization.js', 'server/cardRecurrenceSchedule.js', 'server/productNameCache.js']) {
|
|
assert.ok(loaded.has(path.join(ROOT, file)), `${file} is not reached from server/main.js`);
|
|
}
|
|
});
|
|
|
|
test('negative: no server module that registers something at load time is left unloaded', () => {
|
|
const unloaded = [];
|
|
const walk = dir => {
|
|
for (const e of fs.readdirSync(path.join(ROOT, dir), { withFileTypes: true })) {
|
|
const rel = `${dir}/${e.name}`;
|
|
if (e.isDirectory()) { if (!['node_modules', 'tests', '_build', '.build'].includes(e.name)) walk(rel); }
|
|
else if (e.name.endsWith('.js') && SIDE_EFFECT.test(fs.readFileSync(path.join(ROOT, rel), 'utf8')) &&
|
|
!loaded.has(path.join(ROOT, rel))) unloaded.push(rel);
|
|
}
|
|
};
|
|
walk('server');
|
|
assert.deepEqual(unloaded, [], 'these register something but nothing imports them, so they never run');
|
|
});
|
|
|
|
console.log(`# ${passed} passed`);
|