prunelle 0.0.0-stage → 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.
Files changed (222) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +245 -0
  3. package/package.json +62 -4
  4. package/src/a11y/declaration.ts +373 -0
  5. package/src/a11y/index.ts +477 -0
  6. package/src/a11y/rgaa-map.ts +230 -0
  7. package/src/ambient.d.ts +6 -0
  8. package/src/attrs.ts +43 -0
  9. package/src/build/bundle.ts +661 -0
  10. package/src/build/byte-size.ts +11 -0
  11. package/src/build/carry.ts +57 -0
  12. package/src/build/client-entries.ts +107 -0
  13. package/src/build/client-plugin.ts +175 -0
  14. package/src/build/client-prune.ts +168 -0
  15. package/src/build/compile.ts +130 -0
  16. package/src/build/ecoindex.ts +238 -0
  17. package/src/build/files.ts +171 -0
  18. package/src/build/first-load.ts +235 -0
  19. package/src/build/graph.ts +237 -0
  20. package/src/build/index.ts +678 -0
  21. package/src/build/is-inside.ts +12 -0
  22. package/src/build/island-promote.ts +311 -0
  23. package/src/build/islands.ts +452 -0
  24. package/src/build/manifest.ts +204 -0
  25. package/src/build/output.ts +81 -0
  26. package/src/build/plugin-host.ts +294 -0
  27. package/src/build/precompress.ts +139 -0
  28. package/src/build/prerender.ts +288 -0
  29. package/src/build/reach.ts +200 -0
  30. package/src/build/render-rules.ts +205 -0
  31. package/src/build/report.ts +290 -0
  32. package/src/build/resolve.ts +52 -0
  33. package/src/build/routes.ts +342 -0
  34. package/src/build/server-entry.ts +38 -0
  35. package/src/build/static-headers.ts +112 -0
  36. package/src/build/static.ts +209 -0
  37. package/src/build/status-pages.ts +127 -0
  38. package/src/build/style-bundles.ts +526 -0
  39. package/src/cli/check-forms.ts +636 -0
  40. package/src/cli/check-imports.ts +31 -0
  41. package/src/cli/check-links.ts +632 -0
  42. package/src/cli/check-security.ts +64 -0
  43. package/src/cli/check.ts +409 -0
  44. package/src/cli/commands.ts +372 -0
  45. package/src/cli/docs.ts +403 -0
  46. package/src/cli/index.ts +70 -0
  47. package/src/cli/inspect.ts +406 -0
  48. package/src/cli/mcp-tools.ts +492 -0
  49. package/src/cli/mcp.ts +205 -0
  50. package/src/cli/new.ts +52 -0
  51. package/src/cli/render.ts +416 -0
  52. package/src/cli/upgrade-names.ts +209 -0
  53. package/src/cli/upgrade.ts +367 -0
  54. package/src/compiler/analyze.ts +651 -0
  55. package/src/compiler/ast.ts +82 -0
  56. package/src/compiler/browser-globals.ts +250 -0
  57. package/src/compiler/cacheability-private.ts +566 -0
  58. package/src/compiler/cacheability.ts +335 -0
  59. package/src/compiler/compliance-eco.ts +71 -0
  60. package/src/compiler/compliance-rgaa.ts +614 -0
  61. package/src/compiler/compliance-urls.ts +148 -0
  62. package/src/compiler/compliance.ts +653 -0
  63. package/src/compiler/data-keys.ts +302 -0
  64. package/src/compiler/dev-source.ts +87 -0
  65. package/src/compiler/dom-attrs.ts +452 -0
  66. package/src/compiler/dom.ts +641 -0
  67. package/src/compiler/emit.ts +131 -0
  68. package/src/compiler/expr-context.ts +587 -0
  69. package/src/compiler/foreign-imports.ts +88 -0
  70. package/src/compiler/index.ts +8 -0
  71. package/src/compiler/interactivity.ts +366 -0
  72. package/src/compiler/mistakes.ts +520 -0
  73. package/src/compiler/node-env.ts +50 -0
  74. package/src/compiler/patch.ts +97 -0
  75. package/src/compiler/props-body.ts +60 -0
  76. package/src/compiler/props.ts +511 -0
  77. package/src/compiler/scope.ts +635 -0
  78. package/src/compiler/server-only.ts +365 -0
  79. package/src/compiler/shared.ts +397 -0
  80. package/src/compiler/signal-reads.ts +246 -0
  81. package/src/compiler/slots.ts +227 -0
  82. package/src/compiler/spread-handlers.ts +295 -0
  83. package/src/compiler/ssr-helpers.ts +555 -0
  84. package/src/compiler/ssr-island.ts +90 -0
  85. package/src/compiler/ssr-prunelle-tags.ts +69 -0
  86. package/src/compiler/ssr.ts +525 -0
  87. package/src/context.ts +199 -0
  88. package/src/dev/child.ts +30 -0
  89. package/src/dev/error-log.ts +177 -0
  90. package/src/dev/host-check.ts +32 -0
  91. package/src/dev/index.ts +268 -0
  92. package/src/dev/modules.ts +68 -0
  93. package/src/dev/open-editor.ts +228 -0
  94. package/src/dev/protocol.ts +24 -0
  95. package/src/dev/queue.ts +79 -0
  96. package/src/dev/reload.ts +159 -0
  97. package/src/dev/supervisor.ts +212 -0
  98. package/src/dev/watchers.ts +276 -0
  99. package/src/dom/action.ts +187 -0
  100. package/src/dom/attrs.ts +84 -0
  101. package/src/dom/claim.ts +120 -0
  102. package/src/dom/extras.ts +579 -0
  103. package/src/dom/index.ts +329 -0
  104. package/src/dom/island.ts +318 -0
  105. package/src/dom/loop.ts +484 -0
  106. package/src/dom/revive.ts +36 -0
  107. package/src/eco/declaration.ts +328 -0
  108. package/src/eco/index.ts +69 -0
  109. package/src/index.ts +22 -0
  110. package/src/jsx-runtime.ts +566 -0
  111. package/src/plugins/config.ts +92 -0
  112. package/src/plugins/context.ts +109 -0
  113. package/src/plugins/index.ts +14 -0
  114. package/src/plugins/load.ts +90 -0
  115. package/src/plugins/order.ts +148 -0
  116. package/src/plugins/public.ts +15 -0
  117. package/src/plugins/requires.ts +47 -0
  118. package/src/plugins/services.ts +119 -0
  119. package/src/plugins/types.ts +278 -0
  120. package/src/reactivity/graph.ts +259 -0
  121. package/src/reactivity/index.ts +541 -0
  122. package/src/reactivity/selector.ts +78 -0
  123. package/src/reactivity/store.ts +252 -0
  124. package/src/server/action-flash.ts +158 -0
  125. package/src/server/action-protect.ts +199 -0
  126. package/src/server/action-registry.ts +78 -0
  127. package/src/server/action.ts +511 -0
  128. package/src/server/app-entry.ts +23 -0
  129. package/src/server/app-secret.ts +63 -0
  130. package/src/server/assets.ts +168 -0
  131. package/src/server/compress.ts +646 -0
  132. package/src/server/consent.ts +290 -0
  133. package/src/server/cookies.ts +153 -0
  134. package/src/server/document.ts +286 -0
  135. package/src/server/env.ts +47 -0
  136. package/src/server/errors.ts +396 -0
  137. package/src/server/form-schema.ts +337 -0
  138. package/src/server/health.ts +275 -0
  139. package/src/server/http.ts +588 -0
  140. package/src/server/index.ts +615 -0
  141. package/src/server/lifecycle.ts +75 -0
  142. package/src/server/loader.ts +131 -0
  143. package/src/server/page.ts +122 -0
  144. package/src/server/param-matchers.ts +112 -0
  145. package/src/server/plugin-host.ts +267 -0
  146. package/src/server/prerendered.ts +71 -0
  147. package/src/server/public.ts +20 -0
  148. package/src/server/rate-limit.ts +199 -0
  149. package/src/server/region.ts +96 -0
  150. package/src/server/request-body.ts +27 -0
  151. package/src/server/request-path.ts +73 -0
  152. package/src/server/request-scope.ts +22 -0
  153. package/src/server/route-cache.ts +541 -0
  154. package/src/server/route-table.ts +424 -0
  155. package/src/server/router.ts +261 -0
  156. package/src/server/routing.ts +388 -0
  157. package/src/server/sanitize-html.ts +309 -0
  158. package/src/server/security.ts +550 -0
  159. package/src/server/serve-handlers.ts +93 -0
  160. package/src/server/served-file.ts +128 -0
  161. package/src/server/standard-schema.ts +104 -0
  162. package/src/server/start.ts +143 -0
  163. package/src/server/static-dir.ts +246 -0
  164. package/src/server/stream.ts +233 -0
  165. package/src/ssr/consent-banner.ts +58 -0
  166. package/src/ssr/context.ts +399 -0
  167. package/src/ssr/index.ts +624 -0
  168. package/src/ssr/navigation.ts +96 -0
  169. package/src/ssr/region.ts +192 -0
  170. package/src/style.ts +96 -0
  171. package/src/test/browser.ts +201 -0
  172. package/src/test/index.ts +262 -0
  173. package/src/ts-plugin/diagnostics.ts +505 -0
  174. package/src/ts-plugin/fixes.ts +364 -0
  175. package/src/ts-plugin/index.ts +194 -0
  176. package/src/unrenderable.ts +35 -0
  177. package/templates/_shared/AGENTS.md +10 -0
  178. package/templates/_shared/CLAUDE.md +1 -0
  179. package/templates/_shared/gitignore +8 -0
  180. package/templates/_shared/mcp.json +11 -0
  181. package/templates/_shared/public/robots.txt +2 -0
  182. package/templates/_shared/src/routes/legal.tsx +22 -0
  183. package/templates/_shared/tsconfig.json +25 -0
  184. package/templates/app/.env.example +8 -0
  185. package/templates/app/package.json +22 -0
  186. package/templates/app/prunelle.config.ts +13 -0
  187. package/templates/app/src/auth.ts +12 -0
  188. package/templates/app/src/mail.ts +4 -0
  189. package/templates/app/src/routes/_layout.tsx +40 -0
  190. package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
  191. package/templates/app/src/routes/dashboard/index.tsx +47 -0
  192. package/templates/app/src/routes/index.tsx +15 -0
  193. package/templates/app/src/routes/login.tsx +53 -0
  194. package/templates/app/src/routes/privacy.tsx +25 -0
  195. package/templates/app/src/styles/app.css +14 -0
  196. package/templates/app/tests/app.test.ts +73 -0
  197. package/templates/blog/content/posts/welcome.md +9 -0
  198. package/templates/blog/package.json +22 -0
  199. package/templates/blog/prunelle.config.ts +23 -0
  200. package/templates/blog/src/posts.ts +26 -0
  201. package/templates/blog/src/routes/_layout.tsx +25 -0
  202. package/templates/blog/src/routes/blog/[slug].tsx +31 -0
  203. package/templates/blog/src/routes/index.tsx +33 -0
  204. package/templates/blog/src/styles/app.css +15 -0
  205. package/templates/fullstack/package.json +19 -0
  206. package/templates/fullstack/prunelle.config.ts +6 -0
  207. package/templates/fullstack/src/actions/greet.ts +19 -0
  208. package/templates/fullstack/src/components/Counter.tsx +10 -0
  209. package/templates/fullstack/src/components/GreetForm.tsx +28 -0
  210. package/templates/fullstack/src/routes/_layout.tsx +18 -0
  211. package/templates/fullstack/src/routes/api/health.ts +5 -0
  212. package/templates/fullstack/src/routes/index.tsx +13 -0
  213. package/templates/fullstack/src/styles/app.css +39 -0
  214. package/templates/fullstack/tests/app.test.ts +37 -0
  215. package/templates/minimal/package.json +19 -0
  216. package/templates/minimal/prunelle.config.ts +6 -0
  217. package/templates/minimal/src/components/Counter.tsx +10 -0
  218. package/templates/minimal/src/routes/_layout.tsx +18 -0
  219. package/templates/minimal/src/routes/index.tsx +11 -0
  220. package/templates/minimal/src/styles/app.css +32 -0
  221. package/ts-plugin.cjs +4277 -0
  222. package/README.md +0 -3
