Load SCUM catalog icons on demand instead of importing every icon module

- Resolve the 2604 extracted icons through a generated static asset URL lookup instead of an eager import.meta.glob, so opening a plugin page no longer pulls every icon as its own dev-server module.
- Keep the icon URLs cacheable per rendered element and add a test that the catalog never regains the module glob and that every declared icon file ships.
This commit is contained in:
npc0-hue
2026-09-15 16:43:49 +08:00
parent 59a8657297
commit 839aff35ed
2 changed files with 2641 additions and 9 deletions
+22
View File
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { existsSync, readFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { scumCatalogEntries, scumCatalogIconUrl } from "../examples/scum-server-plugin/features/scum-catalog.js";
const pluginRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../examples/scum-server-plugin");
const catalogSource = readFileSync(join(pluginRoot, "features/scum-catalog.ts"), "utf8");
describe("scum catalog icons", () => {
it("resolves icons on demand instead of importing each icon as its own module", () => {
expect(catalogSource).not.toContain("import.meta.glob");
expect(scumCatalogIconUrl("npcs/zombie11.webp")).toContain("zombie11.webp");
expect(scumCatalogIconUrl("npcs/does-not-exist.webp")).toBe("");
});
it("ships an icon file for every entry that declares one", () => {
const missing = scumCatalogEntries.filter((entry) => entry.icon && !existsSync(join(pluginRoot, "assets/scum-catalog", entry.icon)));
expect(missing.map((entry) => entry.icon)).toEqual([]);
});
});