prunelle 0.8.0 → 0.9.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 +61 -44
- package/package.json +7 -2
- package/src/a11y/declaration.ts +6 -10
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +88 -134
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +14 -6
- package/src/build/index.ts +20 -10
- package/src/build/islands.ts +4 -1
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +19 -1
- package/src/build/plugin-host.ts +2 -0
- package/src/build/prerender.ts +2 -2
- package/src/build/reach.ts +14 -1
- package/src/build/report.ts +1 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +24 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +2 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +16 -100
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +40 -18
- package/src/cli/commands.ts +134 -14
- package/src/cli/docs.ts +21 -2
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +2 -2
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +284 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +70 -42
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +177 -346
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +170 -121
- package/src/compiler/ssr.ts +25 -440
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +1 -1
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/extras.ts +2 -1
- package/src/dom/field-marks.ts +24 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +25 -5
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/prefetch.ts +132 -0
- package/src/dom/regions.ts +498 -0
- package/src/dom/swap.ts +245 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +39 -40
- package/src/eco/index.ts +5 -5
- package/src/href.ts +31 -0
- package/src/index.ts +9 -3
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +8 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +120 -9
- package/src/reactivity/hmr.ts +90 -0
- package/src/reactivity/index.ts +38 -18
- package/src/reactivity/resource.ts +115 -0
- package/src/reactivity/seed.ts +39 -0
- package/src/reactivity/server-seed.ts +194 -0
- package/src/reactivity/store.ts +55 -1
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-registry.ts +6 -8
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +96 -0
- package/src/server/compress.ts +3 -1
- package/src/server/consent.ts +16 -2
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +50 -0
- package/src/server/csp-report.ts +86 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +2 -2
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +33 -12
- package/src/server/http.ts +25 -10
- package/src/server/index.ts +101 -298
- package/src/server/loader.ts +1 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +26 -8
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +39 -10
- package/src/server/region.ts +3 -0
- package/src/server/request-handler.ts +370 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +41 -6
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +35 -19
- package/src/server/routing.ts +12 -11
- package/src/server/sanitize-html.ts +1 -1
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +9 -5
- package/src/server/shared-store.ts +314 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +14 -10
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +48 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +26 -3
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +23 -13
- package/src/ssr/navigation.ts +161 -14
- package/src/test/browser.ts +50 -22
- package/src/test/build-reuse.ts +70 -0
- package/src/test/index.ts +45 -6
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +3674 -2196
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// How each name a destructuring pattern binds is read from a source expression, so a destructured prop or loop row stays reactive.
|
|
2
|
+
|
|
3
|
+
import type { Node, ObjectPattern } from 'oxc-parser'
|
|
4
|
+
import { walk } from './ast'
|
|
5
|
+
import { SourceEditor } from './patch'
|
|
6
|
+
import { referencesAny } from './scope'
|
|
7
|
+
import { collectPatternNames, containsJsx } from './shared'
|
|
8
|
+
|
|
9
|
+
export interface PatternContext {
|
|
10
|
+
code: string
|
|
11
|
+
jsxNodes: WeakSet<Node>
|
|
12
|
+
use: (name: string) => string
|
|
13
|
+
freshVar: (prefix?: string) => string
|
|
14
|
+
compileExpression: (node: Node, rewrites: ReadonlyMap<string, string>) => string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function hoistInto(ctx: PatternContext, hoisted: string[], init: string): string {
|
|
18
|
+
const name = ctx.freshVar('__d')
|
|
19
|
+
hoisted.push(`const ${name} = ${init};`)
|
|
20
|
+
return name
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isReactiveDefault(node: Node, running: ReadonlyMap<string, string>): boolean {
|
|
24
|
+
if (running.size > 0 && referencesAny(node, new Set(running.keys())))
|
|
25
|
+
return true
|
|
26
|
+
let readsValue = false
|
|
27
|
+
walk(node, (child) => {
|
|
28
|
+
if (readsValue)
|
|
29
|
+
return false
|
|
30
|
+
if (child.type === 'ArrowFunctionExpression' || child.type === 'FunctionExpression' || child.type === 'FunctionDeclaration')
|
|
31
|
+
return false
|
|
32
|
+
if (child.type === 'MemberExpression' && !child.computed && child.property.type === 'Identifier' && child.property.name === 'value') {
|
|
33
|
+
readsValue = true
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
return undefined
|
|
37
|
+
})
|
|
38
|
+
return readsValue
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Walks a pattern, recording in `reads` how each identifier is read from `src`. With `hoisted`, defaults and computed keys become statements for the start of the body.
|
|
42
|
+
function createBinder(
|
|
43
|
+
ctx: PatternContext,
|
|
44
|
+
reads: Map<string, string>,
|
|
45
|
+
running: Map<string, string>,
|
|
46
|
+
hoisted: string[] | undefined,
|
|
47
|
+
): (pat: Node, src: string) => void {
|
|
48
|
+
const { jsxNodes, use, freshVar, compileExpression } = ctx
|
|
49
|
+
|
|
50
|
+
const hoist = (init: string): string => hoistInto(ctx, hoisted!, init)
|
|
51
|
+
|
|
52
|
+
function bindDefault(pat: Extract<Node, { type: 'AssignmentPattern' }>, src: string): void {
|
|
53
|
+
const defExpr = compileExpression(pat.right, running)
|
|
54
|
+
const simpleDef = pat.right.type === 'Literal' || pat.right.type === 'Identifier'
|
|
55
|
+
const reactiveDef = !simpleDef && !containsJsx(pat.right, jsxNodes) && isReactiveDefault(pat.right, running)
|
|
56
|
+
let fallback = simpleDef ? defExpr : `(${defExpr})`
|
|
57
|
+
if (!simpleDef && !reactiveDef && hoisted !== undefined)
|
|
58
|
+
fallback = `${hoist(`${use('propDefault')}(() => (${defExpr}), ${src} === undefined)`)}()`
|
|
59
|
+
let nextSrc: string
|
|
60
|
+
if (pat.left.type !== 'Identifier' && hoisted !== undefined) {
|
|
61
|
+
const v = freshVar('__v')
|
|
62
|
+
nextSrc = `${hoist(`() => { const ${v} = ${src}; return ${v} === undefined ? ${fallback} : ${v}; }`)}()`
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
nextSrc = `(${src} === undefined ? ${fallback} : ${src})`
|
|
66
|
+
}
|
|
67
|
+
bind(pat.left, nextSrc)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function bindObject(pat: Extract<Node, { type: 'ObjectPattern' }>, src: string): void {
|
|
71
|
+
const excludedKeys: string[] = []
|
|
72
|
+
let canOmit = hoisted !== undefined
|
|
73
|
+
for (const prop of pat.properties) {
|
|
74
|
+
if (prop.type === 'RestElement') {
|
|
75
|
+
if (canOmit) {
|
|
76
|
+
const restRead = `${use('omit')}(${src}, [${excludedKeys.join(', ')}])`
|
|
77
|
+
bind(prop.argument, restRead)
|
|
78
|
+
}
|
|
79
|
+
continue
|
|
80
|
+
}
|
|
81
|
+
let propSrc: string | undefined
|
|
82
|
+
if (!prop.computed && prop.key.type === 'Identifier') {
|
|
83
|
+
excludedKeys.push(JSON.stringify(prop.key.name))
|
|
84
|
+
propSrc = `${src}.${prop.key.name}`
|
|
85
|
+
}
|
|
86
|
+
else if (!prop.computed && prop.key.type === 'Literal' && (typeof prop.key.value === 'string' || typeof prop.key.value === 'number')) {
|
|
87
|
+
excludedKeys.push(JSON.stringify(String(prop.key.value)))
|
|
88
|
+
propSrc = `${src}[${JSON.stringify(prop.key.value)}]`
|
|
89
|
+
}
|
|
90
|
+
else if (prop.computed && hoisted !== undefined) {
|
|
91
|
+
const keyVar = hoist(compileExpression(prop.key, running))
|
|
92
|
+
excludedKeys.push(`typeof ${keyVar} === 'symbol' ? ${keyVar} : String(${keyVar})`)
|
|
93
|
+
propSrc = `${src}[${keyVar}]`
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
canOmit = false
|
|
97
|
+
}
|
|
98
|
+
if (propSrc !== undefined)
|
|
99
|
+
bind(prop.value, propSrc)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function bind(pat: Node, src: string): void {
|
|
104
|
+
if (pat.type === 'Identifier') {
|
|
105
|
+
reads.set(pat.name, src)
|
|
106
|
+
running.set(pat.name, src)
|
|
107
|
+
}
|
|
108
|
+
else if (pat.type === 'AssignmentPattern') {
|
|
109
|
+
bindDefault(pat, src)
|
|
110
|
+
}
|
|
111
|
+
else if (pat.type === 'ObjectPattern') {
|
|
112
|
+
bindObject(pat, src)
|
|
113
|
+
}
|
|
114
|
+
else if (pat.type === 'ArrayPattern') {
|
|
115
|
+
for (let i = 0; i < pat.elements.length; i++) {
|
|
116
|
+
const el = pat.elements[i]
|
|
117
|
+
if (el == null)
|
|
118
|
+
continue
|
|
119
|
+
if (el.type === 'RestElement')
|
|
120
|
+
bind(el.argument, `Array.from(${src}).slice(${i})`)
|
|
121
|
+
else
|
|
122
|
+
bind(el, `${src}[${i}]`)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return bind
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// The source of a pattern node as a getter parameter: type annotations dropped, defaults and computed keys compiled.
|
|
131
|
+
function compilePatternSource(ctx: PatternContext, patNode: Node, outerRewrites: ReadonlyMap<string, string>): string {
|
|
132
|
+
const sub = new SourceEditor(ctx.code.slice(patNode.start, patNode.end))
|
|
133
|
+
const base = patNode.start
|
|
134
|
+
const patchPattern = (p: Node | null | undefined): void => {
|
|
135
|
+
if (p === null || p === undefined)
|
|
136
|
+
return
|
|
137
|
+
if ('typeAnnotation' in p && p.typeAnnotation != null) {
|
|
138
|
+
const ann = p.typeAnnotation as Node
|
|
139
|
+
sub.remove(ann.start - base, ann.end - base)
|
|
140
|
+
}
|
|
141
|
+
switch (p.type) {
|
|
142
|
+
case 'AssignmentPattern':
|
|
143
|
+
patchPattern(p.left)
|
|
144
|
+
sub.replace(p.right.start - base, p.right.end - base, ctx.compileExpression(p.right, outerRewrites))
|
|
145
|
+
return
|
|
146
|
+
case 'RestElement':
|
|
147
|
+
patchPattern(p.argument)
|
|
148
|
+
return
|
|
149
|
+
case 'ArrayPattern':
|
|
150
|
+
for (const el of p.elements)
|
|
151
|
+
patchPattern(el)
|
|
152
|
+
return
|
|
153
|
+
case 'ObjectPattern':
|
|
154
|
+
for (const prop of p.properties) {
|
|
155
|
+
if (prop.type === 'RestElement') {
|
|
156
|
+
patchPattern(prop.argument)
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (prop.computed)
|
|
160
|
+
sub.replace(prop.key.start - base, prop.key.end - base, ctx.compileExpression(prop.key, outerRewrites))
|
|
161
|
+
patchPattern(prop.value)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
patchPattern(patNode)
|
|
167
|
+
return sub.toString()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// The pattern a read runs: only the property binding `name`, so another property's default does not run on this read.
|
|
171
|
+
function patternFor(ctx: PatternContext, pattern: Node, name: string, outerRewrites: ReadonlyMap<string, string>): string {
|
|
172
|
+
if (pattern.type === 'ObjectPattern') {
|
|
173
|
+
for (const prop of (pattern as ObjectPattern).properties) {
|
|
174
|
+
const bound = new Set<string>()
|
|
175
|
+
collectPatternNames(prop.type === 'RestElement' ? prop.argument : prop.value, bound)
|
|
176
|
+
if (prop.type === 'Property' && bound.has(name)) {
|
|
177
|
+
const sub = new SourceEditor(ctx.code.slice(prop.start, prop.end))
|
|
178
|
+
const base = prop.start
|
|
179
|
+
if (prop.computed)
|
|
180
|
+
sub.replace(prop.key.start - base, prop.key.end - base, ctx.compileExpression(prop.key, outerRewrites))
|
|
181
|
+
sub.replace(prop.value.start - base, prop.value.end - base, compilePatternSource(ctx, prop.value, outerRewrites))
|
|
182
|
+
return `{ ${sub.toString()} }`
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return compilePatternSource(ctx, pattern, outerRewrites)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// How each name a destructuring pattern binds is read from `source` on every access, so reads stay reactive.
|
|
190
|
+
// With `hoisted`, a default (at any nesting depth) and a nested pattern's getter become statements for the start of the body (evaluated once per call/row) instead of running on every read.
|
|
191
|
+
export function patternReads(
|
|
192
|
+
ctx: PatternContext,
|
|
193
|
+
pattern: Node,
|
|
194
|
+
source: string,
|
|
195
|
+
outerRewrites: ReadonlyMap<string, string>,
|
|
196
|
+
hoisted?: string[],
|
|
197
|
+
): Map<string, string> {
|
|
198
|
+
const reads = new Map<string, string>()
|
|
199
|
+
const running = new Map(outerRewrites)
|
|
200
|
+
createBinder(ctx, reads, running, hoisted)(pattern, source)
|
|
201
|
+
|
|
202
|
+
const names = new Set<string>()
|
|
203
|
+
collectPatternNames(pattern, names)
|
|
204
|
+
for (const name of names) {
|
|
205
|
+
if (reads.has(name))
|
|
206
|
+
continue
|
|
207
|
+
const getter = `(${patternFor(ctx, pattern, name, outerRewrites)}) => ${name}`
|
|
208
|
+
reads.set(name, hoisted === undefined ? `(${getter})(${source})` : `${hoistInto(ctx, hoisted, getter)}(${source})`)
|
|
209
|
+
}
|
|
210
|
+
return reads
|
|
211
|
+
}
|