prunelle 0.0.0-stage → 0.5.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 (200) hide show
  1. package/llms.txt +152 -0
  2. package/package.json +59 -4
  3. package/src/a11y/declaration.ts +335 -0
  4. package/src/a11y/index.ts +446 -0
  5. package/src/a11y/rgaa-map.ts +184 -0
  6. package/src/ambient.d.ts +6 -0
  7. package/src/attrs.ts +43 -0
  8. package/src/build/bundle.ts +657 -0
  9. package/src/build/carry.ts +57 -0
  10. package/src/build/client-entries.ts +107 -0
  11. package/src/build/client-plugin.ts +173 -0
  12. package/src/build/client-prune.ts +168 -0
  13. package/src/build/compile.ts +129 -0
  14. package/src/build/ecoindex.ts +229 -0
  15. package/src/build/files.ts +156 -0
  16. package/src/build/first-load.ts +164 -0
  17. package/src/build/graph.ts +247 -0
  18. package/src/build/index.ts +641 -0
  19. package/src/build/is-inside.ts +12 -0
  20. package/src/build/islands.ts +641 -0
  21. package/src/build/manifest.ts +325 -0
  22. package/src/build/output.ts +84 -0
  23. package/src/build/plugin-host.ts +278 -0
  24. package/src/build/precompress.ts +139 -0
  25. package/src/build/prerender.ts +232 -0
  26. package/src/build/render-rules.ts +205 -0
  27. package/src/build/report.ts +268 -0
  28. package/src/build/resolve.ts +52 -0
  29. package/src/build/routes.ts +342 -0
  30. package/src/build/server-entry.ts +38 -0
  31. package/src/build/static.ts +207 -0
  32. package/src/build/status-pages.ts +127 -0
  33. package/src/build/style-bundles.ts +526 -0
  34. package/src/cli/check-forms.ts +654 -0
  35. package/src/cli/check-links.ts +619 -0
  36. package/src/cli/check.ts +381 -0
  37. package/src/cli/commands.ts +345 -0
  38. package/src/cli/docs.ts +402 -0
  39. package/src/cli/index.ts +70 -0
  40. package/src/cli/inspect.ts +345 -0
  41. package/src/cli/mcp-tools.ts +480 -0
  42. package/src/cli/mcp.ts +205 -0
  43. package/src/cli/new.ts +41 -0
  44. package/src/cli/render.ts +261 -0
  45. package/src/cli/upgrade-names.ts +209 -0
  46. package/src/cli/upgrade.ts +354 -0
  47. package/src/compiler/analyze.ts +632 -0
  48. package/src/compiler/ast.ts +82 -0
  49. package/src/compiler/browser-globals.ts +127 -0
  50. package/src/compiler/cacheability.ts +592 -0
  51. package/src/compiler/compliance-rgaa.ts +502 -0
  52. package/src/compiler/compliance.ts +497 -0
  53. package/src/compiler/data-keys.ts +295 -0
  54. package/src/compiler/dev-source.ts +87 -0
  55. package/src/compiler/dom-attrs.ts +452 -0
  56. package/src/compiler/dom.ts +567 -0
  57. package/src/compiler/emit.ts +131 -0
  58. package/src/compiler/expr-context.ts +518 -0
  59. package/src/compiler/index.ts +8 -0
  60. package/src/compiler/interactivity.ts +366 -0
  61. package/src/compiler/mistakes.ts +499 -0
  62. package/src/compiler/node-env.ts +50 -0
  63. package/src/compiler/patch.ts +97 -0
  64. package/src/compiler/props.ts +511 -0
  65. package/src/compiler/scope.ts +607 -0
  66. package/src/compiler/server-only.ts +326 -0
  67. package/src/compiler/shared.ts +369 -0
  68. package/src/compiler/signal-reads.ts +242 -0
  69. package/src/compiler/slots.ts +227 -0
  70. package/src/compiler/ssr-helpers.ts +555 -0
  71. package/src/compiler/ssr-island.ts +90 -0
  72. package/src/compiler/ssr-prunelle-tags.ts +69 -0
  73. package/src/compiler/ssr.ts +526 -0
  74. package/src/context.ts +165 -0
  75. package/src/dev/child.ts +30 -0
  76. package/src/dev/error-log.ts +151 -0
  77. package/src/dev/index.ts +258 -0
  78. package/src/dev/modules.ts +68 -0
  79. package/src/dev/open-editor.ts +204 -0
  80. package/src/dev/protocol.ts +22 -0
  81. package/src/dev/queue.ts +79 -0
  82. package/src/dev/reload.ts +159 -0
  83. package/src/dev/supervisor.ts +204 -0
  84. package/src/dev/watchers.ts +251 -0
  85. package/src/dom/action.ts +164 -0
  86. package/src/dom/attrs.ts +84 -0
  87. package/src/dom/claim.ts +120 -0
  88. package/src/dom/extras.ts +562 -0
  89. package/src/dom/index.ts +289 -0
  90. package/src/dom/island.ts +285 -0
  91. package/src/dom/loop.ts +450 -0
  92. package/src/dom/revive.ts +36 -0
  93. package/src/index.ts +22 -0
  94. package/src/jsx-runtime.ts +566 -0
  95. package/src/plugins/config.ts +86 -0
  96. package/src/plugins/context.ts +66 -0
  97. package/src/plugins/index.ts +14 -0
  98. package/src/plugins/load.ts +70 -0
  99. package/src/plugins/order.ts +111 -0
  100. package/src/plugins/public.ts +15 -0
  101. package/src/plugins/requires.ts +47 -0
  102. package/src/plugins/services.ts +97 -0
  103. package/src/plugins/types.ts +261 -0
  104. package/src/reactivity/graph.ts +249 -0
  105. package/src/reactivity/index.ts +533 -0
  106. package/src/reactivity/selector.ts +51 -0
  107. package/src/reactivity/store.ts +208 -0
  108. package/src/server/action-protect.ts +198 -0
  109. package/src/server/action-registry.ts +78 -0
  110. package/src/server/action.ts +530 -0
  111. package/src/server/app-entry.ts +23 -0
  112. package/src/server/assets.ts +168 -0
  113. package/src/server/compress.ts +642 -0
  114. package/src/server/consent.ts +253 -0
  115. package/src/server/cookies.ts +139 -0
  116. package/src/server/document.ts +271 -0
  117. package/src/server/env.ts +33 -0
  118. package/src/server/errors.ts +391 -0
  119. package/src/server/form-schema.ts +343 -0
  120. package/src/server/health.ts +244 -0
  121. package/src/server/http.ts +538 -0
  122. package/src/server/index.ts +586 -0
  123. package/src/server/lifecycle.ts +75 -0
  124. package/src/server/loader.ts +123 -0
  125. package/src/server/page.ts +107 -0
  126. package/src/server/param-matchers.ts +112 -0
  127. package/src/server/plugin-host.ts +265 -0
  128. package/src/server/prerendered.ts +71 -0
  129. package/src/server/public.ts +19 -0
  130. package/src/server/rate-limit.ts +156 -0
  131. package/src/server/region.ts +96 -0
  132. package/src/server/request-body.ts +27 -0
  133. package/src/server/request-path.ts +73 -0
  134. package/src/server/request-scope.ts +22 -0
  135. package/src/server/route-cache.ts +423 -0
  136. package/src/server/route-table.ts +410 -0
  137. package/src/server/router.ts +261 -0
  138. package/src/server/routing.ts +472 -0
  139. package/src/server/security.ts +499 -0
  140. package/src/server/serve-handlers.ts +83 -0
  141. package/src/server/served-file.ts +128 -0
  142. package/src/server/standard-schema.ts +87 -0
  143. package/src/server/start.ts +143 -0
  144. package/src/server/static-dir.ts +220 -0
  145. package/src/server/stream.ts +211 -0
  146. package/src/ssr/context.ts +383 -0
  147. package/src/ssr/index.ts +596 -0
  148. package/src/ssr/navigation.ts +96 -0
  149. package/src/ssr/region.ts +183 -0
  150. package/src/style.ts +33 -0
  151. package/src/test/browser.ts +192 -0
  152. package/src/test/index.ts +191 -0
  153. package/src/ts-plugin/diagnostics.ts +378 -0
  154. package/src/ts-plugin/fixes.ts +364 -0
  155. package/src/ts-plugin/index.ts +194 -0
  156. package/src/unrenderable.ts +35 -0
  157. package/templates/_shared/AGENTS.md +10 -0
  158. package/templates/_shared/CLAUDE.md +1 -0
  159. package/templates/_shared/gitignore +3 -0
  160. package/templates/_shared/mcp.json +11 -0
  161. package/templates/_shared/public/robots.txt +2 -0
  162. package/templates/_shared/src/routes/legal.tsx +13 -0
  163. package/templates/_shared/tsconfig.json +25 -0
  164. package/templates/app/.env.example +4 -0
  165. package/templates/app/package.json +21 -0
  166. package/templates/app/prunelle.config.ts +11 -0
  167. package/templates/app/src/auth.ts +14 -0
  168. package/templates/app/src/routes/_layout.tsx +32 -0
  169. package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
  170. package/templates/app/src/routes/dashboard/index.tsx +13 -0
  171. package/templates/app/src/routes/index.tsx +15 -0
  172. package/templates/app/src/routes/login.tsx +34 -0
  173. package/templates/app/src/styles/app.css +7 -0
  174. package/templates/app/tests/app.test.ts +32 -0
  175. package/templates/blog/content/posts/welcome.md +9 -0
  176. package/templates/blog/package.json +22 -0
  177. package/templates/blog/prunelle.config.ts +23 -0
  178. package/templates/blog/src/posts.ts +26 -0
  179. package/templates/blog/src/routes/_layout.tsx +20 -0
  180. package/templates/blog/src/routes/blog/[slug].tsx +31 -0
  181. package/templates/blog/src/routes/index.tsx +33 -0
  182. package/templates/blog/src/styles/app.css +10 -0
  183. package/templates/fullstack/package.json +19 -0
  184. package/templates/fullstack/prunelle.config.ts +6 -0
  185. package/templates/fullstack/src/actions/greet.ts +19 -0
  186. package/templates/fullstack/src/components/Counter.tsx +10 -0
  187. package/templates/fullstack/src/components/GreetForm.tsx +27 -0
  188. package/templates/fullstack/src/routes/_layout.tsx +14 -0
  189. package/templates/fullstack/src/routes/api/health.ts +5 -0
  190. package/templates/fullstack/src/routes/index.tsx +13 -0
  191. package/templates/fullstack/src/styles/app.css +29 -0
  192. package/templates/fullstack/tests/app.test.ts +37 -0
  193. package/templates/minimal/package.json +19 -0
  194. package/templates/minimal/prunelle.config.ts +6 -0
  195. package/templates/minimal/src/components/Counter.tsx +10 -0
  196. package/templates/minimal/src/routes/_layout.tsx +14 -0
  197. package/templates/minimal/src/routes/index.tsx +11 -0
  198. package/templates/minimal/src/styles/app.css +22 -0
  199. package/ts-plugin.cjs +4277 -0
  200. package/README.md +0 -3
