File size: 1,590 Bytes
bc11697
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
/**
 * Asserts the build produced a real stylesheet.
 *
 * An unstyled page is a miserable thing to debug from a container log, because
 * every process reports success. Failing the image build instead turns it into
 * one obvious line.
 */
import { readdirSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";

const root = ".next/static";

function walk(dir) {
  const out = [];
  for (const entry of readdirSync(dir, { withFileTypes: true })) {
    const path = join(dir, entry.name);
    if (entry.isDirectory()) out.push(...walk(path));
    else out.push(path);
  }
  return out;
}

let files;
try {
  files = walk(root);
} catch {
  console.error(`verify-build: ${root} does not exist. The build did not emit assets.`);
  process.exit(1);
}

const sheets = files.filter((f) => f.endsWith(".css"));
if (sheets.length === 0) {
  console.error("verify-build: no stylesheet in the build output.");
  process.exit(1);
}

const biggest = sheets
  .map((f) => ({ f, size: statSync(f).size }))
  .sort((a, b) => b.size - a.size)[0];

if (biggest.size < 2000) {
  console.error(`verify-build: ${biggest.f} is only ${biggest.size} bytes, so Tailwind emitted nothing.`);
  process.exit(1);
}

const css = readFileSync(biggest.f, "utf8");
for (const token of ["--color-citron", "--color-void"]) {
  if (!css.includes(token)) {
    console.error(`verify-build: ${token} missing from ${biggest.f}. The theme did not compile.`);
    process.exit(1);
  }
}

console.log(`verify-build: ok, ${biggest.f} is ${biggest.size} bytes with the theme tokens.`);