create-website-build-kit 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-website-build-kit",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Scaffold a production marketing site \u2014 Astro on Cloudflare Workers, with the gates, the migration playbook and the accessibility work already wired.",
5
5
  "keywords": [
6
6
  "astro",
@@ -969,3 +969,38 @@ export removed the guesswork — prose never collides with a real export.
969
969
 
970
970
  **A checker with false positives gets switched off, and then its silence means
971
971
  "nobody looked" rather than "nothing wrong".**
972
+
973
+ ### A checker that counts source AND build output counts everything twice
974
+
975
+ **Symptom:** `npm run tells` reports *"3 auto-fill/auto-fit minmax grids"* on a
976
+ project whose entire source contains **one**. The threshold is "more than
977
+ twice", so a single grid fails the check. Removing grids does not help — the
978
+ count only drops when you get to zero.
979
+
980
+ `tells.mjs` reads `allCss = [...styleFiles, ...distCss]`, and including the
981
+ built stylesheets is deliberate and right *for presence tests*: a rule that
982
+ never reaches the build is not a rule the site has. It is wrong for **counting**.
983
+ Astro inlines shared CSS into every entry bundle, so one rule in `project.css`
984
+ is read once from source and again from each built stylesheet:
985
+
986
+ ```
987
+ 1× src/styles/project.css
988
+ 1× dist/client/_astro/Base.U1P5p-HP.css
989
+ 1× dist/client/_astro/contact.D3DAZGAV.css
990
+ ```
991
+
992
+ One rule, three matches, against a threshold of two.
993
+
994
+ **Fix:** count from source only. `tells.mjs` now builds a separate `sourceCss`
995
+ for the three tells that count rather than test presence — the grid count, the
996
+ long-animation count and the stripped-focus-ring count. The presence tests keep
997
+ reading the built CSS, because for those the build output is the point.
998
+
999
+ **Why it hid for so long:** the other two counting tells threshold at `> 0`, so
1000
+ duplication inflated their *reported number* without ever changing the verdict.
1001
+ Only the grid tell compares against a number greater than one, and only that one
1002
+ gave a wrong answer. The bug was in all three the whole time.
1003
+
1004
+ The general shape is worth keeping: **a checker that reads both a source and a
1005
+ generated copy of that source is counting the same thing more than once.** If
1006
+ its threshold is anything other than "any", it is wrong.
@@ -11,7 +11,8 @@
11
11
  * ── THE FAILURE THIS EXISTS FOR ────────────────────────────────────────────
12
12
  * `PUBLIC_SITE_ENV` decides indexability, canonical host, which KV namespace
13
13
  * leads land in, and whether analytics is emitted at all. `wrangler.jsonc`
14
- * decides which domains answer. Nothing connects the two.
14
+ * decides which domains answer. Nothing connects the two — this script is the
15
+ * only thing that does, so it needs no per-project editing to work.
15
16
  *
16
17
  * At go-live, two edits have to happen together: the routes gain
17
18
  * example.com, and the build command becomes `build:production`. Do
@@ -56,14 +57,68 @@ const patterns = (wrangler.routes ?? []).map((r) => (typeof r === 'string' ? r :
56
57
  was pointed at staging-only routes. It would have blocked the cutover. */
57
58
  const hostOf = (p) => String(p).split('/')[0];
58
59
  /*
59
- * SET THIS PER PROJECT. It must match the production apex, with or without
60
- * `www.` and must NOT match the staging subdomain, which ends in the same
61
- * string. Keep it in step with `PRODUCTION_HOSTS` in src/data/site.ts; those
62
- * two disagreeing is the failure this whole script exists to catch.
60
+ * The production hostnames come from src/data/site.ts the same list the site
61
+ * itself uses to decide indexability, canonicals and which KV namespace leads
62
+ * land in. NOT a copy of it.
63
+ *
64
+ * ── WHY THIS IS NOT A CONSTANT HERE ────────────────────────────────────────
65
+ * It used to be one, with a comment saying to keep it in step with site.ts.
66
+ * On the first real project it was not: site.ts had the client's domain, this
67
+ * file still had the template's example.com. So the guard matched nothing,
68
+ * called every deploy fine, and passed for the whole build — a guard that
69
+ * always passes is worse than none, because it reads as a check that ran.
70
+ *
71
+ * The drift WAS the failure this script exists to catch, reproduced inside the
72
+ * script. One source of truth is the only fix that holds; a sterner comment
73
+ * would not have survived the same afternoon.
74
+ *
75
+ * site.ts is TypeScript and imports `import.meta.env`, so node cannot import
76
+ * it. Read the literal out instead — same reasoning as stripping comments from
77
+ * wrangler.jsonc above rather than adding a parser.
63
78
  */
64
- const PRODUCTION_HOST = /^(www\.)?example\.com$/;
79
+ function readProductionHosts() {
80
+ let src;
81
+ try {
82
+ src = readFileSync('src/data/site.ts', 'utf8');
83
+ } catch {
84
+ /* An ENOENT stack trace is not an answer to someone mid-deploy. It also
85
+ usually means the script is being run from the wrong directory. */
86
+ console.error(
87
+ `\n${RED}✗ src/data/site.ts not found${RESET}\n\n` +
88
+ ' This guard reads the production hostnames from it. Run it from the\n' +
89
+ ' project root — `npm run build:staging` and `build:production` do.\n',
90
+ );
91
+ process.exit(1);
92
+ }
93
+ const m = /export const PRODUCTION_HOSTS\s*=\s*\[([^\]]*)\]/.exec(src);
94
+ /* A guard that cannot find its own input must FAIL, never pass quietly —
95
+ that is the whole lesson above, and it applies to this branch too. */
96
+ if (!m) {
97
+ console.error(
98
+ `\n${RED}✗ cannot read PRODUCTION_HOSTS from src/data/site.ts${RESET}\n\n` +
99
+ ' This guard derives the production hostnames from that export. Without it\n' +
100
+ ' it cannot tell a production deploy from a staging one, so it refuses to\n' +
101
+ ' pass rather than wave the build through.\n\n' +
102
+ " Expected a line like: export const PRODUCTION_HOSTS = ['example.com'] as const;\n",
103
+ );
104
+ process.exit(1);
105
+ }
106
+ const hosts = [...m[1].matchAll(/['"]([^'"]+)['"]/g)].map((h) => h[1].toLowerCase());
107
+ if (!hosts.length) {
108
+ console.error(
109
+ `\n${RED}✗ PRODUCTION_HOSTS in src/data/site.ts is empty${RESET}\n\n` +
110
+ ' Every deploy would read as staging, including the production one.\n',
111
+ );
112
+ process.exit(1);
113
+ }
114
+ return hosts;
115
+ }
116
+
117
+ /* Exact membership, never a suffix match — `new.example.com` ends in
118
+ `example.com` and is NOT production. Same rule as isProductionHost(). */
119
+ const PRODUCTION_HOSTS = readProductionHosts();
65
120
 
66
- const isProdHost = (p) => PRODUCTION_HOST.test(hostOf(p));
121
+ const isProdHost = (p) => PRODUCTION_HOSTS.includes(hostOf(p).toLowerCase());
67
122
  const routesProduction = patterns.some(isProdHost);
68
123
  const routesStagingOnly = patterns.length > 0 && !routesProduction;
69
124
 
@@ -64,6 +64,19 @@ const componentCss = componentFiles
64
64
  .flatMap((source) => [...source.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/g)].map((m) => m[1]))
65
65
  .join('\n');
66
66
  const everyCss = allCss + '\n' + componentCss;
67
+
68
+ /*
69
+ * ⚠ SOURCE ONLY, FOR ANYTHING THAT COUNTS. `allCss` deliberately includes the
70
+ * built stylesheets, which is right for presence tests — a rule that never
71
+ * reaches the build is not a rule the site has. It is wrong for counting: Astro
72
+ * inlines the same CSS into every entry bundle, so ONE rule in project.css is
73
+ * read once from source and again from each built stylesheet.
74
+ *
75
+ * That made the auto-fill grid tell fire on a single grid — 1 rule counted as
76
+ * 3, against a threshold of "more than twice". The tell was telling the truth
77
+ * about its own arithmetic and nothing about the site.
78
+ */
79
+ const sourceCss = styleFiles.map(read).join('\n') + '\n' + componentCss;
67
80
  /**
68
81
  * Raw component source, not just its <style> blocks. Inline `style=`
69
82
  * attributes are exactly where a card grid gets written when someone is
@@ -144,7 +157,7 @@ tell(
144
157
  // "three equal cards, centred, more than twice on one page"
145
158
  {
146
159
  const grids = [
147
- ...(everyCss + componentSource).matchAll(/repeat\(\s*auto-(fill|fit)\s*,\s*minmax/g),
160
+ ...(sourceCss + componentSource).matchAll(/repeat\(\s*auto-(fill|fit)\s*,\s*minmax/g),
148
161
  ].length;
149
162
  tell(
150
163
  'the auto-fill card grid, more than twice',
@@ -185,7 +198,7 @@ tell(
185
198
 
186
199
  // "any animation runs longer than ~400ms"
187
200
  {
188
- const slow = [...everyCss.matchAll(/(?:transition|animation)(?:-duration)?:[^;]*?(\d{3,4})ms/g)]
201
+ const slow = [...sourceCss.matchAll(/(?:transition|animation)(?:-duration)?:[^;]*?(\d{3,4})ms/g)]
189
202
  .map((m) => Number(m[1]))
190
203
  .filter((ms) => ms > 400);
191
204
  tell(
@@ -197,7 +210,7 @@ tell(
197
210
 
198
211
  // "focus rings are the browser default, or removed"
199
212
  {
200
- const stripped = [...everyCss.matchAll(/outline:\s*(none|0)\b/g)].length;
213
+ const stripped = [...sourceCss.matchAll(/outline:\s*(none|0)\b/g)].length;
201
214
  const restored = /:focus-visible[^{]*\{[^}]*outline:/.test(everyCss);
202
215
  tell(
203
216
  'focus ring removed and not replaced',