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.
Files changed (173) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +137 -40
  3. package/package.json +11 -2
  4. package/src/a11y/declaration.ts +369 -0
  5. package/src/a11y/index.ts +466 -0
  6. package/src/a11y/rgaa-map.ts +230 -0
  7. package/src/attrs.ts +11 -3
  8. package/src/build/bundle.ts +88 -40
  9. package/src/build/byte-size.ts +11 -0
  10. package/src/build/client-entries.ts +3 -2
  11. package/src/build/client-plugin.ts +11 -5
  12. package/src/build/client-prune.ts +56 -6
  13. package/src/build/compile.ts +13 -10
  14. package/src/build/ecoindex.ts +230 -0
  15. package/src/build/files.ts +6 -0
  16. package/src/build/first-load.ts +83 -11
  17. package/src/build/graph.ts +29 -39
  18. package/src/build/index.ts +218 -113
  19. package/src/build/island-promote.ts +229 -0
  20. package/src/build/islands.ts +11 -203
  21. package/src/build/manifest.ts +56 -116
  22. package/src/build/output.ts +2 -2
  23. package/src/build/plugin-host.ts +113 -41
  24. package/src/build/precompress.ts +16 -3
  25. package/src/build/prerender.ts +173 -38
  26. package/src/build/reach.ts +136 -0
  27. package/src/build/render-rules.ts +2 -2
  28. package/src/build/report.ts +42 -5
  29. package/src/build/resolve.ts +8 -6
  30. package/src/build/routes.ts +175 -10
  31. package/src/build/static-headers.ts +93 -0
  32. package/src/build/static.ts +139 -39
  33. package/src/build/status-pages.ts +127 -0
  34. package/src/build/style-bundles.ts +526 -0
  35. package/src/cli/check-forms.ts +610 -0
  36. package/src/cli/check-imports.ts +25 -0
  37. package/src/cli/check-links.ts +632 -0
  38. package/src/cli/check-security.ts +64 -0
  39. package/src/cli/check.ts +107 -26
  40. package/src/cli/commands.ts +120 -11
  41. package/src/cli/docs.ts +403 -0
  42. package/src/cli/inspect.ts +105 -15
  43. package/src/cli/mcp-tools.ts +492 -0
  44. package/src/cli/mcp.ts +205 -0
  45. package/src/cli/new.ts +16 -5
  46. package/src/cli/render.ts +416 -0
  47. package/src/cli/upgrade-names.ts +73 -13
  48. package/src/cli/upgrade.ts +156 -18
  49. package/src/compiler/analyze.ts +68 -14
  50. package/src/compiler/browser-globals.ts +140 -17
  51. package/src/compiler/cacheability.ts +636 -0
  52. package/src/compiler/compliance-eco.ts +71 -0
  53. package/src/compiler/compliance-rgaa.ts +614 -0
  54. package/src/compiler/compliance-urls.ts +145 -0
  55. package/src/compiler/compliance.ts +355 -351
  56. package/src/compiler/data-keys.ts +199 -192
  57. package/src/compiler/dev-source.ts +87 -0
  58. package/src/compiler/dom-attrs.ts +138 -65
  59. package/src/compiler/dom.ts +517 -442
  60. package/src/compiler/expr-context.ts +167 -57
  61. package/src/compiler/foreign-imports.ts +88 -0
  62. package/src/compiler/mistakes.ts +23 -2
  63. package/src/compiler/props-body.ts +52 -0
  64. package/src/compiler/props.ts +87 -36
  65. package/src/compiler/scope.ts +400 -333
  66. package/src/compiler/server-only.ts +190 -151
  67. package/src/compiler/shared.ts +42 -14
  68. package/src/compiler/signal-reads.ts +6 -2
  69. package/src/compiler/ssr-prunelle-tags.ts +27 -14
  70. package/src/compiler/ssr.ts +220 -89
  71. package/src/context.ts +34 -0
  72. package/src/dev/error-log.ts +177 -0
  73. package/src/dev/host-check.ts +26 -0
  74. package/src/dev/index.ts +91 -34
  75. package/src/dev/open-editor.ts +208 -0
  76. package/src/dev/protocol.ts +3 -0
  77. package/src/dev/reload.ts +5 -3
  78. package/src/dev/supervisor.ts +50 -25
  79. package/src/dev/watchers.ts +74 -13
  80. package/src/dom/action.ts +47 -21
  81. package/src/dom/attrs.ts +15 -3
  82. package/src/dom/extras.ts +29 -14
  83. package/src/dom/index.ts +39 -10
  84. package/src/dom/island.ts +54 -35
  85. package/src/dom/loop.ts +33 -23
  86. package/src/eco/declaration.ts +257 -0
  87. package/src/eco/index.ts +65 -0
  88. package/src/index.ts +2 -2
  89. package/src/jsx-runtime.ts +2 -2
  90. package/src/plugins/config.ts +8 -7
  91. package/src/plugins/context.ts +16 -1
  92. package/src/plugins/index.ts +2 -2
  93. package/src/plugins/load.ts +30 -10
  94. package/src/plugins/order.ts +38 -1
  95. package/src/plugins/public.ts +6 -3
  96. package/src/plugins/services.ts +84 -0
  97. package/src/plugins/types.ts +51 -2
  98. package/src/reactivity/graph.ts +10 -0
  99. package/src/reactivity/index.ts +24 -16
  100. package/src/reactivity/selector.ts +31 -4
  101. package/src/reactivity/store.ts +45 -13
  102. package/src/server/action-flash.ts +158 -0
  103. package/src/server/action-protect.ts +199 -0
  104. package/src/server/action-registry.ts +1 -1
  105. package/src/server/action.ts +56 -117
  106. package/src/server/app-secret.ts +63 -0
  107. package/src/server/assets.ts +34 -2
  108. package/src/server/compress.ts +96 -10
  109. package/src/server/consent.ts +59 -22
  110. package/src/server/cookies.ts +16 -2
  111. package/src/server/document.ts +25 -10
  112. package/src/server/env.ts +14 -0
  113. package/src/server/errors.ts +305 -65
  114. package/src/server/form-schema.ts +343 -0
  115. package/src/server/health.ts +275 -0
  116. package/src/server/http.ts +177 -38
  117. package/src/server/index.ts +264 -272
  118. package/src/server/loader.ts +11 -2
  119. package/src/server/param-matchers.ts +112 -0
  120. package/src/server/plugin-host.ts +125 -88
  121. package/src/server/public.ts +6 -5
  122. package/src/server/rate-limit.ts +102 -36
  123. package/src/server/request-body.ts +1 -1
  124. package/src/server/route-cache.ts +445 -0
  125. package/src/server/route-table.ts +344 -9
  126. package/src/server/router.ts +125 -40
  127. package/src/server/routing.ts +112 -63
  128. package/src/server/sanitize-html.ts +309 -0
  129. package/src/server/security.ts +277 -50
  130. package/src/server/serve-handlers.ts +31 -7
  131. package/src/server/start.ts +60 -16
  132. package/src/server/static-dir.ts +87 -11
  133. package/src/server/stream.ts +68 -27
  134. package/src/ssr/consent-banner.ts +58 -0
  135. package/src/ssr/context.ts +105 -7
  136. package/src/ssr/index.ts +148 -3
  137. package/src/ssr/navigation.ts +2 -2
  138. package/src/ssr/region.ts +31 -19
  139. package/src/style.ts +32 -1
  140. package/src/test/browser.ts +28 -13
  141. package/src/test/index.ts +97 -12
  142. package/src/ts-plugin/diagnostics.ts +505 -0
  143. package/src/ts-plugin/fixes.ts +364 -0
  144. package/src/ts-plugin/index.ts +194 -0
  145. package/templates/_shared/AGENTS.md +2 -2
  146. package/templates/_shared/gitignore +5 -0
  147. package/templates/_shared/mcp.json +11 -0
  148. package/templates/_shared/src/routes/legal.tsx +15 -1
  149. package/templates/_shared/tsconfig.json +5 -0
  150. package/templates/app/.env.example +4 -0
  151. package/templates/app/package.json +2 -1
  152. package/templates/app/prunelle.config.ts +2 -0
  153. package/templates/app/src/auth.ts +4 -6
  154. package/templates/app/src/mail.ts +4 -0
  155. package/templates/app/src/routes/_layout.tsx +9 -1
  156. package/templates/app/src/routes/dashboard/index.tsx +42 -8
  157. package/templates/app/src/routes/login.tsx +49 -30
  158. package/templates/app/src/routes/privacy.tsx +25 -0
  159. package/templates/app/src/styles/app.css +8 -1
  160. package/templates/app/tests/app.test.ts +44 -3
  161. package/templates/blog/package.json +1 -1
  162. package/templates/blog/prunelle.config.ts +1 -1
  163. package/templates/blog/src/routes/_layout.tsx +6 -1
  164. package/templates/blog/src/routes/index.tsx +5 -1
  165. package/templates/blog/src/styles/app.css +6 -1
  166. package/templates/fullstack/package.json +1 -1
  167. package/templates/fullstack/src/components/GreetForm.tsx +2 -1
  168. package/templates/fullstack/src/routes/_layout.tsx +4 -0
  169. package/templates/fullstack/src/styles/app.css +11 -1
  170. package/templates/minimal/package.json +1 -1
  171. package/templates/minimal/src/routes/_layout.tsx +4 -0
  172. package/templates/minimal/src/styles/app.css +11 -1
  173. package/ts-plugin.cjs +4277 -0
