prunelle 0.1.1 → 0.7.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/LICENSE +21 -0
- package/llms.txt +137 -40
- package/package.json +11 -2
- package/src/a11y/declaration.ts +369 -0
- package/src/a11y/index.ts +466 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +88 -40
- package/src/build/byte-size.ts +11 -0
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +11 -5
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +13 -10
- package/src/build/ecoindex.ts +230 -0
- package/src/build/files.ts +6 -0
- package/src/build/first-load.ts +83 -11
- package/src/build/graph.ts +29 -39
- package/src/build/index.ts +218 -113
- package/src/build/island-promote.ts +229 -0
- package/src/build/islands.ts +11 -203
- package/src/build/manifest.ts +56 -116
- package/src/build/output.ts +2 -2
- package/src/build/plugin-host.ts +113 -41
- package/src/build/precompress.ts +16 -3
- package/src/build/prerender.ts +173 -38
- package/src/build/reach.ts +136 -0
- package/src/build/render-rules.ts +2 -2
- package/src/build/report.ts +42 -5
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static-headers.ts +93 -0
- package/src/build/static.ts +139 -39
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +610 -0
- package/src/cli/check-imports.ts +25 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +107 -26
- package/src/cli/commands.ts +120 -11
- package/src/cli/docs.ts +403 -0
- package/src/cli/inspect.ts +105 -15
- package/src/cli/mcp-tools.ts +492 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +16 -5
- package/src/cli/render.ts +416 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +156 -18
- package/src/compiler/analyze.ts +68 -14
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability.ts +636 -0
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +614 -0
- package/src/compiler/compliance-urls.ts +145 -0
- package/src/compiler/compliance.ts +355 -351
- 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/foreign-imports.ts +88 -0
- package/src/compiler/mistakes.ts +23 -2
- package/src/compiler/props-body.ts +52 -0
- 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 +42 -14
- package/src/compiler/signal-reads.ts +6 -2
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +220 -89
- package/src/context.ts +34 -0
- package/src/dev/error-log.ts +177 -0
- package/src/dev/host-check.ts +26 -0
- package/src/dev/index.ts +91 -34
- package/src/dev/open-editor.ts +208 -0
- package/src/dev/protocol.ts +3 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +50 -25
- package/src/dev/watchers.ts +74 -13
- package/src/dom/action.ts +47 -21
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +29 -14
- package/src/dom/index.ts +39 -10
- package/src/dom/island.ts +54 -35
- package/src/dom/loop.ts +33 -23
- package/src/eco/declaration.ts +257 -0
- package/src/eco/index.ts +65 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +2 -2
- package/src/plugins/config.ts +8 -7
- package/src/plugins/context.ts +16 -1
- package/src/plugins/index.ts +2 -2
- package/src/plugins/load.ts +30 -10
- package/src/plugins/order.ts +38 -1
- package/src/plugins/public.ts +6 -3
- package/src/plugins/services.ts +84 -0
- package/src/plugins/types.ts +51 -2
- 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-flash.ts +158 -0
- package/src/server/action-protect.ts +199 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +56 -117
- package/src/server/app-secret.ts +63 -0
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +96 -10
- package/src/server/consent.ts +59 -22
- package/src/server/cookies.ts +16 -2
- package/src/server/document.ts +25 -10
- package/src/server/env.ts +14 -0
- package/src/server/errors.ts +305 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +177 -38
- package/src/server/index.ts +264 -272
- package/src/server/loader.ts +11 -2
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +125 -88
- package/src/server/public.ts +6 -5
- package/src/server/rate-limit.ts +102 -36
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +445 -0
- package/src/server/route-table.ts +344 -9
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +112 -63
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +277 -50
- package/src/server/serve-handlers.ts +31 -7
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +87 -11
- package/src/server/stream.ts +68 -27
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +105 -7
- package/src/ssr/index.ts +148 -3
- package/src/ssr/navigation.ts +2 -2
- package/src/ssr/region.ts +31 -19
- package/src/style.ts +32 -1
- 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/gitignore +5 -0
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +15 -1
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/app/.env.example +4 -0
- package/templates/app/package.json +2 -1
- package/templates/app/prunelle.config.ts +2 -0
- package/templates/app/src/auth.ts +4 -6
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +9 -1
- package/templates/app/src/routes/dashboard/index.tsx +42 -8
- package/templates/app/src/routes/login.tsx +49 -30
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +8 -1
- package/templates/app/tests/app.test.ts +44 -3
- package/templates/blog/package.json +1 -1
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/_layout.tsx +6 -1
- package/templates/blog/src/routes/index.tsx +5 -1
- package/templates/blog/src/styles/app.css +6 -1
- package/templates/fullstack/package.json +1 -1
- package/templates/fullstack/src/components/GreetForm.tsx +2 -1
- package/templates/fullstack/src/routes/_layout.tsx +4 -0
- package/templates/fullstack/src/styles/app.css +11 -1
- package/templates/minimal/package.json +1 -1
- package/templates/minimal/src/routes/_layout.tsx +4 -0
- package/templates/minimal/src/styles/app.css +11 -1
- package/ts-plugin.cjs +4277 -0
|
@@ -164,67 +164,151 @@ function emitDomExprAttr(
|
|
|
164
164
|
return ''
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
function emitInnerHtmlOp(ctx: ElementAttrCompileContext, attr: Extract<Node, { type: 'JSXAttribute' }>, targetOps: string[]): void {
|
|
168
|
+
const { elVar, scopeRewrites, use, compileExpression } = ctx
|
|
169
|
+
if (attr.value?.type === 'Literal') {
|
|
170
|
+
targetOps.push(`${use('setInnerHtml')}(${elVar}, ${JSON.stringify(String(attr.value.value))});`)
|
|
171
|
+
}
|
|
172
|
+
else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
|
|
173
|
+
const expr = attr.value.expression
|
|
174
|
+
targetOps.push(wrapDomOp(`${use('setInnerHtml')}(${elVar}, ${compileExpression(expr, scopeRewrites)})`, isStaticDomExpr(expr, scopeRewrites), use))
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function emitRefOp(ctx: ElementAttrCompileContext, expr: Node, targetOps: string[]): void {
|
|
179
|
+
const { elVar, scopeRewrites, compileExpression } = ctx
|
|
180
|
+
const refCode = compileExpression(expr, scopeRewrites)
|
|
181
|
+
const unwrapped = unwrapTsExpr(expr)
|
|
182
|
+
if (unwrapped.type === 'ArrowFunctionExpression' || unwrapped.type === 'FunctionExpression')
|
|
183
|
+
targetOps.push(`(${refCode})(${elVar});`)
|
|
184
|
+
else
|
|
185
|
+
targetOps.push(`(${refCode})?.(${elVar});`)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function scanSpreadSpecialIndices(attrs: readonly JSXElement['openingElement']['attributes'][number][]): {
|
|
189
|
+
lastSpreadIdx: number
|
|
190
|
+
lastInnerHtmlIdx: number
|
|
191
|
+
lastRefIdx: number
|
|
192
|
+
} {
|
|
193
|
+
let lastSpreadIdx = -1
|
|
194
|
+
let lastInnerHtmlIdx = -1
|
|
195
|
+
let lastRefIdx = -1
|
|
196
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
197
|
+
const attr = attrs[i]!
|
|
198
|
+
if (attr.type === 'JSXSpreadAttribute') {
|
|
199
|
+
lastSpreadIdx = i
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const rawName = jsxTagName(attr.name)
|
|
203
|
+
if (rawName === 'innerHTML')
|
|
204
|
+
lastInnerHtmlIdx = i
|
|
205
|
+
else if (rawName === 'ref')
|
|
206
|
+
lastRefIdx = i
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return { lastSpreadIdx, lastInnerHtmlIdx, lastRefIdx }
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function compileSpreadAttributes(ctx: ElementAttrCompileContext, isSelect: boolean): string {
|
|
213
|
+
const { el, elVar, scopeRewrites, ops, postChildOps, use, freshVar, compileExpression } = ctx
|
|
170
214
|
const attrs = el.openingElement.attributes
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
|
|
215
|
+
const entries: string[] = []
|
|
216
|
+
const preSpreadOps: string[] = []
|
|
217
|
+
let soleSpreadExpr: string | undefined
|
|
218
|
+
const { lastSpreadIdx, lastInnerHtmlIdx, lastRefIdx } = scanSpreadSpecialIndices(attrs)
|
|
174
219
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
220
|
+
let innerHtmlAttr: Extract<Node, { type: 'JSXAttribute' }> | undefined
|
|
221
|
+
let innerHtmlAfterSpread = false
|
|
222
|
+
let postSpreadRef: Node | undefined
|
|
223
|
+
|
|
224
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
225
|
+
const attr = attrs[i]!
|
|
226
|
+
if (attr.type === 'JSXSpreadAttribute') {
|
|
227
|
+
const argCode = compileExpression(attr.argument, scopeRewrites)
|
|
228
|
+
if (attrs.length === 1)
|
|
229
|
+
soleSpreadExpr = argCode
|
|
230
|
+
entries.push(`...(${argCode})`)
|
|
231
|
+
continue
|
|
232
|
+
}
|
|
233
|
+
const rawName = jsxTagName(attr.name)
|
|
234
|
+
if (rawName === 'key' || rawName === '$hydrate')
|
|
235
|
+
continue
|
|
236
|
+
|
|
237
|
+
if (rawName === 'innerHTML') {
|
|
238
|
+
if (i === lastInnerHtmlIdx) {
|
|
239
|
+
innerHtmlAttr = attr
|
|
240
|
+
innerHtmlAfterSpread = i > lastSpreadIdx
|
|
188
241
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
continue
|
|
242
|
+
continue
|
|
243
|
+
}
|
|
192
244
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
245
|
+
if (rawName === 'ref') {
|
|
246
|
+
if (i !== lastRefIdx && lastRefIdx > lastSpreadIdx)
|
|
247
|
+
continue
|
|
248
|
+
if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
|
|
249
|
+
const expr = attr.value.expression
|
|
250
|
+
const unwrapped = unwrapTsExpr(expr)
|
|
251
|
+
const isInlineFn = unwrapped.type === 'ArrowFunctionExpression' || unwrapped.type === 'FunctionExpression'
|
|
252
|
+
if (i > lastSpreadIdx && (isInlineFn || isStaticPropExpr(expr, scopeRewrites))) {
|
|
253
|
+
entries.push('ref: undefined')
|
|
254
|
+
postSpreadRef = expr
|
|
196
255
|
}
|
|
197
|
-
else if (
|
|
198
|
-
const
|
|
199
|
-
|
|
256
|
+
else if (isInlineFn) {
|
|
257
|
+
const refVar = freshVar('_r')
|
|
258
|
+
preSpreadOps.push(`const ${refVar} = ${compileExpression(expr, scopeRewrites)};`)
|
|
259
|
+
entries.push(`ref: ${refVar}`)
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
entries.push(`ref: ${compileExpression(expr, scopeRewrites)}`)
|
|
200
263
|
}
|
|
201
|
-
continue
|
|
202
264
|
}
|
|
203
|
-
|
|
204
|
-
const name = rawName === 'className' ? 'class' : rawName === 'htmlFor' ? 'for' : rawName
|
|
205
|
-
const isEvent = EVENT_ATTR.test(rawName)
|
|
206
|
-
if (!isEvent && rawName !== 'ref' && isBlockedAttr(name))
|
|
207
|
-
continue
|
|
208
|
-
|
|
209
|
-
const propName = isEvent || rawName === 'ref' ? rawName : name
|
|
210
|
-
const propKey = /^[A-Za-z_$][\w$]*$/.test(propName) ? propName : JSON.stringify(propName)
|
|
211
|
-
if (attr.value === null)
|
|
212
|
-
entries.push(`${propKey}: true`)
|
|
213
|
-
else if (attr.value.type === 'Literal')
|
|
214
|
-
entries.push(`${propKey}: ${JSON.stringify(attr.value.value)}`)
|
|
215
|
-
else if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression')
|
|
216
|
-
entries.push(`${propKey}: ${compileExpression(attr.value.expression, scopeRewrites)}`)
|
|
265
|
+
continue
|
|
217
266
|
}
|
|
218
267
|
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
268
|
+
const name = rawName === 'className' ? 'class' : rawName === 'htmlFor' ? 'for' : rawName
|
|
269
|
+
const isEvent = EVENT_ATTR.test(rawName)
|
|
270
|
+
if (!isEvent && isBlockedAttr(name))
|
|
271
|
+
continue
|
|
272
|
+
|
|
273
|
+
const propName = isEvent ? rawName : name
|
|
274
|
+
const propKey = /^[A-Za-z_$][\w$]*$/.test(propName) ? propName : JSON.stringify(propName)
|
|
275
|
+
if (attr.value === null)
|
|
276
|
+
entries.push(`${propKey}: true`)
|
|
277
|
+
else if (attr.value.type === 'Literal')
|
|
278
|
+
entries.push(`${propKey}: ${JSON.stringify(attr.value.value)}`)
|
|
279
|
+
else if (attr.value.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression')
|
|
280
|
+
entries.push(`${propKey}: ${compileExpression(attr.value.expression, scopeRewrites)}`)
|
|
225
281
|
}
|
|
226
282
|
|
|
283
|
+
const targetOps = isSelect ? postChildOps : ops
|
|
284
|
+
for (const op of preSpreadOps)
|
|
285
|
+
targetOps.push(op)
|
|
286
|
+
if (innerHtmlAttr !== undefined && !innerHtmlAfterSpread)
|
|
287
|
+
emitInnerHtmlOp(ctx, innerHtmlAttr, targetOps)
|
|
288
|
+
if (soleSpreadExpr !== undefined)
|
|
289
|
+
targetOps.push(`${use('spread')}(${elVar}, () => (${soleSpreadExpr}));`)
|
|
290
|
+
else if (entries.length > 0)
|
|
291
|
+
targetOps.push(`${use('spread')}(${elVar}, () => ({ ${entries.join(', ')} }));`)
|
|
292
|
+
if (innerHtmlAttr !== undefined && innerHtmlAfterSpread)
|
|
293
|
+
emitInnerHtmlOp(ctx, innerHtmlAttr, targetOps)
|
|
294
|
+
if (postSpreadRef !== undefined)
|
|
295
|
+
emitRefOp(ctx, postSpreadRef, targetOps)
|
|
296
|
+
return ''
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Compiles an HTML/SVG element's attributes, returning the static attribute HTML fragment and pushing DOM ops. */
|
|
300
|
+
export function compileElementAttributes(ctx: ElementAttrCompileContext): string {
|
|
301
|
+
const { el, tag, elVar, scopeRewrites, ops, postChildOps, delegatedEvents, use, freshVar, compileExpression } = ctx
|
|
302
|
+
const attrs = el.openingElement.attributes
|
|
303
|
+
const hasSpread = attrs.some(a => a.type === 'JSXSpreadAttribute')
|
|
304
|
+
const isFormValueEl = tag === 'textarea' || tag === 'select'
|
|
305
|
+
const isSelect = tag === 'select'
|
|
306
|
+
|
|
307
|
+
if (hasSpread)
|
|
308
|
+
return compileSpreadAttributes(ctx, isSelect)
|
|
309
|
+
|
|
227
310
|
let html = ''
|
|
311
|
+
let lastInnerHtml: Extract<Node, { type: 'JSXAttribute' }> | undefined
|
|
228
312
|
for (const attr of attrs) {
|
|
229
313
|
if (attr.type === 'JSXSpreadAttribute')
|
|
230
314
|
continue
|
|
@@ -233,26 +317,13 @@ export function compileElementAttributes(ctx: ElementAttrCompileContext): string
|
|
|
233
317
|
continue
|
|
234
318
|
|
|
235
319
|
if (rawName === 'ref') {
|
|
236
|
-
if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression')
|
|
237
|
-
|
|
238
|
-
const refCode = compileExpression(expr, scopeRewrites)
|
|
239
|
-
const unwrapped = unwrapTsExpr(expr)
|
|
240
|
-
if (unwrapped.type === 'ArrowFunctionExpression' || unwrapped.type === 'FunctionExpression')
|
|
241
|
-
ops.push(`(${refCode})(${elVar});`)
|
|
242
|
-
else
|
|
243
|
-
ops.push(`(${refCode})?.(${elVar});`)
|
|
244
|
-
}
|
|
320
|
+
if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression')
|
|
321
|
+
emitRefOp(ctx, attr.value.expression, ops)
|
|
245
322
|
continue
|
|
246
323
|
}
|
|
247
324
|
|
|
248
325
|
if (rawName === 'innerHTML') {
|
|
249
|
-
|
|
250
|
-
ops.push(`${use('setInnerHtml')}(${elVar}, ${JSON.stringify(String(attr.value.value))});`)
|
|
251
|
-
}
|
|
252
|
-
else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type !== 'JSXEmptyExpression') {
|
|
253
|
-
const expr = attr.value.expression
|
|
254
|
-
ops.push(wrapDomOp(`${use('setInnerHtml')}(${elVar}, ${compileExpression(expr, scopeRewrites)})`, isStaticDomExpr(expr, scopeRewrites), use))
|
|
255
|
-
}
|
|
326
|
+
lastInnerHtml = attr
|
|
256
327
|
continue
|
|
257
328
|
}
|
|
258
329
|
|
|
@@ -305,6 +376,8 @@ export function compileElementAttributes(ctx: ElementAttrCompileContext): string
|
|
|
305
376
|
html += emitDomExprAttr(ctx, name, attr.value.expression, isSelect)
|
|
306
377
|
}
|
|
307
378
|
}
|
|
379
|
+
if (lastInnerHtml !== undefined)
|
|
380
|
+
emitInnerHtmlOp(ctx, lastInnerHtml, ops)
|
|
308
381
|
return html
|
|
309
382
|
}
|
|
310
383
|
|