feat: add build-time manifest validation and event cleanup guidance

This commit is contained in:
saberzero1 2026-04-03 19:09:54 +02:00
parent ea06f6850c
commit 434551b80d
No known key found for this signature in database
4 changed files with 45 additions and 0 deletions

View file

@ -21,6 +21,13 @@
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
],
"no-restricted-syntax": [
"warn",
{
"selector": "Program:has(CallExpression[callee.property.name='addEventListener']):not(:has(CallExpression[callee.object.name='window'][callee.property.name='addCleanup']))",
"message": "addEventListener should be paired with window.addCleanup() for proper SPA cleanup. See ARCHITECTURE.md for details."
}
]
},
"overrides": [

2
.gitignore vendored
View file

@ -6,6 +6,8 @@ node_modules/
# Build output
build/
*.tsbuildinfo
!src/build/
!src/build/**
# Logs
logs

View file

@ -0,0 +1,33 @@
import fs from "fs";
import path from "path";
export function validateManifest(): void {
const pkgPath = path.resolve("package.json");
if (!fs.existsSync(pkgPath)) {
throw new Error("package.json not found");
}
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
const quartz = pkg.quartz;
if (!quartz) {
console.warn(
"\x1b[33m⚠ No 'quartz' field in package.json. Plugin may not load correctly in Quartz.\x1b[0m",
);
return;
}
const warnings: string[] = [];
if (!quartz.name) warnings.push("quartz.name is missing");
if (!quartz.displayName) warnings.push("quartz.displayName is missing");
if (!quartz.category) warnings.push("quartz.category is missing");
if (!quartz.version) warnings.push("quartz.version is missing");
if (warnings.length > 0) {
console.warn("\x1b[33m⚠ Plugin manifest warnings:\x1b[0m");
for (const w of warnings) {
console.warn(` - ${w}`);
}
}
}

View file

@ -1,6 +1,9 @@
import { defineConfig } from "tsup";
import type { Plugin } from "esbuild";
import path from "path";
import { validateManifest } from "./src/build/validate-manifest";
validateManifest();
/**
* Esbuild plugin that bundles `.inline.ts` files into browser-ready JavaScript strings.