prunelle 0.1.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/llms.txt +137 -40
- package/package.json +11 -2
- package/src/a11y/declaration.ts +373 -0
- package/src/a11y/index.ts +477 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +89 -41
- 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 +238 -0
- package/src/build/files.ts +15 -0
- package/src/build/first-load.ts +85 -14
- package/src/build/graph.ts +29 -39
- package/src/build/index.ts +225 -122
- package/src/build/island-promote.ts +311 -0
- package/src/build/islands.ts +14 -203
- package/src/build/manifest.ts +56 -116
- package/src/build/output.ts +3 -6
- package/src/build/plugin-host.ts +115 -41
- package/src/build/precompress.ts +16 -3
- package/src/build/prerender.ts +177 -39
- package/src/build/reach.ts +200 -0
- package/src/build/render-rules.ts +2 -2
- package/src/build/report.ts +48 -5
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static-headers.ts +112 -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 +636 -0
- package/src/cli/check-imports.ts +31 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +101 -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 -22
- package/src/compiler/analyze.ts +87 -54
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability-private.ts +566 -0
- package/src/compiler/cacheability.ts +335 -0
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +614 -0
- package/src/compiler/compliance-urls.ts +148 -0
- package/src/compiler/compliance.ts +407 -352
- 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 +260 -81
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/mistakes.ts +23 -2
- package/src/compiler/props-body.ts +60 -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/spread-handlers.ts +295 -0
- 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 +32 -0
- package/src/dev/index.ts +94 -34
- package/src/dev/open-editor.ts +228 -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 +57 -40
- package/src/dom/index.ts +54 -14
- package/src/dom/island.ts +102 -68
- package/src/dom/loop.ts +66 -32
- package/src/eco/declaration.ts +328 -0
- package/src/eco/index.ts +69 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +2 -2
- package/src/plugins/config.ts +18 -12
- package/src/plugins/context.ts +44 -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 +64 -20
- 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 +188 -152
- 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 +308 -65
- package/src/server/form-schema.ts +337 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +186 -39
- package/src/server/index.ts +272 -273
- package/src/server/loader.ts +15 -2
- package/src/server/page.ts +15 -0
- 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 +541 -0
- package/src/server/route-table.ts +356 -11
- 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 +279 -52
- package/src/server/serve-handlers.ts +31 -7
- package/src/server/standard-schema.ts +17 -0
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +91 -12
- package/src/server/stream.ts +68 -27
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +106 -8
- package/src/ssr/index.ts +151 -4
- package/src/ssr/navigation.ts +2 -2
- package/src/ssr/region.ts +40 -19
- package/src/style.ts +64 -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
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// The third-party URLs a JSX element makes the browser load, for the rgpd/third-party-url rule.
|
|
2
|
+
|
|
3
|
+
import type { Expression, JSXAttribute, JSXAttributeItem, JSXElement } from 'oxc-parser'
|
|
4
|
+
import { findAttr } from './compliance-rgaa'
|
|
5
|
+
import { unwrapTsExpr } from './shared'
|
|
6
|
+
|
|
7
|
+
// Hosts that only ever mean this machine, never a third party.
|
|
8
|
+
const LOCAL_HOSTS = new Set(['localhost', '127.0.0.1', '::1', '[::1]', '0.0.0.0'])
|
|
9
|
+
const EXPR_PLACEHOLDER = '__prunelle_expr__'
|
|
10
|
+
const LOADING_LINK_RELS = new Set(['stylesheet', 'preload', 'preconnect', 'dns-prefetch', 'modulepreload', 'prefetch', 'prerender', 'icon', 'apple-touch-icon', 'manifest'])
|
|
11
|
+
const SRC_TAGS = new Set(['script', 'iframe', 'img', 'video', 'audio', 'source', 'embed', 'track'])
|
|
12
|
+
const SRCSET_TAGS = new Set(['img', 'source'])
|
|
13
|
+
// SVG elements whose href fetches a resource.
|
|
14
|
+
const SVG_HREF_TAGS = new Set(['image', 'use', 'feImage'])
|
|
15
|
+
export const CSS_IMPORT_RE = /@import\s+(?:url\(\s*)?(?:'([^']+)'|"([^"]+)"|([^'"\s);]+))/gi
|
|
16
|
+
export const CSS_URL_RE = /url\(\s*(?:'([^']+)'|"([^"]+)"|([^'"\s)]+))\s*\)/gi
|
|
17
|
+
|
|
18
|
+
export interface ThirdPartyLoad {
|
|
19
|
+
attr: string
|
|
20
|
+
url: string
|
|
21
|
+
origin: string
|
|
22
|
+
start: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parseOrigin(url: string | undefined): string | undefined {
|
|
26
|
+
if (url === undefined || url.trim() === '')
|
|
27
|
+
return undefined
|
|
28
|
+
try {
|
|
29
|
+
return new URL(url.trim()).origin
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Returns the external origin when `rawUrl` points to a non-localhost third-party URL, or `undefined` otherwise. */
|
|
37
|
+
export function thirdPartyOrigin(rawUrl: string): string | undefined {
|
|
38
|
+
const trimmed = rawUrl.trim()
|
|
39
|
+
if (!/^(?:https?:)?\/\//i.test(trimmed))
|
|
40
|
+
return undefined
|
|
41
|
+
try {
|
|
42
|
+
const parsed = new URL(trimmed.startsWith('//') ? `https:${trimmed}` : trimmed)
|
|
43
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
|
|
44
|
+
return undefined
|
|
45
|
+
const host = parsed.hostname.toLowerCase()
|
|
46
|
+
if (LOCAL_HOSTS.has(host) || host.endsWith('.localhost'))
|
|
47
|
+
return undefined
|
|
48
|
+
return parsed.origin
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return undefined
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Every string an expression can evaluate to, as far as the source shows it: template quasis are joined with a placeholder so CSS url(...) and multi-URL attributes stay intact across interpolations.
|
|
56
|
+
function expressionStrings(expr: Expression): string[] {
|
|
57
|
+
const node = unwrapTsExpr(expr)
|
|
58
|
+
if (node.type === 'Literal')
|
|
59
|
+
return typeof node.value === 'string' ? [node.value] : []
|
|
60
|
+
if (node.type === 'TemplateLiteral')
|
|
61
|
+
return [node.quasis.map(q => q.value.cooked ?? '').join(EXPR_PLACEHOLDER)]
|
|
62
|
+
if (node.type === 'ConditionalExpression')
|
|
63
|
+
return [...expressionStrings(node.consequent), ...expressionStrings(node.alternate)]
|
|
64
|
+
if (node.type === 'LogicalExpression')
|
|
65
|
+
return [...expressionStrings(node.left), ...expressionStrings(node.right)]
|
|
66
|
+
if (node.type === 'ObjectExpression') {
|
|
67
|
+
return node.properties.flatMap(prop => prop.type === 'Property' ? expressionStrings(prop.value) : [])
|
|
68
|
+
}
|
|
69
|
+
return []
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function attrStrings(attr: JSXAttribute): string[] {
|
|
73
|
+
const value = attr.value
|
|
74
|
+
if (value === null)
|
|
75
|
+
return []
|
|
76
|
+
if (value.type === 'Literal')
|
|
77
|
+
return typeof value.value === 'string' ? [value.value] : []
|
|
78
|
+
if (value.type === 'JSXExpressionContainer' && value.expression.type !== 'JSXEmptyExpression')
|
|
79
|
+
return expressionStrings(value.expression)
|
|
80
|
+
return []
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function matches(re: RegExp, text: string): string[] {
|
|
84
|
+
const out: string[] = []
|
|
85
|
+
re.lastIndex = 0
|
|
86
|
+
for (let m = re.exec(text); m !== null; m = re.exec(text)) {
|
|
87
|
+
const url = m[1] ?? m[2] ?? m[3]
|
|
88
|
+
if (url !== undefined)
|
|
89
|
+
out.push(url)
|
|
90
|
+
}
|
|
91
|
+
return out
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
type UrlsOf = (text: string) => string[]
|
|
95
|
+
const whole: UrlsOf = text => [text]
|
|
96
|
+
const srcsetUrls: UrlsOf = text => text.split(',').map(part => part.trim().split(/\s+/, 1)[0] ?? '').filter(Boolean)
|
|
97
|
+
const cssUrls: UrlsOf = text => matches(CSS_URL_RE, text)
|
|
98
|
+
|
|
99
|
+
// `xlink:href`, the only namespaced href there is.
|
|
100
|
+
function findXlinkHref(attributes: readonly JSXAttributeItem[]): JSXAttribute | undefined {
|
|
101
|
+
for (const attr of attributes) {
|
|
102
|
+
if (attr.type === 'JSXAttribute' && attr.name.type === 'JSXNamespacedName' && attr.name.name.name === 'href')
|
|
103
|
+
return attr
|
|
104
|
+
}
|
|
105
|
+
return undefined
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// The attributes of `tag` that load a resource, each with how its value lists URLs.
|
|
109
|
+
function loadingAttrs(element: JSXElement, tag: string): Array<[string, JSXAttribute | undefined, UrlsOf]> {
|
|
110
|
+
const attrs = element.openingElement.attributes
|
|
111
|
+
const out: Array<[string, JSXAttribute | undefined, UrlsOf]> = [['style', findAttr(attrs, 'style'), cssUrls]]
|
|
112
|
+
if (SRC_TAGS.has(tag))
|
|
113
|
+
out.push(['src', findAttr(attrs, 'src'), whole])
|
|
114
|
+
if (SRCSET_TAGS.has(tag))
|
|
115
|
+
out.push(['srcset', findAttr(attrs, 'srcset'), srcsetUrls])
|
|
116
|
+
if (tag === 'video')
|
|
117
|
+
out.push(['poster', findAttr(attrs, 'poster'), whole])
|
|
118
|
+
if (tag === 'object')
|
|
119
|
+
out.push(['data', findAttr(attrs, 'data'), whole])
|
|
120
|
+
if (SVG_HREF_TAGS.has(tag))
|
|
121
|
+
out.push(['href', findAttr(attrs, 'href'), whole], ['xlink:href', findXlinkHref(attrs), whole])
|
|
122
|
+
if (tag === 'link') {
|
|
123
|
+
const rel = findAttr(attrs, 'rel')
|
|
124
|
+
const loads = rel !== undefined && attrStrings(rel).some(value => value.toLowerCase().split(/\s+/).some(r => LOADING_LINK_RELS.has(r)))
|
|
125
|
+
if (loads)
|
|
126
|
+
out.push(['href', findAttr(attrs, 'href'), whole])
|
|
127
|
+
}
|
|
128
|
+
return out
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Distinct third-party origins each loading attribute of a plain element points at. */
|
|
132
|
+
export function thirdPartyLoads(element: JSXElement, tag: string): ThirdPartyLoad[] {
|
|
133
|
+
const out: ThirdPartyLoad[] = []
|
|
134
|
+
for (const [name, attr, urlsOf] of loadingAttrs(element, tag)) {
|
|
135
|
+
if (attr === undefined)
|
|
136
|
+
continue
|
|
137
|
+
const seen = new Set<string>()
|
|
138
|
+
for (const rawUrl of attrStrings(attr).flatMap(urlsOf)) {
|
|
139
|
+
const url = rawUrl.split(EXPR_PLACEHOLDER, 1)[0]!
|
|
140
|
+
const origin = thirdPartyOrigin(url)
|
|
141
|
+
if (origin !== undefined && !seen.has(origin)) {
|
|
142
|
+
seen.add(origin)
|
|
143
|
+
out.push({ attr: name, url, origin, start: attr.start })
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out
|
|
148
|
+
}
|