-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcheck-dist.mjs
More file actions
97 lines (88 loc) · 3.57 KB
/
Copy pathcheck-dist.mjs
File metadata and controls
97 lines (88 loc) · 3.57 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env node
import { existsSync, readFileSync, statSync } from 'node:fs';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const required = [
'dist/agent-3d/latest/agent-3d.js',
'dist/agent-3d/latest/agent-3d.umd.cjs',
'dist/agent-3d/versions.json',
];
let ok = true;
for (const rel of required) {
if (!existsSync(resolve(root, rel))) {
console.error(`[check-dist] MISSING: ${rel}`);
ok = false;
}
}
if (ok) {
const versions = JSON.parse(readFileSync(resolve(root, 'dist/agent-3d/versions.json'), 'utf8'));
const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8'));
if (versions.latest !== pkg.version) {
console.error(
`[check-dist] versions.json "latest" is "${versions.latest}" but package.json is "${pkg.version}"`,
);
ok = false;
}
}
// dist-lib mirror checks
const distLibChecks = [
{ rel: 'dist/dist-lib/agent-3d.js', min: 1_000_000 },
{ rel: 'dist/dist-lib/agent-3d.umd.cjs', min: 100_000 },
];
for (const { rel, min } of distLibChecks) {
const p = resolve(root, rel);
if (!existsSync(p)) {
console.error(`[check-dist] MISSING: ${rel}`);
ok = false;
} else {
const size = statSync(p).size;
if (size < min) {
console.error(`[check-dist] TOO SMALL: ${rel} (${size} bytes, expected >= ${min})`);
ok = false;
}
}
}
// Known high-traffic static pages, checked directly against server/index.mjs's
// resolveStatic() resolution (directory → index.html fallback). A deploy with
// `npm run build` skipped (or run from a stale checkout) ships an incomplete
// dist/ with no error — that's exactly how /dashboard and /pump-dashboard
// 404'd in production on 2026-07-08 while check:dist reported green, because
// this check only ever looked at the agent-3d embed bundle. Not a full sweep
// of data/pages.json's 300 entries: most of those (docs/*, tutorials/*,
// .well-known/*, sitemap.xml) are server-rendered at request time by api/**
// handlers, not static build output, so a naive "every registered path must
// have a dist/ file" check false-flags them. This list is the pages actually
// known to be pure static Vite build output — extend it when another one
// breaks the same way, rather than trying to infer static-vs-dynamic from
// data/pages.json alone.
const criticalStaticPages = ['/', '/dashboard', '/pump-dashboard', '/dashboard-next', '/create', '/discover'];
function resolvesToFile(pagePath) {
// vercel.json rewrites "/" -> "/home.html" (server/index.mjs's phase1Routes,
// exact literal src, no /? suffix) rather than serving dist/index.html.
const candidates =
pagePath === '/'
? ['home.html']
: [pagePath, `${pagePath}/index.html`, `${pagePath}.html`];
for (const rel of candidates) {
const abs = resolve(root, 'dist', rel.replace(/^\//, ''));
try {
const st = statSync(abs);
if (st.isFile()) return true;
if (st.isDirectory() && existsSync(resolve(abs, 'index.html'))) return true;
} catch {
// try next candidate
}
}
return false;
}
const missingPages = criticalStaticPages.filter((p) => !resolvesToFile(p));
if (missingPages.length) {
console.error(`[check-dist] ${missingPages.length} critical static page(s) missing from dist/ (did \`npm run build\` run?):`);
for (const p of missingPages) console.error(`[check-dist] MISSING PAGE: ${p}`);
ok = false;
}
if (!ok) process.exit(1);
console.log('[check-dist] dist-lib mirror OK');
console.log(`[check-dist] all ${criticalStaticPages.length} critical static pages present`);
console.log('[check-dist] OK — dist/agent-3d/latest/ ready for deploy');