@webjsdev/cli 0.10.3 → 0.10.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/bin/webjs.js +9 -15
- package/lib/create.js +2 -2
- package/lib/saas-template.js +1 -1
- package/package.json +1 -1
- package/templates/.agents/rules/workflow.md +3 -2
- package/templates/.cursorrules +2 -2
- package/templates/.github/copilot-instructions.md +2 -2
- package/templates/AGENTS.md +7 -5
- package/templates/CONVENTIONS.md +58 -70
package/bin/webjs.js
CHANGED
|
@@ -15,7 +15,7 @@ const USAGE = `webjs commands:
|
|
|
15
15
|
webjs dev [--port 8080] Start dev server with live reload
|
|
16
16
|
webjs start [--port 8080] Start production server (serves source directly, no build step)
|
|
17
17
|
webjs test [--server|--browser] Run server + browser tests
|
|
18
|
-
webjs check
|
|
18
|
+
webjs check Run correctness checks on the app
|
|
19
19
|
webjs create <name> [--template full-stack|api|saas] [--no-install] Scaffold a new webjs app
|
|
20
20
|
(only 3 templates exist. default: full-stack with Prisma+SQLite)
|
|
21
21
|
Auto-runs the detected package manager's install in the new dir
|
|
@@ -212,22 +212,16 @@ async function main() {
|
|
|
212
212
|
break;
|
|
213
213
|
}
|
|
214
214
|
case 'check': {
|
|
215
|
-
const { checkConventions, RULES
|
|
215
|
+
const { checkConventions, RULES } = await import('@webjsdev/server/check');
|
|
216
216
|
|
|
217
217
|
if (rest.includes('--rules')) {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
console.log('
|
|
221
|
-
console.log('
|
|
222
|
-
console.log('
|
|
223
|
-
console.log(' to false.\n');
|
|
218
|
+
console.log('webjs check, correctness rules:');
|
|
219
|
+
console.log(' Every rule catches objectively broken code (a crash, a');
|
|
220
|
+
console.log(' security leak, or a build/type-strip failure) and always');
|
|
221
|
+
console.log(' runs. Project conventions (layout, style, process) are');
|
|
222
|
+
console.log(' guidance in CONVENTIONS.md, not rules here.\n');
|
|
224
223
|
for (const r of RULES) {
|
|
225
|
-
|
|
226
|
-
const status = off ? '[disabled by override]' : '[enabled]';
|
|
227
|
-
console.log(` ${r.name.padEnd(30)} ${status.padEnd(24)} ${r.description}`);
|
|
228
|
-
}
|
|
229
|
-
if (!anyOverride) {
|
|
230
|
-
console.log('\n (no overrides found; every rule above is active in this project)');
|
|
224
|
+
console.log(` ${r.name.padEnd(30)} ${r.description}`);
|
|
231
225
|
}
|
|
232
226
|
break;
|
|
233
227
|
}
|
|
@@ -235,7 +229,7 @@ async function main() {
|
|
|
235
229
|
const violations = await checkConventions(process.cwd());
|
|
236
230
|
|
|
237
231
|
if (violations.length === 0) {
|
|
238
|
-
console.log('webjs check: all
|
|
232
|
+
console.log('webjs check: all checks pass ✓');
|
|
239
233
|
} else {
|
|
240
234
|
console.log(`webjs check: ${violations.length} violation(s) found\n`);
|
|
241
235
|
for (const v of violations) {
|
package/lib/create.js
CHANGED
|
@@ -536,7 +536,7 @@ export async function POST(req: Request) {
|
|
|
536
536
|
return Response.json(await createUser(body));
|
|
537
537
|
}
|
|
538
538
|
`);
|
|
539
|
-
// Minimal test
|
|
539
|
+
// Minimal starter test so a freshly scaffolded app ships with a test
|
|
540
540
|
// and `webjs test` runs cleanly. Replace these with real assertions
|
|
541
541
|
// once you wire the action/query to a real data source.
|
|
542
542
|
await writeFile(join(appDir, 'test', 'unit', 'users.test.ts'), `import { test } from 'node:test';
|
|
@@ -820,7 +820,7 @@ export default function Home() {
|
|
|
820
820
|
<p class="text-lede leading-[1.5] text-fg-muted max-w-[56ch] m-0 mb-6">
|
|
821
821
|
Edit <code class="font-mono text-[0.9em]">app/page.ts</code> to get started.
|
|
822
822
|
Run \${accentLink('#', 'webjs test')} to run tests and
|
|
823
|
-
\${accentLink('#', 'webjs check')} to
|
|
823
|
+
\${accentLink('#', 'webjs check')} to catch correctness issues.
|
|
824
824
|
</p>
|
|
825
825
|
<div class="flex gap-3 items-center">
|
|
826
826
|
<button class=\${buttonClass()}>Get started</button>
|
package/lib/saas-template.js
CHANGED
|
@@ -174,7 +174,7 @@ export async function writeSaasFiles(appDir) {
|
|
|
174
174
|
].join('\n'));
|
|
175
175
|
|
|
176
176
|
// test/unit/auth.test.ts: minimal stub so the scaffold passes
|
|
177
|
-
// `webjs
|
|
177
|
+
// `webjs test` runs cleanly out of the
|
|
178
178
|
// box. The signup/current-user functions import from lib/prisma.server.ts
|
|
179
179
|
// and lib/auth.server.ts, both of which need `prisma generate` to have run before
|
|
180
180
|
// they can be imported, so we deliberately test only the runtime-
|
package/package.json
CHANGED
|
@@ -12,8 +12,9 @@ cover what you need, the full hosted docs are at **https://docs.webjs.com**.
|
|
|
12
12
|
ANY data the app stores (todos, posts, messages, products, comments), define
|
|
13
13
|
a Prisma model. NEVER create `data/*.json`, `db.json`, or any JSON file as a
|
|
14
14
|
fake database. NEVER use module-scope arrays / Maps as a substitute. NEVER
|
|
15
|
-
use localStorage for app data.
|
|
16
|
-
|
|
15
|
+
use localStorage for app data. These are project conventions in
|
|
16
|
+
CONVENTIONS.md (a JSON file used as a database resets on reload and
|
|
17
|
+
cannot scale).
|
|
17
18
|
- **The scaffold is reference, not the final product.** Replace `app/page.ts`,
|
|
18
19
|
the example `User` model, the example users module, etc. with the app the
|
|
19
20
|
user actually asked for. Do not ship "Hello from <app-name>" as the
|
package/templates/.cursorrules
CHANGED
|
@@ -12,8 +12,8 @@ cover what you need, the full hosted docs are at **https://docs.webjs.com**.
|
|
|
12
12
|
data the app stores (todos, posts, messages, products, comments…),
|
|
13
13
|
define a Prisma model. NEVER create `data/*.json`, `db.json`, or any
|
|
14
14
|
JSON file as a fake database. NEVER use module-scope arrays / Maps as
|
|
15
|
-
a substitute. NEVER use localStorage for app data.
|
|
16
|
-
|
|
15
|
+
a substitute. NEVER use localStorage for app data. These are project conventions in CONVENTIONS.md (a JSON file used as a
|
|
16
|
+
database resets on reload and cannot scale).
|
|
17
17
|
- **The scaffold is reference, not the final product.** Replace
|
|
18
18
|
`app/page.ts`, the example `User` model, the example users module, etc.
|
|
19
19
|
with the app the user actually asked for. Don't ship "Hello from
|
|
@@ -12,8 +12,8 @@ the full hosted docs are at **https://docs.webjs.com**.
|
|
|
12
12
|
data the app stores (todos, posts, messages, products, comments…),
|
|
13
13
|
define a Prisma model. NEVER create `data/*.json`, `db.json`, or any
|
|
14
14
|
JSON file as a fake database. NEVER use module-scope arrays / Maps as
|
|
15
|
-
a substitute. NEVER use localStorage for app data.
|
|
16
|
-
|
|
15
|
+
a substitute. NEVER use localStorage for app data. It resets on reload and cannot scale. This is a project convention
|
|
16
|
+
(CONVENTIONS.md).
|
|
17
17
|
- **The scaffold is reference, not the final product.** Replace
|
|
18
18
|
`app/page.ts`, the example `User` model, the example users module, etc.
|
|
19
19
|
with the app the user actually asked for. Don't ship "Hello from
|
package/templates/AGENTS.md
CHANGED
|
@@ -24,8 +24,8 @@ the app the user actually asked for.
|
|
|
24
24
|
stores (todos, posts, messages, products, comments, anything),
|
|
25
25
|
define a Prisma model and persist there.
|
|
26
26
|
- **NEVER** store app data in JSON files (`data/todos.json`,
|
|
27
|
-
`db.json`, …).
|
|
28
|
-
|
|
27
|
+
`db.json`, …). It resets on reload and cannot scale. This is a project convention,
|
|
28
|
+
and the user's prompt explicitly forbids it.
|
|
29
29
|
- **NEVER** use in-memory arrays or `Map`s as a substitute for the
|
|
30
30
|
database. They vanish on every dev-server reload and aren't
|
|
31
31
|
shared across processes.
|
|
@@ -588,7 +588,8 @@ Practical consequences for agents writing webjs code.
|
|
|
588
588
|
| Class-field initializer for a reactive property (`student: Student = {...}`) | Silently breaks reactivity (overwrites the framework accessor) | `declare student: Student` plus constructor default |
|
|
589
589
|
| `@property()` decorator | Banned by invariant 10 (erasable TS) | `static properties = { ... }` plus `declare` |
|
|
590
590
|
| `static styles = css` block without `static shadow = true` | Styles leak globally; the framework warns at runtime | Add `static shadow = true`, or use Tailwind utilities |
|
|
591
|
-
| `willUpdate` computing SSR-visible derived state |
|
|
591
|
+
| `willUpdate` computing SSR-visible derived state | Works (runs at SSR), but overriding it opts the component out of elision | Fine for interactive components; for display-only, derive inline in `render()` |
|
|
592
|
+
| `this.hasAttribute` / `getAttribute` in `render()` | Works (server attribute shim backs the attribute methods at SSR) | Read attributes directly, or via a `static properties` + `declare` reactive prop |
|
|
592
593
|
| `ContextProvider` for server-known data | Default value during SSR, content shift on hydration | Pass via props from the page function |
|
|
593
594
|
|
|
594
595
|
The full annotated catalog with code examples lives in the framework
|
|
@@ -943,5 +944,6 @@ composition, so a nested shell ends up dropped by the HTML parser.
|
|
|
943
944
|
5. When unsure how a framework feature works, `grep` or `cat` the
|
|
944
945
|
relevant `node_modules/@webjsdev/*/src/` file before asking the user.
|
|
945
946
|
|
|
946
|
-
Project
|
|
947
|
-
|
|
947
|
+
Project conventions live in [CONVENTIONS.md](./CONVENTIONS.md) (guidance
|
|
948
|
+
you follow by judgment). `webjs check` is separate: correctness checks
|
|
949
|
+
only, always on, no per-project disabling.
|
package/templates/CONVENTIONS.md
CHANGED
|
@@ -9,59 +9,41 @@ Edit the content below the marker to change the convention for your project.
|
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
This
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
If
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
###
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
webjs check
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"actions-in-modules": false
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
Only `false` is meaningful. There's no way to tweak rule *behaviour*
|
|
54
|
-
via config. A rule is either on or off.
|
|
55
|
-
|
|
56
|
-
### Rule for AI agents
|
|
57
|
-
|
|
58
|
-
1. Run `webjs check --rules` to learn the active rule set for this
|
|
59
|
-
project.
|
|
60
|
-
2. Treat every rule not explicitly disabled as binding when writing
|
|
61
|
-
code.
|
|
62
|
-
3. To change which rules are active, edit the `webjs.conventions`
|
|
63
|
-
block in `package.json`. Never inline a rule list into prose, since
|
|
64
|
-
it will drift.
|
|
12
|
+
## `CONVENTIONS.md` vs `webjs check`: two different things
|
|
13
|
+
|
|
14
|
+
This file is the source of truth for **project conventions**: how code
|
|
15
|
+
is organized, named, and tested. They are preferences a reasonable
|
|
16
|
+
project could do differently, so they are guidance (for humans and AI
|
|
17
|
+
agents), not a hard gate. Customize any of them; sections marked
|
|
18
|
+
`<!-- OVERRIDE -->` are explicit customization points.
|
|
19
|
+
|
|
20
|
+
`webjs check` is a separate, narrower tool: **correctness checks** that
|
|
21
|
+
catch objectively broken code (a crash, a security leak, a build or
|
|
22
|
+
type-strip failure). Those always run, there is no per-project
|
|
23
|
+
disabling, and they are not listed here (run `webjs check --rules` to
|
|
24
|
+
see them). The line between the two: *could a sensible app legitimately
|
|
25
|
+
want this to pass?* If yes, it is a convention (this file); if no, it is
|
|
26
|
+
a check (the tool).
|
|
27
|
+
|
|
28
|
+
### Project conventions (follow these)
|
|
29
|
+
|
|
30
|
+
These are the architectural conventions for this app. They are not
|
|
31
|
+
enforced by `webjs check`; follow them by judgment.
|
|
32
|
+
|
|
33
|
+
- **Server actions and queries live in `modules/<feature>/actions/` and
|
|
34
|
+
`modules/<feature>/queries/`** (`*.server.{js,ts}`), not loose in the
|
|
35
|
+
app root. Cross-cutting server infrastructure (the Prisma singleton,
|
|
36
|
+
session helpers, auth config) lives in `lib/`.
|
|
37
|
+
- **One exported function per action/query file.** Name the file after
|
|
38
|
+
the function (`create-post.server.ts` exports `createPost`). It keeps
|
|
39
|
+
the action surface greppable.
|
|
40
|
+
- **Every feature has tests.** A `modules/<feature>/` directory should
|
|
41
|
+
have matching test files under `test/<feature>/`. A unit test for
|
|
42
|
+
logic, a browser/e2e test for user-facing behaviour.
|
|
43
|
+
- **Persist data with Prisma + SQLite, never JSON files.** The scaffold
|
|
44
|
+
wires up `prisma/schema.prisma` and `lib/prisma.server.ts`. A
|
|
45
|
+
`data/todos.json` or `db.json` used as a database resets on reload and
|
|
46
|
+
cannot scale; define a Prisma model instead.
|
|
65
47
|
|
|
66
48
|
---
|
|
67
49
|
|
|
@@ -125,9 +107,9 @@ checklist mirrors this list.
|
|
|
125
107
|
If yes, update it on this PR. Common surfaces (non-exhaustive):
|
|
126
108
|
- `AGENTS.md` (root and every nested one) for API surface, invariants,
|
|
127
109
|
file-routing rules, project-wide agent workflow.
|
|
128
|
-
- `CONVENTIONS.md` (this file) for
|
|
129
|
-
|
|
130
|
-
|
|
110
|
+
- `CONVENTIONS.md` (this file) for project conventions (layout,
|
|
111
|
+
naming, testing). The `webjs check` correctness rules are a separate
|
|
112
|
+
tool surface, not documented here (run `webjs check --rules`).
|
|
131
113
|
- `README.md` (root and any nested ones) for install / use / public
|
|
132
114
|
surface descriptions.
|
|
133
115
|
- `CHANGELOG.md` for any user-visible change, including the SHA / PR
|
|
@@ -267,8 +249,8 @@ deploy`, and `npm run db:migrate` / `db:generate` / `db:studio` scripts.
|
|
|
267
249
|
comments, users…), define a Prisma model in `prisma/schema.prisma`
|
|
268
250
|
and persist there.
|
|
269
251
|
2. **NEVER** create JSON files under `data/`, `db.json`, `posts.json`,
|
|
270
|
-
`todos.json`, etc. as a fake database.
|
|
271
|
-
|
|
252
|
+
`todos.json`, etc. as a fake database. It resets on reload and cannot
|
|
253
|
+
scale; this is a project convention (see the conventions section above).
|
|
272
254
|
3. **NEVER** use module-scope arrays or `Map`s as a "store". They
|
|
273
255
|
reset on every dev-server reload and can't scale beyond one process.
|
|
274
256
|
4. **NEVER** use `localStorage` / `sessionStorage` to persist app data -
|
|
@@ -878,11 +860,15 @@ toggle, the tab switch) requires JS.
|
|
|
878
860
|
JS will fill it in. The first paint must be the right content.
|
|
879
861
|
|
|
880
862
|
**SSR-meaningful component state.** The SSR pipeline constructs the
|
|
881
|
-
component, applies its attributes,
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
863
|
+
component, applies its attributes, runs `willUpdate` and controllers'
|
|
864
|
+
`hostUpdate`, and calls `render()`. It does NOT call `connectedCallback`,
|
|
865
|
+
`firstUpdated`, `updated`, or any other browser-only lifecycle hook.
|
|
866
|
+
Whatever state should appear on first paint MUST be set in the
|
|
867
|
+
constructor (after `super()`), derived in `willUpdate`, or derivable
|
|
868
|
+
from `static properties` + attributes on the rendered tag. Reading
|
|
869
|
+
`this.getAttribute` / `hasAttribute` in `render()` works server-side (a
|
|
870
|
+
server attribute shim backs the attribute methods), but a `Task`'s
|
|
871
|
+
fetch still runs only on the client.
|
|
886
872
|
|
|
887
873
|
```ts
|
|
888
874
|
import { WebComponent, html, signal } from '@webjsdev/core';
|
|
@@ -1019,15 +1005,17 @@ This project enforces a git workflow via agent-specific config files
|
|
|
1019
1005
|
|
|
1020
1006
|
---
|
|
1021
1007
|
|
|
1022
|
-
##
|
|
1008
|
+
## Customizing conventions
|
|
1023
1009
|
|
|
1024
|
-
|
|
1025
|
-
the
|
|
1026
|
-
`package.json`
|
|
1027
|
-
|
|
1010
|
+
The conventions in this file are guidance, so customize them directly:
|
|
1011
|
+
edit the prose under any `<!-- OVERRIDE -->` marker. There is no
|
|
1012
|
+
`package.json` switch and nothing to toggle, because conventions are not
|
|
1013
|
+
enforced by a tool.
|
|
1028
1014
|
|
|
1029
|
-
|
|
1030
|
-
|
|
1015
|
+
`webjs check` is separate: it runs only correctness checks (a crash, a
|
|
1016
|
+
security leak, a build/type-strip failure), always, with no per-project
|
|
1017
|
+
disabling. Run `webjs check` to validate, and `webjs check --rules` to
|
|
1018
|
+
list those checks.
|
|
1031
1019
|
|
|
1032
1020
|
---
|
|
1033
1021
|
|