@zero2webmaster/starter-kit 0.44.0 → 0.46.0
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/README.md +7 -3
- package/dist/scaffolders/cf-worker.js +3 -1
- package/dist/scaffolders/library.js +20 -1
- package/dist/scaffolders/nextjs.js +41 -2
- package/dist/scaffolders/node-service.js +3 -1
- package/dist/scaffolders/pre-push-hook.d.ts +30 -0
- package/dist/scaffolders/pre-push-hook.js +148 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# z2w-starter-kit
|
|
2
2
|
|
|
3
|
-
**Version:** 0.
|
|
3
|
+
**Version:** 0.46.0 | **Framework:** 2.19.0
|
|
4
4
|
|
|
5
5
|
> Node CLI to scaffold new Z2W projects from canonical Templates + AGENTS.md.
|
|
6
6
|
|
|
@@ -83,7 +83,11 @@ The Claude Code skill at `~/.claude/skills/instantiate-z2w-project/SKILL.md` and
|
|
|
83
83
|
|
|
84
84
|
## Status
|
|
85
85
|
|
|
86
|
-
- **v0.
|
|
86
|
+
- **v0.46.0 (current)** gets `nextjs` scaffolds ready for phones. Installed to a home screen, the app now draws edge to edge (`viewport-fit=cover`), and the page is padded by the phone's safe areas so the notch and home indicator never cover content; CSS variables (`--safe-top`, `--safe-bottom` and so on) let a fixed bar pad itself. A `prefers-reduced-motion` rule turns any animation or transition into an instant change for people who switch on Reduce Motion. Verified on a real build in Chromium: no change at all on an ordinary screen.
|
|
87
|
+
|
|
88
|
+
- **v0.45.0** runs the tests before every push. `nextjs`, `cf-worker`, `library` and `node-service` scaffolds now ship a tracked `pre-push` hook that runs `npm test`, installed into the repo's own `.git/hooks/` by `npm install` (skipped in CI, never fails an install). Until now the scaffold emitted a test script that nothing ran: `audit-engine` measured 24 of 29 multi-tenant apps whose cross-tenant tests ran only when someone typed the command. A `library` scaffold also gets a starter test, because its first `npm test` used to fail with "No test files found". Verified on real scaffolds from the built `dist/`, through the global hook dispatcher: a green push passes, a red one is refused.
|
|
89
|
+
|
|
90
|
+
- **v0.44.0** stops the PWA service worker from storing pages. Since v0.19.0 it cached every page it loaded, including signed-in ones, which then stayed readable offline after sign-out. Page loads now go to the network, with a built-in "You're offline" page when that fails, and only content-hashed `/_next/static/` files are cached. Verified in Chromium against a dynamic page, with the old worker as a control. Full detail in [CHANGELOG.md](CHANGELOG.md).
|
|
87
91
|
|
|
88
92
|
- **v0.27.0** answers `org-hq`'s two scaffold defects, ten days after they were filed. The headline: **`app/robots.ts` was asking the wrong question.** Its gate required a production deployment AND a real custom domain — and an internal admin console satisfies **both** while still being wrong to index, so `org-hq` served `Allow: /` on a branded public subdomain for a month with every check it had passing, because none of them asked. Indexability now takes a third condition, `hasPublicSurface`, baked in at scaffold time rather than read from the environment, because it is a fact about what an app IS and not about where a copy of it is running. **It fails CLOSED** — omitted reads as "no public surface" — which is the opposite default from every other optional input here and is deliberate: a public site wrongly withheld is one field and a redeploy with nothing having escaped, while an internal console wrongly published is silent, slow to undo, and has already happened by the time anyone notices. The wizard and brief-first flows ask, and the CLI's final summary now **states the posture out loud in both directions**, since a silent default is how the original defect survived. `cf-pages` is fixed in the same release — it published `Allow: /` unconditionally — because shipping the fix only in the type that was reported would have left its sibling quietly broken. The second defect: the `*.vercel.app` alias redirect now **excludes `/api/*`**, whose SEO rationale never applied and whose 308 breaks every server-to-server caller that does not follow redirects. **And re-measuring the report changed it:** the companion claim — that adding the exclusion would silently stop redirecting `/`, because a `:path` param cannot match the empty string — **did not reproduce.** On Next.js 15.5.23 a CUSTOM param pattern supplies its own `.*`, which matches empty, so the wildcard alone still redirected the root; the explicit root rule ships anyway as insurance against a path-to-regexp detail that is not a documented guarantee, described as insurance rather than as a repair. Verified per tier 1 on two real scaffolds from the built `dist/` — `npm install`, a real `next build`, and `curl` with forged `Host` headers against both the shipped form and a control build with the root rule removed. **1241 of 1241 passing.**
|
|
89
93
|
- **v0.26.0** releases two things. First, the **per-service Uptime Kuma health keyword**, built on 2026-08-21 but never released or written down until now: every deploy target's health document serves `{"status":"ok","service":"<slug>","keyword":"<slug>-health-ok"}`, and the emitted standards block tells the reader to match the full keyword. **The old portfolio-wide `"status":"ok"` was worthless as a check** — byte-identical across every Z2W service, so a monitor with a mistyped URL, one copied from a sibling project, or one left pointing at a decommissioned host still went green, which is the exact failure a keyword exists to catch; a portfolio audit found **12 of 23 monitors** keyed on it. The value is DERIVED from the slug via `healthKeyword()`, which is the load-bearing half — a shared constant would rebuild the same trap with extra steps. Second, a fix in `rollup-integrations.mjs`: **a comma in an author's prose is not an edge separator.** Stripping parentheticals before splitting handled the `(why…)` note form and did nothing for the canonical form's `— why` note, which runs to end of line, so `- consumes: contact-registry — people, tags, entitlements.` was about to write **`tags`** into the Project Registry as a dependency of `commerce-engine`, and `audit-engine`'s trailing sentence was about to write **`live-status`**. Both had been PRINTED on every run under `ⓘ not registry slugs (external, or prose noise — check)` — a line that reports and does not filter, so **a reported artifact that is still written is not a caught one**. A comma-part is now an edge only when it is a known registry slug or carries a `:qualifier`, with the first part exempt because that is where the author names the edge and the only position a legitimate non-registry backend occupies. The same work uncovered the inverse defect — a MISS: prose left attached to the last inline item swallowed its slug, so `z2w-observability-bridge`'s section yielded **only `Vercel`**, an external its own sentence had just disclaimed, while its real edge went unread. **1233 of 1233 passing.**
|
|
@@ -137,4 +141,4 @@ Inquiries: kerry@zero2webmaster.com.
|
|
|
137
141
|
---
|
|
138
142
|
|
|
139
143
|
*Scaffolded 2026-05-28 via the [[instantiate-z2w-project]] Claude Code skill v1; reconciled against the consolidated skill v1.1.0 (brief-first + Agent Coordination block) on 2026-05-29.*
|
|
140
|
-
*Version: 0.
|
|
144
|
+
*Version: 0.46.0 | Last Updated: 2026-10-27*
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// to the SEO baseline (no indexable HTML surface). Compatibility date pinned
|
|
5
5
|
// to {{date}} so scaffolded projects start on the user's scaffold day, not
|
|
6
6
|
// some hardcoded past day.
|
|
7
|
+
import { prePushHookFiles, withHookScripts } from "./pre-push-hook.js";
|
|
7
8
|
import { commonBaseFiles, resolveBrandSpec, sub, } from "./common.js";
|
|
8
9
|
const NARRATIVE = `## What this is
|
|
9
10
|
|
|
@@ -171,7 +172,8 @@ export function scaffoldCfWorker(inputs, opts) {
|
|
|
171
172
|
{ path: "wrangler.jsonc", content: sub(WRANGLER_TEMPLATE, inputs, opts, spec) },
|
|
172
173
|
{ path: "src/index.ts", content: sub(SRC_INDEX_TEMPLATE, inputs, opts, spec) },
|
|
173
174
|
{ path: "src/index.test.ts", content: sub(SRC_INDEX_TEST_TEMPLATE, inputs, opts, spec) },
|
|
174
|
-
{ path: "package.json", content: sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec) },
|
|
175
|
+
{ path: "package.json", content: withHookScripts(sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec)) },
|
|
176
|
+
...prePushHookFiles(),
|
|
175
177
|
{ path: "tsconfig.json", content: sub(TSCONFIG_TEMPLATE, inputs, opts, spec) },
|
|
176
178
|
{ path: "vitest.config.ts", content: sub(VITEST_CONFIG_TEMPLATE, inputs, opts, spec) },
|
|
177
179
|
{ path: ".dev.vars", content: sub(DEV_VARS_TEMPLATE, inputs, opts, spec) },
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// No web surface, no /health, no Fathom, no SEO baseline. Just a clean npm
|
|
4
4
|
// package skeleton that compiles with `tsc` and exports a stub `version`.
|
|
5
|
+
import { prePushHookFiles, withHookScripts } from "./pre-push-hook.js";
|
|
5
6
|
import { commonBaseFiles, localEnvFrom, resolveBrandSpec, sub, } from "./common.js";
|
|
6
7
|
const NARRATIVE = `## What this is
|
|
7
8
|
|
|
@@ -102,6 +103,22 @@ const SRC_INDEX_TEMPLATE = `// {{slug}} — public API.
|
|
|
102
103
|
|
|
103
104
|
export const version = "{{version}}";
|
|
104
105
|
`;
|
|
106
|
+
// Until v0.45.0 a library scaffold shipped `"test": "vitest run"` and no test
|
|
107
|
+
// file, so its first `npm test` failed with "No test files found". Harmless
|
|
108
|
+
// while nothing ran it; fatal once the pre-push hook runs it on every push.
|
|
109
|
+
const SRC_INDEX_TEST_TEMPLATE = `import { readFileSync } from "node:fs";
|
|
110
|
+
|
|
111
|
+
import { describe, expect, it } from "vitest";
|
|
112
|
+
|
|
113
|
+
import { version } from "./index.js";
|
|
114
|
+
|
|
115
|
+
describe("{{slug}}", () => {
|
|
116
|
+
it("exports the version that package.json declares", () => {
|
|
117
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
118
|
+
expect(version).toBe(pkg.version);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
`;
|
|
105
122
|
// A no-deploy library has no runtime secrets of its own, but in this portfolio
|
|
106
123
|
// libraries routinely need keys for dogfood scripts, integration tests, or a
|
|
107
124
|
// later HTTP surface (z2w-ai-engine, a library wrapping embedding providers, is
|
|
@@ -132,9 +149,11 @@ export function scaffoldLibrary(inputs, opts) {
|
|
|
132
149
|
const base = commonBaseFiles(inputs, opts, NARRATIVE);
|
|
133
150
|
const envExample = sub(ENV_EXAMPLE_TEMPLATE, inputs, opts, spec);
|
|
134
151
|
const typeSpecific = [
|
|
135
|
-
{ path: "package.json", content: sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec) },
|
|
152
|
+
{ path: "package.json", content: withHookScripts(sub(PACKAGE_JSON_TEMPLATE, inputs, opts, spec)) },
|
|
153
|
+
...prePushHookFiles(),
|
|
136
154
|
{ path: "tsconfig.json", content: sub(TSCONFIG_TEMPLATE, inputs, opts, spec) },
|
|
137
155
|
{ path: "src/index.ts", content: sub(SRC_INDEX_TEMPLATE, inputs, opts, spec) },
|
|
156
|
+
{ path: "src/index.test.ts", content: sub(SRC_INDEX_TEST_TEMPLATE, inputs, opts, spec) },
|
|
138
157
|
{ path: "LICENSE", content: sub(LICENSE_TEMPLATE, inputs, opts, spec) },
|
|
139
158
|
{ path: ".env.example", content: envExample },
|
|
140
159
|
// A library's local-env convention is `.env` (gitignored), like python — not
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
// allowlist stub in `.env.example`. This CLI emits no auth code, so it plants the
|
|
47
47
|
// seam + the pointer at [[z2w-magic-link-auth]] §0 rule 2b rather than a check —
|
|
48
48
|
// see CANONICAL_HOSTS_ENV_BLOCK for why that is the honest half.
|
|
49
|
+
import { prePushHookFiles, withHookScripts } from "./pre-push-hook.js";
|
|
49
50
|
import { GUIDE_MODULE_TEMPLATE, GUIDE_PAGE_TEMPLATE, GUIDE_TEST_TEMPLATE, WHATS_NEW_PAGE_TEMPLATE, } from "./nextjs-guide.js";
|
|
50
51
|
import { commonBaseFiles, EMAIL_DEPS, EMAIL_ENV_BLOCK, emailFiles, localEnvFrom, accessibleOn, contrastRatio, readableInkOn, resolveBrandSpec, SENTRY_DEPS, NEON_DRIVER_DEP, sub, } from "./common.js";
|
|
51
52
|
const NARRATIVE = `## What this is
|
|
@@ -1474,8 +1475,8 @@ const PAGE_SURFACE = "#ffffff";
|
|
|
1474
1475
|
*
|
|
1475
1476
|
* What is deliberately NOT interpolated here is as load-bearing as what is:
|
|
1476
1477
|
* the required marker and the info-hint summary use FIXED accessible colors,
|
|
1477
|
-
* never `{{accent_color}}`. Z2W gold (`#FFD700`) is
|
|
1478
|
-
* orange (`#f5821f`)
|
|
1478
|
+
* never `{{accent_color}}`. Z2W gold (`#FFD700`) is 1.40:1 on white and STF
|
|
1479
|
+
* orange (`#f5821f`) 2.59:1 (both measured) — using the brand accent as small text ships an
|
|
1479
1480
|
* illegible glyph under a brand-consistency rationale.
|
|
1480
1481
|
*/
|
|
1481
1482
|
function globalsCss(primaryColor) {
|
|
@@ -1529,10 +1530,39 @@ function globalsCss(primaryColor) {
|
|
|
1529
1530
|
/* The page itself. Named so \`test/contrast.test.ts\` can enumerate SURFACES
|
|
1530
1531
|
rather than assume one — the whole point of that file. */
|
|
1531
1532
|
--page-surface: ${PAGE_SURFACE};
|
|
1533
|
+
/* The phone's notch, rounded corners and home indicator. app/layout.tsx sets
|
|
1534
|
+
\`viewportFit: "cover"\`, so the page is drawn edge to edge and these say how
|
|
1535
|
+
much of each edge the hardware hides. They are 0px on a desktop and on any
|
|
1536
|
+
phone without a notch, so they cost nothing where they are not needed.
|
|
1537
|
+
<body> already pads by them. A FIXED or STICKY bar does not inherit that
|
|
1538
|
+
padding (it is positioned against the viewport, not the body), so give it
|
|
1539
|
+
its own, e.g. \`padding-bottom: var(--safe-bottom)\` on a bottom tab bar —
|
|
1540
|
+
otherwise the home indicator sits on top of its buttons once installed. */
|
|
1541
|
+
--safe-top: env(safe-area-inset-top, 0px);
|
|
1542
|
+
--safe-right: env(safe-area-inset-right, 0px);
|
|
1543
|
+
--safe-bottom: env(safe-area-inset-bottom, 0px);
|
|
1544
|
+
--safe-left: env(safe-area-inset-left, 0px);
|
|
1532
1545
|
}
|
|
1533
1546
|
|
|
1534
1547
|
body {
|
|
1535
1548
|
background: var(--page-surface);
|
|
1549
|
+
padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
/* Reduce Motion (an OS accessibility setting) means "no movement": it is there
|
|
1553
|
+
for people who get dizzy or nauseous from animation. The scaffold itself has
|
|
1554
|
+
no animation, so this is for the first one somebody adds. It shortens every
|
|
1555
|
+
animation and transition to an instant rather than removing it, so code that
|
|
1556
|
+
waits for \`transitionend\` or \`animationend\` still gets the event. */
|
|
1557
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1558
|
+
*,
|
|
1559
|
+
*::before,
|
|
1560
|
+
*::after {
|
|
1561
|
+
animation-duration: 0.01ms !important;
|
|
1562
|
+
animation-iteration-count: 1 !important;
|
|
1563
|
+
transition-duration: 0.01ms !important;
|
|
1564
|
+
scroll-behavior: auto !important;
|
|
1565
|
+
}
|
|
1536
1566
|
}
|
|
1537
1567
|
|
|
1538
1568
|
html {
|
|
@@ -3999,6 +4029,10 @@ export const metadata: Metadata = {
|
|
|
3999
4029
|
|
|
4000
4030
|
export const viewport: Viewport = {
|
|
4001
4031
|
themeColor: "{{primary_color}}",
|
|
4032
|
+
// Draw edge to edge, under the notch and home indicator, when installed.
|
|
4033
|
+
// Safe only because app/globals.css pads <body> by env(safe-area-inset-*);
|
|
4034
|
+
// remove that padding and this hides content behind the notch in landscape.
|
|
4035
|
+
viewportFit: "cover",
|
|
4002
4036
|
};
|
|
4003
4037
|
|
|
4004
4038
|
const organizationJsonLd = {
|
|
@@ -4316,6 +4350,8 @@ Not SEO, but it is a pre-launch check and this is the pre-launch file.
|
|
|
4316
4350
|
- ✅ \`public/icon.svg\` — 512×512, listed twice in the manifest (\`purpose: "any"\` **and** \`purpose: "maskable"\`)
|
|
4317
4351
|
- ✅ \`public/sw.js\` — never stores a page (signed-in pages would stay readable offline after sign-out); page loads go to the network with a built-in offline page; only \`/_next/static/\` build files are cached
|
|
4318
4352
|
- ✅ \`components/ServiceWorker.tsx\` — registers the worker in **production only**, mounted from \`app/layout.tsx\`
|
|
4353
|
+
- ✅ Safe areas — \`viewportFit: "cover"\` in \`app/layout.tsx\`, and \`<body>\` padded by \`env(safe-area-inset-*)\` in \`app/globals.css\`
|
|
4354
|
+
- [ ] **Every fixed or sticky bar pads itself** with \`var(--safe-top)\` / \`var(--safe-bottom)\` (it does not inherit the body's padding); check it on a real iPhone with the app installed to the home screen
|
|
4319
4355
|
- [ ] **Verify installability on the deployed site, not locally** — the worker does not register under \`next dev\` by design. Chrome DevTools → Application → Manifest should list the manifest with no errors and both icon purposes; Application → Service Workers should show \`sw.js\` activated
|
|
4320
4356
|
- [ ] **Confirm no page or API response is cached** — DevTools → Application → Cache Storage → \`{{slug}}-v2\` should list only \`/_next/static/\` files
|
|
4321
4357
|
- [ ] Replace \`public/icon.svg\` with real artwork; keep the 512×512 frame and keep the mark inside the central ~80% (Android crops the rest)
|
|
@@ -5786,6 +5822,8 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
5786
5822
|
else if (durableLimit) {
|
|
5787
5823
|
packageJson = withExtraDeps(packageJson, NEON_DRIVER_DEP);
|
|
5788
5824
|
}
|
|
5825
|
+
// A test script nothing runs is not a gate (ROADMAP Step 52).
|
|
5826
|
+
packageJson = withHookScripts(packageJson);
|
|
5789
5827
|
let envExample = sub(ENV_EXAMPLE_TEMPLATE, inputs, opts, spec);
|
|
5790
5828
|
// Gated on the DB STRATEGY, not on `durableLimit` — the variable belongs to
|
|
5791
5829
|
// the project's database, not to the one emitted module that happens to read
|
|
@@ -5804,6 +5842,7 @@ export function scaffoldNextjs(inputs, opts) {
|
|
|
5804
5842
|
envExample += CARD_PATH_ENV_BLOCK;
|
|
5805
5843
|
const typeSpecific = [
|
|
5806
5844
|
{ path: "package.json", content: packageJson },
|
|
5845
|
+
...prePushHookFiles(),
|
|
5807
5846
|
{
|
|
5808
5847
|
path: "next.config.mjs",
|
|
5809
5848
|
content: sub(hostRouted ? NEXT_CONFIG_HOST_ROUTED_TEMPLATE : NEXT_CONFIG_TEMPLATE, inputs, opts, spec),
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// NOT subject to the SEO baseline (API-only service, no public HTML surface)
|
|
15
15
|
// and NOT to Fathom (no web UI). IS a deploy target, so the standards resolver
|
|
16
16
|
// inserts the Uptime Kuma + (when applicable) Neon-careful disciplines.
|
|
17
|
+
import { prePushHookFiles, withHookScripts } from "./pre-push-hook.js";
|
|
17
18
|
import { commonBaseFiles, EMAIL_DEPS, EMAIL_ENV_BLOCK, emailFiles, localEnvFrom, resolveBrandSpec, sub, } from "./common.js";
|
|
18
19
|
function buildNarrative(usesNeon) {
|
|
19
20
|
const dbParagraph = usesNeon
|
|
@@ -317,7 +318,8 @@ export function scaffoldNodeService(inputs, opts) {
|
|
|
317
318
|
const base = commonBaseFiles(inputs, opts, buildNarrative(usesNeon));
|
|
318
319
|
const envExample = sub(buildEnvExample(usesNeon, sendsEmail), inputs, opts, spec);
|
|
319
320
|
const typeSpecific = [
|
|
320
|
-
{ path: "package.json", content: sub(buildPackageJson(usesNeon, sendsEmail), inputs, opts, spec) },
|
|
321
|
+
{ path: "package.json", content: withHookScripts(sub(buildPackageJson(usesNeon, sendsEmail), inputs, opts, spec)) },
|
|
322
|
+
...prePushHookFiles(),
|
|
321
323
|
{ path: "tsconfig.json", content: sub(TSCONFIG_TEMPLATE, inputs, opts, spec) },
|
|
322
324
|
{ path: "vitest.config.ts", content: sub(VITEST_CONFIG_TEMPLATE, inputs, opts, spec) },
|
|
323
325
|
{ path: "src/index.ts", content: sub(SRC_INDEX_TEMPLATE, inputs, opts, spec) },
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tracked `pre-push` hook that runs `npm test`, for every scaffold whose
|
|
3
|
+
* package.json has a test script (`nextjs`, `cf-worker`, `library`,
|
|
4
|
+
* `node-service`).
|
|
5
|
+
*
|
|
6
|
+
* Why (ROADMAP Step 52, `audit-engine`'s 2026-10-25 ACTION): the scaffold
|
|
7
|
+
* emitted `"test": "vitest run"` and nothing that ever ran it. Across 29 apps
|
|
8
|
+
* with tenants, 24 had cross-tenant tests that ran only when an agent typed the
|
|
9
|
+
* command. A local hook costs zero Actions minutes and fails while the author is
|
|
10
|
+
* still at the keyboard ([[github-actions-minute-budget]];
|
|
11
|
+
* [[second-tenant-audit]] Hazard 11). No Actions workflow is emitted: the
|
|
12
|
+
* account's 2,000 shared minutes are the scarce resource.
|
|
13
|
+
*
|
|
14
|
+
* Ported from `file-server`'s `tools/install-hooks.sh`, keeping its three
|
|
15
|
+
* safety rules (each learned when its first draft overwrote Kerry's GLOBAL hook
|
|
16
|
+
* dispatcher), plus one more: in a linked worktree the hooks folder belongs to
|
|
17
|
+
* the main checkout, so the installer skips rather than reaching outside.
|
|
18
|
+
*
|
|
19
|
+
* `prepare` runs on every `npm install`, so it must never fail one: the Node
|
|
20
|
+
* wrapper skips under CI (Vercel and Actions both set `CI`), skips when there is
|
|
21
|
+
* no git repo yet, and turns any installer failure into a warning.
|
|
22
|
+
*/
|
|
23
|
+
import type { ScaffoldFile } from "./common.js";
|
|
24
|
+
export declare const PRE_PUSH_HOOK = "#!/usr/bin/env bash\n#\n# pre-push hook: runs `npm test` before every push.\n# Installed into .git/hooks/ by `npm run hooks:install` (and by `npm install`).\n#\n# Why a hook and not CI: it costs no Actions minutes, and it fails while you are\n# still here to fix it, instead of in a badge nobody re-reads.\n#\n# Skip once: `git push --no-verify`, or `SKIP_PREPUSH=1 git push`.\n\nset -euo pipefail\n\nif [ \"${SKIP_PREPUSH:-}\" = \"1\" ]; then\n echo \"\u00B7 pre-push: skipped (SKIP_PREPUSH=1)\"\n exit 0\nfi\n\ncd \"$(git rev-parse --show-toplevel)\"\n\necho \"\u00B7 pre-push: npm test (skip once with --no-verify)\"\n\n# git passes the refs being pushed on stdin; the tests must not read them.\nif ! npm test < /dev/null; then\n echo \"\"\n echo \"\u2717 pre-push blocked: the tests failed.\"\n echo \" Fix them, or push anyway with: git push --no-verify\"\n exit 1\nfi\n\necho \"\u2713 pre-push: tests passed\"\n";
|
|
25
|
+
export declare const INSTALL_HOOKS_SH = "#!/usr/bin/env bash\n#\n# Install this repo's git hooks. Run: `npm run hooks:install`\n# (`npm install` also runs it, through tools/prepare-hooks.mjs.)\n#\n# Hooks live in tools/ (tracked in git) and are copied into THIS repo's\n# .git/hooks/ (not tracked). Safe to re-run.\n#\n# Four safety rules. The first three were learned when an earlier installer\n# overwrote a machine-wide git hook dispatcher:\n#\n# 1. Find the hooks folder with `git rev-parse --git-dir`, never\n# `git rev-parse --git-path hooks`. The latter follows a global\n# `core.hooksPath`, so a repo installer would write machine-wide.\n# 2. Refuse to write anywhere outside this repository.\n# 3. `rm -f` the destination before copying. A global hooks folder often\n# holds SYMLINKS to a shared dispatcher, and `cp` follows a symlink.\n# 4. In a linked worktree, do nothing: the hooks folder is the main\n# checkout's, outside this folder. Run this from the main checkout.\n#\n# A global `core.hooksPath` dispatcher that chains to `.git/hooks/<name>`\n# runs first and then runs this hook. Both run, in that order.\nset -euo pipefail\n\nrepo_root=\"$(cd \"$(dirname \"$0\")/..\" && pwd)\"\ncd \"$repo_root\"\n\n# Rule 4: a linked worktree shares the main checkout's hooks.\ngit_dir=\"$(cd \"$(git rev-parse --git-dir)\" && pwd)\"\ncommon_dir=\"$(cd \"$(git rev-parse --git-common-dir)\" && pwd)\"\nif [ \"$git_dir\" != \"$common_dir\" ]; then\n echo \"\u00B7 hooks: this is a linked worktree; its hooks are the main checkout's.\"\n echo \" Run \\`npm run hooks:install\\` there instead. Nothing was installed.\"\n exit 0\nfi\n\n# Rule 1: --git-dir, not --git-path hooks.\nhooks_dir=\"$git_dir/hooks\"\n\n# Rule 2: never write outside the repository.\ncase \"$hooks_dir\" in\n \"$repo_root\"/*) ;;\n *)\n echo \"\u2717 refusing to install: the hooks folder is outside this repo\" >&2\n echo \" repo: $repo_root\" >&2\n echo \" hooks: $hooks_dir\" >&2\n exit 1\n ;;\nesac\n\nlocal_hooks=\"$(git config --local --get core.hooksPath || true)\"\nif [ -n \"$local_hooks\" ]; then\n echo \"! this repo sets core.hooksPath to $local_hooks, so git will not read .git/hooks.\" >&2\n echo \" Copy tools/pre-push there by hand, or unset it. Nothing was installed.\" >&2\n exit 1\nfi\n\nmkdir -p \"$hooks_dir\"\n\nfor src in tools/pre-push; do\n dest=\"$hooks_dir/$(basename \"$src\")\"\n\n # Rule 3: clear the path first so cp cannot follow a symlink to its target.\n if [ -L \"$dest\" ]; then\n echo \"\u00B7 $dest was a symlink to $(readlink \"$dest\"); replacing the link, not its target\"\n fi\n rm -f \"$dest\"\n\n cp \"$src\" \"$dest\"\n chmod +x \"$dest\"\n\n if [ ! -f \"$dest\" ] || [ -L \"$dest\" ] || [ ! -x \"$dest\" ] || ! cmp -s \"$src\" \"$dest\"; then\n echo \"\u2717 failed to install $src to $dest\" >&2\n exit 1\n fi\n echo \"\u2713 installed $src \u2192 $dest\"\ndone\n\necho \"The tests now run before each push. Skip once with: git push --no-verify\"\n";
|
|
26
|
+
export declare const PREPARE_HOOKS_MJS = "// Runs on every `npm install` (the \"prepare\" script). Installs the git hooks\n// in tools/ and must NEVER fail an install: it skips in CI (Vercel and GitHub\n// Actions set CI), skips when there is no git repo yet, and turns any installer\n// error into a one-line warning. To install by hand: npm run hooks:install\nimport { spawnSync } from \"node:child_process\";\n\nif (process.env.CI) process.exit(0);\n\nconst inRepo = spawnSync(\"git\", [\"rev-parse\", \"--git-dir\"], { stdio: \"ignore\" });\nif (inRepo.status !== 0) {\n console.log(\"\u00B7 hooks: no git repo yet; run `npm run hooks:install` after `git init`.\");\n process.exit(0);\n}\n\nconst run = spawnSync(\"bash\", [\"tools/install-hooks.sh\"], { stdio: \"inherit\" });\nif (run.status !== 0) {\n console.warn(\"! hooks were not installed (see above). npm install itself is fine.\");\n}\nprocess.exit(0);\n";
|
|
27
|
+
export declare const HOOK_SCRIPTS: Readonly<Record<string, string>>;
|
|
28
|
+
export declare function prePushHookFiles(): ScaffoldFile[];
|
|
29
|
+
/** Adds {@link HOOK_SCRIPTS} to a package.json string, keeping its layout. */
|
|
30
|
+
export declare function withHookScripts(pkgJson: string): string;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
export const PRE_PUSH_HOOK = `#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# pre-push hook: runs \`npm test\` before every push.
|
|
4
|
+
# Installed into .git/hooks/ by \`npm run hooks:install\` (and by \`npm install\`).
|
|
5
|
+
#
|
|
6
|
+
# Why a hook and not CI: it costs no Actions minutes, and it fails while you are
|
|
7
|
+
# still here to fix it, instead of in a badge nobody re-reads.
|
|
8
|
+
#
|
|
9
|
+
# Skip once: \`git push --no-verify\`, or \`SKIP_PREPUSH=1 git push\`.
|
|
10
|
+
|
|
11
|
+
set -euo pipefail
|
|
12
|
+
|
|
13
|
+
if [ "\${SKIP_PREPUSH:-}" = "1" ]; then
|
|
14
|
+
echo "· pre-push: skipped (SKIP_PREPUSH=1)"
|
|
15
|
+
exit 0
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
cd "$(git rev-parse --show-toplevel)"
|
|
19
|
+
|
|
20
|
+
echo "· pre-push: npm test (skip once with --no-verify)"
|
|
21
|
+
|
|
22
|
+
# git passes the refs being pushed on stdin; the tests must not read them.
|
|
23
|
+
if ! npm test < /dev/null; then
|
|
24
|
+
echo ""
|
|
25
|
+
echo "✗ pre-push blocked: the tests failed."
|
|
26
|
+
echo " Fix them, or push anyway with: git push --no-verify"
|
|
27
|
+
exit 1
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
echo "✓ pre-push: tests passed"
|
|
31
|
+
`;
|
|
32
|
+
export const INSTALL_HOOKS_SH = `#!/usr/bin/env bash
|
|
33
|
+
#
|
|
34
|
+
# Install this repo's git hooks. Run: \`npm run hooks:install\`
|
|
35
|
+
# (\`npm install\` also runs it, through tools/prepare-hooks.mjs.)
|
|
36
|
+
#
|
|
37
|
+
# Hooks live in tools/ (tracked in git) and are copied into THIS repo's
|
|
38
|
+
# .git/hooks/ (not tracked). Safe to re-run.
|
|
39
|
+
#
|
|
40
|
+
# Four safety rules. The first three were learned when an earlier installer
|
|
41
|
+
# overwrote a machine-wide git hook dispatcher:
|
|
42
|
+
#
|
|
43
|
+
# 1. Find the hooks folder with \`git rev-parse --git-dir\`, never
|
|
44
|
+
# \`git rev-parse --git-path hooks\`. The latter follows a global
|
|
45
|
+
# \`core.hooksPath\`, so a repo installer would write machine-wide.
|
|
46
|
+
# 2. Refuse to write anywhere outside this repository.
|
|
47
|
+
# 3. \`rm -f\` the destination before copying. A global hooks folder often
|
|
48
|
+
# holds SYMLINKS to a shared dispatcher, and \`cp\` follows a symlink.
|
|
49
|
+
# 4. In a linked worktree, do nothing: the hooks folder is the main
|
|
50
|
+
# checkout's, outside this folder. Run this from the main checkout.
|
|
51
|
+
#
|
|
52
|
+
# A global \`core.hooksPath\` dispatcher that chains to \`.git/hooks/<name>\`
|
|
53
|
+
# runs first and then runs this hook. Both run, in that order.
|
|
54
|
+
set -euo pipefail
|
|
55
|
+
|
|
56
|
+
repo_root="$(cd "$(dirname "$0")/.." && pwd)"
|
|
57
|
+
cd "$repo_root"
|
|
58
|
+
|
|
59
|
+
# Rule 4: a linked worktree shares the main checkout's hooks.
|
|
60
|
+
git_dir="$(cd "$(git rev-parse --git-dir)" && pwd)"
|
|
61
|
+
common_dir="$(cd "$(git rev-parse --git-common-dir)" && pwd)"
|
|
62
|
+
if [ "$git_dir" != "$common_dir" ]; then
|
|
63
|
+
echo "· hooks: this is a linked worktree; its hooks are the main checkout's."
|
|
64
|
+
echo " Run \\\`npm run hooks:install\\\` there instead. Nothing was installed."
|
|
65
|
+
exit 0
|
|
66
|
+
fi
|
|
67
|
+
|
|
68
|
+
# Rule 1: --git-dir, not --git-path hooks.
|
|
69
|
+
hooks_dir="$git_dir/hooks"
|
|
70
|
+
|
|
71
|
+
# Rule 2: never write outside the repository.
|
|
72
|
+
case "$hooks_dir" in
|
|
73
|
+
"$repo_root"/*) ;;
|
|
74
|
+
*)
|
|
75
|
+
echo "✗ refusing to install: the hooks folder is outside this repo" >&2
|
|
76
|
+
echo " repo: $repo_root" >&2
|
|
77
|
+
echo " hooks: $hooks_dir" >&2
|
|
78
|
+
exit 1
|
|
79
|
+
;;
|
|
80
|
+
esac
|
|
81
|
+
|
|
82
|
+
local_hooks="$(git config --local --get core.hooksPath || true)"
|
|
83
|
+
if [ -n "$local_hooks" ]; then
|
|
84
|
+
echo "! this repo sets core.hooksPath to $local_hooks, so git will not read .git/hooks." >&2
|
|
85
|
+
echo " Copy tools/pre-push there by hand, or unset it. Nothing was installed." >&2
|
|
86
|
+
exit 1
|
|
87
|
+
fi
|
|
88
|
+
|
|
89
|
+
mkdir -p "$hooks_dir"
|
|
90
|
+
|
|
91
|
+
for src in tools/pre-push; do
|
|
92
|
+
dest="$hooks_dir/$(basename "$src")"
|
|
93
|
+
|
|
94
|
+
# Rule 3: clear the path first so cp cannot follow a symlink to its target.
|
|
95
|
+
if [ -L "$dest" ]; then
|
|
96
|
+
echo "· $dest was a symlink to $(readlink "$dest"); replacing the link, not its target"
|
|
97
|
+
fi
|
|
98
|
+
rm -f "$dest"
|
|
99
|
+
|
|
100
|
+
cp "$src" "$dest"
|
|
101
|
+
chmod +x "$dest"
|
|
102
|
+
|
|
103
|
+
if [ ! -f "$dest" ] || [ -L "$dest" ] || [ ! -x "$dest" ] || ! cmp -s "$src" "$dest"; then
|
|
104
|
+
echo "✗ failed to install $src to $dest" >&2
|
|
105
|
+
exit 1
|
|
106
|
+
fi
|
|
107
|
+
echo "✓ installed $src → $dest"
|
|
108
|
+
done
|
|
109
|
+
|
|
110
|
+
echo "The tests now run before each push. Skip once with: git push --no-verify"
|
|
111
|
+
`;
|
|
112
|
+
export const PREPARE_HOOKS_MJS = `// Runs on every \`npm install\` (the "prepare" script). Installs the git hooks
|
|
113
|
+
// in tools/ and must NEVER fail an install: it skips in CI (Vercel and GitHub
|
|
114
|
+
// Actions set CI), skips when there is no git repo yet, and turns any installer
|
|
115
|
+
// error into a one-line warning. To install by hand: npm run hooks:install
|
|
116
|
+
import { spawnSync } from "node:child_process";
|
|
117
|
+
|
|
118
|
+
if (process.env.CI) process.exit(0);
|
|
119
|
+
|
|
120
|
+
const inRepo = spawnSync("git", ["rev-parse", "--git-dir"], { stdio: "ignore" });
|
|
121
|
+
if (inRepo.status !== 0) {
|
|
122
|
+
console.log("· hooks: no git repo yet; run \`npm run hooks:install\` after \`git init\`.");
|
|
123
|
+
process.exit(0);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const run = spawnSync("bash", ["tools/install-hooks.sh"], { stdio: "inherit" });
|
|
127
|
+
if (run.status !== 0) {
|
|
128
|
+
console.warn("! hooks were not installed (see above). npm install itself is fine.");
|
|
129
|
+
}
|
|
130
|
+
process.exit(0);
|
|
131
|
+
`;
|
|
132
|
+
export const HOOK_SCRIPTS = {
|
|
133
|
+
"hooks:install": "bash tools/install-hooks.sh",
|
|
134
|
+
prepare: "node tools/prepare-hooks.mjs",
|
|
135
|
+
};
|
|
136
|
+
export function prePushHookFiles() {
|
|
137
|
+
return [
|
|
138
|
+
{ path: "tools/pre-push", content: PRE_PUSH_HOOK },
|
|
139
|
+
{ path: "tools/install-hooks.sh", content: INSTALL_HOOKS_SH },
|
|
140
|
+
{ path: "tools/prepare-hooks.mjs", content: PREPARE_HOOKS_MJS },
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
/** Adds {@link HOOK_SCRIPTS} to a package.json string, keeping its layout. */
|
|
144
|
+
export function withHookScripts(pkgJson) {
|
|
145
|
+
const obj = JSON.parse(pkgJson);
|
|
146
|
+
obj.scripts = { ...obj.scripts, ...HOOK_SCRIPTS };
|
|
147
|
+
return JSON.stringify(obj, null, 2) + "\n";
|
|
148
|
+
}
|