prunelle 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/llms.txt +245 -0
- package/package.json +62 -4
- package/src/a11y/declaration.ts +373 -0
- package/src/a11y/index.ts +477 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/ambient.d.ts +6 -0
- package/src/attrs.ts +43 -0
- package/src/build/bundle.ts +661 -0
- package/src/build/byte-size.ts +11 -0
- package/src/build/carry.ts +57 -0
- package/src/build/client-entries.ts +107 -0
- package/src/build/client-plugin.ts +175 -0
- package/src/build/client-prune.ts +168 -0
- package/src/build/compile.ts +130 -0
- package/src/build/ecoindex.ts +238 -0
- package/src/build/files.ts +171 -0
- package/src/build/first-load.ts +235 -0
- package/src/build/graph.ts +237 -0
- package/src/build/index.ts +678 -0
- package/src/build/is-inside.ts +12 -0
- package/src/build/island-promote.ts +311 -0
- package/src/build/islands.ts +452 -0
- package/src/build/manifest.ts +204 -0
- package/src/build/output.ts +81 -0
- package/src/build/plugin-host.ts +294 -0
- package/src/build/precompress.ts +139 -0
- package/src/build/prerender.ts +288 -0
- package/src/build/reach.ts +200 -0
- package/src/build/render-rules.ts +205 -0
- package/src/build/report.ts +290 -0
- package/src/build/resolve.ts +52 -0
- package/src/build/routes.ts +342 -0
- package/src/build/server-entry.ts +38 -0
- package/src/build/static-headers.ts +112 -0
- package/src/build/static.ts +209 -0
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +636 -0
- package/src/cli/check-imports.ts +31 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +409 -0
- package/src/cli/commands.ts +372 -0
- package/src/cli/docs.ts +403 -0
- package/src/cli/index.ts +70 -0
- package/src/cli/inspect.ts +406 -0
- package/src/cli/mcp-tools.ts +492 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +52 -0
- package/src/cli/render.ts +416 -0
- package/src/cli/upgrade-names.ts +209 -0
- package/src/cli/upgrade.ts +367 -0
- package/src/compiler/analyze.ts +651 -0
- package/src/compiler/ast.ts +82 -0
- package/src/compiler/browser-globals.ts +250 -0
- package/src/compiler/cacheability-private.ts +566 -0
- package/src/compiler/cacheability.ts +335 -0
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +614 -0
- package/src/compiler/compliance-urls.ts +148 -0
- package/src/compiler/compliance.ts +653 -0
- package/src/compiler/data-keys.ts +302 -0
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +452 -0
- package/src/compiler/dom.ts +641 -0
- package/src/compiler/emit.ts +131 -0
- package/src/compiler/expr-context.ts +587 -0
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/index.ts +8 -0
- package/src/compiler/interactivity.ts +366 -0
- package/src/compiler/mistakes.ts +520 -0
- package/src/compiler/node-env.ts +50 -0
- package/src/compiler/patch.ts +97 -0
- package/src/compiler/props-body.ts +60 -0
- package/src/compiler/props.ts +511 -0
- package/src/compiler/scope.ts +635 -0
- package/src/compiler/server-only.ts +365 -0
- package/src/compiler/shared.ts +397 -0
- package/src/compiler/signal-reads.ts +246 -0
- package/src/compiler/slots.ts +227 -0
- package/src/compiler/spread-handlers.ts +295 -0
- package/src/compiler/ssr-helpers.ts +555 -0
- package/src/compiler/ssr-island.ts +90 -0
- package/src/compiler/ssr-prunelle-tags.ts +69 -0
- package/src/compiler/ssr.ts +525 -0
- package/src/context.ts +199 -0
- package/src/dev/child.ts +30 -0
- package/src/dev/error-log.ts +177 -0
- package/src/dev/host-check.ts +32 -0
- package/src/dev/index.ts +268 -0
- package/src/dev/modules.ts +68 -0
- package/src/dev/open-editor.ts +228 -0
- package/src/dev/protocol.ts +24 -0
- package/src/dev/queue.ts +79 -0
- package/src/dev/reload.ts +159 -0
- package/src/dev/supervisor.ts +212 -0
- package/src/dev/watchers.ts +276 -0
- package/src/dom/action.ts +187 -0
- package/src/dom/attrs.ts +84 -0
- package/src/dom/claim.ts +120 -0
- package/src/dom/extras.ts +579 -0
- package/src/dom/index.ts +329 -0
- package/src/dom/island.ts +318 -0
- package/src/dom/loop.ts +484 -0
- package/src/dom/revive.ts +36 -0
- package/src/eco/declaration.ts +328 -0
- package/src/eco/index.ts +69 -0
- package/src/index.ts +22 -0
- package/src/jsx-runtime.ts +566 -0
- package/src/plugins/config.ts +92 -0
- package/src/plugins/context.ts +109 -0
- package/src/plugins/index.ts +14 -0
- package/src/plugins/load.ts +90 -0
- package/src/plugins/order.ts +148 -0
- package/src/plugins/public.ts +15 -0
- package/src/plugins/requires.ts +47 -0
- package/src/plugins/services.ts +119 -0
- package/src/plugins/types.ts +278 -0
- package/src/reactivity/graph.ts +259 -0
- package/src/reactivity/index.ts +541 -0
- package/src/reactivity/selector.ts +78 -0
- package/src/reactivity/store.ts +252 -0
- package/src/server/action-flash.ts +158 -0
- package/src/server/action-protect.ts +199 -0
- package/src/server/action-registry.ts +78 -0
- package/src/server/action.ts +511 -0
- package/src/server/app-entry.ts +23 -0
- package/src/server/app-secret.ts +63 -0
- package/src/server/assets.ts +168 -0
- package/src/server/compress.ts +646 -0
- package/src/server/consent.ts +290 -0
- package/src/server/cookies.ts +153 -0
- package/src/server/document.ts +286 -0
- package/src/server/env.ts +47 -0
- package/src/server/errors.ts +396 -0
- package/src/server/form-schema.ts +337 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +588 -0
- package/src/server/index.ts +615 -0
- package/src/server/lifecycle.ts +75 -0
- package/src/server/loader.ts +131 -0
- package/src/server/page.ts +122 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +267 -0
- package/src/server/prerendered.ts +71 -0
- package/src/server/public.ts +20 -0
- package/src/server/rate-limit.ts +199 -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-cache.ts +541 -0
- package/src/server/route-table.ts +424 -0
- package/src/server/router.ts +261 -0
- package/src/server/routing.ts +388 -0
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +550 -0
- package/src/server/serve-handlers.ts +93 -0
- package/src/server/served-file.ts +128 -0
- package/src/server/standard-schema.ts +104 -0
- package/src/server/start.ts +143 -0
- package/src/server/static-dir.ts +246 -0
- package/src/server/stream.ts +233 -0
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +399 -0
- package/src/ssr/index.ts +624 -0
- package/src/ssr/navigation.ts +96 -0
- package/src/ssr/region.ts +192 -0
- package/src/style.ts +96 -0
- package/src/test/browser.ts +201 -0
- package/src/test/index.ts +262 -0
- package/src/ts-plugin/diagnostics.ts +505 -0
- package/src/ts-plugin/fixes.ts +364 -0
- package/src/ts-plugin/index.ts +194 -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 +8 -0
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/public/robots.txt +2 -0
- package/templates/_shared/src/routes/legal.tsx +22 -0
- package/templates/_shared/tsconfig.json +25 -0
- package/templates/app/.env.example +8 -0
- package/templates/app/package.json +22 -0
- package/templates/app/prunelle.config.ts +13 -0
- package/templates/app/src/auth.ts +12 -0
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +40 -0
- package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
- package/templates/app/src/routes/dashboard/index.tsx +47 -0
- package/templates/app/src/routes/index.tsx +15 -0
- package/templates/app/src/routes/login.tsx +53 -0
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +14 -0
- package/templates/app/tests/app.test.ts +73 -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 +25 -0
- package/templates/blog/src/routes/blog/[slug].tsx +31 -0
- package/templates/blog/src/routes/index.tsx +33 -0
- package/templates/blog/src/styles/app.css +15 -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 +28 -0
- package/templates/fullstack/src/routes/_layout.tsx +18 -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 +39 -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 +18 -0
- package/templates/minimal/src/routes/index.tsx +11 -0
- package/templates/minimal/src/styles/app.css +32 -0
- package/ts-plugin.cjs +4277 -0
- package/README.md +0 -3
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
// The plugin contract: what a `PrunellePlugin` declares and what the build, check and server hosts hand its hooks.
|
|
2
|
+
|
|
3
|
+
import type { BunPlugin } from 'bun'
|
|
4
|
+
import type { RouteManifestEntry } from '../build/index'
|
|
5
|
+
import type { ComplianceConfig } from '../compiler/compliance'
|
|
6
|
+
import type { ConsentConfig } from '../server/consent'
|
|
7
|
+
import type { HealthCheckConfig, HealthCheckFn, HealthCheckResult } from '../server/health'
|
|
8
|
+
import type { Middleware, RequestContext } from '../server/index'
|
|
9
|
+
import type { RateLimit, RateLimiter } from '../server/rate-limit'
|
|
10
|
+
import type { RouteCacheOptions } from '../server/route-cache'
|
|
11
|
+
import type { SecurityHeadersOptions, TrustProxy } from '../server/security'
|
|
12
|
+
import type { NavigationConfig } from '../ssr/navigation'
|
|
13
|
+
import type { ServiceKey } from './services'
|
|
14
|
+
|
|
15
|
+
export type { HealthCheckConfig, HealthCheckFn, HealthCheckResult }
|
|
16
|
+
|
|
17
|
+
export type BuildPluginTarget = 'client' | 'server' | 'compile'
|
|
18
|
+
|
|
19
|
+
export interface BuildPluginContext {
|
|
20
|
+
readonly root: string
|
|
21
|
+
readonly outDir: string
|
|
22
|
+
readonly assetPrefix: string
|
|
23
|
+
readonly site?: string | undefined
|
|
24
|
+
readonly minify: boolean
|
|
25
|
+
readonly isStatic: boolean
|
|
26
|
+
readonly dev: boolean
|
|
27
|
+
readonly routes: readonly RouteManifestEntry[]
|
|
28
|
+
/** Reachable source files (layouts, page, islands, local imports) for each route path. */
|
|
29
|
+
readonly routeSourceFiles?: ReadonlyMap<string, readonly string[]> | undefined
|
|
30
|
+
/** Reachable source files of the root layout and status/error pages (shared across the site). */
|
|
31
|
+
readonly globalSourceFiles?: readonly string[] | undefined
|
|
32
|
+
/** Emit an immutable build asset into dist/client/<relPath>; returns its public URL (`/_pru/<relPath>`). */
|
|
33
|
+
emitAsset(relPath: string, content: string | Uint8Array): string
|
|
34
|
+
/** Emit a static file into dist/public/<relPath> served at `/<relPath>`. */
|
|
35
|
+
emitPublic(relPath: string, content: string | Uint8Array): string
|
|
36
|
+
/** Add a stylesheet URL to <head> on every page. */
|
|
37
|
+
addStyle(href: string): void
|
|
38
|
+
/** Prepend a global stylesheet URL before app stylesheets (preserving plugin-before-app cascade order). */
|
|
39
|
+
prependStyle?(href: string): void
|
|
40
|
+
/** Add a stylesheet URL to <head> on a specific route path only. */
|
|
41
|
+
addRouteStyle(routePath: string, href: string): void
|
|
42
|
+
/** Prepend a route-specific stylesheet URL before that route's app stylesheets. */
|
|
43
|
+
prependRouteStyle?(routePath: string, href: string): void
|
|
44
|
+
/** Add raw HTML to <head> on every page (e.g. font preloads, default meta/OG, JSON-LD). */
|
|
45
|
+
addHead(html: string): void
|
|
46
|
+
/** Add raw HTML to <head> on a specific route path only. */
|
|
47
|
+
addRouteHead(routePath: string, html: string): void
|
|
48
|
+
/** Register an explicit build-scoped service for other plugins or render-time helpers. */
|
|
49
|
+
provide<T>(key: ServiceKey<T>, value: T): void
|
|
50
|
+
/** Look up a build-scoped service registered by another plugin. */
|
|
51
|
+
inject<T>(key: ServiceKey<T>): T | undefined
|
|
52
|
+
/** Persist JSON-serializable build data into `manifest.pluginData[plugin.name]` for cold-start servers and `--compile`. */
|
|
53
|
+
setData(data: Record<string, unknown>): void
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface FinalizeBuildContext {
|
|
57
|
+
readonly root: string
|
|
58
|
+
readonly outDir: string
|
|
59
|
+
/** Base directory that `route.prerendered` relative paths resolve against (equals `stageDir` in `--static`, `outDir` otherwise). */
|
|
60
|
+
readonly prerenderDir?: string | undefined
|
|
61
|
+
readonly assetPrefix: string
|
|
62
|
+
readonly site?: string | undefined
|
|
63
|
+
readonly minify: boolean
|
|
64
|
+
readonly isStatic: boolean
|
|
65
|
+
readonly dev: boolean
|
|
66
|
+
/** Route manifest entries with `prerendered` maps populated after Step 3 prerendering. */
|
|
67
|
+
readonly routes: readonly RouteManifestEntry[]
|
|
68
|
+
/** Relative paths of all public files known so far (including files registered during prerender). */
|
|
69
|
+
readonly publicFiles: readonly string[]
|
|
70
|
+
/** Relative paths of all client build assets under `dist/client/` (served at `${assetPrefix}/<rel>`). */
|
|
71
|
+
readonly assets?: readonly string[] | undefined
|
|
72
|
+
/** Emit an immutable build asset into dist/client/<relPath>; returns its public URL (`/_pru/<relPath>`). */
|
|
73
|
+
emitAsset(relPath: string, content: string | Uint8Array): string
|
|
74
|
+
/** Emit a static file into dist/public/<relPath> served at `/<relPath>` (included in `--static` and `--compile`). */
|
|
75
|
+
emitPublic(relPath: string, content: string | Uint8Array): string
|
|
76
|
+
/** Register a build-scoped service. */
|
|
77
|
+
provide<T>(key: ServiceKey<T>, value: T): void
|
|
78
|
+
/** Look up a build-scoped service. */
|
|
79
|
+
inject<T>(key: ServiceKey<T>): T | undefined
|
|
80
|
+
/** Merge/persist JSON-serializable build data into `manifest.pluginData[plugin.name]`. */
|
|
81
|
+
setData(data: Record<string, unknown>): void
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface CheckPluginContext {
|
|
85
|
+
readonly root: string
|
|
86
|
+
readonly routesDir: string
|
|
87
|
+
/** The app's own static folder (`publicDir`, `public/` by default), as `prunelle check` resolved it. */
|
|
88
|
+
readonly publicDir?: string | undefined
|
|
89
|
+
/** Report a validation error from `prunelle check`. */
|
|
90
|
+
error(message: string): void
|
|
91
|
+
/** Report what may be intended but usually is not; `prunelle check --strict` fails on it. */
|
|
92
|
+
warn(message: string): void
|
|
93
|
+
/** Register a check-scoped service for downstream plugins. */
|
|
94
|
+
provide?<T>(key: ServiceKey<T>, value: T): void
|
|
95
|
+
/** Look up a check-scoped service registered by an earlier plugin. */
|
|
96
|
+
inject?<T>(key: ServiceKey<T>): T | undefined
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface RequiresPluginContext {
|
|
100
|
+
readonly root: string
|
|
101
|
+
/** `PrunelleConfig.site`, when the app sets it. */
|
|
102
|
+
readonly site: string | undefined
|
|
103
|
+
/** The categories `consent.categories` declares, `essential` left out; empty when the app declares none. */
|
|
104
|
+
readonly consentCategories: readonly string[]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface PluginRouteOptions {
|
|
108
|
+
/** Enable CSRF Origin/Sec-Fetch-Site verification on unsafe methods (default: true). Set `false` to opt out (e.g. webhooks, bearer-token APIs). */
|
|
109
|
+
csrf?: boolean | undefined
|
|
110
|
+
/** Additional trusted origins merged with `PrunelleConfig.trustedOrigins` for this route's CSRF check. */
|
|
111
|
+
trustedOrigins?: readonly string[] | undefined
|
|
112
|
+
/** Override `PrunelleConfig.trustProxy` for this route's CSRF check. */
|
|
113
|
+
trustProxy?: TrustProxy | undefined
|
|
114
|
+
/** How often one client may call the route: past `max` per `windowMs`, it answers 429 with `Retry-After` before the handler runs. */
|
|
115
|
+
rateLimit?: RateLimit<RequestContext> | undefined
|
|
116
|
+
/**
|
|
117
|
+
* Let the route's catch-all take a segment with an encoded `/`, `\` or NUL (`%2F`, `%5C`, `%00`), which every route refuses by default.
|
|
118
|
+
* Such a segment reaches the param still encoded, never as a separator: for a route that reads it as text (a QR code of a URL), never one that joins it into a file path.
|
|
119
|
+
*/
|
|
120
|
+
encodedSlashes?: boolean | undefined
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface MiddlewareOptions {
|
|
124
|
+
/**
|
|
125
|
+
* `'all'` (default) runs on every request, prerendered pages included.
|
|
126
|
+
* `'rendered'` skips prerendered pages, which were rendered at build time and never read `ctx.locals`: for middleware that only feeds rendering, such as a session.
|
|
127
|
+
* `'dynamic'` also skips pages with no `load`, which render the same for everyone.
|
|
128
|
+
* A path prefix runs on the pathnames under it.
|
|
129
|
+
*/
|
|
130
|
+
scope?: 'all' | 'rendered' | 'dynamic' | string | undefined
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface ServerPluginAPI {
|
|
134
|
+
readonly root: string
|
|
135
|
+
readonly outDir: string
|
|
136
|
+
readonly assetPrefix: string
|
|
137
|
+
readonly site?: string | undefined
|
|
138
|
+
readonly dev: boolean
|
|
139
|
+
/** True when `prunelle dev --host` binds an address other machines reach (`0.0.0.0`, a LAN address): a dev-only route that writes or reveals data then needs a guard. */
|
|
140
|
+
readonly devExposed: boolean
|
|
141
|
+
/** Readonly server security configuration so plugins inherit `trustProxy` / `trustedOrigins` without overriding them. */
|
|
142
|
+
readonly trustProxy: TrustProxy
|
|
143
|
+
readonly trustedOrigins: readonly string[]
|
|
144
|
+
/** Readonly runtime config forwarded from `prunelle.config.ts` (minus build-only keys). */
|
|
145
|
+
readonly config?: Readonly<Record<string, unknown>> | undefined
|
|
146
|
+
/** Register global (or scoped) middleware that runs before route handlers. */
|
|
147
|
+
use(middleware: Middleware, options?: MiddlewareOptions): void
|
|
148
|
+
/** Register a custom HTTP route (e.g. GET /sitemap.xml, POST /auth/callback). */
|
|
149
|
+
route(method: string, path: string, handler: (ctx: RequestContext) => Response | Promise<Response>, options?: PluginRouteOptions): void
|
|
150
|
+
/** A limiter counting in this server's store, for limits a route option cannot express (per account, per email): `hit(key)` returns 0, or the seconds to wait, and `peek(key)` answers the same without counting. */
|
|
151
|
+
rateLimiter(limit: Pick<RateLimit, 'max' | 'windowMs'>): RateLimiter
|
|
152
|
+
/** Rewrite an incoming pathname before route matching (e.g. strip /fr locale prefix). */
|
|
153
|
+
rewrite(fn: (pathname: string, ctx: RequestContext) => string | undefined): void
|
|
154
|
+
/** Register a server-scoped service for other plugins or render-time helpers (isolated per server instance). */
|
|
155
|
+
provide<T>(key: ServiceKey<T>, value: T): void
|
|
156
|
+
/** Look up a server-scoped service registered by another plugin. */
|
|
157
|
+
inject<T>(key: ServiceKey<T>): T | undefined
|
|
158
|
+
/** Read persisted build data from `manifest.pluginData` (defaults to the current plugin's name). */
|
|
159
|
+
getBuildData<T = Record<string, unknown>>(pluginName?: string): T | undefined
|
|
160
|
+
/** Register a named health check evaluated on `GET ${assetPrefix}/health`. */
|
|
161
|
+
healthCheck(name: string, fn: HealthCheckFn): void
|
|
162
|
+
/** Register a shutdown cleanup callback run when `app.dispose()` is called (dev reloads, tests, graceful exit). */
|
|
163
|
+
onShutdown(fn: () => void | Promise<void>): void
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface ServerErrorInfo {
|
|
167
|
+
error: unknown
|
|
168
|
+
request: Request
|
|
169
|
+
source: 'route' | 'action' | 'plugin'
|
|
170
|
+
requestId?: string | undefined
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface DocumentHeadContext {
|
|
174
|
+
/** Current document `lang` attribute (mutating sets `<html lang="...">`). */
|
|
175
|
+
lang: string
|
|
176
|
+
/** Extra attributes emitted on `<html>`. */
|
|
177
|
+
readonly htmlAttrs: Record<string, string>
|
|
178
|
+
/** Inner HTML of the page's `<title>` tag (if rendered via `<Head><title>...</title></Head>`), or `undefined`. */
|
|
179
|
+
title: string | undefined
|
|
180
|
+
/** Read-only view of head HTML already collected from `<Head>`, build `addHead`, and earlier plugins. */
|
|
181
|
+
readonly headHtml: string
|
|
182
|
+
/** Append raw HTML to `<head>` (emitted once by core when assembling the document). */
|
|
183
|
+
add(html: string): void
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export interface PrunellePlugin {
|
|
187
|
+
name: string
|
|
188
|
+
/** Execution phase: `'pre'` runs before normal plugins, `'post'` runs after them. */
|
|
189
|
+
enforce?: 'pre' | 'post' | undefined
|
|
190
|
+
/** Names of plugins that must run before this plugin when present. */
|
|
191
|
+
after?: readonly string[] | undefined
|
|
192
|
+
/** `ctx.locals` keys this plugin populates (used for startup order validation). */
|
|
193
|
+
providesLocals?: readonly string[] | undefined
|
|
194
|
+
/** `ctx.locals` keys this plugin reads (startup fails if a provider is ordered after it). */
|
|
195
|
+
readsLocals?: readonly string[] | undefined
|
|
196
|
+
/** Register server routes, global middleware, URL rewrites, or runtime services. */
|
|
197
|
+
server?: (api: ServerPluginAPI) => void | Promise<void>
|
|
198
|
+
/** Error hook called whenever a route, action, or plugin handler throws an unhandled error. */
|
|
199
|
+
onError?: (info: ServerErrorInfo) => void
|
|
200
|
+
/** Build hook run after route compilation, before prerender / --static / --compile. */
|
|
201
|
+
build?: (ctx: BuildPluginContext) => void | Promise<void>
|
|
202
|
+
/** Post-prerender build hook run after `route.prerendered` is populated, before `--static` / `--compile` / final manifest write. */
|
|
203
|
+
afterPrerender?: (ctx: FinalizeBuildContext) => void | Promise<void>
|
|
204
|
+
/** Code transform run during client & server compilation (`.ts` and `.tsx`). */
|
|
205
|
+
transform?: (code: string, id: string, target: 'server' | 'client') => string | undefined | void
|
|
206
|
+
/** Native Bun.build plugins (e.g. bun-plugin-tailwind, images, icons). Factory is invoked per build target. */
|
|
207
|
+
bunPlugins?: BunPlugin[] | ((info: { root: string, assetPrefix: string, minify: boolean, target: BuildPluginTarget, lang?: string | undefined }) => BunPlugin[]) | undefined
|
|
208
|
+
/** Global CSS files to bundle and inject as <link rel="stylesheet"> in <head>. */
|
|
209
|
+
css?: string[] | undefined
|
|
210
|
+
/** Mutate `<html lang>`, `htmlAttrs`, `<title>`, or append tags to `<head>` before core renders the document once. */
|
|
211
|
+
head?: (head: DocumentHeadContext, ctx: RequestContext) => void | Promise<void>
|
|
212
|
+
/** Post-process rendered HTML before sending (applies to pages, `<Suspense>` shells, `_error.tsx`, and `_404.tsx`). */
|
|
213
|
+
transformHtml?: (html: string, ctx: RequestContext) => string | Promise<string>
|
|
214
|
+
/** Expand or filter prerender URLs for a route (e.g. @prunellejs/i18n expanding `/posts/a` -> `['/posts/a', '/fr/posts/a']`). */
|
|
215
|
+
prerenderPaths?: (paths: string[], route: RouteManifestEntry) => string[] | Promise<string[]>
|
|
216
|
+
/** Client bootstrap module path — bundled ONLY when this plugin is active. */
|
|
217
|
+
clientEntry?: string | undefined
|
|
218
|
+
/** Inline scripts the plugin writes into pages (from `head`, `transformHtml` or `addHead`), each as it stands between its tags: the CSP of every page allows them by hash. */
|
|
219
|
+
inlineScripts?: readonly string[] | undefined
|
|
220
|
+
/** Client module bundled on its own and loaded only on routes whose tree renders a `<Region>`; every other page stays free of it. */
|
|
221
|
+
regionClientEntry?: string | undefined
|
|
222
|
+
/**
|
|
223
|
+
* What the plugin needs to run in production, read from its options, the app's config and the environment: one message per unmet setting, naming it and its fix.
|
|
224
|
+
* A production start refuses while any is unmet, listing them all; `prunelle dev`, tests and `prunelle check` warn.
|
|
225
|
+
*/
|
|
226
|
+
requires?: (ctx: RequiresPluginContext) => readonly string[] | Promise<readonly string[]>
|
|
227
|
+
/** Validate plugin-specific invariants during `prunelle check` (e.g. missing i18n keys, content frontmatter). */
|
|
228
|
+
check?: (ctx: CheckPluginContext) => void | Promise<void>
|
|
229
|
+
/** Extra directories or files (relative to app root or absolute) for `prunelle dev` to watch. */
|
|
230
|
+
watchPaths?: string[] | ((root: string) => string[]) | undefined
|
|
231
|
+
/** Register custom CLI subcommands (e.g. `prunelle i18n check`). */
|
|
232
|
+
commands?: Record<string, (args: string[], root: string) => void | Promise<void>> | undefined
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Shared runtime server options inherited from `prunelle.config.ts` and overridable by `createServer`, `testApp`, `devServer`, and `--compile`. */
|
|
236
|
+
export interface ServerRuntimeConfig {
|
|
237
|
+
/** Public origin of the site (e.g. 'https://example.com'), inherited by @prunellejs/seo, @prunellejs/i18n, @prunellejs/content, @prunellejs/images, and @prunellejs/auth. */
|
|
238
|
+
site?: string | undefined
|
|
239
|
+
lang?: string | undefined
|
|
240
|
+
assetPrefix?: string | undefined
|
|
241
|
+
security?: SecurityHeadersOptions | false | undefined
|
|
242
|
+
trustedOrigins?: string[] | undefined
|
|
243
|
+
trustProxy?: TrustProxy | undefined
|
|
244
|
+
maxRequestBodySize?: number | undefined
|
|
245
|
+
/** How plain page changes feel without client JS: view transitions between pages, Speculation Rules prefetch on hover, opt-in prerender. */
|
|
246
|
+
navigation?: NavigationConfig | undefined
|
|
247
|
+
/** Milliseconds a streamed `<Suspense>` boundary may take before it renders its error and the response ends (default 30000). */
|
|
248
|
+
streamTimeout?: number | undefined
|
|
249
|
+
/** CNIL/RGPD consent categories, cookie name, retention, and POST endpoint. */
|
|
250
|
+
consent?: ConsentConfig | undefined
|
|
251
|
+
compress?: boolean | undefined
|
|
252
|
+
/** Bounded in-memory cache for routes exporting `export const cache = ...` (default: 500 entries / 32 MiB; set `false` to disable). */
|
|
253
|
+
routeCache?: RouteCacheOptions | false | undefined
|
|
254
|
+
/** Health check function or named check map evaluated on `GET ${assetPrefix}/health`. */
|
|
255
|
+
healthCheck?: HealthCheckConfig | undefined
|
|
256
|
+
onError?: ((info: ServerErrorInfo) => void) | undefined
|
|
257
|
+
plugins?: PrunellePlugin[] | undefined
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface PrunelleConfig extends ServerRuntimeConfig {
|
|
261
|
+
port?: number | undefined
|
|
262
|
+
routesDir?: string | undefined
|
|
263
|
+
outDir?: string | undefined
|
|
264
|
+
publicDir?: string | undefined
|
|
265
|
+
/** French web law compliance checks (RGAA, RGPD, LCEN) configuration and rule silencing. */
|
|
266
|
+
compliance?: ComplianceConfig | undefined
|
|
267
|
+
/** Automatically prerender static pages that read nothing from the request or clock (and have no middleware or `cache` export). */
|
|
268
|
+
autoPrerender?: boolean | undefined
|
|
269
|
+
/** Page weight caps `prunelle build` fails on: bytes, or a size like `'40kb'`. */
|
|
270
|
+
budget?: BudgetConfig | undefined
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface BudgetConfig {
|
|
274
|
+
/** Eager JS per route, gzipped (`--max-js` overrides it for one run). */
|
|
275
|
+
js?: number | string | undefined
|
|
276
|
+
/** What a first visit downloads, brotli: the stylesheets, scripts and fonts, and on a prerendered page its HTML and every image. */
|
|
277
|
+
firstLoad?: number | string | undefined
|
|
278
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// Internal dependency-graph links, flags, and ownership list primitives for the reactive kernel.
|
|
2
|
+
|
|
3
|
+
const enum F {
|
|
4
|
+
DISPOSED = 8,
|
|
5
|
+
COMPUTED = 16,
|
|
6
|
+
UNOBSERVED = 128,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Link {
|
|
10
|
+
d: DepNode
|
|
11
|
+
s: SubNode
|
|
12
|
+
v: number // dep version at link time
|
|
13
|
+
e: number // sub run epoch
|
|
14
|
+
pd: Link | undefined
|
|
15
|
+
nd: Link | undefined
|
|
16
|
+
ps: Link | undefined
|
|
17
|
+
ns: Link | undefined
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface DepNode {
|
|
21
|
+
v: number // version
|
|
22
|
+
s: Link | undefined // subs head
|
|
23
|
+
st: Link | undefined // subs tail
|
|
24
|
+
le: number // lastEpoch
|
|
25
|
+
f: number // flags (0 on SignalNode, bitmask on ComputedNode)
|
|
26
|
+
u?: (() => void) | undefined // called when the last subscriber detaches
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Anything an owner holds: a child owner, an effect or a computed.
|
|
30
|
+
export interface Owned {
|
|
31
|
+
f: number // flags
|
|
32
|
+
o?: Owner | undefined // owner
|
|
33
|
+
po?: Owned | undefined // prevOwned
|
|
34
|
+
no?: Owned | undefined // nextOwned
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface SubNode extends Owned {
|
|
38
|
+
e: number // epoch
|
|
39
|
+
d: Link | undefined // deps head
|
|
40
|
+
dt: Link | undefined // deps tail
|
|
41
|
+
c: Link | undefined // cursor
|
|
42
|
+
r(): void // run
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface IdScope {
|
|
46
|
+
p: string
|
|
47
|
+
n: number
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface Owner extends Owned {
|
|
51
|
+
fs?: Owned | undefined // first owned
|
|
52
|
+
cl?: (() => void)[] | undefined // cleanups
|
|
53
|
+
cx?: Map<symbol, unknown> | undefined // context values provided at this owner
|
|
54
|
+
id?: IdScope | undefined // deterministic useId() scope
|
|
55
|
+
eh?: ((error: unknown) => void) | undefined // error handler of a <Catch>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface Signal<T> {
|
|
59
|
+
value: T
|
|
60
|
+
peek(): T
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ReadonlySignal<T> {
|
|
64
|
+
readonly value: T
|
|
65
|
+
peek(): T
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function linkSub(dep: DepNode, sub: SubNode): void {
|
|
69
|
+
if (sub.f & F.DISPOSED)
|
|
70
|
+
return
|
|
71
|
+
|
|
72
|
+
const e = sub.e
|
|
73
|
+
if (dep.le === e)
|
|
74
|
+
return
|
|
75
|
+
|
|
76
|
+
// A nested computed or effect may have bumped dep.le past sub.e; scan links already added in this run to avoid duplicates.
|
|
77
|
+
if (dep.le > e) {
|
|
78
|
+
for (let l = sub.d; l && l !== sub.c; l = l.nd) {
|
|
79
|
+
if (l.d === dep) {
|
|
80
|
+
dep.le = e
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
dep.le = e
|
|
87
|
+
|
|
88
|
+
const cur = sub.c
|
|
89
|
+
if (cur && cur.d === dep) {
|
|
90
|
+
cur.e = e
|
|
91
|
+
cur.v = dep.v
|
|
92
|
+
sub.c = cur.nd
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const link: Link = {
|
|
97
|
+
d: dep,
|
|
98
|
+
s: sub,
|
|
99
|
+
v: dep.v,
|
|
100
|
+
e,
|
|
101
|
+
pd: undefined,
|
|
102
|
+
nd: undefined,
|
|
103
|
+
ps: undefined,
|
|
104
|
+
ns: undefined,
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (!(sub.f & F.UNOBSERVED))
|
|
108
|
+
addSub(link)
|
|
109
|
+
|
|
110
|
+
if (cur) {
|
|
111
|
+
const prev = cur.pd
|
|
112
|
+
link.pd = prev
|
|
113
|
+
link.nd = cur
|
|
114
|
+
cur.pd = link
|
|
115
|
+
if (prev)
|
|
116
|
+
prev.nd = link
|
|
117
|
+
else
|
|
118
|
+
sub.d = link
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const tail = sub.dt
|
|
122
|
+
link.pd = tail
|
|
123
|
+
if (tail)
|
|
124
|
+
tail.nd = link
|
|
125
|
+
else
|
|
126
|
+
sub.d = link
|
|
127
|
+
sub.dt = link
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Puts a link at the end of its source's subscriber list; a computed gaining its first subscriber follows its own sources again.
|
|
132
|
+
export function addSub(link: Link): void {
|
|
133
|
+
const dep = link.d
|
|
134
|
+
const tail = dep.st
|
|
135
|
+
link.ps = tail
|
|
136
|
+
link.ns = undefined
|
|
137
|
+
if (tail) {
|
|
138
|
+
tail.ns = link
|
|
139
|
+
dep.st = link
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
dep.s = dep.st = link
|
|
143
|
+
if (dep.f & F.UNOBSERVED) {
|
|
144
|
+
const comp = dep as unknown as SubNode
|
|
145
|
+
comp.f &= ~F.UNOBSERVED
|
|
146
|
+
for (let l = comp.d; l; l = l.nd)
|
|
147
|
+
addSub(l)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function unobserve(comp: SubNode): void {
|
|
152
|
+
comp.f |= F.UNOBSERVED
|
|
153
|
+
for (let l = comp.d; l; l = l.nd)
|
|
154
|
+
removeSub(l)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Takes a link out of its source's subscriber list; a computed losing its last subscriber lets go of its own sources.
|
|
158
|
+
export function removeSub(link: Link): void {
|
|
159
|
+
const { d, ps, ns } = link
|
|
160
|
+
if (ps)
|
|
161
|
+
ps.ns = ns
|
|
162
|
+
else
|
|
163
|
+
d.s = ns
|
|
164
|
+
if (ns)
|
|
165
|
+
ns.ps = ps
|
|
166
|
+
else
|
|
167
|
+
d.st = ps
|
|
168
|
+
link.ps = link.ns = undefined
|
|
169
|
+
if (!d.s) {
|
|
170
|
+
if ((d.f & (F.COMPUTED | F.UNOBSERVED)) === F.COMPUTED)
|
|
171
|
+
unobserve(d as unknown as SubNode)
|
|
172
|
+
else if (d.u)
|
|
173
|
+
d.u()
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function unlink(l: Link): void {
|
|
178
|
+
const { s, pd, nd } = l
|
|
179
|
+
if (s.c === l)
|
|
180
|
+
s.c = nd
|
|
181
|
+
if (pd)
|
|
182
|
+
pd.nd = nd
|
|
183
|
+
else
|
|
184
|
+
s.d = nd
|
|
185
|
+
if (nd)
|
|
186
|
+
nd.pd = pd
|
|
187
|
+
else
|
|
188
|
+
s.dt = pd
|
|
189
|
+
l.pd = l.nd = undefined
|
|
190
|
+
if (!(s.f & F.UNOBSERVED))
|
|
191
|
+
removeSub(l)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function unlinkSubs(dep: DepNode): void {
|
|
195
|
+
for (let l = dep.s, next: Link | undefined; l; l = next) {
|
|
196
|
+
next = l.ns
|
|
197
|
+
unlink(l)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function unlinkRemaining(sub: SubNode): void {
|
|
202
|
+
let l = sub.c
|
|
203
|
+
const e = sub.e
|
|
204
|
+
sub.c = undefined
|
|
205
|
+
while (l) {
|
|
206
|
+
const next = l.nd
|
|
207
|
+
if (l.e !== e)
|
|
208
|
+
unlink(l)
|
|
209
|
+
l = next
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function unlinkAll(sub: SubNode): void {
|
|
214
|
+
let l = sub.d
|
|
215
|
+
sub.d = sub.dt = sub.c = undefined
|
|
216
|
+
if (sub.f & F.UNOBSERVED)
|
|
217
|
+
return
|
|
218
|
+
while (l) {
|
|
219
|
+
const next = l.nd
|
|
220
|
+
removeSub(l)
|
|
221
|
+
l = next
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// A node adopted by a disposed owner is born disposed; otherwise it joins the head of the owner's list.
|
|
226
|
+
export function adopt(node: Owned, owner: Owner): void {
|
|
227
|
+
if (owner.f & F.DISPOSED) {
|
|
228
|
+
node.f |= F.DISPOSED
|
|
229
|
+
return
|
|
230
|
+
}
|
|
231
|
+
node.o = owner
|
|
232
|
+
const first = owner.fs
|
|
233
|
+
node.no = first
|
|
234
|
+
if (first)
|
|
235
|
+
first.po = node
|
|
236
|
+
owner.fs = node
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function unadopt(node: Owned): void {
|
|
240
|
+
const owner = node.o
|
|
241
|
+
if (!owner)
|
|
242
|
+
return
|
|
243
|
+
const { po, no } = node
|
|
244
|
+
if (po)
|
|
245
|
+
po.no = no
|
|
246
|
+
else if (owner.fs === node)
|
|
247
|
+
owner.fs = no
|
|
248
|
+
if (no)
|
|
249
|
+
no.po = po
|
|
250
|
+
node.o = node.po = node.no = undefined
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function throwErrors(errors: unknown[] | undefined): void {
|
|
254
|
+
if (!errors || !errors.length)
|
|
255
|
+
return
|
|
256
|
+
if (errors.length === 1)
|
|
257
|
+
throw errors[0]
|
|
258
|
+
throw new AggregateError(errors, `prunelle: ${errors.length} errors`)
|
|
259
|
+
}
|