prunelle 0.1.1 → 0.5.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 +23 -19
- 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 +91 -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 +654 -0
- package/src/cli/check-links.ts +619 -0
- package/src/cli/check.ts +52 -5
- package/src/cli/commands.ts +86 -4
- package/src/cli/docs.ts +402 -0
- package/src/cli/inspect.ts +31 -2
- package/src/cli/mcp-tools.ts +480 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +2 -2
- package/src/cli/render.ts +261 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +137 -16
- package/src/compiler/analyze.ts +20 -6
- package/src/compiler/cacheability.ts +592 -0
- package/src/compiler/compliance-rgaa.ts +502 -0
- package/src/compiler/compliance.ts +120 -221
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +12 -11
- package/src/compiler/expr-context.ts +167 -57
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +56 -17
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +216 -84
- 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 +4 -1
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +2 -2
- package/src/dom/island.ts +11 -10
- package/src/plugins/config.ts +4 -4
- package/src/plugins/index.ts +2 -2
- package/src/plugins/public.ts +5 -2
- package/src/plugins/services.ts +62 -0
- package/src/plugins/types.ts +32 -0
- 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/errors.ts +303 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +128 -31
- package/src/server/index.ts +230 -260
- 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 +120 -1
- package/src/ssr/region.ts +31 -19
- package/src/test/browser.ts +6 -0
- package/src/test/index.ts +17 -3
- package/src/ts-plugin/diagnostics.ts +378 -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/dev/watchers.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { FSWatcher } from 'node:fs'
|
|
4
4
|
import type { loadConfig } from '../plugins/index'
|
|
5
5
|
import { existsSync, readFileSync, realpathSync, statSync, watch } from 'node:fs'
|
|
6
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path'
|
|
6
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path'
|
|
7
7
|
import { isInNodeModules } from '../build/files'
|
|
8
8
|
import { isInside } from '../build/is-inside'
|
|
9
9
|
import { createAppContext, resolvePlugins, runWithAppContext } from '../plugins/index'
|
|
@@ -54,6 +54,33 @@ export function localImports(entry: string): string[] {
|
|
|
54
54
|
|
|
55
55
|
const isInsideDir = (parent: string, target: string): boolean => isInside(parent, target, { orSame: true })
|
|
56
56
|
|
|
57
|
+
/** Watches files through their parent directory (filtering by basename) so atomic rename saves on Linux keep firing. */
|
|
58
|
+
function watchFilesByParentDir(files: Iterable<string>, onMatch: (filename: string) => void, out: FSWatcher[]): void {
|
|
59
|
+
const byDir = new Map<string, Set<string>>()
|
|
60
|
+
for (const file of files) {
|
|
61
|
+
const dir = dirname(file)
|
|
62
|
+
if (!existsSync(dir))
|
|
63
|
+
continue
|
|
64
|
+
let names = byDir.get(dir)
|
|
65
|
+
if (names === undefined) {
|
|
66
|
+
names = new Set()
|
|
67
|
+
byDir.set(dir, names)
|
|
68
|
+
}
|
|
69
|
+
names.add(basename(file))
|
|
70
|
+
}
|
|
71
|
+
for (const [dir, names] of byDir) {
|
|
72
|
+
try {
|
|
73
|
+
out.push(watch(dir, (_ev, filename) => {
|
|
74
|
+
if (typeof filename === 'string' && names.has(filename))
|
|
75
|
+
onMatch(filename)
|
|
76
|
+
}))
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
console.warn(`[prunelle dev] could not watch ${dir}: ${err instanceof Error ? err.message : String(err)}`)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
57
84
|
export interface DevWatcherOptions {
|
|
58
85
|
root: string
|
|
59
86
|
devRoot: string
|
|
@@ -67,6 +94,7 @@ export function createDevWatchers({ root, devRoot, srcDir, routesDir, schedule }
|
|
|
67
94
|
const dirWatchers = new Map<string, FSWatcher>()
|
|
68
95
|
const pluginWatchers: FSWatcher[] = []
|
|
69
96
|
const graphWatchers = new Map<string, FSWatcher>()
|
|
97
|
+
const rootGraphFiles = new Set<string>()
|
|
70
98
|
let activeRoutesDir = resolve(root, routesDir ?? 'src/routes')
|
|
71
99
|
let activePublicDir = resolve(root, 'public')
|
|
72
100
|
let builtPublic = new Set<string>()
|
|
@@ -120,6 +148,7 @@ export function createDevWatchers({ root, devRoot, srcDir, routesDir, schedule }
|
|
|
120
148
|
w.close()
|
|
121
149
|
pluginWatchers.length = 0
|
|
122
150
|
const seen = new Set<string>(dirWatchers.keys())
|
|
151
|
+
const watchFiles: string[] = []
|
|
123
152
|
const watchCtx = createAppContext({ root, outDir: devRoot, publicDir: activePublicDir, assetPrefix, site: cfg.site, dev: true })
|
|
124
153
|
for (const plugin of resolvePlugins(cfg.plugins)) {
|
|
125
154
|
const paths = runWithAppContext(watchCtx, () =>
|
|
@@ -129,14 +158,18 @@ export function createDevWatchers({ root, devRoot, srcDir, routesDir, schedule }
|
|
|
129
158
|
if (seen.has(abs) || !existsSync(abs))
|
|
130
159
|
continue
|
|
131
160
|
seen.add(abs)
|
|
132
|
-
|
|
133
|
-
|
|
161
|
+
if (statSync(abs).isDirectory())
|
|
162
|
+
pluginWatchers.push(watch(abs, { recursive: true }, () => schedule('full')))
|
|
163
|
+
else
|
|
164
|
+
watchFiles.push(abs)
|
|
134
165
|
}
|
|
135
166
|
}
|
|
167
|
+
watchFilesByParentDir(watchFiles, () => schedule('full'), pluginWatchers)
|
|
136
168
|
},
|
|
137
169
|
|
|
138
170
|
syncBuild(watchedFiles: ReadonlySet<string>, publicFiles: readonly string[]): void {
|
|
139
171
|
builtPublic = new Set(publicFiles)
|
|
172
|
+
rootGraphFiles.clear()
|
|
140
173
|
const nextDirs = new Set<string>()
|
|
141
174
|
let realRoot: string
|
|
142
175
|
try {
|
|
@@ -151,10 +184,11 @@ export function createDevWatchers({ root, devRoot, srcDir, routesDir, schedule }
|
|
|
151
184
|
if (isInsideDir(devRoot, file) || isInsideDir(join(root, '.prunelle-cache'), file))
|
|
152
185
|
continue
|
|
153
186
|
const dir = dirname(file)
|
|
154
|
-
//
|
|
187
|
+
// Never watch unfiltered project root (which would fire on .prunelle-dev, .prunelle-cache, lockfiles); filter to tracked root filenames in watchRoot.
|
|
155
188
|
if (dir === root || dir === realRoot) {
|
|
156
|
-
if (file
|
|
157
|
-
|
|
189
|
+
if (file !== join(root, 'prunelle.config.ts') && file !== join(realRoot, 'prunelle.config.ts'))
|
|
190
|
+
rootGraphFiles.add(basename(file))
|
|
191
|
+
continue
|
|
158
192
|
}
|
|
159
193
|
if (isCoveredByStaticWatchers(dir))
|
|
160
194
|
continue
|
|
@@ -181,17 +215,19 @@ export function createDevWatchers({ root, devRoot, srcDir, routesDir, schedule }
|
|
|
181
215
|
}
|
|
182
216
|
},
|
|
183
217
|
|
|
184
|
-
// The root, non-recursively: prunelle.config.ts, and a public, routes or src folder created after startup; with `configImports`, the local files prunelle.config.ts imports too.
|
|
218
|
+
// The root, non-recursively: prunelle.config.ts, tracked root graph files, and a public, routes or src folder created after startup; with `configImports`, the local files prunelle.config.ts imports too.
|
|
185
219
|
watchRoot(currentConfig: () => PrunelleConfig, configImports: boolean): void {
|
|
186
|
-
if (configImports)
|
|
187
|
-
|
|
188
|
-
rootWatchers.push(watch(file, () => schedule('config')))
|
|
189
|
-
}
|
|
220
|
+
if (configImports)
|
|
221
|
+
watchFilesByParentDir(localImports(join(root, 'prunelle.config.ts')), () => schedule('config'), rootWatchers)
|
|
190
222
|
rootWatchers.push(watch(root, (_ev, filename) => {
|
|
191
223
|
if (filename === 'prunelle.config.ts') {
|
|
192
224
|
schedule('config')
|
|
193
225
|
return
|
|
194
226
|
}
|
|
227
|
+
if (typeof filename === 'string' && rootGraphFiles.has(filename)) {
|
|
228
|
+
schedule(srcChangeKind(filename))
|
|
229
|
+
return
|
|
230
|
+
}
|
|
195
231
|
const changed = typeof filename === 'string' && filename !== '' ? resolve(root, filename) : undefined
|
|
196
232
|
for (const dir of [activePublicDir, activeRoutesDir, srcDir]) {
|
|
197
233
|
if (!dirWatchers.has(dir) && existsSync(dir) && (changed === undefined || isInsideDir(changed, dir))) {
|
package/src/dom/action.ts
CHANGED
|
@@ -88,7 +88,10 @@ export function useAction<Input, Output>(
|
|
|
88
88
|
fieldErrors,
|
|
89
89
|
data,
|
|
90
90
|
get action() {
|
|
91
|
-
|
|
91
|
+
const u = action.url || String(action)
|
|
92
|
+
if ('__pruAction' in action)
|
|
93
|
+
(globalThis as { __pruAct?: (url: string, act: unknown) => void }).__pruAct?.(u, action)
|
|
94
|
+
return u
|
|
92
95
|
},
|
|
93
96
|
onSubmit(event) {
|
|
94
97
|
event.preventDefault()
|
package/src/dom/attrs.ts
CHANGED
|
@@ -24,13 +24,22 @@ export function setClass(el: Element, value: unknown): void {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
const XLINK_NS = 'http://www.w3.org/1999/xlink'
|
|
28
|
+
|
|
27
29
|
export function setAttr(el: Element, name: string, value: unknown): void {
|
|
28
30
|
if (isBlockedAttr(name))
|
|
29
31
|
return
|
|
30
32
|
if (process.env.NODE_ENV !== 'production')
|
|
31
33
|
assertRenderable(value, name)
|
|
34
|
+
const isXlink = name === 'xlink:href'
|
|
35
|
+
const remove = (): void => {
|
|
36
|
+
if (isXlink)
|
|
37
|
+
el.removeAttributeNS(XLINK_NS, 'href')
|
|
38
|
+
else
|
|
39
|
+
el.removeAttribute(name)
|
|
40
|
+
}
|
|
32
41
|
if (value == null) {
|
|
33
|
-
|
|
42
|
+
remove()
|
|
34
43
|
}
|
|
35
44
|
else if (typeof value === 'boolean') {
|
|
36
45
|
if (isStringBoolAttr(name))
|
|
@@ -38,12 +47,15 @@ export function setAttr(el: Element, name: string, value: unknown): void {
|
|
|
38
47
|
else if (value)
|
|
39
48
|
el.setAttribute(name, '')
|
|
40
49
|
else
|
|
41
|
-
|
|
50
|
+
remove()
|
|
42
51
|
}
|
|
43
52
|
else if (isUnsafeUrlAttr(name, value, el.tagName)) {
|
|
44
53
|
if (process.env.NODE_ENV !== 'production')
|
|
45
54
|
console.warn(`prunelle: dropped unsafe URL on <${el.tagName.toLowerCase()} ${name}>.`)
|
|
46
|
-
|
|
55
|
+
remove()
|
|
56
|
+
}
|
|
57
|
+
else if (isXlink) {
|
|
58
|
+
el.setAttributeNS(XLINK_NS, name, String(value))
|
|
47
59
|
}
|
|
48
60
|
else {
|
|
49
61
|
el.setAttribute(name, String(value))
|
package/src/dom/extras.ts
CHANGED
|
@@ -61,7 +61,7 @@ export function propDefault<T>(fn: () => T, now: boolean): () => T {
|
|
|
61
61
|
let done = false
|
|
62
62
|
const get = (): T => {
|
|
63
63
|
if (!done) {
|
|
64
|
-
value = fn
|
|
64
|
+
value = untrack(fn)
|
|
65
65
|
done = true
|
|
66
66
|
}
|
|
67
67
|
return value
|
|
@@ -127,7 +127,7 @@ export function spread(el: Element, getProps: () => Record<string, unknown> | nu
|
|
|
127
127
|
if (!isBlockedAttr(name)) {
|
|
128
128
|
if (DOM_PROPS.has(name))
|
|
129
129
|
setProp(el, name, name === 'value' ? '' : false)
|
|
130
|
-
el
|
|
130
|
+
setAttr(el, name, null)
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
}
|
package/src/dom/island.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Native <pru-island> Custom Element: the build defines which strategies an app uses, so the loader drops the code of the others.
|
|
2
2
|
|
|
3
|
-
import { hydrate, mount } from './index'
|
|
4
|
-
|
|
3
|
+
import type { hydrate, mount } from './index'
|
|
5
4
|
|
|
6
5
|
declare const PRUNELLE_VISIBLE: boolean | undefined
|
|
7
6
|
declare const PRUNELLE_IDLE: boolean | undefined
|
|
@@ -14,7 +13,8 @@ declare const PRUNELLE_REVIVE: string | undefined
|
|
|
14
13
|
// Only props holding a Date, Map, Set or another tagged value load the revivers: plain JSON parses with no extra file.
|
|
15
14
|
const reviver = (): Promise<typeof import('./revive')> => typeof PRUNELLE_REVIVE === 'undefined' ? import('./revive') : import(PRUNELLE_REVIVE)
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
// An island chunk also re-exports the DOM runtime it imports (`writeClientEntries`), `mount` only in an app with a client-only island.
|
|
17
|
+
type IslandModule = { default: (props: Record<string, unknown>) => Node | DocumentFragment | null, hydrate: typeof hydrate, mount?: typeof mount }
|
|
18
18
|
|
|
19
19
|
/** Finds this island's own `<script type="application/json" data-pru-props>` direct child. */
|
|
20
20
|
function findOwnPropsScript(root: Element): Element | null {
|
|
@@ -91,18 +91,19 @@ function replayEvent(root: Element, ev: Event, target: EventTarget | null): void
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
function isAllowedChunkUrl(chunk: string): boolean {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return chunk[1] !== '/' && chunk[1] !== '\\'
|
|
94
|
+
if (/[\u0000-\u0020\u007F]/.test(chunk))
|
|
95
|
+
return false
|
|
97
96
|
if (typeof location !== 'undefined' && location.origin && location.origin !== 'null') {
|
|
98
97
|
try {
|
|
99
|
-
|
|
100
|
-
return parsed.origin === location.origin
|
|
98
|
+
return new URL(chunk, location.href).origin === location.origin
|
|
101
99
|
}
|
|
102
100
|
catch {
|
|
103
101
|
return false
|
|
104
102
|
}
|
|
105
103
|
}
|
|
104
|
+
// A browser reads `//host` and `/\host` as another site.
|
|
105
|
+
if (chunk[0] === '/')
|
|
106
|
+
return chunk[1] !== '/' && chunk[1] !== '\\'
|
|
106
107
|
return !/^(?:javascript|data|vbscript):/i.test(chunk)
|
|
107
108
|
}
|
|
108
109
|
|
|
@@ -262,8 +263,8 @@ export function defineIslandElement(): void {
|
|
|
262
263
|
const idPrefix = this.getAttribute('i') ?? `c${clientIslandIdSeq++}-`
|
|
263
264
|
const render = () => loaded.default(props)
|
|
264
265
|
dispose = (typeof PRUNELLE_CLIENT_ONLY === 'undefined' || PRUNELLE_CLIENT_ONLY) && clientOnly
|
|
265
|
-
? mount(this, render, idPrefix)
|
|
266
|
-
: hydrate(this, render, idPrefix)
|
|
266
|
+
? loaded.mount!(this, render, idPrefix)
|
|
267
|
+
: loaded.hydrate(this, render, idPrefix)
|
|
267
268
|
if (!this.isConnected || token !== this._t) {
|
|
268
269
|
dispose()
|
|
269
270
|
return
|
package/src/plugins/config.ts
CHANGED
|
@@ -6,17 +6,17 @@ export function defineConfig(config: PrunelleConfig): PrunelleConfig {
|
|
|
6
6
|
return config
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
/** Forwards every runtime key from `prunelle.config.ts`, stripping build/CLI-only keys (`routesDir`, `outDir`, `publicDir`, `port`, `compliance`). */
|
|
9
|
+
/** Forwards every runtime key from `prunelle.config.ts`, stripping build/CLI-only keys (`routesDir`, `outDir`, `publicDir`, `port`, `compliance`, `autoPrerender`). */
|
|
10
10
|
export function pickRuntimeConfig(config: PrunelleConfig | undefined): ServerRuntimeConfig {
|
|
11
11
|
if (config === undefined)
|
|
12
12
|
return {}
|
|
13
|
-
const { routesDir: _r, outDir: _o, publicDir: _p, port: _pt, compliance: _c, ...runtime } = config
|
|
13
|
+
const { routesDir: _r, outDir: _o, publicDir: _p, port: _pt, compliance: _c, autoPrerender: _ap, ...runtime } = config
|
|
14
14
|
return runtime
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// Typed as records so that a key added to the config types without being listed here fails the typecheck.
|
|
18
|
-
const RUNTIME_KEYS: Record<keyof ServerRuntimeConfig, true> = { site: true, lang: true, assetPrefix: true, security: true, trustedOrigins: true, trustProxy: true, maxRequestBodySize: true, navigation: true, streamTimeout: true, consent: true, compress: true, onError: true, plugins: true }
|
|
19
|
-
const BUILD_KEYS: Record<Exclude<keyof PrunelleConfig, keyof ServerRuntimeConfig>, true> = { port: true, routesDir: true, outDir: true, publicDir: true, compliance: true }
|
|
18
|
+
const RUNTIME_KEYS: Record<keyof ServerRuntimeConfig, true> = { site: true, lang: true, assetPrefix: true, security: true, trustedOrigins: true, trustProxy: true, maxRequestBodySize: true, navigation: true, streamTimeout: true, consent: true, compress: true, routeCache: true, healthCheck: true, onError: true, plugins: true }
|
|
19
|
+
const BUILD_KEYS: Record<Exclude<keyof PrunelleConfig, keyof ServerRuntimeConfig>, true> = { port: true, routesDir: true, outDir: true, publicDir: true, compliance: true, autoPrerender: true }
|
|
20
20
|
const RUNTIME_CONFIG_KEYS = Object.keys(RUNTIME_KEYS) as (keyof ServerRuntimeConfig)[]
|
|
21
21
|
const CONFIG_KEYS = [...RUNTIME_CONFIG_KEYS, ...Object.keys(BUILD_KEYS)]
|
|
22
22
|
|
package/src/plugins/index.ts
CHANGED
|
@@ -7,8 +7,8 @@ export { createAppContext, getAppContext, runWithAppContext } from './context'
|
|
|
7
7
|
export type { AppRuntimeContext, CreateAppContextOptions } from './context'
|
|
8
8
|
export { loadConfig } from './load'
|
|
9
9
|
export { resolvePlugins } from './order'
|
|
10
|
-
export { CONTENT_IMAGE_RESOLVER_SERVICE, I18N_CONFIG_SERVICE, serviceKey } from './services'
|
|
11
|
-
export type { ActiveI18nConfig, ContentImageResolver, ContentImageResult, ServiceKey } from './services'
|
|
10
|
+
export { CMS_INLINE_ENABLED_SERVICE, CONTENT_COLLECTIONS_SERVICE, CONTENT_IMAGE_RESOLVER_SERVICE, I18N_CONFIG_SERVICE, JOBS_SERVICE, serviceKey } from './services'
|
|
11
|
+
export type { AccessedContentEntry, ActiveI18nConfig, ContentCollectionDescriptor, ContentCollectionEntrySummary, ContentCollectionsService, ContentImageResolver, ContentImageResult, JobsEnqueueOptions, JobsQueueOptions, JobsService, ServiceKey } from './services'
|
|
12
12
|
export type { ComplianceConfig, ComplianceRule } from '../compiler/compliance'
|
|
13
13
|
export type { ConsentConfig } from '../server/consent'
|
|
14
14
|
export type { BuildPluginContext, BuildPluginTarget, CheckPluginContext, DocumentHeadContext, FinalizeBuildContext, PrunelleConfig, PrunellePlugin, MiddlewareOptions, PluginRouteOptions, RequiresPluginContext, ServerErrorInfo, ServerPluginAPI, ServerRuntimeConfig } from './types'
|
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, serviceKey } from './services'
|
|
12
|
+
export type { AccessedContentEntry, ActiveI18nConfig, ContentCollectionDescriptor, ContentCollectionEntrySummary, ContentCollectionsService, ContentImageResolver, ContentImageResult, JobsEnqueueOptions, JobsQueueOptions, JobsService, ServiceKey } 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,62 @@ 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
|
+
}
|
|
96
|
+
|
|
97
|
+
export const JOBS_SERVICE = serviceKey<JobsService>('prunelle.jobs.service')
|
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
|
|
@@ -72,6 +86,10 @@ export interface CheckPluginContext {
|
|
|
72
86
|
error(message: string): void
|
|
73
87
|
/** Report what may be intended but usually is not; `prunelle check --strict` fails on it. */
|
|
74
88
|
warn(message: string): void
|
|
89
|
+
/** Register a check-scoped service for downstream plugins. */
|
|
90
|
+
provide?<T>(key: ServiceKey<T>, value: T): void
|
|
91
|
+
/** Look up a check-scoped service registered by an earlier plugin. */
|
|
92
|
+
inject?<T>(key: ServiceKey<T>): T | undefined
|
|
75
93
|
}
|
|
76
94
|
|
|
77
95
|
export interface RequiresPluginContext {
|
|
@@ -89,6 +107,11 @@ export interface PluginRouteOptions {
|
|
|
89
107
|
trustProxy?: TrustProxy | undefined
|
|
90
108
|
/** How often one client may call the route: past `max` per `windowMs`, it answers 429 with `Retry-After` before the handler runs. */
|
|
91
109
|
rateLimit?: RateLimit<RequestContext> | undefined
|
|
110
|
+
/**
|
|
111
|
+
* Let the route's catch-all take a segment with an encoded `/`, `\` or NUL (`%2F`, `%5C`, `%00`), which every route refuses by default.
|
|
112
|
+
* 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.
|
|
113
|
+
*/
|
|
114
|
+
encodedSlashes?: boolean | undefined
|
|
92
115
|
}
|
|
93
116
|
|
|
94
117
|
export interface MiddlewareOptions {
|
|
@@ -126,6 +149,8 @@ export interface ServerPluginAPI {
|
|
|
126
149
|
inject<T>(key: ServiceKey<T>): T | undefined
|
|
127
150
|
/** Read persisted build data from `manifest.pluginData` (defaults to the current plugin's name). */
|
|
128
151
|
getBuildData<T = Record<string, unknown>>(pluginName?: string): T | undefined
|
|
152
|
+
/** Register a named health check evaluated on `GET ${assetPrefix}/health`. */
|
|
153
|
+
healthCheck(name: string, fn: HealthCheckFn): void
|
|
129
154
|
/** Register a shutdown cleanup callback run when `app.dispose()` is called (dev reloads, tests, graceful exit). */
|
|
130
155
|
onShutdown(fn: () => void | Promise<void>): void
|
|
131
156
|
}
|
|
@@ -134,6 +159,7 @@ export interface ServerErrorInfo {
|
|
|
134
159
|
error: unknown
|
|
135
160
|
request: Request
|
|
136
161
|
source: 'route' | 'action' | 'plugin'
|
|
162
|
+
requestId?: string | undefined
|
|
137
163
|
}
|
|
138
164
|
|
|
139
165
|
export interface DocumentHeadContext {
|
|
@@ -215,6 +241,10 @@ export interface ServerRuntimeConfig {
|
|
|
215
241
|
/** CNIL/RGPD consent categories, cookie name, retention, and POST endpoint. */
|
|
216
242
|
consent?: ConsentConfig | undefined
|
|
217
243
|
compress?: boolean | undefined
|
|
244
|
+
/** Bounded in-memory cache for routes exporting `export const cache = ...` (default: 500 entries / 32 MiB; set `false` to disable). */
|
|
245
|
+
routeCache?: RouteCacheOptions | false | undefined
|
|
246
|
+
/** Health check function or named check map evaluated on `GET ${assetPrefix}/health`. */
|
|
247
|
+
healthCheck?: HealthCheckConfig | undefined
|
|
218
248
|
onError?: ((info: ServerErrorInfo) => void) | undefined
|
|
219
249
|
plugins?: PrunellePlugin[] | undefined
|
|
220
250
|
}
|
|
@@ -226,4 +256,6 @@ export interface PrunelleConfig extends ServerRuntimeConfig {
|
|
|
226
256
|
publicDir?: string | undefined
|
|
227
257
|
/** French web law compliance checks (RGAA, RGPD, LCEN) configuration and rule silencing. */
|
|
228
258
|
compliance?: ComplianceConfig | undefined
|
|
259
|
+
/** Automatically prerender static pages that read nothing from the request or clock (and have no middleware or `cache` export). */
|
|
260
|
+
autoPrerender?: boolean | undefined
|
|
229
261
|
}
|