@kerf-js/cli 0.0.0-stage → 0.1.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/LICENSE +16 -0
- package/README.md +554 -2
- package/bin/kerf.mjs +15 -0
- package/docs/async.md +50 -0
- package/docs/browser.md +53 -0
- package/docs/config.md +127 -0
- package/docs/core.md +30 -0
- package/docs/deploy.md +108 -0
- package/docs/design.md +106 -0
- package/docs/entrypoints.md +83 -0
- package/docs/fonts.md +118 -0
- package/docs/icons.md +108 -0
- package/docs/lists.md +25 -0
- package/docs/meta.md +92 -0
- package/docs/plugins.md +166 -0
- package/docs/props.md +88 -0
- package/docs/reactivity.md +26 -0
- package/docs/rules.md +39 -0
- package/docs/rust.md +253 -0
- package/docs/start-short.md +10 -0
- package/docs/start.md +642 -0
- package/docs/state.md +122 -0
- package/docs/style.md +82 -0
- package/docs/surface.md +158 -0
- package/docs/testing.md +81 -0
- package/docs/theme.md +263 -0
- package/docs/ui-state.md +105 -0
- package/docs/verify.md +61 -0
- package/package.json +47 -3
- package/src/add/config.mjs +93 -0
- package/src/add/errors.mjs +2 -0
- package/src/add/setup.mjs +88 -0
- package/src/add-rust.mjs +178 -0
- package/src/add.mjs +392 -0
- package/src/agents-md.mjs +240 -0
- package/src/alias.mjs +70 -0
- package/src/audit/page.mjs +313 -0
- package/src/audit/report.mjs +69 -0
- package/src/audit/utils.mjs +5 -0
- package/src/audit.mjs +319 -0
- package/src/browser/cli.mjs +53 -0
- package/src/browser/client.mjs +299 -0
- package/src/browser/commands.mjs +258 -0
- package/src/capture.mjs +21 -0
- package/src/catalog/audit.mjs +129 -0
- package/src/catalog/auth.mjs +40 -0
- package/src/catalog/compiler.mjs +337 -0
- package/src/catalog/contracts.mjs +18 -0
- package/src/catalog/database.mjs +52 -0
- package/src/catalog/deploy.mjs +117 -0
- package/src/catalog/design.mjs +159 -0
- package/src/catalog/forms.mjs +25 -0
- package/src/catalog/hydration.mjs +29 -0
- package/src/catalog/icons.mjs +24 -0
- package/src/catalog/media.mjs +163 -0
- package/src/catalog/metadata.mjs +116 -0
- package/src/catalog/plugins.mjs +228 -0
- package/src/catalog/realtime.mjs +195 -0
- package/src/catalog/rust.mjs +75 -0
- package/src/catalog/server-functions.mjs +100 -0
- package/src/catalog/state.mjs +39 -0
- package/src/catalog/style-groups.mjs +54 -0
- package/src/catalog/tests.mjs +127 -0
- package/src/catalog/text.mjs +200 -0
- package/src/catalog/ui-state.mjs +42 -0
- package/src/catalog.mjs +103 -0
- package/src/check/runtime.mjs +280 -0
- package/src/check.mjs +321 -0
- package/src/cli/authoring.mjs +213 -0
- package/src/cli/project.mjs +302 -0
- package/src/cli.mjs +340 -0
- package/src/config.d.ts +1 -0
- package/src/config.mjs +5 -0
- package/src/contributions.mjs +119 -0
- package/src/db-layer.mjs +41 -0
- package/src/deploy/cdn.mjs +142 -0
- package/src/deploy/files.mjs +266 -0
- package/src/deploy/fit.mjs +166 -0
- package/src/deploy/hosts.mjs +126 -0
- package/src/deploy/index/cli.mjs +20 -0
- package/src/deploy/index/environment.mjs +69 -0
- package/src/deploy/index/steps.mjs +87 -0
- package/src/deploy/index.mjs +387 -0
- package/src/deploy/needs.mjs +149 -0
- package/src/design-checks/accessible-names.mjs +62 -0
- package/src/design-checks/contrast.mjs +43 -0
- package/src/design-checks/csp.mjs +60 -0
- package/src/design-checks/files.mjs +59 -0
- package/src/design-checks/heading-links.mjs +61 -0
- package/src/design-checks/interaction.mjs +65 -0
- package/src/design-checks/jsx.mjs +67 -0
- package/src/design-checks/layout-values.mjs +68 -0
- package/src/design-checks/native-controls.mjs +48 -0
- package/src/design-checks/outline.mjs +39 -0
- package/src/design-checks/reporter.mjs +37 -0
- package/src/design-checks/rules.mjs +274 -0
- package/src/design-checks/values.mjs +262 -0
- package/src/design-checks.mjs +49 -0
- package/src/diag.mjs +98 -0
- package/src/docs.mjs +228 -0
- package/src/doctor.mjs +42 -0
- package/src/files.mjs +60 -0
- package/src/fix.mjs +48 -0
- package/src/gate/after.mjs +40 -0
- package/src/gate/before.mjs +54 -0
- package/src/gate/classify.mjs +72 -0
- package/src/gate/mutation.mjs +209 -0
- package/src/gate/resolve-cases.mjs +22 -0
- package/src/gate/result.mjs +63 -0
- package/src/gate/run.mjs +75 -0
- package/src/gate.mjs +178 -0
- package/src/index.mjs +9 -0
- package/src/infer/box-props.cjs +140 -0
- package/src/infer/core-boxes.cjs +46 -0
- package/src/infer/derived-writes.cjs +95 -0
- package/src/infer/engine/checks.cjs +193 -0
- package/src/infer/engine/flow.cjs +293 -0
- package/src/infer/engine/report.cjs +158 -0
- package/src/infer/engine/utils.cjs +15 -0
- package/src/infer/engine.cjs +265 -0
- package/src/infer/facts/sites.cjs +114 -0
- package/src/infer/facts.cjs +345 -0
- package/src/infer/hosts.cjs +161 -0
- package/src/infer/lsp.mjs +240 -0
- package/src/infer/session.cjs +161 -0
- package/src/infer/shadow.cjs +54 -0
- package/src/infer/worker.cjs +145 -0
- package/src/jsx-scan.mjs +128 -0
- package/src/kerf.mjs +98 -0
- package/src/load-config/schema.mjs +300 -0
- package/src/load-config.mjs +302 -0
- package/src/map.mjs +177 -0
- package/src/mcp/browser-tools.mjs +155 -0
- package/src/mcp.mjs +273 -0
- package/src/meta-table.mjs +63 -0
- package/src/mutate.mjs +224 -0
- package/src/plugin-checks.mjs +118 -0
- package/src/plugins.mjs +258 -0
- package/src/project.mjs +310 -0
- package/src/props-checks.mjs +64 -0
- package/src/props-listener.mjs +56 -0
- package/src/react-checks.mjs +67 -0
- package/src/server-state-checks.mjs +34 -0
- package/src/share-checks.mjs +158 -0
- package/src/site.mjs +46 -0
- package/src/slots.mjs +181 -0
- package/src/start/build.mjs +116 -0
- package/src/start/routes.mjs +38 -0
- package/src/start.mjs +394 -0
- package/src/state-checks/core-state.mjs +223 -0
- package/src/state-checks/modules.mjs +17 -0
- package/src/state-checks/scan.mjs +232 -0
- package/src/state-checks/server-graph.mjs +65 -0
- package/src/state-checks.mjs +189 -0
- package/src/style/find.mjs +121 -0
- package/src/style.mjs +327 -0
- package/src/surface-checks.mjs +384 -0
- package/src/tailwind.mjs +23 -0
- package/src/tasks.mjs +261 -0
- package/src/test-rules/context.mjs +109 -0
- package/src/test-rules/file-rules.mjs +279 -0
- package/src/test-rules/rule-helpers.mjs +244 -0
- package/src/test-rules/syntax.mjs +223 -0
- package/src/test-rules/test-rules.mjs +127 -0
- package/src/testdiff.mjs +219 -0
- package/src/tests.mjs +120 -0
- package/src/text-checks.mjs +332 -0
- package/src/tokens.mjs +33 -0
- package/src/trust/scan.mjs +95 -0
- package/src/trust.mjs +394 -0
- package/src/workspace.mjs +182 -0
- package/ts-plugin/context.js +57 -0
- package/ts-plugin/index.js +17 -0
- package/ts-plugin/mapping.js +65 -0
- package/ts-plugin/package.json +1 -0
- package/ts-plugin/proxy.js +144 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ravonus
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
11
|
+
Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
14
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
15
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
16
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,555 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/Ravonus/kerf">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/Ravonus/kerf/main/site/public/logo.svg" width="88" height="88" alt="Kerf">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
<h1 align="center">@kerf-js/cli</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<strong>The <code>kerf</code> command: run, check, build, audit and deploy a Kerf app.</strong><br>
|
|
11
|
+
Every finding has a code, a reason and a fix, as text for you and as JSON or MCP tools for an agent.
|
|
12
|
+
</p>
|
|
13
|
+
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://www.npmjs.com/package/@kerf-js/cli"><img src="https://img.shields.io/npm/v/@kerf-js/cli?color=145c3c&label=npm" alt="npm version"></a>
|
|
16
|
+
<a href="https://github.com/Ravonus/kerf/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-145c3c" alt="MIT license"></a>
|
|
17
|
+
<a href="https://github.com/Ravonus/kerf/actions"><img src="https://img.shields.io/github/actions/workflow/status/Ravonus/kerf/quality.yml?branch=main&label=checks" alt="checks"></a>
|
|
18
|
+
<img src="https://img.shields.io/badge/node-%3E%3D24-145c3c" alt="Node 24 or later">
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#quick-start">Quick start</a> ·
|
|
23
|
+
<a href="https://github.com/Ravonus/kerf/tree/main/packages/cli/docs">Docs</a> ·
|
|
24
|
+
<a href="https://github.com/Ravonus/kerf/tree/main/examples">Examples</a> ·
|
|
25
|
+
<a href="https://github.com/Ravonus/kerf/blob/main/CHANGELOG.md">Changelog</a> ·
|
|
26
|
+
<a href="https://github.com/Ravonus/kerf">GitHub</a>
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
> [!IMPORTANT]
|
|
30
|
+
> **Early release (0.1.x).** The command works end to end, and commands, flags and output can still change between
|
|
31
|
+
> minor versions.
|
|
32
|
+
|
|
33
|
+
`kerf` is the one command a Kerf app needs. It runs the app (`dev`, `build`, `start`), checks it (`check`, `tsc`, `fix`,
|
|
34
|
+
`audit`, `test --gate`), ships it (`deploy`), serves its docs to people and agents (`docs`, `agents-md`, `map`, `mcp`)
|
|
35
|
+
and manages plugins (`add`, `plugins`). An app made with
|
|
36
|
+
[`npm create kerf`](https://github.com/Ravonus/kerf/tree/main/packages/create-kerf) already has it.
|
|
37
|
+
|
|
38
|
+
It is built for two readers. A person gets short lines on stderr, and a tool gets the same result as JSON on stdout
|
|
39
|
+
with `--json`, or as MCP tools through `kerf mcp`.
|
|
40
|
+
|
|
41
|
+
## Highlights
|
|
42
|
+
|
|
43
|
+
- **Diagnostics with fixes.** `kerf check` compiles every component in check mode. Each problem prints as
|
|
44
|
+
`file:line:col CODE severity why`, with a `fix:` line under it, and `kerf fix` applies the safe ones.
|
|
45
|
+
- **Docs that match the install.** `kerf docs W014` prints the page for a code, with whether the installed Kerf reports
|
|
46
|
+
it. `kerf agents-md` writes an `AGENTS.md` for the version you have.
|
|
47
|
+
- **A build that audits itself.** `kerf build` opens the built pages in a clean Chrome at a phone's and a desktop's
|
|
48
|
+
width, runs axe-core's WCAG rules, and fails on an error.
|
|
49
|
+
- **The running app, driven from the terminal.** `kerf browser snapshot`, `act` and `assert` work against any browser
|
|
50
|
+
connected to the dev server, and `record` turns a session into a test.
|
|
51
|
+
- **A test gate on the diff.** `kerf test --gate` checks that new tests fail on the old code, kill mutants of the changed
|
|
52
|
+
lines, and that no existing test got weaker.
|
|
53
|
+
- **Deploys that say why not.** `kerf deploy hosts` says which hosts can run this app before you have an account, and
|
|
54
|
+
`kerf deploy` is a dry run until you pass `--yes`.
|
|
55
|
+
- **An MCP server.** `kerf mcp` serves `docs`, `check`, `audit`, the style tools, the test gate and the `browser_*`
|
|
56
|
+
tools on stdio.
|
|
57
|
+
|
|
58
|
+
## Contents
|
|
59
|
+
|
|
60
|
+
- [Install](#install)
|
|
61
|
+
- [Quick start](#quick-start)
|
|
62
|
+
- [Global flags, output and exit codes](#global-flags-output-and-exit-codes)
|
|
63
|
+
- [Commands](#commands)
|
|
64
|
+
- [Run the app](#run-the-app): `dev`, `build`, `start`
|
|
65
|
+
- [Check it](#check-it): `check`, `tsc`, `fix`, `doctor`, `audit`, `routes`, `surfaces`
|
|
66
|
+
- [Test and verify](#test-and-verify): `test --gate`, `browser`
|
|
67
|
+
- [Deploy](#deploy): `deploy`, `deploy hosts`, `deploy init`
|
|
68
|
+
- [Data](#data): `db generate`, `db live`, `db listen`
|
|
69
|
+
- [Add things](#add-things): `add`, `plugins`
|
|
70
|
+
- [Docs for people and agents](#docs-for-people-and-agents): `docs`, `agents-md`, `map`, `mcp`, `tasks`, `run`
|
|
71
|
+
- [Style and design](#style-and-design): `style`, `tokens`, `icons`
|
|
72
|
+
- [Editors](#editors): `lsp`
|
|
73
|
+
- [The diagnostic shape](#the-diagnostic-shape)
|
|
74
|
+
- [Diagnostic families](#diagnostic-families)
|
|
75
|
+
- [The package API](#the-package-api)
|
|
76
|
+
- [Troubleshooting](#troubleshooting)
|
|
77
|
+
- [Related packages](#related-packages)
|
|
78
|
+
|
|
79
|
+
## Install
|
|
80
|
+
|
|
81
|
+
A new app already lists it in `devDependencies`. To add it to an existing one:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npm install -D @kerf-js/cli
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pnpm add -D @kerf-js/cli
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
bun add -d @kerf-js/cli
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
deno add -D npm:@kerf-js/cli
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
It needs Node 24 or later, or Bun or Deno in its place. `@kerf-js/core` is a peer dependency: the CLI uses the project's
|
|
100
|
+
own compiler, and falls back to its own copy only when the project has none.
|
|
101
|
+
|
|
102
|
+
## Quick start
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Compile every component, report diagnostics with fixes
|
|
106
|
+
npx kerf check
|
|
107
|
+
npx kerf dev # the dev server, for an app with src/routes
|
|
108
|
+
# The production build into .output/, then the audit
|
|
109
|
+
npx kerf build
|
|
110
|
+
npx kerf start # run the build
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
When `check` finds something, it looks like this:
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
src/routes/counter.tsx:8:8 W015 error
|
|
117
|
+
`count` is a box; JSX needs its value.
|
|
118
|
+
fix: Read `count.value`. (autofix)
|
|
119
|
+
kerf check: 12 files, 1 errors, 0 warnings (84 ms)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Then:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npx kerf docs W015 # the page for that code
|
|
126
|
+
npx kerf fix # apply the safe autofixes
|
|
127
|
+
npx kerf check --json # the same result, for a tool
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`npx kerf help` prints the full command list.
|
|
131
|
+
|
|
132
|
+
## Global flags, output and exit codes
|
|
133
|
+
|
|
134
|
+
Every command takes these:
|
|
135
|
+
|
|
136
|
+
| Flag | Default | What it does |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `--root <dir>` (or `--root=<dir>`) | the working directory | The app to work on |
|
|
139
|
+
| `--json` | off | Print the result as JSON on stdout. Text for people still goes to stderr |
|
|
140
|
+
| `--check` | off | Used by `agents-md`: report, don't write |
|
|
141
|
+
| `--stdout` | off | Used by `agents-md`, `map` and `style matrix`: print instead of writing a file |
|
|
142
|
+
|
|
143
|
+
A flag that takes a value accepts `--flag value` or `--flag=value`. An unknown flag is a usage error.
|
|
144
|
+
|
|
145
|
+
| Exit code | Meaning |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `0` | OK |
|
|
148
|
+
| `1` | Errors found: diagnostics with `error` severity, a build refused on one, a failed assertion, or a stale `AGENTS.md` under `--check` |
|
|
149
|
+
| `2` | A usage error or an internal error. With `--json`, stdout gets `{ "ok": false, "error": { "code", "message" } }` |
|
|
150
|
+
|
|
151
|
+
## Commands
|
|
152
|
+
|
|
153
|
+
### Run the app
|
|
154
|
+
|
|
155
|
+
| Command | Flags | What it does |
|
|
156
|
+
|---|---|---|
|
|
157
|
+
| `kerf dev` | `--port <n>` | The dev server for an app with `src/routes` (Vite and Nitro). Loads `.env` under what's already set, writes `.kerf/map.md`, and starts any Rust `remote()` sidecars before the server |
|
|
158
|
+
| `kerf build` | `--runtime node\|bun\|deno`, `--preset <p>`, `--unsafe-allow <codes>` | The production build, into `.output/`, plus `.kerf/contract.json`. Then the built pages are audited (L-codes), and an error fails the build |
|
|
159
|
+
| `kerf start` | `--runtime <r>` | Runs `.output/server/index.mjs` on its runtime: `--runtime`, else the config's `runtime`, else the one running `kerf`. Starts sidecars first |
|
|
160
|
+
|
|
161
|
+
`--runtime` picks Node, Bun or Deno. `--preset` picks a host preset instead, such as `netlify`, `vercel` or
|
|
162
|
+
`cloudflare_durable`; with `deploy.target` in the config, `kerf build` builds for that host.
|
|
163
|
+
|
|
164
|
+
`--unsafe-allow` lets a build go past codes you have looked at: a code (`R002`), a family (`L`), several
|
|
165
|
+
(`L003,R002`) or `all`. Each one it lets through is listed as a warning, every build. To keep that in the config with a
|
|
166
|
+
reason, use `build.unsafeAllow`:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
// kerf.config.ts
|
|
170
|
+
export default defineConfig({
|
|
171
|
+
build: {
|
|
172
|
+
unsafeAllow: { L003: 'the legacy page is replaced next sprint' },
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
A build that fails still writes its output, and says so: fix the errors, or force it with `--unsafe-allow <code>`.
|
|
178
|
+
|
|
179
|
+
### Check it
|
|
180
|
+
|
|
181
|
+
| Command | Flags | What it does |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| `kerf check [files…]` | `--preset <p>`, `--verbose` | Compiles every component in check mode and reports W-, P-, D- and the other codes, with fixes. Files limit it to those. `--verbose` says which compiler ran (native addon or WASM). Ends with `files, errors, warnings (ms)` |
|
|
184
|
+
| `kerf tsc` | | Type-checks the whole project with inferred props (tsc or tsgo). For CI |
|
|
185
|
+
| `kerf fix [files…]` | | Applies the safe autofixes and lists each one as `file:line:col CODE` |
|
|
186
|
+
| `kerf doctor` | `--preset <p>`, `--runtime <r>` | Which compiler this install uses, whether Rust is around (it's optional), and which hosts fit. For an app with `src/realtime.server.ts`, or with `--preset`, also what live data does on that target, what it requires and the options |
|
|
187
|
+
| `kerf audit [routes…]` | `--url <u>`, `--indexing public\|private\|auto`, `--all`, `--max <n>` | The built pages, or a running site with `--url`, in a clean Chrome at a phone's and a desktop's width: axe-core's WCAG rules, console errors, deprecations, the head, sideways scroll and layout shift |
|
|
188
|
+
| `kerf routes` | `--meta`, `--preset <p>` | The route table, path and file. `--meta` adds each route's merged metadata, tags, card mode and H-diagnostics |
|
|
189
|
+
| `kerf surfaces` | | The canvas and WebGL surfaces this project already defines, with their kind, file and props |
|
|
190
|
+
|
|
191
|
+
`kerf audit` samples up to 30 pages unless you pass `--all` or `--max <n>`. Without Chrome it skips, with an `L000`
|
|
192
|
+
warning. `--indexing public` makes a `noindex` an error (L024), for a site meant for search. Run it again with `--url`
|
|
193
|
+
after a deploy: a host or proxy can add a header a local build can't see.
|
|
194
|
+
|
|
195
|
+
### Test and verify
|
|
196
|
+
|
|
197
|
+
#### `kerf test --gate`
|
|
198
|
+
|
|
199
|
+
The test gate runs on the diff, in scratch copies. Your working tree is never touched.
|
|
200
|
+
|
|
201
|
+
| Flag | Default | What it does |
|
|
202
|
+
|---|---|---|
|
|
203
|
+
| `--gate` | required | Run the gate. `kerf test` without it is a usage error: run the suite itself with vitest |
|
|
204
|
+
| `--base <ref>` | `HEAD` (the uncommitted change) | What the diff is against |
|
|
205
|
+
| `--budget <sec>` | `60`, or `test.gate.mutationBudgetSec` | Time for mutants |
|
|
206
|
+
| `--max-mutants <n>` | `40`, or `test.gate.maxMutants` | Mutants sampled |
|
|
207
|
+
| `--concurrency <n>` | up to 4, from the CPU count | Parallel runs |
|
|
208
|
+
| `--refactor` | off | Promise no behavior change: then no test may change |
|
|
209
|
+
| `--no-mutation` | off | Skip the mutants |
|
|
210
|
+
|
|
211
|
+
It reports **T010** (a new or changed test must fail on the code before the change), **T011** (each new test must kill
|
|
212
|
+
at least one mutant of the changed lines) and **T020** (deleting, skipping or loosening a test needs
|
|
213
|
+
`// kerf-allow T020: <reason>`). `kerf docs verify` has the details.
|
|
214
|
+
|
|
215
|
+
#### `kerf browser <cmd>`
|
|
216
|
+
|
|
217
|
+
Drives the running app. The page is the app open in any browser connected to the dev server: yours, an agent's, or one
|
|
218
|
+
`launch` starts. In a browser that runs JS, the same commands are `await __kerf__.agent.run('<command>', args)`.
|
|
219
|
+
|
|
220
|
+
Every `browser` command takes `--url <dev server>`, `--tab <id>` and `--json`.
|
|
221
|
+
|
|
222
|
+
| Command | Flags and arguments | What it does |
|
|
223
|
+
|---|---|---|
|
|
224
|
+
| `tabs` | | Tabs connected to the dev server |
|
|
225
|
+
| `launch [route]` | `--headed` | Starts a headless Chrome on the app, for when you have no browser |
|
|
226
|
+
| `open <route>` | | Navigates the tab and waits for the new page |
|
|
227
|
+
| `snapshot` | `--interactive`, `--delta`, `--scope role:name\|@ref`, `--graph-only`, `--no-graph`, `--full` | Roles, names and refs, plus the reactive graph (`Cart.total = 42.5 ← …`). Long output spills to a file unless `--full` |
|
|
228
|
+
| `act <target> <action> [value]` | | `click`, `dblclick`, `hover`, `focus`, `clear`, `fill`, `type`, `press`, `select`, `check`, `uncheck` (default `click`) |
|
|
229
|
+
| `assert <target> <expectation> [value]` | `--timeout <ms>` | `visible` (default), `absent`, `text`, `exactText`, `value`, `checked`, `unchecked`, `disabled`, `enabled`, `focused`, `count`. Retries until the timeout. Exits 1 on a failure |
|
|
230
|
+
| `graph [filter]` | `--full` | The named reactive graph |
|
|
231
|
+
| `set <Name.box> <json>` | | Writes state by its graph name (dev only) |
|
|
232
|
+
| `time pause\|advance <ms>\|resume\|status` | `--reload` | The page's clock |
|
|
233
|
+
| `net offline\|online\|latency <ms>\|drop\|reset\|status` | | The page's network |
|
|
234
|
+
| `record start\|stop\|note <text>\|code` | `--component`, `--from`, `--props '{…}'`, `--name`, `--out file.test.tsx` | Records actions and assertions; `code` writes them as a test |
|
|
235
|
+
| `logs` | | Console errors and warnings, and uncaught errors, since the last call |
|
|
236
|
+
| `overlay [on\|off]` | | The graph panel in the page (Alt+Shift+G) |
|
|
237
|
+
| `info` | | What the tab is showing, starting with its URL |
|
|
238
|
+
| `reload` | | Reloads the tab |
|
|
239
|
+
| `screenshot` | `--out file.png` | Launched Chrome only; use your own browser's screenshot otherwise |
|
|
240
|
+
| `close` | | Stops the launched Chrome |
|
|
241
|
+
|
|
242
|
+
A target is `<role> <name>` (`button "Add Banana"`), `label <text>`, `text <text>`, or a ref from a snapshot (`@e5`).
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
npx kerf browser launch /cart
|
|
246
|
+
npx kerf browser act button "Add Banana" click
|
|
247
|
+
npx kerf browser assert text Cart text "1 item"
|
|
248
|
+
npx kerf browser record code --component Cart \
|
|
249
|
+
--from ./Cart --out src/Cart.test.tsx
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Deploy
|
|
253
|
+
|
|
254
|
+
| Command | Flags | What it does |
|
|
255
|
+
|---|---|---|
|
|
256
|
+
| `kerf deploy hosts` | | Which hosts can run this app, why not, what each costs, and the one Kerf suggests |
|
|
257
|
+
| `kerf deploy init [target]` | `--target <t>`, `--dry-run`, `--force` | Writes the host's files (`netlify.toml`, `fly.toml` and a Dockerfile…), a GitHub workflow that checks and deploys on push, and `deploy` in the config. Then prints the one-time commands to run yourself |
|
|
258
|
+
| `kerf deploy` | `--target <t>`, `--prod`, `--yes`, `--unsafe-allow <codes>` | Checks the fit, builds for the target, then runs the host's own CLI and prints the live URL. Without `--yes` it's a dry run that prints what would run and which environment variables it reads. Without `--prod` it's a preview |
|
|
259
|
+
|
|
260
|
+
| Target | Kind | Reads from the environment |
|
|
261
|
+
|---|---|---|
|
|
262
|
+
| `netlify` | functions | `NETLIFY_AUTH_TOKEN`, `NETLIFY_SITE_ID` |
|
|
263
|
+
| `vercel` | functions | `VERCEL_TOKEN`, `VERCEL_ORG_ID`, `VERCEL_PROJECT_ID` |
|
|
264
|
+
| `cloudflare` | Workers, with Durable Objects | `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_ACCOUNT_ID` |
|
|
265
|
+
| `fly` | a server that stays up | `FLY_API_TOKEN` |
|
|
266
|
+
| `render` | a server that stays up | `RENDER_DEPLOY_HOOK_URL` |
|
|
267
|
+
|
|
268
|
+
`kerf deploy hosts` also rates AWS Lambda, which `kerf deploy` doesn't ship to yet. Nothing in Kerf creates a site, an
|
|
269
|
+
app, a volume or a DNS record, and a token written into the config, a host file or a workflow is **E008**.
|
|
270
|
+
`kerf docs deploy` covers which app features each host can run (E001–E003), `deploy` in the config, and the CDN.
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
npx kerf deploy hosts # fit, cost and the suggestion
|
|
274
|
+
npx kerf deploy init fly # host files and the GitHub workflow
|
|
275
|
+
npx kerf deploy # dry run: what --yes would run
|
|
276
|
+
npx kerf deploy --yes --prod # ship it
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Data
|
|
280
|
+
|
|
281
|
+
| Command | What it does |
|
|
282
|
+
|---|---|
|
|
283
|
+
| `kerf db generate [name]` | A migration for the schema's changes, through the app's data layer (Drizzle, Prisma or native SQL). It applies on the next request |
|
|
284
|
+
| `kerf db live` | A migration that adds change triggers to the tables in `changes` (`src/realtime.server.ts`), on Postgres, SQLite or MySQL. On Prisma or native SQL it prints the SQL for you to add |
|
|
285
|
+
| `kerf db listen` | The change feed as its own process, for an app on functions |
|
|
286
|
+
|
|
287
|
+
An app with no database gets a usage error that points at `kerf add db`.
|
|
288
|
+
|
|
289
|
+
### Add things
|
|
290
|
+
|
|
291
|
+
#### `kerf add <feature>`
|
|
292
|
+
|
|
293
|
+
Installs a package with the app's package manager (found from its lockfile: pnpm, bun, yarn, deno or npm) and wires it
|
|
294
|
+
into the config, whichever format it's in.
|
|
295
|
+
|
|
296
|
+
| Feature | What it does |
|
|
297
|
+
|---|---|
|
|
298
|
+
| `db [engine]` | A database on an app that has none: `sqlite` (default), `postgres` or `mysql`, with `--layer drizzle\|prisma\|native` (default `drizzle`). Writes the same wiring a new app gets, without the todo app. Refuses if the app has a database, or if a file it writes exists |
|
|
299
|
+
| `auth` | Better Auth on an app with a database: `src/auth.server.ts`, `src/server/session.ts`, a sign-in page and the auth tables. Refuses without a database or with an existing `src/auth.server.ts` |
|
|
300
|
+
| `tailwind` | Tailwind: the Vite plugin, a Tailwind entry in `src/app.css` (without its reset when Veneer is there), and the layout's import of it |
|
|
301
|
+
| `rust [name]` | A Rust crate, its server module and one working function. `native()` by default (in process); `--remote` for a sidecar behind HTTP |
|
|
302
|
+
| `veneer`, `icons`, `text` | `@kerf-js/veneer`, [`@kerf-js/veneer-icons`](https://www.npmjs.com/package/@kerf-js/veneer-icons), [`@kerf-js/text`](https://www.npmjs.com/package/@kerf-js/text) |
|
|
303
|
+
| `media`, `media-ffmpeg`, `surface-keel` | [`@kerf-js/media`](https://www.npmjs.com/package/@kerf-js/media), [`@kerf-js/media-ffmpeg`](https://www.npmjs.com/package/@kerf-js/media-ffmpeg), [`@kerf-js/keel-pixel`](https://www.npmjs.com/package/@kerf-js/keel-pixel) |
|
|
304
|
+
| `redis`, `nats` | [`@kerf-js/realtime-redis`](https://www.npmjs.com/package/@kerf-js/realtime-redis), [`@kerf-js/realtime-nats`](https://www.npmjs.com/package/@kerf-js/realtime-nats) |
|
|
305
|
+
| `pay`, `pay-stripe` | [`@kerf-js/pay`](https://www.npmjs.com/package/@kerf-js/pay), `@kerf-js/pay/stripe` |
|
|
306
|
+
| any other name | Another `@kerf-js/<name>` add-on, or a package name as given |
|
|
307
|
+
|
|
308
|
+
| Flag | What it does |
|
|
309
|
+
|---|---|
|
|
310
|
+
| `--dry-run` | Print what it would install and write, and change nothing |
|
|
311
|
+
| `--no-install` | Wire it in without installing |
|
|
312
|
+
| `--layer drizzle\|prisma\|native` | For `add db` |
|
|
313
|
+
| `--remote` | For `add rust` |
|
|
314
|
+
|
|
315
|
+
Some add-ons (`pay`, `text`, the media plugins and the realtime transports) aren't released on npm yet.
|
|
316
|
+
|
|
317
|
+
#### `kerf plugins`
|
|
318
|
+
|
|
319
|
+
| Command | Flags | What it does |
|
|
320
|
+
|---|---|---|
|
|
321
|
+
| `kerf plugins` (or `plugins list`) | | Each plugin, its version, the slots it provides and whether they're bound, its tokens, and diagnostics |
|
|
322
|
+
| `kerf plugins explain <slot>` | | The binding chain: config, plugin, module, `.kerf/slots/<id>.ts` |
|
|
323
|
+
| `kerf plugins sync` | | Regenerates `.kerf/slots/*`, `.kerf/slots.d.ts` and `.kerf/tokens/*` |
|
|
324
|
+
| `kerf plugins audit` | | Each plugin's permissions and code against `.kerf/plugins.lock.json`, and what it uses that it didn't declare |
|
|
325
|
+
| `kerf plugins approve [name…]` | `--all` | Records plugins in the lock. With no names and no `--all`, shows what's waiting and writes nothing |
|
|
326
|
+
|
|
327
|
+
`kerf docs plugins` walks through writing one.
|
|
328
|
+
|
|
329
|
+
### Docs for people and agents
|
|
330
|
+
|
|
331
|
+
| Command | Flags | What it does |
|
|
332
|
+
|---|---|---|
|
|
333
|
+
| `kerf docs [topic\|code]` | | Prints a docs page or a diagnostic (`kerf docs props`, `kerf docs W014`). With no topic, the index |
|
|
334
|
+
| `kerf agents-md` | `--check`, `--stdout` | Writes `AGENTS.md` from the installed Kerf. `--check` exits 1 when it's stale; `--stdout` prints it. Any run exits 1 when it's over the 9 KB limit |
|
|
335
|
+
| `kerf map` | `--stdout` | Writes `.kerf/map.md` and `.kerf/map.json`: a matrix of what to call in this app |
|
|
336
|
+
| `kerf mcp` | | An MCP server on stdio (below) |
|
|
337
|
+
| `kerf tasks` | | The built-in commands and the project's tasks, with arguments, side effects and environments |
|
|
338
|
+
| `kerf run <task>` | | Runs a project task from `tasks` in `kerf.config.ts` |
|
|
339
|
+
|
|
340
|
+
`kerf docs` topics:
|
|
341
|
+
|
|
342
|
+
| Topic | Covers |
|
|
343
|
+
|---|---|
|
|
344
|
+
| `rules` | The nine rules: boxes, derived, live JSX and props, run-once bodies. Start here |
|
|
345
|
+
| `state` | Every reactive function and `defineState` with persist, sync and history |
|
|
346
|
+
| `props` | How props stay live |
|
|
347
|
+
| `lists` | Keyed lists, conditionals and stable items |
|
|
348
|
+
| `async` | `resource`, `<Boundary>`, `@kerf-js/core/ssr` and hydrate |
|
|
349
|
+
| `start` | The full stack: routes, `load`, `query`, `mutation`, the database, auth, realtime, runtimes |
|
|
350
|
+
| `rust` | Rust bodies: `native()` addons with a WASM fallback, `remote()` sidecars, `kerf add rust` |
|
|
351
|
+
| `deploy` | Hosts, `kerf deploy`, the push workflow, the CDN |
|
|
352
|
+
| `plugins` | Building a plugin: slots, server extensions, check hooks, docs, `kerf add` |
|
|
353
|
+
| `theme` | `veneer()` options, worked looks, button tone channels |
|
|
354
|
+
| `testing` | `@kerf-js/core/test`: render, screen, user, flush, clock |
|
|
355
|
+
| `browser` | `@kerf-js/core/browser`: online, visible, lifecycle, media, the fakes |
|
|
356
|
+
| `ui-state` | Hover, press and focus as state: `interaction()`, the `ui` prop |
|
|
357
|
+
| `surface` | `@kerf-js/core/surface`: canvas and WebGL as layout children |
|
|
358
|
+
| `verify` | `kerf browser`, `__kerf__.agent` and the test gate |
|
|
359
|
+
| `icons` | `@kerf-js/veneer-icons`: per-icon exports, tiers, sizes |
|
|
360
|
+
| `fonts` | Fonts with `@kerf-js/text` |
|
|
361
|
+
| `meta` | Page metadata and share cards, `kerf routes --meta` |
|
|
362
|
+
| `config` | `kerf.config.ts`: scope, tasks, environments, plugins |
|
|
363
|
+
| `design` | The design language: `Stack`, `Row`, `Heading`, `Text`, `Link`, `kerf fix`, `kerf tokens` |
|
|
364
|
+
| `style` | Style groups, `kerf style find` and `explain` |
|
|
365
|
+
| `diagnostics` | Every code, and which ones the installed Kerf reports |
|
|
366
|
+
| `commands` | This project's commands and tasks |
|
|
367
|
+
| `agents` | The generated `AGENTS.md` |
|
|
368
|
+
|
|
369
|
+
Installed plugins can add their own topics; `kerf docs` with no topic lists them.
|
|
370
|
+
|
|
371
|
+
#### `kerf mcp`
|
|
372
|
+
|
|
373
|
+
An MCP server on stdio, rooted at `--root`. Its tools:
|
|
374
|
+
|
|
375
|
+
| Tool | Same as |
|
|
376
|
+
|---|---|
|
|
377
|
+
| `docs` | `kerf docs` |
|
|
378
|
+
| `check` | `kerf check` |
|
|
379
|
+
| `audit` | `kerf audit` |
|
|
380
|
+
| `routes_meta` | `kerf routes --meta` |
|
|
381
|
+
| `map` | `kerf map` |
|
|
382
|
+
| `tasks` | `kerf tasks` |
|
|
383
|
+
| `surfaces` | `kerf surfaces` |
|
|
384
|
+
| `style_find`, `style_explain` | `kerf style find`, `kerf style explain` |
|
|
385
|
+
| `test_gate` | `kerf test --gate` |
|
|
386
|
+
| `browser_tabs`, `browser_launch`, `browser_open`, `browser_snapshot`, `browser_act`, `browser_assert`, `browser_state`, `browser_time`, `browser_net`, `browser_record`, `browser_logs`, `browser_screenshot` | `kerf browser` |
|
|
387
|
+
|
|
388
|
+
To add it to an MCP client:
|
|
389
|
+
|
|
390
|
+
```json
|
|
391
|
+
{
|
|
392
|
+
"mcpServers": {
|
|
393
|
+
"kerf": { "command": "npx", "args": ["kerf", "mcp"] }
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Style and design
|
|
399
|
+
|
|
400
|
+
| Command | Flags | What it does |
|
|
401
|
+
|---|---|---|
|
|
402
|
+
| `kerf style find <query>` | | Style groups that fit what you're about to style (`card`, `status badge`). Reuse before you write |
|
|
403
|
+
| `kerf style explain <group\|selector>` | `--<axis> <value>`, `--states a,b`, `--accent intent:token`, `--part <p>` | The resolved CSS for one variation, and where each value came from. The group's own axes are flags (`--status late`) |
|
|
404
|
+
| `kerf style matrix` | `--stdout` | Writes `.kerf/styles.json`: every group, with axes, parts, accents, resolved CSS and uses |
|
|
405
|
+
| `kerf tokens` | | Veneer's resolved tokens as DTCG, in `.kerf/tokens/` |
|
|
406
|
+
| `kerf icons publish <dir>` | | Every icon and variant as static `.svg` files with a `manifest.json`, for a CDN. Nothing is uploaded: host the folder, then set `icons({ source })` |
|
|
407
|
+
|
|
408
|
+
### Editors
|
|
409
|
+
|
|
410
|
+
| Command | What it does |
|
|
411
|
+
|---|---|
|
|
412
|
+
| `kerf lsp` | A language server for editors on TypeScript 7: `tsc --lsp` with inferred props |
|
|
413
|
+
|
|
414
|
+
A new app's `tsconfig.json` also loads `@kerf-js/cli/ts-plugin`, which gives the editor the same inferred props.
|
|
415
|
+
|
|
416
|
+
## The diagnostic shape
|
|
417
|
+
|
|
418
|
+
`check`, `tasks` and the MCP tools report the same shape:
|
|
419
|
+
|
|
420
|
+
```json
|
|
421
|
+
{
|
|
422
|
+
"code": "W014",
|
|
423
|
+
"severity": "error",
|
|
424
|
+
"owner": "core",
|
|
425
|
+
"file": "src/App.tsx",
|
|
426
|
+
"span": [21, 44, 21, 117],
|
|
427
|
+
"offset": [867, 940],
|
|
428
|
+
"why": "Copying every item gives each a new identity.",
|
|
429
|
+
"fix": { "text": "Keep unchanged items stable." },
|
|
430
|
+
"project": true,
|
|
431
|
+
"related": [{
|
|
432
|
+
"file": "src/components/ProductList.tsx",
|
|
433
|
+
"span": [29, 10, 29, 10],
|
|
434
|
+
"why": "rendered here as a keyed list"
|
|
435
|
+
}],
|
|
436
|
+
"docs": "kerf docs W014"
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
| Field | What it is |
|
|
441
|
+
|---|---|
|
|
442
|
+
| `span` | 1-based `[line, col, endLine, endCol]`, with columns in UTF-16 units |
|
|
443
|
+
| `offset` | UTF-16 indices into the file's text |
|
|
444
|
+
| `fix.text` | The fix, in words |
|
|
445
|
+
| `fix.edits` | `{ file, span, offset, text }`, when there's a mechanical change |
|
|
446
|
+
| `fix.safe` | Whether `kerf fix` applies it without asking |
|
|
447
|
+
| `project` | `true` for a result that needed more than one file to find |
|
|
448
|
+
| `related` | Other places that explain it |
|
|
449
|
+
| `docs` | The command that prints its page |
|
|
450
|
+
|
|
451
|
+
## Diagnostic families
|
|
452
|
+
|
|
453
|
+
`kerf docs diagnostics` lists every code and whether the installed Kerf reports it.
|
|
454
|
+
|
|
455
|
+
| Prefix | Area |
|
|
456
|
+
|---|---|
|
|
457
|
+
| `W` | Reactivity, from the compiler |
|
|
458
|
+
| `S` | State and `defineState` |
|
|
459
|
+
| `P` | Plugins and config |
|
|
460
|
+
| `D` | Design language and style groups |
|
|
461
|
+
| `H` | Page metadata and hydration |
|
|
462
|
+
| `Q`, `A`, `C`, `F`, `R` | Server functions and the database, auth, the contract, forms, realtime and Rust |
|
|
463
|
+
| `E` | Deploys |
|
|
464
|
+
| `L` | Built pages, from `kerf build` and `kerf audit` |
|
|
465
|
+
| `T` | Tests and the test gate |
|
|
466
|
+
| `U` | UI state |
|
|
467
|
+
| `X` | Surfaces and text |
|
|
468
|
+
| `M`, `I` | Media and icons |
|
|
469
|
+
|
|
470
|
+
A test that needs a T-code on purpose keeps it with `// kerf-allow <code>: <why>`, in the file header or on the line
|
|
471
|
+
above. Adding a diagnostic is in [CONTRIBUTING.md](https://github.com/Ravonus/kerf/blob/main/CONTRIBUTING.md).
|
|
472
|
+
|
|
473
|
+
## The package API
|
|
474
|
+
|
|
475
|
+
Most people only run the command. The package also exports what the command is built from:
|
|
476
|
+
|
|
477
|
+
| Import | Exports |
|
|
478
|
+
|---|---|
|
|
479
|
+
| `@kerf-js/cli` | `check`, `docs`, `topics`, `agentsMd`, `writeAgentsMd`, `catalog`, `entry`, `probe`, `loadConfig`, `tasks`, `bindSlots`, `slotTable`, and the MCP server's `serve`, `handle` and `tools` |
|
|
480
|
+
| `@kerf-js/cli/config` | `defineConfig`. Apps import it from `@kerf-js/core/config`; this is the fallback when a project's Kerf doesn't resolve |
|
|
481
|
+
|
|
482
|
+
```js
|
|
483
|
+
import { check } from '@kerf-js/cli'
|
|
484
|
+
|
|
485
|
+
const result = await check(process.cwd(), {
|
|
486
|
+
files: ['src/routes/index.tsx'],
|
|
487
|
+
})
|
|
488
|
+
console.log(result.summary) // { files, errors, warnings }
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
## Troubleshooting
|
|
492
|
+
|
|
493
|
+
<details>
|
|
494
|
+
<summary><code>kerf is not installed</code> (E_NO_KERF)</summary>
|
|
495
|
+
|
|
496
|
+
`@kerf-js/core/compiler` resolves neither from the project nor from the CLI. Install `@kerf-js/core` in the app.
|
|
497
|
+
</details>
|
|
498
|
+
|
|
499
|
+
<details>
|
|
500
|
+
<summary>Which compiler am I running?</summary>
|
|
501
|
+
|
|
502
|
+
`kerf doctor`, or `kerf check --verbose`. The WASM build gives the same output as the native addon; the addon only adds
|
|
503
|
+
speed. Rust is never needed to use Kerf.
|
|
504
|
+
</details>
|
|
505
|
+
|
|
506
|
+
<details>
|
|
507
|
+
<summary><code>kerf build</code> refused with a code</summary>
|
|
508
|
+
|
|
509
|
+
The build found an error in the built pages or the target. The message has the fix, and the way past it:
|
|
510
|
+
`--unsafe-allow <code>`, or `build.unsafeAllow` in `kerf.config.ts` with a reason. It exits 1, not 2.
|
|
511
|
+
</details>
|
|
512
|
+
|
|
513
|
+
<details>
|
|
514
|
+
<summary><code>kerf audit</code> skipped</summary>
|
|
515
|
+
|
|
516
|
+
It needs a Chrome or Chromium on the machine. Without one it reports `L000` as a warning and checks nothing.
|
|
517
|
+
</details>
|
|
518
|
+
|
|
519
|
+
<details>
|
|
520
|
+
<summary><code>kerf test</code> says to use vitest</summary>
|
|
521
|
+
|
|
522
|
+
`kerf test` only runs the gate, with `--gate`. Run your suite with vitest.
|
|
523
|
+
</details>
|
|
524
|
+
|
|
525
|
+
<details>
|
|
526
|
+
<summary><code>kerf agents-md --check</code> fails in CI</summary>
|
|
527
|
+
|
|
528
|
+
`AGENTS.md` is stale for the installed Kerf. Run `kerf agents-md` and commit the file. A file over 9 KB fails every run.
|
|
529
|
+
</details>
|
|
530
|
+
|
|
531
|
+
## Related packages
|
|
532
|
+
|
|
533
|
+
| Package | What it is |
|
|
534
|
+
|---|---|
|
|
535
|
+
| [`@kerf-js/core`](https://www.npmjs.com/package/@kerf-js/core) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/core)</sup> | The runtime, the compiler binding, the Vite plugin, SSR and test utilities |
|
|
536
|
+
| [`@kerf-js/start`](https://www.npmjs.com/package/@kerf-js/start) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/start)</sup> | The full stack: file routes, server functions, SSR, a database, auth and live data |
|
|
537
|
+
| [`create-kerf`](https://www.npmjs.com/package/create-kerf) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/create-kerf)</sup> | `npm create kerf`: a new app with this CLI in it |
|
|
538
|
+
| [`@kerf-js/db`](https://www.npmjs.com/package/@kerf-js/db) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/db)</sup> | Prisma and native SQL layers, and list sources |
|
|
539
|
+
| [`@kerf-js/veneer`](https://www.npmjs.com/package/@kerf-js/veneer) <sup>[source](https://github.com/Ravonus/kerf/tree/main/packages/veneer)</sup> | Veneer's components, and the `veneer()` theming plugin |
|
|
540
|
+
|
|
541
|
+
## Contributing
|
|
542
|
+
|
|
543
|
+
[CONTRIBUTING.md](https://github.com/Ravonus/kerf/blob/main/CONTRIBUTING.md) has the setup. To work on this package:
|
|
544
|
+
|
|
545
|
+
```bash
|
|
546
|
+
pnpm --filter @kerf-js/cli test
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
The pages `kerf docs` prints are in
|
|
550
|
+
[`packages/cli/docs`](https://github.com/Ravonus/kerf/tree/main/packages/cli/docs). Report security problems privately,
|
|
551
|
+
as [SECURITY.md](https://github.com/Ravonus/kerf/blob/main/.github/SECURITY.md) says.
|
|
552
|
+
|
|
553
|
+
## License
|
|
554
|
+
|
|
555
|
+
[MIT](https://github.com/Ravonus/kerf/blob/main/LICENSE).
|
package/bin/kerf.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { main } from '../src/cli.mjs'
|
|
3
|
+
|
|
4
|
+
// Not `exitCode`: an app's module can leave a pool open, and a finished command must still end.
|
|
5
|
+
const code = await main(process.argv.slice(2))
|
|
6
|
+
// A pipe holds about 64 KB: exiting first would cut off long --json output.
|
|
7
|
+
await Promise.all(
|
|
8
|
+
[process.stdout, process.stderr].map(
|
|
9
|
+
(out) =>
|
|
10
|
+
new Promise((done) => {
|
|
11
|
+
out.write('', done)
|
|
12
|
+
}),
|
|
13
|
+
),
|
|
14
|
+
)
|
|
15
|
+
process.exit(code)
|
package/docs/async.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Async data, Boundary and SSR
|
|
2
|
+
|
|
3
|
+
```tsx
|
|
4
|
+
import { resource, Boundary } from '@kerf-js/core'
|
|
5
|
+
|
|
6
|
+
type User = { name: string }
|
|
7
|
+
|
|
8
|
+
function Name({ id }: { id: string }) {
|
|
9
|
+
// A new id refetches and aborts the old request.
|
|
10
|
+
const user = resource(signal =>
|
|
11
|
+
fetch(`/api/users/${id}`, { signal })
|
|
12
|
+
.then(r => r.json() as Promise<User>),
|
|
13
|
+
)
|
|
14
|
+
// On a refetch, dim the old value rather than replace it (X033).
|
|
15
|
+
return (
|
|
16
|
+
<h1 aria-busy={user.pending ? 'true' : 'false'}>
|
|
17
|
+
{user.value?.name}
|
|
18
|
+
</h1>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Name makes the resource inside the Boundary, which waits for it.
|
|
23
|
+
export function Profile({ id }: { id: string }) {
|
|
24
|
+
return (
|
|
25
|
+
<Boundary
|
|
26
|
+
pending={<p>Loading…</p>}
|
|
27
|
+
error={(e, retry) => <button onClick={retry}>Retry</button>}
|
|
28
|
+
>
|
|
29
|
+
<Name id={id} />
|
|
30
|
+
</Boundary>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- **`resource(fetcher)`** is async `derived`: `.value`, `.pending`, `.error`, `.refresh()`. It re-fetches when what it
|
|
36
|
+
read before the first `await` changes, and aborts the superseded fetch through `signal`. `derived(async …)` is
|
|
37
|
+
**W012**.
|
|
38
|
+
- **`<Boundary pending error>`** covers every resource created while its children are built, and every error they
|
|
39
|
+
throw. A resource made above the `<Boundary>` in the same component isn't below it, and the fallback never shows (X037). The fallback shows after 150 ms and
|
|
40
|
+
stays at least 400 ms; refetches keep the current content (no flash). `error(e, retry)` gets failed resources and
|
|
41
|
+
children that throw during render.
|
|
42
|
+
- **`@kerf-js/core/ssr`**: `renderToString(() => <App />)` renders what it can now; `await renderToStringAsync(() => <App />)`
|
|
43
|
+
waits for resources first and puts their values in the page. Pass `{ hydratable: true }` when the client hydrates.
|
|
44
|
+
`renderToStream(() => <App />, { hydratable: true })` sends `shell` at once, then one chunk per `<Boundary>` as its
|
|
45
|
+
resources resolve (`chunks`, an async iterable), and `data()` for `hydrate` when they're done. `@kerf-js/start`
|
|
46
|
+
streams this way for you.
|
|
47
|
+
- **`hydrate(() => <App />, el)`** from `@kerf-js/core/dom` takes over server HTML without rewriting it. Use it instead of
|
|
48
|
+
`render` when the HTML came from `@kerf-js/core/ssr`.
|
|
49
|
+
- Import only `renderToString`, `renderToStringAsync` and `renderToStream` from `@kerf-js/core/ssr`; its other exports are
|
|
50
|
+
what compiled server code calls.
|