prunelle 0.0.0-stage → 0.1.2
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/llms.txt +148 -0
- package/package.json +53 -4
- package/src/ambient.d.ts +6 -0
- package/src/attrs.ts +35 -0
- package/src/build/bundle.ts +613 -0
- package/src/build/carry.ts +57 -0
- package/src/build/client-entries.ts +106 -0
- package/src/build/client-plugin.ts +169 -0
- package/src/build/client-prune.ts +118 -0
- package/src/build/compile.ts +127 -0
- package/src/build/files.ts +156 -0
- package/src/build/first-load.ts +164 -0
- package/src/build/graph.ts +247 -0
- package/src/build/index.ts +575 -0
- package/src/build/is-inside.ts +12 -0
- package/src/build/islands.ts +641 -0
- package/src/build/manifest.ts +264 -0
- package/src/build/output.ts +84 -0
- package/src/build/plugin-host.ts +220 -0
- package/src/build/precompress.ts +126 -0
- package/src/build/prerender.ts +150 -0
- package/src/build/render-rules.ts +205 -0
- package/src/build/report.ts +247 -0
- package/src/build/resolve.ts +50 -0
- package/src/build/routes.ts +177 -0
- package/src/build/server-entry.ts +38 -0
- package/src/build/static.ts +109 -0
- package/src/cli/check.ts +334 -0
- package/src/cli/commands.ts +265 -0
- package/src/cli/index.ts +70 -0
- package/src/cli/inspect.ts +316 -0
- package/src/cli/new.ts +41 -0
- package/src/cli/upgrade-names.ts +149 -0
- package/src/cli/upgrade.ts +258 -0
- package/src/compiler/analyze.ts +618 -0
- package/src/compiler/ast.ts +82 -0
- package/src/compiler/browser-globals.ts +127 -0
- package/src/compiler/compliance.ts +598 -0
- package/src/compiler/data-keys.ts +295 -0
- package/src/compiler/dom-attrs.ts +379 -0
- package/src/compiler/dom.ts +566 -0
- package/src/compiler/emit.ts +131 -0
- package/src/compiler/expr-context.ts +408 -0
- package/src/compiler/index.ts +8 -0
- package/src/compiler/interactivity.ts +366 -0
- package/src/compiler/mistakes.ts +499 -0
- package/src/compiler/node-env.ts +50 -0
- package/src/compiler/patch.ts +97 -0
- package/src/compiler/props.ts +460 -0
- package/src/compiler/scope.ts +568 -0
- package/src/compiler/server-only.ts +326 -0
- package/src/compiler/shared.ts +369 -0
- package/src/compiler/signal-reads.ts +242 -0
- package/src/compiler/slots.ts +227 -0
- package/src/compiler/ssr-helpers.ts +555 -0
- package/src/compiler/ssr-island.ts +90 -0
- package/src/compiler/ssr-prunelle-tags.ts +56 -0
- package/src/compiler/ssr.ts +394 -0
- package/src/context.ts +165 -0
- package/src/dev/child.ts +30 -0
- package/src/dev/index.ts +208 -0
- package/src/dev/modules.ts +68 -0
- package/src/dev/protocol.ts +21 -0
- package/src/dev/queue.ts +79 -0
- package/src/dev/reload.ts +157 -0
- package/src/dev/supervisor.ts +187 -0
- package/src/dev/watchers.ts +215 -0
- package/src/dom/action.ts +161 -0
- package/src/dom/attrs.ts +72 -0
- package/src/dom/claim.ts +120 -0
- package/src/dom/extras.ts +562 -0
- package/src/dom/index.ts +289 -0
- package/src/dom/island.ts +284 -0
- package/src/dom/loop.ts +450 -0
- package/src/dom/revive.ts +36 -0
- package/src/index.ts +22 -0
- package/src/jsx-runtime.ts +566 -0
- package/src/plugins/config.ts +86 -0
- package/src/plugins/context.ts +66 -0
- package/src/plugins/index.ts +14 -0
- package/src/plugins/load.ts +70 -0
- package/src/plugins/order.ts +111 -0
- package/src/plugins/public.ts +12 -0
- package/src/plugins/requires.ts +47 -0
- package/src/plugins/services.ts +35 -0
- package/src/plugins/types.ts +234 -0
- package/src/reactivity/graph.ts +249 -0
- package/src/reactivity/index.ts +533 -0
- package/src/reactivity/selector.ts +51 -0
- package/src/reactivity/store.ts +208 -0
- package/src/server/action-registry.ts +78 -0
- package/src/server/action.ts +475 -0
- package/src/server/app-entry.ts +23 -0
- package/src/server/assets.ts +136 -0
- package/src/server/compress.ts +560 -0
- package/src/server/consent.ts +253 -0
- package/src/server/cookies.ts +139 -0
- package/src/server/document.ts +271 -0
- package/src/server/env.ts +33 -0
- package/src/server/errors.ts +153 -0
- package/src/server/http.ts +441 -0
- package/src/server/index.ts +616 -0
- package/src/server/lifecycle.ts +75 -0
- package/src/server/loader.ts +118 -0
- package/src/server/page.ts +107 -0
- package/src/server/plugin-host.ts +251 -0
- package/src/server/prerendered.ts +71 -0
- package/src/server/public.ts +19 -0
- package/src/server/rate-limit.ts +133 -0
- package/src/server/region.ts +96 -0
- package/src/server/request-body.ts +27 -0
- package/src/server/request-path.ts +73 -0
- package/src/server/request-scope.ts +22 -0
- package/src/server/route-table.ts +79 -0
- package/src/server/router.ts +184 -0
- package/src/server/routing.ts +339 -0
- package/src/server/security.ts +323 -0
- package/src/server/serve-handlers.ts +69 -0
- package/src/server/served-file.ts +128 -0
- package/src/server/standard-schema.ts +87 -0
- package/src/server/start.ts +99 -0
- package/src/server/static-dir.ts +167 -0
- package/src/server/stream.ts +192 -0
- package/src/ssr/context.ts +301 -0
- package/src/ssr/index.ts +477 -0
- package/src/ssr/navigation.ts +96 -0
- package/src/ssr/region.ts +171 -0
- package/src/style.ts +33 -0
- package/src/test/browser.ts +186 -0
- package/src/test/index.ts +177 -0
- package/src/unrenderable.ts +35 -0
- package/templates/_shared/AGENTS.md +10 -0
- package/templates/_shared/CLAUDE.md +1 -0
- package/templates/_shared/gitignore +3 -0
- package/templates/_shared/public/robots.txt +2 -0
- package/templates/_shared/src/routes/legal.tsx +8 -0
- package/templates/_shared/tsconfig.json +20 -0
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +21 -0
- package/templates/app/prunelle.config.ts +11 -0
- package/templates/app/src/auth.ts +14 -0
- package/templates/app/src/routes/_layout.tsx +32 -0
- package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
- package/templates/app/src/routes/dashboard/index.tsx +13 -0
- package/templates/app/src/routes/index.tsx +15 -0
- package/templates/app/src/routes/login.tsx +34 -0
- package/templates/app/src/styles/app.css +7 -0
- package/templates/app/tests/app.test.ts +32 -0
- package/templates/blog/content/posts/welcome.md +9 -0
- package/templates/blog/package.json +22 -0
- package/templates/blog/prunelle.config.ts +23 -0
- package/templates/blog/src/posts.ts +26 -0
- package/templates/blog/src/routes/_layout.tsx +20 -0
- package/templates/blog/src/routes/blog/[slug].tsx +31 -0
- package/templates/blog/src/routes/index.tsx +29 -0
- package/templates/blog/src/styles/app.css +10 -0
- package/templates/fullstack/package.json +19 -0
- package/templates/fullstack/prunelle.config.ts +6 -0
- package/templates/fullstack/src/actions/greet.ts +19 -0
- package/templates/fullstack/src/components/Counter.tsx +10 -0
- package/templates/fullstack/src/components/GreetForm.tsx +27 -0
- package/templates/fullstack/src/routes/_layout.tsx +14 -0
- package/templates/fullstack/src/routes/api/health.ts +5 -0
- package/templates/fullstack/src/routes/index.tsx +13 -0
- package/templates/fullstack/src/styles/app.css +29 -0
- package/templates/fullstack/tests/app.test.ts +37 -0
- package/templates/minimal/package.json +19 -0
- package/templates/minimal/prunelle.config.ts +6 -0
- package/templates/minimal/src/components/Counter.tsx +10 -0
- package/templates/minimal/src/routes/_layout.tsx +14 -0
- package/templates/minimal/src/routes/index.tsx +11 -0
- package/templates/minimal/src/styles/app.css +22 -0
- package/README.md +0 -3
package/llms.txt
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Prunelle Reference (for humans & coding agents)
|
|
2
|
+
|
|
3
|
+
> Prunelle is a Bun-native TSX web framework with zero-directive automatic islands, `.value` fine-grained signals, flat-string SSR, unified Standard-Schema actions, single-binary `--compile`, and a composable `PrunellePlugin` API.
|
|
4
|
+
|
|
5
|
+
## Core Rules (everything fits on one page)
|
|
6
|
+
|
|
7
|
+
- **Imports**: `prunelle` (signals, `Head`, `Suspense`, `Catch`, `Region`, `ConsentGate`, `createContext`, `provideContext`, `useContext`, `useId`, `useAction`), `prunelle/server` (`action`, `getActionError`, `notFound`, `defineEnv`, `nodeEnv`, `raw`, `esc`, `escAttr`, `escJson` (JSON text for a `<script>`), `getClientIp`, `isHttpsRequest`, `isTrustedOrigin`, `verifyOrigin`, `safeRedirect`, `safeEqual` (constant-time secret compare), `wantsJson`, `readStringFields` (a body's string fields, on a null-prototype record), `createRateLimitStore({ maxKeys?, maxHits? })` (a standalone sliding-window store: `.limiter({ max, windowMs }).hit(key)` returns 0 or the seconds to wait; plugins use `api.rateLimiter()`), `validateSchema`, `validateSchemaSync`, `formatSchemaIssues`, `formatIssuePath`, route types, `createServer({ root })` to run a built app inside another program), `prunelle/config` (`defineConfig`, `definePlugin`, `serviceKey`, `isInside(dir, target, { orSame })`, plugin types), `prunelle/test` (`testApp`, `testBrowser`). An `@kayjs/*` import, prunelle's name when it was kay v2, fails the compile (`prunelle upgrade` rewrites them); `prunelle/internal/*` is compiler output, outside semver.
|
|
8
|
+
- **Standard TSX & compiler guardrails**: `.tsx` files with `jsxImportSource: "prunelle"`. Use `class` or `className` (never both). Standard `.map()` (with `key={...}`), `&&`, ternaries, `{...spread}`, SVG elements, style strings or objects (`style={{ color: 'red' }}`), and CSS / `*.module.css` imports work natively. Compiler/runtime refuse common React/Solid/Astro habits: `innerHTML={html}` takes a string or `raw(html)` (never `{ __html }`, never `dangerouslySetInnerHTML`, never on void elements or with children); events are camelCase DOM names (`onClick`, `onDblClick`, `onKeyDown` — never lowercase `onclick`, `on:click`, `onDoubleClick`, `*Capture`, string handlers, or render-time assignments); `ref` is always a callback `ref={el => ...}` (never `{ current }`); SVG attrs use kebab-case (`stroke-width`, `fill-opacity`); entities in string attrs and props decode like text (`title="a & b"` is `a & b`; an `innerHTML` string stays as written); use `value`/`checked` (not `defaultValue`/`defaultChecked`) and boolean `{false}` (not `"false"`); no `client:*`/`use:*`/`class:list`/`set:html` directives and no `'use client'`/`'use server'`; no Promises, functions, signals, or plain objects in JSX text/attrs. Spreads drop `on*`, `innerHTML`, `srcdoc`, and `javascript:`/`vbscript:` URLs.
|
|
9
|
+
- **Signals, Context & IDs (`prunelle`)**: `const count = signal(0)` (`.value` read/write, `.peek()` untracked), `computed(() => ...)`, `effect(() => ...)` (return cleanup, never `async`; skipped while an island renders on the server, so derive values with `computed`; a local signal read without `.value` in JSX, an `if`/ternary/loop test or `!`, and `const { value } = count`, fail compile), `batch(() => ...)`, `untrack(() => ...)`, `root(dispose => ...)`, `onMount(() => ...)` (runs after DOM attach; return cleanup), `onCleanup(() => ...)`, `getOwner()`, `selector(() => id.value)` (O(1) selection), `store(obj)` + `snapshot(s)`. Context: `const Ctx = createContext(defaultValue)`, `<Ctx.Provider value={v}>` or `provideContext(Ctx, v, fn)`, `useContext(Ctx)`. Deterministic hydration-safe IDs: `useId(prefix = 'k')` (scoped per island or SSR request). To let a child mutate parent state, pass the signal directly (`<Modal open={isOpen} />`).
|
|
10
|
+
- **Reactive props**: Destructuring props (`function Badge({ count = 0, ...rest }: Props)`) stays reactive in client components, and a default beyond a literal or a name (`items = []`, `id = useId()`) runs once per call; server-rendered children inside islands are preserved via `<pru-slot>`.
|
|
11
|
+
- **Automatic islands**: Any component using reactive primitives (`signal`, `computed`, `effect`, `onMount`, `store`, `selector`), DOM `on*` handlers/`ref`, or imported reactive module state becomes an island automatically, decided per component: a static export beside an island stays static, a component that needs the browser is an island of its own wherever server code renders it as a tag, same file included (the page around it stays static; its chunk keeps only the code of the file it reaches, so an async page importing server code can render a local widget; its props cross the island boundary), a same-file helper that needs the browser makes each component calling it an island, and a primitive called at a file's top level makes every component of it one. Control hydration per call site with `$hydrate="load" | "visible" | "idle" | "interaction" | "media(...)" | "client"`, or the component file's default `export const hydrate = 'visible'` (unknown modes and `$hydrate` on non-islands fail compile); the loader carries only the strategies the app's islands can use, and a page modulepreloads its eager islands with every chunk they and the runtime import (a streamed page its route's eager islands only). `<Head>`/`<Suspense>` in an island fail compile (`<Catch>` works in both); an island reading a context provided outside it throws in SSR (pass the value as a prop); server children handed to an island render before it, in the page's scope. Hydration steps over a node an extension injected and redraws a part whose tag differs from the server's and drops the server rows past a list's last row, in production too (dev also warns). Island props crossing the server boundary must be serializable (JSON primitives + `Date`, `Map`, `Set`, `URL`, `RegExp` — functions, signals and JSX in a prop other than `children` are refused; only a page whose props hold one of those classes loads, and preloads, the small file that revives them); an `on*` function passed from server code to a component that is not an island fails build and check too, since it would never run. A browser global (`window`, `document`, `localStorage`, ...) read while a component renders or its module loads warns, since the server has none: read it in `onMount()`, an effect or a handler, or behind `typeof window !== 'undefined'`. Islands cannot import server-only modules (`bun:sqlite`, `node:*`, `prunelle/server`) or read `process.env` other than `process.env.PUBLIC_*` (inlined at build time); action files are stubbed on the client (non-action exports from them cannot be imported by islands).
|
|
12
|
+
- **Routes (`src/routes/`)**:
|
|
13
|
+
- `export default async function Page({ params, locals, url })`: strictly server-only (`0 KB` JS; cannot use signals/handlers directly).
|
|
14
|
+
- Sync `export default function Page({ data, params, locals, url }: PageProps<typeof load>)`: static or auto-island; optional `export async function load(ctx)` runs server-only and returns data, `notFound()` (from `prunelle/server` — return or throw to render `_404.tsx` with HTTP `404`), or a `Response` (e.g. redirect).
|
|
15
|
+
- Special files: `_layout.tsx` (nested outer→inner, receives `{ children, params, locals, url }`, server-only), `_middleware.ts` (`(ctx, next) => Response`, outer→inner), `_error.tsx` (receives `{ error }`, server-only, wrapped in root layout), `_404.tsx` (server-only, wrapped in root layout, also emitted as `404.html` in `--static`); each needs a default export. Any other file under `src/routes/` must export a page, a method handler or an action (guarded by its folder's `_middleware.ts`), else `prunelle build`/`prunelle check` fail: prefix helpers or their folder with `_`.
|
|
16
|
+
- Params: `[slug].tsx` → `params.slug`; `[...path].tsx` → `params.path` (segments joined by `/`). Params arrive percent-decoded; a segment holding an encoded `/`, `\` or NUL, or a `.`/`..` segment, matches no dynamic route (404), unless a plugin catch-all route sets `encodedSlashes`, so a param is safe to join into a path; static pages, `public/` files and `prunelle start --static` decode by the same rule (`/a%2fb.txt` never serves `a/b.txt`).
|
|
17
|
+
- API routes: `.ts` files exporting `GET`, `POST`, `PUT`, `PATCH`, `DELETE` receiving `RequestContext` (`request`, `url`, `params`, `cookies`, `locals`, `ip`, `region`, `json()`, `text()`, `redirect()`, `deny()`). Optional `export const csrf = false` opts out of origin checks (e.g. webhooks/bearer APIs).
|
|
18
|
+
- Prerendering: `export const prerender = true` (+ `export function paths() { return ['/posts/a'] }` required for dynamic routes, and for every dynamic page under `--static`, or `prunelle build` fails; unlisted params return `404`). Skipped in `prunelle dev`.
|
|
19
|
+
- **Streaming & Head**: `<Head><title>...</title></Head>` (innermost `<title>` wins); `<Suspense fallback={<p>Loading</p>} error={<p>Failed</p>}><AsyncComp /></Suspense>` streams resolved HTML inline with 0 KB external JS (takes exactly one child; an async component anywhere but as the only child of `<Suspense>` fails build and check, even inside an async page; nested boundaries supported; times out after `streamTimeout`, default `30000` ms; errors also fire `onError`). `<Catch fallback={<p>Failed</p> | (error, retry) => ...}>` renders its fallback in place of children that throw or an awaited child that rejects, on the server (firing `onError`; nothing streams) and in an island, where it also catches a child effect's later throw and `retry()` renders the children again (there it is written as a tag: calling `Catch()` as a function throws); errors thrown by event handlers are not caught.
|
|
20
|
+
- **Regions** (`@prunellejs/spa`, `regions()`): `<Region name="pane" as="section" ...attrs>children</Region>` (from `prunelle`, server-only like `Head`) renders `<div data-pru-region="pane">`; its children are read only when the page or the requested region needs them. `<a href data-pru-target="pane">` swaps that region in place: the browser sends `x-pru-region: pane`, the server answers with the region's inner HTML alone (no layouts, no document; `ctx.region` tells `load()` which, `vary: x-pru-region`), history is pushed and back/forward re-fetch it, focus moves to the region, its `aria-label` is announced, `aria-busy="true"` is set after 150 ms and cleared on swap or failure. Add `data-pru-append` and the response is appended and the clicked link removed (Load more; the history entry is replaced, not pushed). `<form method="get" data-pru-target="results">` swaps on submit; with `data-pru-live` also on input (debounced 200 ms; one history entry per typing burst, a 1 s pause ends it). `data-pru-sync="q icon"` on a link, or on an input/select (its `name`), copies those params of the current URL after every swap so links outside the region stay in step. A link inside `[data-pru-prefetch]` prefetches its region on hover/focus through the cache `spa()` shares. A region may sit inside another (give each its own name): asking for the inner one renders it alone (header `x-pru-region: results/sets`, the path outermost first, which the client computes), asking for the outer renders it with a fresh inner, and an outer swap drops in-flight fetches of the regions inside it. Every region swap also sets `document.title` from the page's `<Head><title>` at that URL (title template applied; the server sends it in `x-pru-title`), and back/forward restore it. `await refreshRegion(name)` from `@prunellejs/spa/regions` redraws a region of the current address from script (after a background `fetch` to an action): no history entry, focus left alone, prefetch cache skipped, `pru:region` fired; it rejects when the page has no such region, the fetch fails or the answer lacks it. `<form method="post" data-pru-target="x">` posts through fetch, follows the redirect and swaps region x (without JS it posts normally); empty fields are dropped from a GET form's URL. A swap runs in a view transition where supported and not under reduced motion; each history entry remembers the window's and the regions' scroll, a pushed swap resets the region's own scroll unless it has `data-pru-keep-scroll="<key>"`; links to the new URL get `aria-current="page"`; a `#hash` link to an element on the page scrolls with no fetch when its page and query are the ones shown or appended by Load more. The regions client ships only on routes whose tree renders a `<Region>`. Without JS, or when a fetch fails or the response lacks the region, the link loads the whole page. Mistakes: `<Region>` without `name`, `data-pru-target` off `<a>`/`<form>`, `data-pru-live` on a non-GET form, `data-pru-append`/`data-pru-live` without their target, a region inside a region of the same name (compile errors); a target naming no `<Region>` in `src/` (`prunelle check`); two regions of one name, a requested region the route does not render (runtime throws).
|
|
21
|
+
- **Actions (`prunelle/server` & `useAction` from `prunelle`)**: `export const fn = action(standardSchema, async (input, ctx) => ..., options?)` or `action(async (ctx) => ...)` — must be a top-level named export so Prunelle can assign a URL. Works as zero-JS `<form action={fn} method="post">` (array fields auto-coerced from checkboxes/multi-selects; validation failures set an `HttpOnly` flash cookie readable via `getActionError(ctx.locals)` with sensitive fields stripped or `flashFields` allowlisted and `303` redirect to trusted Referer; `action(schema, fn, { rateLimit: { max, windowMs, key? } })` refuses a client past `max` per window the same way with `Too many requests`, or a `429` `ActionResult` and `Retry-After` from script) and as typed island RPC `const res = await fn(data)` (always resolves to `{ ok: true, data }` or `{ ok: false, status, error, fieldErrors?, issues? }`; accepts `FormData` for files; redirects navigate the page). In islands, `const form = useAction(fn, { reset?, onSuccess?, onError? })` returns `{ pending, error, fieldErrors, data, action, onSubmit, submit, reset }` (`pending`/`error`/`fieldErrors`/`data` are `ReadonlySignal`s; wire `<form action={form.action} method="post" onSubmit={form.onSubmit}>` for progressive enhancement). A route, `load()`, middleware or another action may also call it: it runs in that request, schema and folder `_middleware.ts` included, and resolves to the same result; called outside a request it throws. Server code is stripped from client bundles; CSRF `Origin`/`Sec-Fetch-Site` is checked before middleware and body parsing; folder `_middleware.ts` runs before the handler. `ctx` provides `redirect()` and `deny(status, message, fieldErrors?)`.
|
|
22
|
+
- **Config, Security & Server Helpers (`prunelle.config.ts`, `prunelle/config`, `prunelle/server`)**: `defineConfig({ lang, port, routesDir, outDir, publicDir, assetPrefix, security, trustedOrigins, trustProxy, maxRequestBodySize, streamTimeout, consent, compliance, compress, onError, plugins })`. Default security headers (`security: false` to disable, or override `csp`, `hsts`, `frameOptions`, `referrerPolicy`, `contentTypeOptions`) attach strict `DEFAULT_CSP` (style attributes allowed) with automatic SHA-256 hashes for island/Suspense styles, the app's own `<style>` blocks and stream scripts, plus `HSTS` on HTTPS requests. `trustProxy: true | number` trusts that many right-most proxy hops for `X-Forwarded-*`. `maxRequestBodySize` defaults to `1 MiB`. `prunelle/server` also exports `defineEnv(standardSchema)` (validates env vars at startup), `nodeEnv()` (safe in `--compile`; server code reads it, never `process.env.NODE_ENV`, which `prunelle build` leaves unset for a prerendered page, and build and `prunelle check` warn on such a read outside island code), HTML escaping (`raw`, `esc`, `escAttr`), HTTP security helpers (`getClientIp`, `isHttpsRequest`, `isTrustedOrigin`, `verifyOrigin`, and `safeRedirect(target, fallback = '/')`, which returns the trimmed target only when it is a path on this site, refusing absolute and protocol-relative URLs, backslashes and control characters, and which `@prunellejs/auth` and the consent endpoint use), and Standard Schema helpers (`validateSchema`, `validateSchemaSync`, `formatSchemaIssues`, `formatIssuePath`).
|
|
23
|
+
- **French web law & Consent (RGPD, CNIL, RGAA, LCEN — 0 B client JS)**: `prunelle check` and production `prunelle build` emit actionable warnings (never hard errors): `rgaa/img-alt` (`<img>` without `alt`), `rgaa/form-label` (unlabelled `<input>`/`<select>`/`<textarea>`), `rgaa/accessible-name` (empty or icon-only `<button>`/`<a>`), `rgpd/third-party-url` (third-party `<script src>`, `<link rel="stylesheet|preload|preconnect|dns-prefetch">`, `<iframe src>`, and CSS `@import`/`url(...)` outside `<ConsentGate>` or `site`), `lcen/legal-notice` (page app missing `/mentions-legales` or `/legal`), and `rgaa/accessibility-statement` (when `compliance: { publicBody: true }`, missing `/accessibilite`). Silence explicitly per rule via `compliance: { ignore: [...], legalNotice?: string | false, publicBody?: boolean }` in `prunelle.config.ts`, or `// prunelle-ignore <rule>` / `/* prunelle-ignore <rule> */` / `// prunelle-ignore-file <rule>`. One-declaration consent: configure `consent: { categories: ['analytics', 'media'], cookieName?: 'pru_consent', maxAge?: 15552000, endpoint?: '/_pru/consent' }` in `prunelle.config.ts` — Prunelle wires a CSRF-protected `POST /_pru/consent` endpoint (works with zero-JS HTML `<form method="post" action="/_pru/consent">` via `action="accept-all"|"reject-all"` or category checkboxes -> `303`, and JSON -> `200`), exposes `ctx.consent` (`decided`, `categories`, `has(cat)`, `all()`), refuses `ctx.cookies.set(name, val, { category })` before consent is granted, and exports server-only `<ConsentGate category="media" fallback={...}>` (0 KB browser JS, refused inside islands).
|
|
24
|
+
- **Page changes (plain multi-page navigation, 0 B of JS)**: every page carries inline, CSP-hashed `@view-transition { navigation: auto }` (inside `@media (prefers-reduced-motion: no-preference)`) and a `<script type="speculationrules">` prefetching same-origin links on hover (`eagerness: moderate`); never links to another origin, `/_pru/*` (actions included), `[download]`, `[rel~=nofollow]`, nor a link or ancestor with `data-pru-no-prefetch`. Name an element that stays still with CSS `view-transition-name`. `defineConfig({ navigation: { viewTransitions?: boolean (true), prefetch?: 'conservative' | 'moderate' | 'eager' | false ('moderate'), prerender?: 'conservative' | 'moderate' | 'eager' | boolean (false; true is 'moderate'; it runs `load()` of pages nobody opens) } })`; a bad value throws `prunelle: navigation.<key> is ...`. `data-pru-keep-scroll="<key>"` on a scrolling element keeps its `scrollTop` across page loads (restored before first paint when the next page has the same key; per history entry on back/forward/reload; `sessionStorage` blocked = no-op): the page gets one inline hashed script at the end of `<body>` only when it uses the attribute. The key is a literal string without `"<>&` (compile error otherwise, also for a nested panel of the same key); the same key on two elements of one rendered page throws `prunelle: data-pru-keep-scroll="..." is on two elements of one page`. `@prunellejs/spa` keeps the same attribute across its swaps.
|
|
25
|
+
- **Static files & CSS**: Files in `public/` are served at `/` with ETag/`304` (and `Cache-Control: no-cache` in `prunelle dev`; embedded in `--static` and `--compile`); prerendered pages and hashed assets answer an ETag, a `304` and a `HEAD` length too. `prunelle build` compresses hashed assets, `public/` files and prerendered pages of 256 B or more into `.br` and `.gz` files beside them, kept when smaller, and the server sends those as they are; it compresses on the fly (zstd, gzip) only what has none, such as pages rendered per request, and flushes a page streamed past `<Suspense>` with each part. A `public/x.css.br` the app ships is kept and sent as `x.css` in brotli. `prunelle start` on a `--static` export lists its files at startup (`x` serves `x.html` or `x/index.html`, a miss `404.html`), re-lists them when one changes in place, and loads a new export with no restart. Import `.css` or `*.module.css` directly from any component or layout.
|
|
26
|
+
- **CLI**: `prunelle new <dir> [--template minimal|fullstack|blog|app] [--force]` (its `AGENTS.md` points agents at this file, installed at `node_modules/prunelle/llms.txt`; its `.gitignore` lists `node_modules/`, `dist/` and `.prunelle-cache/`), `prunelle check [dir] [--no-typecheck] [--json] [--strict]` (every compiler mistake of a file, each at its `file:line:col: error:`, warnings as `file:line:col: warning:`; `--json` prints `{ ok, checkedFiles, typecheck, errors, warnings }` with `file`/`line`/`col`/`severity`/`message`, `typecheck` being `{ ran: true, tool }` or `{ ran: false, reason }` (no tsconfig, `--no-typecheck`, no checker), which the summary line also names; `--strict` exits 1 on a warning; `prunelle build` refuses the same mistakes, without the typecheck; a plugin `check(ctx)` reports with `ctx.error()` or `ctx.warn()`), `prunelle inspect [dir] [--json]` (fast static report of routes, islands with interactivity `reason` and `hydrate` mode, actions with URLs and guarding `_middleware.ts`, and active plugins in resolved order without bundling; `--json` prints `{ routes, islands, actions, plugins }`), `prunelle dev [dir] [--port 3000] [--host [addr]]` (loopback `127.0.0.1` default; a `prunelle.config.ts` that fails to load stops it naming `prunelle.config.ts:<line>:<col>: <error>`; the app runs in a child process behind the port: a save rebuilds in it, an edit to `prunelle.config.ts` or a local file it imports, or the child passing 2 GB after a rebuild, starts a fresh one (module and plugin memory reset, requests wait, the reload stream stays open); a crash answers with its exit and stderr until the next save; an edited `public/` file reloads with no rebuild), `prunelle build [dir] [--static] [--compile [out]] [--analyze] [--json] [--max-js <size>]` (`--analyze` lists each route's eager JS (the runtime a plugin's `clientEntry` puts on every page included), CSS, fonts and first load (what a first visit downloads besides the HTML, brotli) and its islands with why each is one; `firstLoadUrls`, `distLocator` and `measureFirstLoad` from `prunelle/config` give a plugin the same figure for a page (`measureFirstLoad(urls, locate, htmlBytes, cacheable)` also returns `cached`, the bytes of the URLs `cacheable` accepts, such as the hashed `/_pru/` files a browser keeps for the next page), and `await brotliSize(html)` the page's own bytes as prunelle serves it, from the build's brotli cache, as the docs footer does; `--analyze --json` outputs `BundleReport` JSON on stdout without summary lines; `--max-js 40kb` fails on a route whose gzipped eager JS is over it, naming its eager islands), `prunelle start [dir] [--port 3000] [--host [addr]]`, `prunelle upgrade [dir] [--no-install]` (moves a kay v2 app onto prunelle: `@kayjs/*` dependencies and imports, `kay.config.ts`, every `Kay*` name it imports, the `kay` names the browser receives, build and CI files, `AGENTS.md` and `CLAUDE.md`, in each package of a bun workspace that depends on kay or prunelle; a package on kay v1 is left as it is; a kay `sqliteAuthStore()` database keeps its accounts), plus plugin commands (`prunelle ui-eject <grammar> [dest]`, `prunelle mcp-footprint`, `prunelle i18n-check`, `prunelle icons-find <words> [--set <prefix>] [--limit <n>]`). `prunelle --help`, `prunelle <command> --help` and `prunelle --completions fish|bash|zsh` come from `@kaynooo/cli-kit`; a typo'd command or option names the one meant. Exit codes: 0 done, 1 a finding or failure (`prunelle check` found an error, `prunelle upgrade` has steps left by hand, a build failed), 2 a usage error (unknown command or option, bad port or `--max-js`). Plugin commands are read from `prunelle.config.ts` only when the first word is no built-in, and take `--root <dir>` and `--help`; a config that fails to load leaves `prunelle --help` and the built-ins working, and a plugin command typed then names the error (exit 1).
|
|
27
|
+
- **Testing (`prunelle/test`)**: `const app = await testApp({ root, prebuilt?, outDir? })` (builds into its own `.prunelle-cache/test-*` folder, removed at exit, never into `dist/`; `prebuilt: true` reuses the latest testApp build of that root in the process, else `dist/`) — in-process `app.get()`, `app.post()`, `app.import(path)` (the app's bundled copy of a route, action file or `prunelle.config.ts`), `app.submit(action | url, fields)`, `app.fetch()`, `app.cookies`, `app.clearCookies()` with persistent cookie jar and zero port binding; `app.errors` lists unhandled route/action/plugin errors (`route GET /p: message`), and `testApp({ dev: true })` shows them in the 500 like `prunelle dev` does. Unhandled errors with `dev` (prunelle dev, `dev: true`): `console.error` unless an `onError` hook exists, and the 500 carries message and stack, each frame at its `src/` file and line (under `prunelle start` too, through the source maps `prunelle build` writes; a `--compile` binary names its own code) (JSON `{ ok: false, status: 500, error, stack }` when the request wants JSON, else text; `_error.tsx` still renders); production stays `Internal Server Error`. `prunelle dev` build errors also answer JSON/text per `Accept`. Islands: `const b = await testBrowser({ root, timeout?, browserPath? })` (needs `playwright-core` as a dev dependency and Chrome/Chromium; production build served on `b.origin`, a free 127.0.0.1 port) then `const page = await b.open(path)` (resolves once the page has loaded and its `load`/`client` islands have hydrated; `visible`, `idle` and `interaction` ones are the test's to trigger) (`b.open(path, { reducedMotion: true })` opens it for a visitor asking for less motion) with `page.click(sel)`, `page.hover(sel)`, `page.fill(sel, value)`, `page.text(sel)`, `page.waitFor(sel | fn)`, `page.evaluate(fn)`, `page.errors` (page errors, console errors, 4xx/5xx responses), `page.close()`, and `await b.close()` at the end.
|
|
28
|
+
- **Plugins (`prunelle.config.ts`)**: `export default defineConfig({ plugins: [...] })` / `definePlugin(...)`. Order with `enforce: 'pre' | 'post'` and `after: ['@prunellejs/i18n']` (a name no plugin has is an optional dependency, unless it is one typo from one that is, which fails). Two plugins sharing a `name` fail, and so does an unknown config key, naming the closest one.
|
|
29
|
+
- A stateful plugin's `createX()` returns the plugin and the app's handle in one object: `plugins: [auth, mail, rooms]`, with `auth.guard()`, `mail.send()`, `rooms.publish()` in routes. Stateless plugins are `x()`.
|
|
30
|
+
- Hooks: `server(api)` (`use(mw, { scope? })` (`'all'` default, prerendered pages included; `'rendered'` skips prerendered pages, for middleware that only feeds rendering such as a session; `'dynamic'` also skips pages with no `load`; or a path prefix), `rewrite` (also run once per prerendered page at start, on an anonymous GET: no side effects), `route(method, path, handler, { csrf?, trustedOrigins?, trustProxy?, rateLimit?, encodedSlashes? })` (`rateLimit: { max, windowMs, key? }` answers `429` with `Retry-After` before the handler past `max` per window, per `ctx.ip` or `key(ctx)`; `encodedSlashes: true` lets a `*name` catch-all take a segment holding `%2F`, `%5C` or `%00`, left encoded in the param, for text such as a URL, never a file path; on a path with no catch-all it throws; responses get the security headers; an HTML one without its own CSP gets the app's, its `<style>` blocks hashed), `provide(key, value)`/`inject(key)` typed by `serviceKey<T>(name)` from `prunelle/config`, `getBuildData`), `onError(info)`, `build(ctx)` (`emitAsset`, `emitPublic`, `addStyle`, `addRouteStyle`, `addHead`, `addRouteHead`, `provide`, `inject`, `setData`, `routes`), `afterPrerender(ctx)` (`routes`, `publicFiles`, `emitAsset`, `emitPublic`, `setData`), `transform`, `bunPlugins` (array or `({ root, assetPrefix, minify, target }) => [...]`), `css`, `head(head, ctx)`, `transformHtml`, `inlineScripts` (the inline scripts the plugin writes into pages, each as it stands between its tags: the CSP of every page allows them by hash, since prunelle never hashes a script it finds in a page), `prerenderPaths`, `clientEntry`, `check(ctx)`, `requires({ root, site })` (one message per setting the plugin needs in production, naming it and its fix: a production start (`NODE_ENV=production`, not `prunelle dev`) refuses while any is unmet, listing them all; `prunelle dev`, tests and `prunelle check` warn once each; a throwing `requires` counts as unmet; first-party: auth refuses an in-memory store, mail a missing transport or `from`, mcp a missing `token`, seo and a content feed a missing `site`), `watchPaths`, `commands`.
|
|
31
|
+
- `api.rateLimiter({ max, windowMs })` returns a limiter in the server's store (bounded to 10 000 keys and 1 000 000 hits, swept every minute, dropped with the server) for a limit a route option cannot key, such as per email: `hit(key)` returns 0, or the whole seconds to wait.
|
|
32
|
+
- Runtime state (timers, connections, caches) is created in `server(api)` and released in `api.onShutdown()`, never in the plugin factory (a throwing `onShutdown` or `onError` hook is logged with its plugin's name; the others still run): `prunelle dev` starts the next server on the same instance before shutting the last one down, and a new process on a `prunelle.config.ts` edit.
|
|
33
|
+
- First-party packages (13 total with `prunelle`; each ships its full reference at `node_modules/@prunellejs/<name>/llms.txt`):
|
|
34
|
+
- `@prunellejs/ui` (`node_modules/@prunellejs/ui/llms.txt`): Zero-JS layout/form primitives (`Stack`, `Cluster`, `Grid`, `Sidebar`, `Split`, `Button`, `Card`, `Badge`, `Notice`, `Field`, `Switch`, `Checkbox`, `RadioGroup`, `Progress`, `Accordion`, `Popover`), island widgets (`Dialog`, `Drawer`, `Tabs`, `Menu`, `Select`, `CommandPalette`, `DataTable`, `Toaster` + `toast()`), `@layer kui` Style Grammars (`prunelle`, `orbit`, `editorial`, `workshop`, `console`, `soft`, `bare`), `prunelle ui-eject`.
|
|
35
|
+
- `@prunellejs/auth` (`node_modules/@prunellejs/auth/llms.txt`): Argon2id passwords, hashed sessions, email verification (`requireEmailVerification: true`), magic links, OAuth 2.0 + PKCE, `auth.guard()`, RGPD helpers (`listSessions`, `exportUser`, `deleteUser`), `memoryAuthStore()` & `sqliteAuthStore()`.
|
|
36
|
+
- `@prunellejs/content` (`node_modules/@prunellejs/content/llms.txt`): Zero-dep `Bun.markdown` + `Bun.YAML` collections, Standard Schema frontmatter, lazy `entry.render()` (`highlight`, MDX-lite `components`, `headingLinks`), auto-wired `@prunellejs/images`, localized collections, TOC, and RSS feeds (`content({ feeds })`).
|
|
37
|
+
- `@prunellejs/live` (`node_modules/@prunellejs/live/llms.txt`): Typed SSE rooms (`createRooms()`), `publish()`, microtask `coalesce()`, `rooms.stream()`, and browser `useLive()` hook (`@prunellejs/live/client`).
|
|
38
|
+
- `@prunellejs/mcp` (`node_modules/@prunellejs/mcp/llms.txt`): MCP Streamable HTTP (`2025-03-26`) exposing `action()`/handlers & compacted Standard JSON Schemas at `/mcp/tools` with bearer auth, `schemas`/`schemaRef`, `resources`, `formatLines`/`formatTable`, `budget`, and `prunelle mcp-footprint`.
|
|
39
|
+
- `@prunellejs/images` (`node_modules/@prunellejs/images/llms.txt`): Build-time AVIF/WebP pipeline + disk cache (`images()`, `image()`, `<Picture>`, `optimizeImageFile()`) and 1200×630 PNG OG `shareCard()`.
|
|
40
|
+
- `@prunellejs/seo` (`node_modules/@prunellejs/seo/llms.txt`): `titleTemplate`, localized `description`, canonical URLs, OG/Twitter/`jsonLd()`, i18n-aware `sitemap.xml`, redirects, manifest, favicons, and self-hosted fonts.
|
|
41
|
+
- `@prunellejs/i18n` (`node_modules/@prunellejs/i18n/llms.txt`): Locale URL rewriting (`ctx.locals.locale`/`t`/`localize`/`alternates`), `<html lang>` + internal link prefixing (`data-no-localize`), `prerenderPaths`, `hreflang`, `Intl` formatters, `prunelle i18n-check`.
|
|
42
|
+
- `@prunellejs/icons` (`node_modules/@prunellejs/icons/llms.txt`): Virtual `~icons/<set>/<name>` & `src/icons` (`~icons/local/<name>`) inline SVG imports + accessible `<Icon>`, `icons()` from `@prunellejs/icons/plugin`, `prunelle icons-find`, and server-only `@prunellejs/icons/search`.
|
|
43
|
+
- `@prunellejs/mail` (`node_modules/@prunellejs/mail/llms.txt`): `createMailer()`, `resend()` HTTP or custom transport, and dev-only `/_pru/mail` (+ `.json`) outbox preview.
|
|
44
|
+
- `@prunellejs/tailwind` (`node_modules/@prunellejs/tailwind/llms.txt`): Tailwind v4 via `tailwind()` (auto-loads `bun-plugin-tailwind`, defaults `css: 'src/app.css'`).
|
|
45
|
+
- `@prunellejs/spa` (`node_modules/@prunellejs/spa/llms.txt`): `regions()` (`refreshRegion()` from `@prunellejs/spa/regions`) for `<Region>` swaps and opt-in `spa()` full-page navigation with `[data-persist]` islands and `[data-pru-prefetch]`.
|
|
46
|
+
- **Server builds & `--compile`**: `prunelle build` writes a stage folder beside `outDir` and renames it in only once every step (bundles, plugin hooks, prerender, `--compile`) passed, so a failed build leaves the previous `outDir` byte-identical and a running `prunelle start` keeps serving it; once a build lands, `prunelle start` loads it in-process with no restart (requests arriving meanwhile wait for it, plugin `server()` runs again and the old build's `api.onShutdown()` hooks run, a build that fails to load is logged and the old one keeps answering, a new port/host/`maxRequestBodySize` needs a restart), and a file it can no longer read answers `404` `no-store`; the hashed client files the previous build made and this one dropped are hard-linked in (`manifest.carriedAssets`, never linked from a page) and served one more deploy, by `prunelle start`, a `--static` export and `--compile`, so a page loaded before the deploy still loads its deferred island chunks; each build is marked with `.prunelle-output`, and a folder holding files prunelle did not build is refused by name (an empty one or an unmarked older prunelle build is replaced). Server `Bun.build` keeps npm dependencies external (`packages: 'external'`) while compiling `@prunellejs/*` TSX packages; `prunelle build --compile` bundles everything + `public/` assets (`with { type: "file" }`) into one standalone Bun executable (`NODE_ENV` defaults to `production`). `prunelle start` and compiled binaries stop gracefully on `SIGTERM`/`SIGINT`/`SIGHUP`: no new connections, `api.onShutdown()` hooks run (`@prunellejs/live` ends its streams), exit 0 once in-flight requests answer, exit 1 after 10 s.
|
|
47
|
+
|
|
48
|
+
## Canonical Snippets
|
|
49
|
+
|
|
50
|
+
### 1. Route with `load()`, `notFound()`, and `<Head>`
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
// src/routes/posts/[slug].tsx
|
|
54
|
+
import type { PageProps, RouteContext } from 'prunelle'
|
|
55
|
+
import { Head } from 'prunelle'
|
|
56
|
+
import { notFound } from 'prunelle/server'
|
|
57
|
+
import { getPost } from '../../db'
|
|
58
|
+
|
|
59
|
+
export async function load(ctx: RouteContext<'/posts/[slug]'>) {
|
|
60
|
+
const post = await getPost(ctx.params.slug)
|
|
61
|
+
if (!post) return notFound()
|
|
62
|
+
return { post }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default function PostPage({ data }: PageProps<typeof load>) {
|
|
66
|
+
return (
|
|
67
|
+
<article>
|
|
68
|
+
<Head><title>{data.post.title}</title></Head>
|
|
69
|
+
<h1>{data.post.title}</h1>
|
|
70
|
+
</article>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 2. Automatic Island (`signal`, `computed`, `useId`)
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
// src/components/Counter.tsx — becomes an island automatically (no directive)
|
|
79
|
+
import { computed, signal, useId } from 'prunelle'
|
|
80
|
+
|
|
81
|
+
export function Counter({ initial = 0 }: { initial?: number }) {
|
|
82
|
+
const count = signal(initial)
|
|
83
|
+
const doubled = computed(() => count.value * 2)
|
|
84
|
+
const id = useId('counter')
|
|
85
|
+
return (
|
|
86
|
+
<div id={id}>
|
|
87
|
+
<button type="button" onClick={() => count.value++}>Count: {count.value}</button>
|
|
88
|
+
<span> (x2: {doubled.value})</span>
|
|
89
|
+
</div>
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 3. Server Action & Progressive `useAction()` Form
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
// src/actions/subscribe.ts
|
|
98
|
+
import { action } from 'prunelle/server'
|
|
99
|
+
import { z } from 'zod'
|
|
100
|
+
|
|
101
|
+
export const subscribe = action(z.object({ email: z.string().email() }), async ({ email }) => {
|
|
102
|
+
return { subscribed: email }
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
// src/components/SubscribeForm.tsx
|
|
108
|
+
import { useAction } from 'prunelle'
|
|
109
|
+
import { subscribe } from '../actions/subscribe'
|
|
110
|
+
|
|
111
|
+
export function SubscribeForm() {
|
|
112
|
+
const form = useAction(subscribe, { reset: true })
|
|
113
|
+
return (
|
|
114
|
+
<form action={form.action} method="post" onSubmit={form.onSubmit}>
|
|
115
|
+
<input name="email" type="email" required />
|
|
116
|
+
<button type="submit" disabled={form.pending.value}>Join</button>
|
|
117
|
+
{form.fieldErrors.value.email && <p role="alert">{form.fieldErrors.value.email}</p>}
|
|
118
|
+
{form.data.value && <p>Subscribed {form.data.value.subscribed}</p>}
|
|
119
|
+
</form>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 4. Config (`prunelle.config.ts`) & In-Process Test (`prunelle/test`)
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
// prunelle.config.ts
|
|
128
|
+
import { defineConfig } from 'prunelle/config'
|
|
129
|
+
import { seo } from '@prunellejs/seo'
|
|
130
|
+
import { auth } from './src/auth'
|
|
131
|
+
|
|
132
|
+
export default defineConfig({
|
|
133
|
+
site: 'https://example.com',
|
|
134
|
+
plugins: [auth, seo({ name: 'Acme', titleTemplate: '%s | Acme' })],
|
|
135
|
+
})
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
// tests/app.test.ts
|
|
140
|
+
import { expect, test } from 'bun:test'
|
|
141
|
+
import { testApp } from 'prunelle/test'
|
|
142
|
+
|
|
143
|
+
test('home renders', async () => {
|
|
144
|
+
const app = await testApp({ root: '.' })
|
|
145
|
+
const res = await app.get('/')
|
|
146
|
+
expect(res.status).toBe(200)
|
|
147
|
+
})
|
|
148
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prunelle",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Bun-native TSX web framework with zero-directive automatic islands, fine-grained signals, and single-binary deploys",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://prunelle.kaynooo.fr",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"bin": {
|
|
10
|
+
"prunelle": "./src/cli/index.ts"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src",
|
|
14
|
+
"templates",
|
|
15
|
+
"llms.txt"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./src/index.ts",
|
|
19
|
+
"./server": "./src/server/public.ts",
|
|
20
|
+
"./config": "./src/plugins/public.ts",
|
|
21
|
+
"./test": "./src/test/index.ts",
|
|
22
|
+
"./build": "./src/build/index.ts",
|
|
23
|
+
"./jsx-runtime": "./src/jsx-runtime.ts",
|
|
24
|
+
"./jsx-dev-runtime": "./src/jsx-runtime.ts",
|
|
25
|
+
"./internal/dom": "./src/dom/index.ts",
|
|
26
|
+
"./internal/dom-attrs": "./src/dom/attrs.ts",
|
|
27
|
+
"./internal/dom-claim": "./src/dom/claim.ts",
|
|
28
|
+
"./internal/dom-extras": "./src/dom/extras.ts",
|
|
29
|
+
"./internal/dom-loop": "./src/dom/loop.ts",
|
|
30
|
+
"./internal/action": "./src/dom/action.ts",
|
|
31
|
+
"./internal/island": "./src/dom/island.ts",
|
|
32
|
+
"./internal/ssr": "./src/ssr/index.ts",
|
|
33
|
+
"./internal/server": "./src/server/index.ts"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"bun": ">=1.4.0"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/Kayno0o/prunelle",
|
|
41
|
+
"directory": "packages/prunelle"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@kaynooo/cli-kit": "^0.52.0",
|
|
45
|
+
"oxc-parser": "^0.155.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"playwright-core": "^1.64.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"playwright-core": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/ambient.d.ts
ADDED
package/src/attrs.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Shared HTML attribute safety & classification rules used identically by compiler, SSR, and DOM runtimes.
|
|
2
|
+
|
|
3
|
+
export const VALID_ATTR_NAME = /^[A-Za-z_:][-\w:.]*$/
|
|
4
|
+
export const URL_ATTRS = new Set(['href', 'src', 'action', 'formaction', 'xlink:href', 'data'])
|
|
5
|
+
const UNSAFE_URL_RE = /^(?:javascript|vbscript):/i
|
|
6
|
+
const SAFE_IMAGE_DATA_URL_RE = /^data:image\/(?:png|jpe?g|gif|webp|avif|bmp|ico|x-icon|vnd\.microsoft\.icon|svg\+xml)[;,]/i
|
|
7
|
+
const STRING_BOOL_ATTRS = new Set(['draggable', 'spellcheck', 'contenteditable'])
|
|
8
|
+
|
|
9
|
+
export const DOM_PROPS = new Set(['value', 'checked', 'selected', 'muted', 'indeterminate'])
|
|
10
|
+
|
|
11
|
+
export function isBlockedAttr(name: string): boolean {
|
|
12
|
+
if (!VALID_ATTR_NAME.test(name))
|
|
13
|
+
return true
|
|
14
|
+
const lower = name.toLowerCase()
|
|
15
|
+
return lower.startsWith('on') || lower === 'innerhtml' || lower === 'srcdoc'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isStringBoolAttr(name: string): boolean {
|
|
19
|
+
const lower = name.toLowerCase()
|
|
20
|
+
return lower.startsWith('aria-') || STRING_BOOL_ATTRS.has(lower)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function isUnsafeUrlAttr(name: string, value: unknown, tag?: string): boolean {
|
|
24
|
+
const lower = name.toLowerCase()
|
|
25
|
+
if (!URL_ATTRS.has(lower))
|
|
26
|
+
return false
|
|
27
|
+
const cleaned = String(value).replace(/[\u0000-\u0020]+/g, '')
|
|
28
|
+
if (UNSAFE_URL_RE.test(cleaned))
|
|
29
|
+
return true
|
|
30
|
+
if (!/^data:/i.test(cleaned))
|
|
31
|
+
return false
|
|
32
|
+
if (lower === 'src' || (lower === 'href' && tag?.toLowerCase() === 'link'))
|
|
33
|
+
return !SAFE_IMAGE_DATA_URL_RE.test(cleaned)
|
|
34
|
+
return true
|
|
35
|
+
}
|