@@ -0,0 +1,237 @@
1
+ // The module graph of one build: every .ts/.tsx file reachable from the routes, analyzed once (and reused across `prunelle dev` rebuilds while mtime and size match).
2
+
3
+ import type { ModuleAnalysis } from '../compiler/index'
4
+ import { existsSync, readFileSync, statSync } from 'node:fs'
5
+ import { parseTsx } from '../compiler/analyze'
6
+ import { computeJsxNodes } from '../compiler/ast'
7
+ import { analyzeModule } from '../compiler/index'
8
+ import { PrunelleMistake } from '../compiler/mistakes'
9
+ import { formatCodeFrame, formatDiagnostic, formatLoc } from '../compiler/shared'
10
+ import { isTsFile, relPosix } from './files'
11
+ import { resolveExportTarget } from './island-promote'
12
+ import { resolveImportPath } from './resolve'
13
+
14
+ export interface FileStamp {
15
+ mtimeMs: number
16
+ size: number
17
+ }
18
+
19
+ export interface CachedClientBuild {
20
+ signature: string
21
+ clientDir: string
22
+ inputStamps: Map<string, FileStamp>
23
+ islandChunks: Map<string, string>
24
+ srcCssToUrl: Map<string, string>
25
+ islandCssUrl: Map<string, string>
26
+ assetFiles: string[]
27
+ styleUrls: string[]
28
+ runtimeScript: string | undefined
29
+ regionScript: string | undefined
30
+ reviveScript: string | undefined
31
+ chunkImports: Record<string, string[]>
32
+ }
33
+
34
+ export interface CachedServerBuild {
35
+ signature: string
36
+ serverDir: string
37
+ inputStamps: Map<string, FileStamp>
38
+ }
39
+
40
+ export interface BuildCacheStats {
41
+ clientBuilds: number
42
+ clientSkips: number
43
+ serverBuilds: number
44
+ serverSkips: number
45
+ }
46
+
47
+ /** An analysis without the AST and what is keyed by its nodes: the cache outlives a build, the AST (many times the size of the source) does not need to. */
48
+ export type SlimAnalysis = Omit<ModuleAnalysis, 'program' | 'jsxNodes' | 'exprContext'>
49
+
50
+ export function slimAnalysis(analysis: ModuleAnalysis): SlimAnalysis {
51
+ const { program: _program, jsxNodes: _jsxNodes, exprContext: _exprContext, ...slim } = analysis
52
+ return slim
53
+ }
54
+
55
+ /** The analysis again, its program and JSX node set parsed together on first use: the node set only matches the program it was computed from. */
56
+ export function reviveAnalysis(slim: SlimAnalysis, code: string): ModuleAnalysis {
57
+ let program: ModuleAnalysis['program'] | undefined
58
+ let jsxNodes: ModuleAnalysis['jsxNodes'] | undefined
59
+ const parsed = (): ModuleAnalysis['program'] => program ??= parseTsx(slim.filename, code)
60
+ return Object.defineProperties({ ...slim } as ModuleAnalysis, {
61
+ program: { get: parsed, enumerable: true, configurable: true },
62
+ jsxNodes: { get: () => jsxNodes ??= slim.hasJsx ? computeJsxNodes(parsed()) : new WeakSet(), enumerable: true, configurable: true },
63
+ exprContext: { value: undefined, writable: true, enumerable: true, configurable: true },
64
+ })
65
+ }
66
+
67
+ export interface BuildCache {
68
+ analyses: Map<string, FileStamp & { code: string, analysis: SlimAnalysis }>
69
+ domCompiled: Map<string, FileStamp & { key?: string | undefined, code: string }>
70
+ ssrCompiled: Map<string, FileStamp & { key: string, code: string }>
71
+ lastClient?: CachedClientBuild | undefined
72
+ lastServer?: CachedServerBuild | undefined
73
+ watchedFiles: Set<string>
74
+ stats: BuildCacheStats
75
+ }
76
+
77
+ export function createBuildCache(): BuildCache {
78
+ return {
79
+ analyses: new Map(),
80
+ domCompiled: new Map(),
81
+ ssrCompiled: new Map(),
82
+ watchedFiles: new Set(),
83
+ stats: { clientBuilds: 0, clientSkips: 0, serverBuilds: 0, serverSkips: 0 },
84
+ }
85
+ }
86
+
87
+ export function clearBuildCache(cache: BuildCache): void {
88
+ cache.analyses.clear()
89
+ cache.domCompiled.clear()
90
+ cache.ssrCompiled.clear()
91
+ cache.lastClient = undefined
92
+ cache.lastServer = undefined
93
+ cache.watchedFiles.clear()
94
+ }
95
+
96
+ export function stampFiles(files: Iterable<string>): Map<string, FileStamp> {
97
+ const out = new Map<string, FileStamp>()
98
+ for (const file of files) {
99
+ if (out.has(file))
100
+ continue
101
+ try {
102
+ const st = statSync(file)
103
+ if (st.isFile())
104
+ out.set(file, { mtimeMs: st.mtimeMs, size: st.size })
105
+ }
106
+ catch {}
107
+ }
108
+ return out
109
+ }
110
+
111
+ export function stampsMatch(inputStamps: ReadonlyMap<string, FileStamp>): boolean {
112
+ for (const [file, prev] of inputStamps) {
113
+ if (!existsSync(file))
114
+ return false
115
+ try {
116
+ const st = statSync(file)
117
+ if (st.mtimeMs !== prev.mtimeMs || st.size !== prev.size)
118
+ return false
119
+ }
120
+ catch {
121
+ return false
122
+ }
123
+ }
124
+ return true
125
+ }
126
+
127
+
128
+ export class ModuleGraph {
129
+ readonly analyses = new Map<string, ModuleAnalysis>()
130
+ private readonly sources = new Map<string, string>()
131
+ private readonly stamps = new Map<string, FileStamp>()
132
+ private readonly resolved = new Map<string, string | undefined>()
133
+ private readonly deps = new Map<string, string[]>()
134
+
135
+ /** `root` is the app's folder, for the root-relative paths in errors. */
136
+ constructor(private readonly root: string, private readonly cache?: BuildCache) {}
137
+
138
+ /** The file's mtime and size; only tracked when a cache is in use. */
139
+ stamp(file: string): FileStamp | undefined {
140
+ const known = this.stamps.get(file)
141
+ if (known !== undefined || this.cache === undefined)
142
+ return known
143
+ try {
144
+ const st = statSync(file)
145
+ const stamp = { mtimeMs: st.mtimeMs, size: st.size }
146
+ this.stamps.set(file, stamp)
147
+ return stamp
148
+ }
149
+ catch {
150
+ return undefined
151
+ }
152
+ }
153
+
154
+ /** The text of a file, read once per build. */
155
+ source(file: string): string {
156
+ let code = this.sources.get(file)
157
+ if (code === undefined) {
158
+ code = readFileSync(file, 'utf8')
159
+ this.sources.set(file, code)
160
+ }
161
+ return code
162
+ }
163
+
164
+ /** `resolveImportPath`, remembered for the build. */
165
+ resolve(from: string, specifier: string): string | undefined {
166
+ const key = `${from}\0${specifier}`
167
+ if (this.resolved.has(key))
168
+ return this.resolved.get(key)
169
+ const target = resolveImportPath(from, specifier)
170
+ this.resolved.set(key, target)
171
+ return target
172
+ }
173
+
174
+ /** The .ts/.tsx modules a loaded file imports or re-exports from. */
175
+ localDeps(file: string): string[] {
176
+ let list = this.deps.get(file)
177
+ if (list === undefined) {
178
+ list = []
179
+ const analysis = this.analyses.get(file)
180
+ for (const { source } of [...(analysis?.imports ?? []), ...(analysis?.reexports ?? [])]) {
181
+ const target = this.resolve(file, source)
182
+ if (target !== undefined && isTsFile(target))
183
+ list.push(target)
184
+ }
185
+ if (analysis !== undefined)
186
+ this.deps.set(file, list)
187
+ }
188
+ return list
189
+ }
190
+
191
+ /** Analyzes `file` and everything it imports. */
192
+ load(file: string): ModuleAnalysis {
193
+ const existing = this.analyses.get(file)
194
+ if (existing !== undefined)
195
+ return existing
196
+ const stamp = this.stamp(file)
197
+ const cached = stamp === undefined ? undefined : this.cache?.analyses.get(file)
198
+ let analysis: ModuleAnalysis
199
+ if (cached !== undefined && cached.mtimeMs === stamp!.mtimeMs && cached.size === stamp!.size) {
200
+ analysis = reviveAnalysis(cached.analysis, cached.code)
201
+ this.sources.set(file, cached.code)
202
+ }
203
+ else {
204
+ const code = this.source(file)
205
+ analysis = this.analyze(file, code)
206
+ if (this.cache !== undefined && stamp !== undefined)
207
+ this.cache.analyses.set(file, { mtimeMs: stamp.mtimeMs, size: stamp.size, code, analysis: slimAnalysis(analysis) })
208
+ }
209
+ this.analyses.set(file, analysis)
210
+ for (const dep of this.localDeps(file))
211
+ this.load(dep)
212
+ return analysis
213
+ }
214
+
215
+ /** `analyzeModule`, its errors naming the file from the app's root, a mistake at its line with a code frame as a syntax error has. */
216
+ private analyze(file: string, code: string): ModuleAnalysis {
217
+ try {
218
+ return analyzeModule(file, code)
219
+ }
220
+ catch (err) {
221
+ if (!(err instanceof Error))
222
+ throw err
223
+ const rel = relPosix(this.root, file)
224
+ err.message = err.message.replaceAll(file, rel)
225
+ if (err instanceof PrunelleMistake && err.start !== undefined) {
226
+ const frame = formatCodeFrame(code, err.start)
227
+ err.message = `${formatDiagnostic(formatLoc(rel, code, err.start), err.message)}${frame === '' ? '' : `\n${frame}`}`
228
+ }
229
+ throw err
230
+ }
231
+ }
232
+
233
+ /** The module that declares `exportName`, following re-export chains and loading each file (parse errors are never swallowed). */
234
+ exportTarget(file: string, exportName: string): { file: string, exportName: string } {
235
+ return resolveExportTarget(this, f => this.load(f), file, exportName) ?? { file, exportName }
236
+ }
237
+ }