@@ -0,0 +1,145 @@
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 LOADING_LINK_RELS = new Set(['stylesheet', 'preload', 'preconnect', 'dns-prefetch', 'modulepreload', 'prefetch', 'prerender', 'icon', 'apple-touch-icon', 'manifest'])
10
+ const SRC_TAGS = new Set(['script', 'iframe', 'img', 'video', 'audio', 'source', 'embed', 'track'])
11
+ const SRCSET_TAGS = new Set(['img', 'source'])
12
+ // SVG elements whose href fetches a resource.
13
+ const SVG_HREF_TAGS = new Set(['image', 'use', 'feImage'])
14
+ export const CSS_IMPORT_RE = /@import\s+(?:url\(\s*)?(?:'([^']+)'|"([^"]+)"|([^'"\s);]+))/gi
15
+ export const CSS_URL_RE = /url\(\s*(?:'([^']+)'|"([^"]+)"|([^'"\s)]+))\s*\)/gi
16
+
17
+ export interface ThirdPartyLoad {
18
+ attr: string
19
+ url: string
20
+ origin: string
21
+ start: number
22
+ }
23
+
24
+ export function parseOrigin(url: string | undefined): string | undefined {
25
+ if (url === undefined || url.trim() === '')
26
+ return undefined
27
+ try {
28
+ return new URL(url.trim()).origin
29
+ }
30
+ catch {
31
+ return undefined
32
+ }
33
+ }
34
+
35
+ /** Returns the external origin when `rawUrl` points to a non-localhost third-party URL, or `undefined` otherwise. */
36
+ export function thirdPartyOrigin(rawUrl: string): string | undefined {
37
+ const trimmed = rawUrl.trim()
38
+ if (!/^(?:https?:)?\/\//i.test(trimmed))
39
+ return undefined
40
+ try {
41
+ const parsed = new URL(trimmed.startsWith('//') ? `https:${trimmed}` : trimmed)
42
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:')
43
+ return undefined
44
+ const host = parsed.hostname.toLowerCase()
45
+ if (LOCAL_HOSTS.has(host) || host.endsWith('.localhost'))
46
+ return undefined
47
+ return parsed.origin
48
+ }
49
+ catch {
50
+ return undefined
51
+ }
52
+ }
53
+
54
+ // Every string an expression can evaluate to, as far as the source shows it: a template literal gives its leading text, which holds the origin.
55
+ function expressionStrings(expr: Expression): string[] {
56
+ const node = unwrapTsExpr(expr)
57
+ if (node.type === 'Literal')
58
+ return typeof node.value === 'string' ? [node.value] : []
59
+ if (node.type === 'TemplateLiteral')
60
+ return [node.quasis[0]?.value.cooked ?? '']
61
+ if (node.type === 'ConditionalExpression')
62
+ return [...expressionStrings(node.consequent), ...expressionStrings(node.alternate)]
63
+ if (node.type === 'LogicalExpression')
64
+ return [...expressionStrings(node.left), ...expressionStrings(node.right)]
65
+ if (node.type === 'ObjectExpression') {
66
+ return node.properties.flatMap(prop => prop.type === 'Property' ? expressionStrings(prop.value) : [])
67
+ }
68
+ return []
69
+ }
70
+
71
+ function attrStrings(attr: JSXAttribute): string[] {
72
+ const value = attr.value
73
+ if (value === null)
74
+ return []
75
+ if (value.type === 'Literal')
76
+ return typeof value.value === 'string' ? [value.value] : []
77
+ if (value.type === 'JSXExpressionContainer' && value.expression.type !== 'JSXEmptyExpression')
78
+ return expressionStrings(value.expression)
79
+ return []
80
+ }
81
+
82
+ function matches(re: RegExp, text: string): string[] {
83
+ const out: string[] = []
84
+ re.lastIndex = 0
85
+ for (let m = re.exec(text); m !== null; m = re.exec(text)) {
86
+ const url = m[1] ?? m[2] ?? m[3]
87
+ if (url !== undefined)
88
+ out.push(url)
89
+ }
90
+ return out
91
+ }
92
+
93
+ type UrlsOf = (text: string) => string[]
94
+ const whole: UrlsOf = text => [text]
95
+ const srcsetUrls: UrlsOf = text => text.split(',').map(part => part.trim().split(/\s+/, 1)[0] ?? '').filter(Boolean)
96
+ const cssUrls: UrlsOf = text => matches(CSS_URL_RE, text)
97
+
98
+ // `xlink:href`, the only namespaced href there is.
99
+ function findXlinkHref(attributes: readonly JSXAttributeItem[]): JSXAttribute | undefined {
100
+ for (const attr of attributes) {
101
+ if (attr.type === 'JSXAttribute' && attr.name.type === 'JSXNamespacedName' && attr.name.name.name === 'href')
102
+ return attr
103
+ }
104
+ return undefined
105
+ }
106
+
107
+ // The attributes of `tag` that load a resource, each with how its value lists URLs.
108
+ function loadingAttrs(element: JSXElement, tag: string): Array<[string, JSXAttribute | undefined, UrlsOf]> {
109
+ const attrs = element.openingElement.attributes
110
+ const out: Array<[string, JSXAttribute | undefined, UrlsOf]> = [['style', findAttr(attrs, 'style'), cssUrls]]
111
+ if (SRC_TAGS.has(tag))
112
+ out.push(['src', findAttr(attrs, 'src'), whole])
113
+ if (SRCSET_TAGS.has(tag))
114
+ out.push(['srcset', findAttr(attrs, 'srcset'), srcsetUrls])
115
+ if (tag === 'video')
116
+ out.push(['poster', findAttr(attrs, 'poster'), whole])
117
+ if (tag === 'object')
118
+ out.push(['data', findAttr(attrs, 'data'), whole])
119
+ if (SVG_HREF_TAGS.has(tag))
120
+ out.push(['href', findAttr(attrs, 'href'), whole], ['xlink:href', findXlinkHref(attrs), whole])
121
+ if (tag === 'link') {
122
+ const rel = findAttr(attrs, 'rel')
123
+ const loads = rel !== undefined && attrStrings(rel).some(value => value.toLowerCase().split(/\s+/).some(r => LOADING_LINK_RELS.has(r)))
124
+ if (loads)
125
+ out.push(['href', findAttr(attrs, 'href'), whole])
126
+ }
127
+ return out
128
+ }
129
+
130
+ /** The first third-party URL each loading attribute of a plain element points at. */
131
+ export function thirdPartyLoads(element: JSXElement, tag: string): ThirdPartyLoad[] {
132
+ const out: ThirdPartyLoad[] = []
133
+ for (const [name, attr, urlsOf] of loadingAttrs(element, tag)) {
134
+ if (attr === undefined)
135
+ continue
136
+ for (const url of attrStrings(attr).flatMap(urlsOf)) {
137
+ const origin = thirdPartyOrigin(url)
138
+ if (origin !== undefined) {
139
+ out.push({ attr: name, url, origin, start: attr.start })
140
+ break
141
+ }
142
+ }
143
+ }
144
+ return out
145
+ }