prunelle 0.1.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/llms.txt +130 -38
- package/package.json +8 -2
- package/src/a11y/declaration.ts +335 -0
- package/src/a11y/index.ts +446 -0
- package/src/a11y/rgaa-map.ts +184 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +80 -36
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +8 -4
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +11 -9
- package/src/build/ecoindex.ts +229 -0
- package/src/build/index.ts +174 -108
- package/src/build/islands.ts +2 -2
- package/src/build/manifest.ts +66 -5
- package/src/build/output.ts +2 -2
- package/src/build/plugin-host.ts +92 -33
- package/src/build/precompress.ts +15 -2
- package/src/build/prerender.ts +128 -46
- package/src/build/report.ts +23 -2
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static.ts +137 -39
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +561 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check.ts +75 -20
- package/src/cli/commands.ts +85 -4
- package/src/cli/docs.ts +402 -0
- package/src/cli/inspect.ts +103 -14
- package/src/cli/mcp-tools.ts +490 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +2 -2
- package/src/cli/render.ts +421 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +137 -16
- package/src/compiler/analyze.ts +42 -9
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability.ts +636 -0
- package/src/compiler/compliance-rgaa.ts +508 -0
- package/src/compiler/compliance.ts +241 -289
- package/src/compiler/data-keys.ts +199 -192
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +517 -442
- package/src/compiler/expr-context.ts +167 -57
- package/src/compiler/mistakes.ts +4 -1
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +400 -333
- package/src/compiler/server-only.ts +190 -151
- package/src/compiler/shared.ts +40 -12
- package/src/compiler/signal-reads.ts +6 -2
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +218 -87
- package/src/dev/error-log.ts +151 -0
- package/src/dev/index.ts +84 -34
- package/src/dev/open-editor.ts +204 -0
- package/src/dev/protocol.ts +1 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +42 -25
- package/src/dev/watchers.ts +47 -11
- package/src/dom/action.ts +43 -20
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +28 -12
- package/src/dom/index.ts +26 -8
- package/src/dom/island.ts +35 -28
- package/src/dom/loop.ts +10 -9
- package/src/plugins/config.ts +8 -7
- package/src/plugins/index.ts +2 -2
- package/src/plugins/load.ts +26 -7
- package/src/plugins/order.ts +38 -1
- package/src/plugins/public.ts +5 -2
- package/src/plugins/services.ts +81 -0
- package/src/plugins/types.ts +34 -0
- package/src/reactivity/graph.ts +10 -0
- package/src/reactivity/index.ts +24 -16
- package/src/reactivity/selector.ts +31 -4
- package/src/reactivity/store.ts +45 -13
- package/src/server/action-protect.ts +198 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +82 -27
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +91 -9
- package/src/server/document.ts +25 -10
- package/src/server/errors.ts +303 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +131 -32
- package/src/server/index.ts +231 -261
- package/src/server/loader.ts +5 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +123 -88
- package/src/server/public.ts +3 -3
- package/src/server/rate-limit.ts +58 -35
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +423 -0
- package/src/server/route-table.ts +339 -8
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +196 -63
- package/src/server/security.ts +208 -32
- package/src/server/serve-handlers.ts +21 -7
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +61 -8
- package/src/server/stream.ts +41 -22
- package/src/ssr/context.ts +85 -3
- package/src/ssr/index.ts +130 -3
- package/src/ssr/region.ts +31 -19
- package/src/test/browser.ts +28 -13
- package/src/test/index.ts +97 -12
- 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/templates/_shared/AGENTS.md +2 -2
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +5 -0
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/index.tsx +4 -0
- package/ts-plugin.cjs +4277 -0
package/src/plugins/order.ts
CHANGED
|
@@ -7,6 +7,43 @@ function enforceRank(plugin: PrunellePlugin): number {
|
|
|
7
7
|
return plugin.enforce === 'pre' ? 0 : plugin.enforce === 'post' ? 2 : 1
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
function splitScope(name: string): { scope: string | undefined, pkg: string } {
|
|
11
|
+
if (name.startsWith('@')) {
|
|
12
|
+
const slash = name.indexOf('/')
|
|
13
|
+
if (slash > 1 && slash < name.length - 1)
|
|
14
|
+
return { scope: name.slice(0, slash), pkg: name.slice(slash + 1) }
|
|
15
|
+
}
|
|
16
|
+
return { scope: undefined, pkg: name }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Compares scoped plugin names without their shared `@scope/` prefix so short official plugins (`@prunellejs/cms` vs `@prunellejs/mcp`, `@prunellejs/seo` vs `@prunellejs/spa`) never false-positive as typos.
|
|
20
|
+
function closestPluginName(depName: string, names: readonly string[]): string | undefined {
|
|
21
|
+
const dep = splitScope(depName)
|
|
22
|
+
if (dep.scope === undefined)
|
|
23
|
+
return closestName(depName, names.filter(n => splitScope(n).scope === undefined))
|
|
24
|
+
|
|
25
|
+
const sameScopePkgs: string[] = []
|
|
26
|
+
const byPkg = new Map<string, string>()
|
|
27
|
+
const samePkgScopes: string[] = []
|
|
28
|
+
const byScope = new Map<string, string>()
|
|
29
|
+
for (const known of names) {
|
|
30
|
+
const parts = splitScope(known)
|
|
31
|
+
if (parts.scope === dep.scope) {
|
|
32
|
+
sameScopePkgs.push(parts.pkg)
|
|
33
|
+
byPkg.set(parts.pkg, known)
|
|
34
|
+
}
|
|
35
|
+
else if (parts.scope !== undefined && parts.pkg === dep.pkg) {
|
|
36
|
+
samePkgScopes.push(parts.scope)
|
|
37
|
+
byScope.set(parts.scope, known)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const nearPkg = closestName(dep.pkg, sameScopePkgs)
|
|
41
|
+
if (nearPkg !== undefined)
|
|
42
|
+
return byPkg.get(nearPkg)
|
|
43
|
+
const nearScope = closestName(dep.scope, samePkgScopes)
|
|
44
|
+
return nearScope !== undefined ? byScope.get(nearScope) : undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
10
47
|
/**
|
|
11
48
|
* Sorts plugins stably by `enforce` (`'pre'` -> normal -> `'post'`) and `after` dependencies,
|
|
12
49
|
* then fails fast if any plugin declares `readsLocals` for a key whose provider runs after it.
|
|
@@ -44,7 +81,7 @@ export function resolvePlugins(plugins: readonly PrunellePlugin[] | undefined):
|
|
|
44
81
|
const depIdx = indexByName.get(depName)
|
|
45
82
|
// A name no plugin has is an optional dependency that is not installed, unless it is one typo away from one that is.
|
|
46
83
|
if (depIdx === undefined) {
|
|
47
|
-
const near =
|
|
84
|
+
const near = closestPluginName(depName, names)
|
|
48
85
|
if (near !== undefined)
|
|
49
86
|
throw new Error(`prunelle: plugin "${base[i]!.name}" runs \`after\` "${depName}", which no plugin is named: did you mean "${near}"?`)
|
|
50
87
|
continue
|
package/src/plugins/public.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
// `prunelle/config`: what `prunelle.config.ts` and plugin packages use.
|
|
2
2
|
|
|
3
|
+
export { a11y, auditAccessibility, draftAccessibilityStatement, formatA11yReport, rgaaCriteriaForAxeRule } from '../a11y/index'
|
|
4
|
+
export type { A11yAuditOptions, A11yAuditReport, A11yImpact, A11yPluginOptions, A11yRouteReport, A11yViolation, A11yViolationNode, AccessibilityDeclarationOptions, AccessibilityDeclarationResult, ComplianceStatus, RgaaCriterion } from '../a11y/index'
|
|
3
5
|
export { isInside } from '../build/is-inside'
|
|
4
6
|
export { distLocator, firstLoadUrls, measureFirstLoad } from '../build/first-load'
|
|
5
7
|
export type { FirstLoad, Locate } from '../build/first-load'
|
|
6
8
|
export { brotliSize } from '../build/precompress'
|
|
9
|
+
export { minifyCss } from '../build/style-bundles'
|
|
7
10
|
export { defineConfig, definePlugin } from './config'
|
|
8
|
-
export { CONTENT_IMAGE_RESOLVER_SERVICE, I18N_CONFIG_SERVICE, serviceKey } from './services'
|
|
9
|
-
export type { ActiveI18nConfig, ContentImageResolver, ContentImageResult, ServiceKey } from './services'
|
|
11
|
+
export { CMS_INLINE_ENABLED_SERVICE, CONTENT_COLLECTIONS_SERVICE, CONTENT_IMAGE_RESOLVER_SERVICE, I18N_CONFIG_SERVICE, JOBS_SERVICE, WEB_MANIFEST_SERVICE, serviceKey } from './services'
|
|
12
|
+
export type { AccessedContentEntry, ActiveI18nConfig, ContentCollectionDescriptor, ContentCollectionEntrySummary, ContentCollectionsService, ContentImageResolver, ContentImageResult, JobsEnqueueOptions, JobsQueueOptions, JobsService, ServiceKey, WebManifestIcon, WebManifestInfo } from './services'
|
|
10
13
|
export type { ComplianceConfig, ComplianceRule } from '../compiler/compliance'
|
|
11
14
|
export type { ConsentConfig } from '../server/consent'
|
|
12
15
|
export type { BuildPluginContext, BuildPluginTarget, CheckPluginContext, DocumentHeadContext, FinalizeBuildContext, PrunelleConfig, PrunellePlugin, MiddlewareOptions, PluginRouteOptions, RequiresPluginContext, ServerErrorInfo, ServerPluginAPI, ServerRuntimeConfig } from './types'
|
package/src/plugins/services.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// Service keys: `serviceKey` for any plugin, and the keys shared between two plugins, kept in core as contracts so neither depends on the other.
|
|
2
2
|
|
|
3
|
+
import type { RequestContext } from '../server/http'
|
|
4
|
+
import type { StandardSchemaV1 } from '../server/standard-schema'
|
|
5
|
+
|
|
3
6
|
declare const SERVICE_TYPE: unique symbol
|
|
4
7
|
|
|
5
8
|
/** Names a service and the type of its value; `provide` and `inject` take one instead of a string. */
|
|
@@ -33,3 +36,81 @@ export interface ContentImageResult {
|
|
|
33
36
|
export type ContentImageResolver = (src: string, file: string | undefined) => ContentImageResult | string | undefined
|
|
34
37
|
|
|
35
38
|
export const CONTENT_IMAGE_RESOLVER_SERVICE = serviceKey<ContentImageResolver>('prunelle.content.imageResolver')
|
|
39
|
+
|
|
40
|
+
export interface ContentCollectionEntrySummary {
|
|
41
|
+
readonly slug: string
|
|
42
|
+
readonly locale?: string | undefined
|
|
43
|
+
readonly file?: string | undefined
|
|
44
|
+
readonly data: Record<string, unknown>
|
|
45
|
+
readonly body: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ContentCollectionDescriptor {
|
|
49
|
+
/** Collection identifier (directory basename or explicit name). */
|
|
50
|
+
readonly name: string
|
|
51
|
+
/** Optional URL prefix registered via feeds or collection config (e.g. '/blog'). */
|
|
52
|
+
readonly linkPrefix?: string | undefined
|
|
53
|
+
/** Absolute directory path for file-backed collections; undefined for loader-backed collections. */
|
|
54
|
+
readonly dir?: string | undefined
|
|
55
|
+
readonly localized: boolean
|
|
56
|
+
readonly defaultLocale: string
|
|
57
|
+
readonly locales?: readonly string[] | undefined
|
|
58
|
+
readonly schema?: StandardSchemaV1 | undefined
|
|
59
|
+
all(locale?: string): readonly ContentCollectionEntrySummary[] | Promise<readonly ContentCollectionEntrySummary[]>
|
|
60
|
+
get(slug: string, locale?: string): ContentCollectionEntrySummary | undefined | Promise<ContentCollectionEntrySummary | undefined>
|
|
61
|
+
clearCache(): void
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface AccessedContentEntry {
|
|
65
|
+
readonly collection: string
|
|
66
|
+
readonly slug: string
|
|
67
|
+
readonly locale?: string | undefined
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ContentCollectionsService {
|
|
71
|
+
list(root?: string): readonly ContentCollectionDescriptor[] | Promise<readonly ContentCollectionDescriptor[]>
|
|
72
|
+
discover?(root: string): Promise<readonly ContentCollectionDescriptor[]>
|
|
73
|
+
/** Returns file-backed content entries accessed during the given dev request (primary `get()` entries first). */
|
|
74
|
+
accessedEntries?(ctx: RequestContext): readonly AccessedContentEntry[]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const CONTENT_COLLECTIONS_SERVICE = serviceKey<ContentCollectionsService>('prunelle.content.collections')
|
|
78
|
+
|
|
79
|
+
/** Provided by `@prunellejs/cms` in dev mode when in-page editing is enabled so `@prunellejs/content` emits body anchor comments. */
|
|
80
|
+
export const CMS_INLINE_ENABLED_SERVICE = serviceKey<boolean>('prunelle.cms.inline')
|
|
81
|
+
|
|
82
|
+
export interface JobsQueueOptions {
|
|
83
|
+
attempts?: number | undefined
|
|
84
|
+
backoff?: 'exponential' | 'fixed' | number | undefined
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface JobsEnqueueOptions {
|
|
88
|
+
delay?: number | undefined
|
|
89
|
+
key?: string | undefined
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface JobsService {
|
|
93
|
+
queue<T = unknown>(name: string, handler: (data: T) => void | Promise<void>, options?: JobsQueueOptions): void
|
|
94
|
+
enqueue<T = unknown>(name: string, data: T, options?: JobsEnqueueOptions): Promise<void> | void
|
|
95
|
+
drain?(options?: { now?: number | undefined, includeDelayed?: boolean | undefined }): Promise<number>
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const JOBS_SERVICE = serviceKey<JobsService>('prunelle.jobs.service')
|
|
99
|
+
|
|
100
|
+
export interface WebManifestIcon {
|
|
101
|
+
readonly src: string
|
|
102
|
+
readonly sizes?: string | undefined
|
|
103
|
+
readonly type?: string | undefined
|
|
104
|
+
readonly purpose?: string | undefined
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface WebManifestInfo {
|
|
108
|
+
readonly name?: string | undefined
|
|
109
|
+
readonly shortName?: string | undefined
|
|
110
|
+
readonly startUrl?: string | undefined
|
|
111
|
+
readonly display?: string | undefined
|
|
112
|
+
readonly icons?: readonly WebManifestIcon[] | undefined
|
|
113
|
+
readonly source?: string | undefined
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const WEB_MANIFEST_SERVICE = serviceKey<WebManifestInfo>('prunelle.webManifest')
|
package/src/plugins/types.ts
CHANGED
|
@@ -4,12 +4,16 @@ import type { BunPlugin } from 'bun'
|
|
|
4
4
|
import type { RouteManifestEntry } from '../build/index'
|
|
5
5
|
import type { ComplianceConfig } from '../compiler/compliance'
|
|
6
6
|
import type { ConsentConfig } from '../server/consent'
|
|
7
|
+
import type { HealthCheckConfig, HealthCheckFn, HealthCheckResult } from '../server/health'
|
|
7
8
|
import type { Middleware, RequestContext } from '../server/index'
|
|
8
9
|
import type { RateLimit, RateLimiter } from '../server/rate-limit'
|
|
10
|
+
import type { RouteCacheOptions } from '../server/route-cache'
|
|
9
11
|
import type { SecurityHeadersOptions, TrustProxy } from '../server/security'
|
|
10
12
|
import type { NavigationConfig } from '../ssr/navigation'
|
|
11
13
|
import type { ServiceKey } from './services'
|
|
12
14
|
|
|
15
|
+
export type { HealthCheckConfig, HealthCheckFn, HealthCheckResult }
|
|
16
|
+
|
|
13
17
|
export type BuildPluginTarget = 'client' | 'server' | 'compile'
|
|
14
18
|
|
|
15
19
|
export interface BuildPluginContext {
|
|
@@ -21,14 +25,22 @@ export interface BuildPluginContext {
|
|
|
21
25
|
readonly isStatic: boolean
|
|
22
26
|
readonly dev: boolean
|
|
23
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
|
|
24
32
|
/** Emit an immutable build asset into dist/client/<relPath>; returns its public URL (`/_pru/<relPath>`). */
|
|
25
33
|
emitAsset(relPath: string, content: string | Uint8Array): string
|
|
26
34
|
/** Emit a static file into dist/public/<relPath> served at `/<relPath>`. */
|
|
27
35
|
emitPublic(relPath: string, content: string | Uint8Array): string
|
|
28
36
|
/** Add a stylesheet URL to <head> on every page. */
|
|
29
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
|
|
30
40
|
/** Add a stylesheet URL to <head> on a specific route path only. */
|
|
31
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
|
|
32
44
|
/** Add raw HTML to <head> on every page (e.g. font preloads, default meta/OG, JSON-LD). */
|
|
33
45
|
addHead(html: string): void
|
|
34
46
|
/** Add raw HTML to <head> on a specific route path only. */
|
|
@@ -44,6 +56,8 @@ export interface BuildPluginContext {
|
|
|
44
56
|
export interface FinalizeBuildContext {
|
|
45
57
|
readonly root: string
|
|
46
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
|
|
47
61
|
readonly assetPrefix: string
|
|
48
62
|
readonly site?: string | undefined
|
|
49
63
|
readonly minify: boolean
|
|
@@ -53,6 +67,8 @@ export interface FinalizeBuildContext {
|
|
|
53
67
|
readonly routes: readonly RouteManifestEntry[]
|
|
54
68
|
/** Relative paths of all public files known so far (including files registered during prerender). */
|
|
55
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
|
|
56
72
|
/** Emit an immutable build asset into dist/client/<relPath>; returns its public URL (`/_pru/<relPath>`). */
|
|
57
73
|
emitAsset(relPath: string, content: string | Uint8Array): string
|
|
58
74
|
/** Emit a static file into dist/public/<relPath> served at `/<relPath>` (included in `--static` and `--compile`). */
|
|
@@ -72,6 +88,10 @@ export interface CheckPluginContext {
|
|
|
72
88
|
error(message: string): void
|
|
73
89
|
/** Report what may be intended but usually is not; `prunelle check --strict` fails on it. */
|
|
74
90
|
warn(message: string): void
|
|
91
|
+
/** Register a check-scoped service for downstream plugins. */
|
|
92
|
+
provide?<T>(key: ServiceKey<T>, value: T): void
|
|
93
|
+
/** Look up a check-scoped service registered by an earlier plugin. */
|
|
94
|
+
inject?<T>(key: ServiceKey<T>): T | undefined
|
|
75
95
|
}
|
|
76
96
|
|
|
77
97
|
export interface RequiresPluginContext {
|
|
@@ -89,6 +109,11 @@ export interface PluginRouteOptions {
|
|
|
89
109
|
trustProxy?: TrustProxy | undefined
|
|
90
110
|
/** How often one client may call the route: past `max` per `windowMs`, it answers 429 with `Retry-After` before the handler runs. */
|
|
91
111
|
rateLimit?: RateLimit<RequestContext> | undefined
|
|
112
|
+
/**
|
|
113
|
+
* Let the route's catch-all take a segment with an encoded `/`, `\` or NUL (`%2F`, `%5C`, `%00`), which every route refuses by default.
|
|
114
|
+
* 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.
|
|
115
|
+
*/
|
|
116
|
+
encodedSlashes?: boolean | undefined
|
|
92
117
|
}
|
|
93
118
|
|
|
94
119
|
export interface MiddlewareOptions {
|
|
@@ -126,6 +151,8 @@ export interface ServerPluginAPI {
|
|
|
126
151
|
inject<T>(key: ServiceKey<T>): T | undefined
|
|
127
152
|
/** Read persisted build data from `manifest.pluginData` (defaults to the current plugin's name). */
|
|
128
153
|
getBuildData<T = Record<string, unknown>>(pluginName?: string): T | undefined
|
|
154
|
+
/** Register a named health check evaluated on `GET ${assetPrefix}/health`. */
|
|
155
|
+
healthCheck(name: string, fn: HealthCheckFn): void
|
|
129
156
|
/** Register a shutdown cleanup callback run when `app.dispose()` is called (dev reloads, tests, graceful exit). */
|
|
130
157
|
onShutdown(fn: () => void | Promise<void>): void
|
|
131
158
|
}
|
|
@@ -134,6 +161,7 @@ export interface ServerErrorInfo {
|
|
|
134
161
|
error: unknown
|
|
135
162
|
request: Request
|
|
136
163
|
source: 'route' | 'action' | 'plugin'
|
|
164
|
+
requestId?: string | undefined
|
|
137
165
|
}
|
|
138
166
|
|
|
139
167
|
export interface DocumentHeadContext {
|
|
@@ -215,6 +243,10 @@ export interface ServerRuntimeConfig {
|
|
|
215
243
|
/** CNIL/RGPD consent categories, cookie name, retention, and POST endpoint. */
|
|
216
244
|
consent?: ConsentConfig | undefined
|
|
217
245
|
compress?: boolean | undefined
|
|
246
|
+
/** Bounded in-memory cache for routes exporting `export const cache = ...` (default: 500 entries / 32 MiB; set `false` to disable). */
|
|
247
|
+
routeCache?: RouteCacheOptions | false | undefined
|
|
248
|
+
/** Health check function or named check map evaluated on `GET ${assetPrefix}/health`. */
|
|
249
|
+
healthCheck?: HealthCheckConfig | undefined
|
|
218
250
|
onError?: ((info: ServerErrorInfo) => void) | undefined
|
|
219
251
|
plugins?: PrunellePlugin[] | undefined
|
|
220
252
|
}
|
|
@@ -226,4 +258,6 @@ export interface PrunelleConfig extends ServerRuntimeConfig {
|
|
|
226
258
|
publicDir?: string | undefined
|
|
227
259
|
/** French web law compliance checks (RGAA, RGPD, LCEN) configuration and rule silencing. */
|
|
228
260
|
compliance?: ComplianceConfig | undefined
|
|
261
|
+
/** Automatically prerender static pages that read nothing from the request or clock (and have no middleware or `cache` export). */
|
|
262
|
+
autoPrerender?: boolean | undefined
|
|
229
263
|
}
|
package/src/reactivity/graph.ts
CHANGED
|
@@ -176,6 +176,8 @@ export function removeSub(link: Link): void {
|
|
|
176
176
|
|
|
177
177
|
function unlink(l: Link): void {
|
|
178
178
|
const { s, pd, nd } = l
|
|
179
|
+
if (s.c === l)
|
|
180
|
+
s.c = nd
|
|
179
181
|
if (pd)
|
|
180
182
|
pd.nd = nd
|
|
181
183
|
else
|
|
@@ -184,10 +186,18 @@ function unlink(l: Link): void {
|
|
|
184
186
|
nd.pd = pd
|
|
185
187
|
else
|
|
186
188
|
s.dt = pd
|
|
189
|
+
l.pd = l.nd = undefined
|
|
187
190
|
if (!(s.f & F.UNOBSERVED))
|
|
188
191
|
removeSub(l)
|
|
189
192
|
}
|
|
190
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
|
+
|
|
191
201
|
export function unlinkRemaining(sub: SubNode): void {
|
|
192
202
|
let l = sub.c
|
|
193
203
|
const e = sub.e
|
package/src/reactivity/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Glitch-free lazy computed values, O(1) link/unlink, compact internal fields for tiny bundle size.
|
|
3
3
|
|
|
4
4
|
import type { DepNode, Link, Owned, Owner, ReadonlySignal, Signal, SubNode } from './graph'
|
|
5
|
-
import { adopt, linkSub, throwErrors, unadopt, unlinkAll, unlinkRemaining, unobserve } from './graph'
|
|
5
|
+
import { adopt, linkSub, throwErrors, unadopt, unlinkAll, unlinkRemaining, unlinkSubs, unobserve } from './graph'
|
|
6
6
|
|
|
7
7
|
export type { IdScope, Owner, ReadonlySignal, Signal } from './graph'
|
|
8
8
|
|
|
@@ -34,16 +34,24 @@ let writes = 0
|
|
|
34
34
|
let propWave = 0
|
|
35
35
|
|
|
36
36
|
// A child effect can sit ahead of its parent in the queue; the parent runs first, since its run may dispose the child.
|
|
37
|
-
function runParentFirst(sub: SubNode): void {
|
|
38
|
-
sub.f &= ~F.PENDING
|
|
37
|
+
function runParentFirst(sub: SubNode, errors: unknown[]): void {
|
|
38
|
+
sub.f &= ~(F.PENDING | F.QUEUED)
|
|
39
39
|
for (let o = sub.o; o; o = o.o) {
|
|
40
40
|
if (o.f & (F.PENDING | F.QUEUED)) {
|
|
41
|
-
runParentFirst(o as unknown as SubNode)
|
|
41
|
+
runParentFirst(o as unknown as SubNode, errors)
|
|
42
42
|
break
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
if (!(sub.f & F.DISPOSED)
|
|
46
|
-
|
|
45
|
+
if (!(sub.f & F.DISPOSED)) {
|
|
46
|
+
try {
|
|
47
|
+
if (shouldRun(sub))
|
|
48
|
+
sub.r()
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (!catchEffectError?.(sub, err))
|
|
52
|
+
errors.push(err)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
function enqueue(sub: SubNode): void {
|
|
@@ -94,15 +102,8 @@ function flush(): void {
|
|
|
94
102
|
for (const node of round)
|
|
95
103
|
node.f = (node.f & ~F.QUEUED) | F.PENDING
|
|
96
104
|
for (const node of round) {
|
|
97
|
-
if (node.f & F.PENDING)
|
|
98
|
-
|
|
99
|
-
runParentFirst(node)
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
if (!catchEffectError?.(node, err))
|
|
103
|
-
errors.push(err)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
105
|
+
if (node.f & F.PENDING)
|
|
106
|
+
runParentFirst(node, errors)
|
|
106
107
|
}
|
|
107
108
|
round.length = 0
|
|
108
109
|
}
|
|
@@ -344,7 +345,9 @@ export function disposeOwner(node: Owner): void {
|
|
|
344
345
|
unadopt(node)
|
|
345
346
|
if (f & (F.COMPUTED | F.EFFECT))
|
|
346
347
|
unlinkAll(node as unknown as SubNode)
|
|
347
|
-
if (
|
|
348
|
+
if (f & F.COMPUTED)
|
|
349
|
+
unlinkSubs(node as unknown as DepNode)
|
|
350
|
+
else
|
|
348
351
|
releaseOwned(node)
|
|
349
352
|
}
|
|
350
353
|
|
|
@@ -417,6 +420,11 @@ export function isObserving(): boolean {
|
|
|
417
420
|
return !!currentSub && !(currentSub.f & (F.UNOBSERVED | F.DISPOSED))
|
|
418
421
|
}
|
|
419
422
|
|
|
423
|
+
/** Internal: total signal writes so far, used by selector() to detect un-flushed changes without importing computed. */
|
|
424
|
+
export function writeCount(): number {
|
|
425
|
+
return writes
|
|
426
|
+
}
|
|
427
|
+
|
|
420
428
|
/** Internal: signal that runs `onUnsub` and bumps its version when its last subscriber detaches. */
|
|
421
429
|
export function watchedSignal<T>(initial: T, onUnsub: () => void): Signal<T> {
|
|
422
430
|
const s = new SignalNode(initial)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// O(1) row selection primitive: zero WeakSet overhead per row.
|
|
2
2
|
|
|
3
3
|
import type { Signal } from './index'
|
|
4
|
-
import { effect, isObserving, isTracking, watchedSignal } from './index'
|
|
4
|
+
import { effect, isObserving, isTracking, untrack, watchedSignal, writeCount } from './index'
|
|
5
5
|
|
|
6
6
|
export interface Selector<K> {
|
|
7
7
|
is(key: K): boolean
|
|
@@ -11,9 +11,31 @@ export function selector<K>(source: () => K): Selector<K> {
|
|
|
11
11
|
const subs = new Map<K, Signal<boolean>>()
|
|
12
12
|
let current: K | undefined
|
|
13
13
|
let active = false
|
|
14
|
+
let checked = -1
|
|
15
|
+
let latest: K | undefined
|
|
16
|
+
let pending: Set<K> | undefined
|
|
17
|
+
|
|
18
|
+
const readLatest = (): K => {
|
|
19
|
+
const w = writeCount()
|
|
20
|
+
if (checked !== w) {
|
|
21
|
+
latest = untrack(source)
|
|
22
|
+
checked = w
|
|
23
|
+
}
|
|
24
|
+
return latest as K
|
|
25
|
+
}
|
|
14
26
|
|
|
15
27
|
effect(() => {
|
|
16
28
|
const next = source()
|
|
29
|
+
latest = next
|
|
30
|
+
checked = writeCount()
|
|
31
|
+
if (pending !== undefined) {
|
|
32
|
+
for (const k of pending) {
|
|
33
|
+
const s = subs.get(k)
|
|
34
|
+
if (s !== undefined)
|
|
35
|
+
s.value = Object.is(next, k)
|
|
36
|
+
}
|
|
37
|
+
pending = undefined
|
|
38
|
+
}
|
|
17
39
|
if (active && Object.is(current, next))
|
|
18
40
|
return
|
|
19
41
|
|
|
@@ -35,17 +57,22 @@ export function selector<K>(source: () => K): Selector<K> {
|
|
|
35
57
|
if (!active)
|
|
36
58
|
return Object.is(source(), key)
|
|
37
59
|
if (!isObserving())
|
|
38
|
-
return isTracking() ?
|
|
60
|
+
return Object.is(isTracking() ? source() : readLatest(), key)
|
|
39
61
|
|
|
62
|
+
const val = readLatest()
|
|
63
|
+
const matched = Object.is(val, key)
|
|
40
64
|
let sub = subs.get(key)
|
|
41
65
|
if (sub === undefined) {
|
|
42
|
-
sub = watchedSignal(
|
|
66
|
+
sub = watchedSignal(matched, () => {
|
|
43
67
|
if (subs.get(key) === sub)
|
|
44
68
|
subs.delete(key)
|
|
45
69
|
})
|
|
46
70
|
subs.set(key, sub)
|
|
71
|
+
if (!Object.is(current, val))
|
|
72
|
+
(pending ??= new Set()).add(key)
|
|
47
73
|
}
|
|
48
|
-
|
|
74
|
+
sub.value
|
|
75
|
+
return matched
|
|
49
76
|
},
|
|
50
77
|
}
|
|
51
78
|
}
|
package/src/reactivity/store.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Deep reactive proxy store (tree-shakable: 0 B if unused).
|
|
2
2
|
|
|
3
3
|
import type { Signal } from './index'
|
|
4
|
-
import { batch, isTracking, signal, untrack } from './index'
|
|
4
|
+
import { batch, isObserving, isTracking, signal, untrack, watchedSignal } from './index'
|
|
5
5
|
|
|
6
6
|
const RAW = Symbol('prunelle.store.raw')
|
|
7
7
|
const OWN_KEYS = Symbol('prunelle.store.keys')
|
|
@@ -18,6 +18,7 @@ const batchedMutators = new Map<PropertyKey, (this: unknown[], ...args: unknown[
|
|
|
18
18
|
|
|
19
19
|
const proxyCache = new WeakMap<object, object>()
|
|
20
20
|
const depsCache = new WeakMap<object, Map<PropertyKey, Signal<number>>>()
|
|
21
|
+
const verCache = new WeakMap<object, Signal<number>>()
|
|
21
22
|
|
|
22
23
|
function isPlain(value: unknown): value is Record<PropertyKey, unknown> {
|
|
23
24
|
if (typeof value !== 'object' || value === null)
|
|
@@ -33,7 +34,24 @@ function unwrap<T>(value: T): T {
|
|
|
33
34
|
return typeof value === 'object' && value !== null && RAW in value ? (value as Record<symbol, T>)[RAW]! : value
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
function bumpVer(target: object): void {
|
|
38
|
+
const ver = verCache.get(target)
|
|
39
|
+
if (ver !== undefined)
|
|
40
|
+
ver.value = ver.peek() + 1
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
function getDep(target: object, key: PropertyKey): Signal<number> {
|
|
44
|
+
if (!isObserving()) {
|
|
45
|
+
const existing = depsCache.get(target)?.get(key)
|
|
46
|
+
if (existing !== undefined)
|
|
47
|
+
return existing
|
|
48
|
+
let ver = verCache.get(target)
|
|
49
|
+
if (ver === undefined) {
|
|
50
|
+
ver = signal(0)
|
|
51
|
+
verCache.set(target, ver)
|
|
52
|
+
}
|
|
53
|
+
return ver
|
|
54
|
+
}
|
|
37
55
|
let map = depsCache.get(target)
|
|
38
56
|
if (map === undefined) {
|
|
39
57
|
map = new Map()
|
|
@@ -41,7 +59,13 @@ function getDep(target: object, key: PropertyKey): Signal<number> {
|
|
|
41
59
|
}
|
|
42
60
|
let dep = map.get(key)
|
|
43
61
|
if (dep === undefined) {
|
|
44
|
-
dep =
|
|
62
|
+
dep = watchedSignal(0, () => {
|
|
63
|
+
if (map!.get(key) === dep) {
|
|
64
|
+
map!.delete(key)
|
|
65
|
+
if (map!.size === 0)
|
|
66
|
+
depsCache.delete(target)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
45
69
|
map.set(key, dep)
|
|
46
70
|
}
|
|
47
71
|
return dep
|
|
@@ -51,6 +75,7 @@ function notifyKey(target: object, key: PropertyKey): void {
|
|
|
51
75
|
const dep = depsCache.get(target)?.get(key)
|
|
52
76
|
if (dep !== undefined)
|
|
53
77
|
dep.value = dep.peek() + 1
|
|
78
|
+
bumpVer(target)
|
|
54
79
|
}
|
|
55
80
|
|
|
56
81
|
function deleteDep(target: object, key: PropertyKey): void {
|
|
@@ -62,23 +87,25 @@ function deleteDep(target: object, key: PropertyKey): void {
|
|
|
62
87
|
if (map!.size === 0)
|
|
63
88
|
depsCache.delete(target)
|
|
64
89
|
}
|
|
90
|
+
bumpVer(target)
|
|
65
91
|
}
|
|
66
92
|
|
|
67
93
|
function evictTruncated(target: object, nextLen: number, prevLen: number): void {
|
|
68
94
|
const map = depsCache.get(target)
|
|
69
|
-
if (map
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
if (map !== undefined) {
|
|
96
|
+
for (const [k, dep] of map) {
|
|
97
|
+
if (typeof k === 'string') {
|
|
98
|
+
const idx = Number(k)
|
|
99
|
+
if ((idx >>> 0) === idx && idx >= nextLen && idx < prevLen && String(idx) === k) {
|
|
100
|
+
dep.value = dep.peek() + 1
|
|
101
|
+
map.delete(k)
|
|
102
|
+
}
|
|
77
103
|
}
|
|
78
104
|
}
|
|
105
|
+
if (map.size === 0)
|
|
106
|
+
depsCache.delete(target)
|
|
79
107
|
}
|
|
80
|
-
|
|
81
|
-
depsCache.delete(target)
|
|
108
|
+
bumpVer(target)
|
|
82
109
|
}
|
|
83
110
|
|
|
84
111
|
function wrap<T extends object>(target: T): T {
|
|
@@ -100,7 +127,12 @@ function wrap<T extends object>(target: T): T {
|
|
|
100
127
|
getDep(obj, OWN_KEYS).value
|
|
101
128
|
}
|
|
102
129
|
const value = Reflect.get(obj, key, receiver)
|
|
103
|
-
|
|
130
|
+
if (!isPlain(value))
|
|
131
|
+
return value
|
|
132
|
+
const desc = Object.getOwnPropertyDescriptor(obj, key)
|
|
133
|
+
if (desc !== undefined && !desc.configurable && !desc.writable && !desc.get)
|
|
134
|
+
return value
|
|
135
|
+
return wrap(value)
|
|
104
136
|
},
|
|
105
137
|
set(obj, key, value, receiver) {
|
|
106
138
|
const rawValue = unwrap(value)
|