@@ -0,0 +1,247 @@
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 { analyzeModule } from '../compiler/index'
6
+ import { PrunelleMistake } from '../compiler/mistakes'
7
+ import { formatCodeFrame, formatDiagnostic, formatLoc } from '../compiler/shared'
8
+ import { isTsFile, relPosix } from './files'
9
+ import { resolveImportPath } from './resolve'
10
+
11
+ export interface FileStamp {
12
+ mtimeMs: number
13
+ size: number
14
+ }
15
+
16
+ export interface CachedClientBuild {
17
+ signature: string
18
+ clientDir: string
19
+ inputStamps: Map<string, FileStamp>
20
+ islandChunks: Map<string, string>
21
+ srcCssToUrl: Map<string, string>
22
+ islandCssUrl: Map<string, string>
23
+ assetFiles: string[]
24
+ styleUrls: string[]
25
+ runtimeScript: string | undefined
26
+ regionScript: string | undefined
27
+ reviveScript: string | undefined
28
+ chunkImports: Record<string, string[]>
29
+ }
30
+
31
+ export interface CachedServerBuild {
32
+ signature: string
33
+ serverDir: string
34
+ inputStamps: Map<string, FileStamp>
35
+ }
36
+
37
+ export interface BuildCacheStats {
38
+ clientBuilds: number
39
+ clientSkips: number
40
+ serverBuilds: number
41
+ serverSkips: number
42
+ }
43
+
44
+ export interface BuildCache {
45
+ analyses: Map<string, FileStamp & { code: string, analysis: ModuleAnalysis }>
46
+ domCompiled: Map<string, FileStamp & { key?: string | undefined, code: string }>
47
+ ssrCompiled: Map<string, FileStamp & { key: string, code: string }>
48
+ lastClient?: CachedClientBuild | undefined
49
+ lastServer?: CachedServerBuild | undefined
50
+ watchedFiles: Set<string>
51
+ stats: BuildCacheStats
52
+ }
53
+
54
+ export function createBuildCache(): BuildCache {
55
+ return {
56
+ analyses: new Map(),
57
+ domCompiled: new Map(),
58
+ ssrCompiled: new Map(),
59
+ watchedFiles: new Set(),
60
+ stats: { clientBuilds: 0, clientSkips: 0, serverBuilds: 0, serverSkips: 0 },
61
+ }
62
+ }
63
+
64
+ export function clearBuildCache(cache: BuildCache): void {
65
+ cache.analyses.clear()
66
+ cache.domCompiled.clear()
67
+ cache.ssrCompiled.clear()
68
+ cache.lastClient = undefined
69
+ cache.lastServer = undefined
70
+ cache.watchedFiles.clear()
71
+ }
72
+
73
+ export function stampFiles(files: Iterable<string>): Map<string, FileStamp> {
74
+ const out = new Map<string, FileStamp>()
75
+ for (const file of files) {
76
+ if (out.has(file))
77
+ continue
78
+ try {
79
+ const st = statSync(file)
80
+ if (st.isFile())
81
+ out.set(file, { mtimeMs: st.mtimeMs, size: st.size })
82
+ }
83
+ catch {}
84
+ }
85
+ return out
86
+ }
87
+
88
+ export function stampsMatch(inputStamps: ReadonlyMap<string, FileStamp>): boolean {
89
+ for (const [file, prev] of inputStamps) {
90
+ if (!existsSync(file))
91
+ return false
92
+ try {
93
+ const st = statSync(file)
94
+ if (st.mtimeMs !== prev.mtimeMs || st.size !== prev.size)
95
+ return false
96
+ }
97
+ catch {
98
+ return false
99
+ }
100
+ }
101
+ return true
102
+ }
103
+
104
+ const MAX_REEXPORT_DEPTH = 8
105
+
106
+ export class ModuleGraph {
107
+ readonly analyses = new Map<string, ModuleAnalysis>()
108
+ private readonly sources = new Map<string, string>()
109
+ private readonly stamps = new Map<string, FileStamp>()
110
+ private readonly resolved = new Map<string, string | undefined>()
111
+ private readonly deps = new Map<string, string[]>()
112
+
113
+ /** `root` is the app's folder, for the root-relative paths in errors. */
114
+ constructor(private readonly root: string, private readonly cache?: BuildCache) {}
115
+
116
+ /** The file's mtime and size; only tracked when a cache is in use. */
117
+ stamp(file: string): FileStamp | undefined {
118
+ const known = this.stamps.get(file)
119
+ if (known !== undefined || this.cache === undefined)
120
+ return known
121
+ try {
122
+ const st = statSync(file)
123
+ const stamp = { mtimeMs: st.mtimeMs, size: st.size }
124
+ this.stamps.set(file, stamp)
125
+ return stamp
126
+ }
127
+ catch {
128
+ return undefined
129
+ }
130
+ }
131
+
132
+ /** The text of a file, read once per build. */
133
+ source(file: string): string {
134
+ let code = this.sources.get(file)
135
+ if (code === undefined) {
136
+ code = readFileSync(file, 'utf8')
137
+ this.sources.set(file, code)
138
+ }
139
+ return code
140
+ }
141
+
142
+ /** `resolveImportPath`, remembered for the build. */
143
+ resolve(from: string, specifier: string): string | undefined {
144
+ const key = `${from}\0${specifier}`
145
+ if (this.resolved.has(key))
146
+ return this.resolved.get(key)
147
+ const target = resolveImportPath(from, specifier)
148
+ this.resolved.set(key, target)
149
+ return target
150
+ }
151
+
152
+ /** The .ts/.tsx modules a loaded file imports or re-exports from. */
153
+ localDeps(file: string): string[] {
154
+ let list = this.deps.get(file)
155
+ if (list === undefined) {
156
+ list = []
157
+ const analysis = this.analyses.get(file)
158
+ for (const { source } of [...(analysis?.imports ?? []), ...(analysis?.reexports ?? [])]) {
159
+ const target = this.resolve(file, source)
160
+ if (target !== undefined && isTsFile(target))
161
+ list.push(target)
162
+ }
163
+ if (analysis !== undefined)
164
+ this.deps.set(file, list)
165
+ }
166
+ return list
167
+ }
168
+
169
+ /** Analyzes `file` and everything it imports. */
170
+ load(file: string): ModuleAnalysis {
171
+ const existing = this.analyses.get(file)
172
+ if (existing !== undefined)
173
+ return existing
174
+ const stamp = this.stamp(file)
175
+ const cached = stamp === undefined ? undefined : this.cache?.analyses.get(file)
176
+ let analysis: ModuleAnalysis
177
+ if (cached !== undefined && cached.mtimeMs === stamp!.mtimeMs && cached.size === stamp!.size) {
178
+ analysis = cached.analysis
179
+ this.sources.set(file, cached.code)
180
+ }
181
+ else {
182
+ const code = this.source(file)
183
+ analysis = this.analyze(file, code)
184
+ if (this.cache !== undefined && stamp !== undefined)
185
+ this.cache.analyses.set(file, { mtimeMs: stamp.mtimeMs, size: stamp.size, code, analysis })
186
+ }
187
+ this.analyses.set(file, analysis)
188
+ for (const dep of this.localDeps(file))
189
+ this.load(dep)
190
+ return analysis
191
+ }
192
+
193
+ /** `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. */
194
+ private analyze(file: string, code: string): ModuleAnalysis {
195
+ try {
196
+ return analyzeModule(file, code)
197
+ }
198
+ catch (err) {
199
+ if (!(err instanceof Error))
200
+ throw err
201
+ const rel = relPosix(this.root, file)
202
+ err.message = err.message.replaceAll(file, rel)
203
+ if (err instanceof PrunelleMistake && err.start !== undefined) {
204
+ const frame = formatCodeFrame(code, err.start)
205
+ err.message = `${formatDiagnostic(formatLoc(rel, code, err.start), err.message)}${frame === '' ? '' : `\n${frame}`}`
206
+ }
207
+ throw err
208
+ }
209
+ }
210
+
211
+ /** Follows `export { x } from './y'` and `export * from './y'` chains to the module that declares the export. */
212
+ exportTarget(file: string, exportName: string, depth = 0, seen = new Set<string>()): { file: string, exportName: string } {
213
+ if (depth > MAX_REEXPORT_DEPTH)
214
+ return { file, exportName }
215
+ const key = `${file}\0${exportName}`
216
+ if (seen.has(key))
217
+ return { file, exportName }
218
+ seen.add(key)
219
+
220
+ const analysis = this.load(file)
221
+ const direct = analysis.reexports.find(r => r.exported === exportName)
222
+ if (direct !== undefined) {
223
+ const next = this.resolve(file, direct.source)
224
+ if (next !== undefined && isTsFile(next))
225
+ return this.exportTarget(next, direct.local, depth + 1, seen)
226
+ }
227
+
228
+ if (analysis.exportedNames.includes(exportName))
229
+ return { file, exportName }
230
+
231
+ // Follow `export * from './y'` barrel re-exports (named exports only, per ESM spec `export *` never re-exports `default`).
232
+ if (exportName !== 'default') {
233
+ for (const re of analysis.reexports) {
234
+ if (re.exported !== '*')
235
+ continue
236
+ const next = this.resolve(file, re.source)
237
+ if (next === undefined || !isTsFile(next))
238
+ continue
239
+ const candidate = this.exportTarget(next, exportName, depth + 1, seen)
240
+ if (this.load(candidate.file).exportedNames.includes(candidate.exportName))
241
+ return candidate
242
+ }
243
+ }
244
+
245
+ return { file, exportName }
246
+ }
247
+ }