Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/html/styles-builder/css-provider-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,15 @@ describe("styles-builder CSS provider sessions", () => {
assertEquals(generated.css, "missing-optimizer|sheet|alpha");
});

it("reports a missing optimizer once, with the package that provides one", () => {
it("reports a missing optimizer once, with the steps that actually enable one", () => {
// `regenerateCSSByHash` acquires a session per request, so warning on every
// acquisition made this line the most frequent entry in a hosted project's
// logs -- once per render, at warn level, naming a registration hook with no
// documented way to act on it. State the package that registers an engine,
// and say it once while the engine stays absent.
// logs -- once per render, at warn level. Say it once while the engine stays
// absent, and give the whole recipe: `@veryfront/ext-css-lightning` declares
// `activation: "explicit"`, so installing the package registers nothing on
// its own. Only a `veryfront.config.ts` `extensions` entry activates it, and
// advice that stops at the install leaves the developer with unminified CSS
// and no next step.
installProcessor(createProcessor("warn-rearm"));
register(CSSOptimizationEngineName, createOptimizer("warn-rearm"));
// Observing an engine re-arms the warning, so this test does not depend on
Expand All @@ -236,10 +239,19 @@ describe("styles-builder CSS provider sessions", () => {
__resetLogRecordEmitterForTests();
}

const reports = records.filter((entry) => entry.message.includes("CSSOptimizationEngine"));
const reports = records.filter((entry) => entry.message.includes("unminified CSS"));
assertEquals(reports.length, 1);
const report = reports[0]?.message ?? "";
assertEquals(reports[0]?.level, "warn");
assertEquals(reports[0]?.message.includes("@veryfront/ext-css-lightning"), true);
assertEquals(report.includes("@veryfront/ext-css-lightning"), true);
assertEquals(report.includes("veryfront.config.ts"), true);
assertEquals(report.includes("extensions"), true);
// `deno add` is wrong twice over: scaffolded projects are npm projects, and
// no package manager can activate an explicit-activation extension.
assertEquals(report.includes("deno add"), false);
// The contract name is an internal registration hook the guides never
// mention, so it cannot appear as the developer-facing instruction.
assertEquals(report.includes("CSSOptimizationEngine"), false);
});

it("keeps minified and unminified output in separate cache identities", async () => {
Expand Down
18 changes: 14 additions & 4 deletions src/html/styles-builder/tailwind-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,24 @@ export function acquireCSSGenerationSession(minify: boolean): CSSGenerationSessi
//
// Once per process, not once per acquisition: regenerateCSSByHash acquires
// a session on every cold-cache request, which made this the single most
// frequent line in a hosted project's logs. Name the package that registers
// an engine, or the message asks for a hook with no way to reach it.
// frequent line in a hosted project's logs.
//
// State the effect and the whole remedy. An earlier revision borrowed
// `resolve()`'s "install it with: deno add <package>" hint, which is only
// true for an auto-activating extension: `@veryfront/ext-css-lightning`
// declares `activation: "explicit"`, so installing it registers nothing
// until a `veryfront.config.ts` `extensions` entry activates it, and
// scaffolded projects are npm projects where `deno add` is the wrong
// command besides. Advice that stops at the install reads as actionable and
// leaves the CSS exactly as unminified as before. The contract name stays
// out of the instruction: it is an internal registration hook the guides
// never mention, and `component=css-compiler` already identifies the source.
reportedMissingOptimizationEngine = true;
const recommendation = getRecommendation(CSSOptimizationEngineName);
logger.warn(
recommendation === undefined
? "No CSSOptimizationEngine registered; emitting unminified CSS"
: `No CSSOptimizationEngine registered; emitting unminified CSS. Install one with: deno add ${recommendation}`,
? "Veryfront emits unminified CSS because no CSS optimizer is active"
: `Veryfront emits unminified CSS because no CSS optimizer is active. Install ${recommendation}, then add it to "extensions" in veryfront.config.ts`,
);
}
const optimizationEngine = optimizationProvider === undefined
Expand Down