Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Walk the entry's transitive static import graph in the preload posture check

rcourtman42f3668c2527
diff --git a/frontend-modern/scripts/check-bundle-size.mjs b/frontend-modern/scripts/check-bundle-size.mjs
old mode 100644
new mode 100755
index 50518763f7..bddd56b634
--- a/frontend-modern/scripts/check-bundle-size.mjs
+++ b/frontend-modern/scripts/check-bundle-size.mjs
@@ -166,10 +166,33 @@ function checkPreloadPosture() {
// Static imports/re-exports in Rollup output: import ... from"./x.js",
// import"./x.js", export ... from"./x.js". Dynamic imports never match:
// their specifier follows an opening parenthesis, not the keyword.
- const allowedPreloads = new Set([entryFile]);
const staticImportRe = /\b(?:import|export)\s*(?:[\w$*{},\s]+?\s*from\s*)?["']\.\/([^"']+\.js)["']/g;
- let m;
- while ((m = staticImportRe.exec(entrySource))) allowedPreloads.add(m[1]);
+ function staticImportsOf(source) {
+ const specifiers = [];
+ let m;
+ while ((m = staticImportRe.exec(source))) specifiers.push(m[1]);
+ return specifiers;
+ }
+
+ // Vite preloads the entry's TRANSITIVE static import graph, so walk it:
+ // a chunk is preloadable iff it is reachable from the entry through static
+ // imports alone. Lazy route chunks are only reachable dynamically and stay
+ // excluded, as do their own static-only dependencies.
+ const allowedPreloads = new Set([entryFile]);
+ const queue = staticImportsOf(entrySource);
+ while (queue.length > 0) {
+ const file = queue.pop();
+ if (allowedPreloads.has(file)) continue;
+ allowedPreloads.add(file);
+ let source;
+ try {
+ source = readFileSync(join(DIST_ASSETS, file), 'utf8');
+ } catch {
+ errors.push(`statically imported chunk ${file} not found in dist/assets/`);
+ continue;
+ }
+ queue.push(...staticImportsOf(source));
+ }
for (const tag of html.match(/<link rel="modulepreload"[^>]*>/g) ?? []) {
const href = tag.match(/\bhref="\/assets\/([^"]+)"/);