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,406 @@
1
+ // `prunelle inspect [dir] [--json]`: fast static report of routes, islands, actions, and active plugins without running a full bundle.
2
+
3
+ import type { ActionsByFile } from '../build/islands'
4
+ import type { StatusPageKind } from '../build/manifest'
5
+ import type { PrunelleConfig, PrunellePlugin, ServerPluginAPI } from '../plugins/index'
6
+ import type { RouteCacheSpec } from '../server/route-cache'
7
+ import { existsSync } from 'node:fs'
8
+ import { basename, join, resolve } from 'node:path'
9
+ import { relPosix, walkRoutes } from '../build/files'
10
+ import { ModuleGraph } from '../build/graph'
11
+ import { analyzeIslands } from '../build/islands'
12
+ import { buildActionEntries, buildRouteEntries } from '../build/manifest'
13
+ import { discoverRouteMatchers, hasRouteHandlerExport, routeGroupsOf, SPECIAL_ROUTE_FILES } from '../build/routes'
14
+ import { createAppContext, loadConfig, pickRuntimeConfig, resolvePlugins, runWithAppContext } from '../plugins/index'
15
+ import { actionHash } from '../server/action'
16
+ import { extractOptionalParams, extractPatternMatchers } from '../server/param-matchers'
17
+ import { formatCacheSpec } from '../server/route-cache'
18
+
19
+ const HTTP_METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'])
20
+
21
+ export interface InspectRoute {
22
+ path: string
23
+ file?: string | undefined
24
+ plugin?: string | undefined
25
+ methods?: string[] | undefined
26
+ groups?: string[] | undefined
27
+ matchers?: Record<string, string> | undefined
28
+ optionalParams?: string[] | undefined
29
+ layouts: string[]
30
+ middlewares: string[]
31
+ load: boolean
32
+ prerender: boolean
33
+ cache?: RouteCacheSpec | undefined
34
+ cacheable?: boolean | undefined
35
+ }
36
+
37
+ export interface InspectIsland {
38
+ exportName: string
39
+ file: string
40
+ reason: string
41
+ hydrate: string
42
+ }
43
+
44
+ export interface InspectAction {
45
+ exportName: string
46
+ file: string
47
+ url: string
48
+ middlewares: string[]
49
+ }
50
+
51
+ export interface InspectPlugin {
52
+ name: string
53
+ enforce?: 'pre' | 'post' | undefined
54
+ providesLocals: string[]
55
+ readsLocals: string[]
56
+ commands: string[]
57
+ }
58
+
59
+ export interface InspectStatusPage {
60
+ kind: StatusPageKind
61
+ dirPattern: string
62
+ file: string
63
+ layouts: string[]
64
+ inGroup?: boolean | undefined
65
+ }
66
+
67
+ export interface InspectParamMatcher {
68
+ name: string
69
+ file: string
70
+ }
71
+
72
+ export interface InspectReport {
73
+ routes: InspectRoute[]
74
+ statusPages: InspectStatusPage[]
75
+ paramMatchers: InspectParamMatcher[]
76
+ islands: InspectIsland[]
77
+ actions: InspectAction[]
78
+ plugins: InspectPlugin[]
79
+ }
80
+
81
+ // Collects routes registered by plugins via `server(api)` without booting a server, then runs every `onShutdown` hook so timers and handles close immediately.
82
+ async function discoverPluginRoutes(
83
+ plugins: readonly PrunellePlugin[],
84
+ config: PrunelleConfig,
85
+ paths: { root: string, outDir: string, assetPrefix: string, site: string | undefined },
86
+ ): Promise<InspectRoute[]> {
87
+ const { root, outDir, assetPrefix, site } = paths
88
+ const appCtx = createAppContext({
89
+ root,
90
+ outDir,
91
+ publicDir: join(outDir, 'public'),
92
+ assetPrefix,
93
+ site,
94
+ dev: false,
95
+ nodeEnv: 'production',
96
+ })
97
+ const shutdowns: (() => void | Promise<void>)[] = []
98
+ const routes: InspectRoute[] = []
99
+ const runtimeConfig = pickRuntimeConfig(config) as Readonly<Record<string, unknown>>
100
+
101
+ try {
102
+ await runWithAppContext(appCtx, async () => {
103
+ for (const plugin of plugins) {
104
+ if (plugin.server === undefined)
105
+ continue
106
+ const byPath = new Map<string, string[]>()
107
+ const api: ServerPluginAPI = {
108
+ root,
109
+ outDir,
110
+ assetPrefix,
111
+ site,
112
+ dev: false,
113
+ devExposed: false,
114
+ trustProxy: config.trustProxy ?? false,
115
+ trustedOrigins: config.trustedOrigins ?? [],
116
+ config: runtimeConfig,
117
+ use: () => {},
118
+ route: (method, path) => {
119
+ const upper = method.toUpperCase()
120
+ const methods = byPath.get(path)
121
+ if (methods === undefined)
122
+ byPath.set(path, [upper])
123
+ else if (!methods.includes(upper))
124
+ methods.push(upper)
125
+ },
126
+ rateLimiter: () => ({ hit: () => 0, peek: () => 0 }),
127
+ rewrite: () => {},
128
+ provide: appCtx.provide,
129
+ inject: appCtx.inject,
130
+ getBuildData: () => undefined,
131
+ healthCheck: () => {},
132
+ onShutdown: (fn) => {
133
+ shutdowns.push(fn)
134
+ },
135
+ }
136
+ try {
137
+ await plugin.server(api)
138
+ }
139
+ catch {
140
+ // A plugin whose server() requires build artifacts or live services is skipped gracefully during static inspection.
141
+ }
142
+ for (const [path, methods] of byPath) {
143
+ routes.push({
144
+ path,
145
+ plugin: plugin.name,
146
+ methods,
147
+ layouts: [],
148
+ middlewares: [],
149
+ load: false,
150
+ prerender: false,
151
+ })
152
+ }
153
+ }
154
+ })
155
+ }
156
+ finally {
157
+ for (let i = shutdowns.length - 1; i >= 0; i--) {
158
+ try {
159
+ await shutdowns[i]!()
160
+ }
161
+ catch {}
162
+ }
163
+ }
164
+ return routes
165
+ }
166
+
167
+ /** Statically inspects a Prunelle app's routes, islands, server actions, and active plugins without running a full bundle. */
168
+ export async function inspectProject(rootDir: string): Promise<InspectReport> {
169
+ const root = resolve(rootDir)
170
+ const config = await loadConfig(root)
171
+ const routesDir = resolve(root, config.routesDir ?? 'src/routes')
172
+ const outDir = resolve(root, config.outDir ?? 'dist')
173
+ const assetPrefix = (config.assetPrefix ?? '/_pru').replace(/\/$/, '')
174
+ const site = config.site?.replace(/\/$/, '') || undefined
175
+ const activePlugins = resolvePlugins(config.plugins)
176
+
177
+ const allRouteFiles = walkRoutes(routesDir).sort()
178
+ const specialFiles = allRouteFiles.filter(f => SPECIAL_ROUTE_FILES.has(basename(f)))
179
+ const candidateFiles = allRouteFiles.filter(f => !basename(f).startsWith('_'))
180
+ const configSrc = join(root, 'prunelle.config.ts')
181
+ const hasConfigFile = existsSync(configSrc)
182
+
183
+ const graph = new ModuleGraph(root)
184
+ try {
185
+ for (const f of [...specialFiles, ...candidateFiles, ...(hasConfigFile ? [configSrc] : [])])
186
+ graph.load(f)
187
+ }
188
+ catch (err) {
189
+ if (err instanceof Error && (err.message.startsWith('prunelle: ') || err.message.startsWith('prunelle inspect: ')))
190
+ throw err
191
+ throw new Error(`prunelle inspect: ${err instanceof Error ? err.message : String(err)}`, { cause: err })
192
+ }
193
+
194
+ const pageFiles = candidateFiles.filter(f => hasRouteHandlerExport(graph.analyses.get(f)!))
195
+ const actionsByFile: ActionsByFile = new Map()
196
+ for (const [file, analysis] of graph.analyses) {
197
+ if (analysis.exportedActions.length > 0) {
198
+ const rel = relPosix(root, file)
199
+ actionsByFile.set(file, analysis.exportedActions.map(exportName => ({
200
+ exportName,
201
+ url: `${assetPrefix}/action/${actionHash(rel, exportName)}`,
202
+ })))
203
+ }
204
+ }
205
+
206
+ const islandPlan = analyzeIslands({ graph, root, pageFiles, specialFiles })
207
+ const toSrcRel = (srcFile: string): string => relPosix(root, srcFile)
208
+ const islandKeys = new Map<string, string>([...islandPlan.targets.keys()].map(k => [k, k]))
209
+
210
+ const { routes: routeEntries, statusPages: statusPageEntries } = buildRouteEntries({
211
+ graph,
212
+ islands: islandPlan,
213
+ islandChunks: islandKeys,
214
+ srcCssToUrl: new Map(),
215
+ islandCssUrl: new Map(),
216
+ routesDir,
217
+ pageFiles,
218
+ specialFiles,
219
+ pluginCssFiles: [],
220
+ isStatic: false,
221
+ autoPrerender: config.autoPrerender,
222
+ toOutRel: toSrcRel,
223
+ })
224
+
225
+ const { customFiles: customMatcherFiles } = discoverRouteMatchers({
226
+ root,
227
+ routesDir,
228
+ routeFiles: [...specialFiles, ...pageFiles],
229
+ loadAnalysis: file => graph.load(file),
230
+ })
231
+
232
+ const statusPages: InspectStatusPage[] = statusPageEntries
233
+ .map(sp => ({
234
+ kind: sp.kind,
235
+ dirPattern: sp.dirPattern,
236
+ file: sp.file,
237
+ layouts: sp.layouts,
238
+ ...(sp.inGroup === true ? { inGroup: true } : {}),
239
+ }))
240
+ .sort((a, b) => a.dirPattern.localeCompare(b.dirPattern) || a.kind.localeCompare(b.kind))
241
+
242
+ const paramMatchers: InspectParamMatcher[] = [...customMatcherFiles.entries()]
243
+ .map(([name, file]) => ({ name, file: toSrcRel(file) }))
244
+ .sort((a, b) => a.name.localeCompare(b.name))
245
+
246
+ const fileRoutes: InspectRoute[] = routeEntries.map((entry, idx) => {
247
+ const pageFile = pageFiles[idx]!
248
+ const analysis = graph.analyses.get(pageFile)
249
+ const hasDefault = analysis?.exportedNames.includes('default') === true
250
+ const methods = analysis?.exportedNames.filter(name => HTTP_METHODS.has(name)) ?? []
251
+ const groups = routeGroupsOf(routesDir, pageFile)
252
+ const matcherRefs = extractPatternMatchers(entry.path)
253
+ const matchers = matcherRefs.length > 0 ? Object.fromEntries(matcherRefs.map(m => [m.param, m.matcher])) : undefined
254
+ const optionalParams = extractOptionalParams(entry.path)
255
+ return {
256
+ path: entry.path,
257
+ file: entry.file,
258
+ ...(methods.length > 0 ? { methods } : {}),
259
+ ...(groups.length > 0 ? { groups } : {}),
260
+ ...(matchers !== undefined ? { matchers } : {}),
261
+ ...(optionalParams.length > 0 ? { optionalParams } : {}),
262
+ layouts: hasDefault ? entry.layouts : [],
263
+ middlewares: entry.middlewares,
264
+ load: entry.hasLoad === true,
265
+ prerender: entry.prerender === true,
266
+ ...(entry.cache !== undefined ? { cache: entry.cache } : {}),
267
+ ...(entry.cacheable === true ? { cacheable: true } : {}),
268
+ }
269
+ })
270
+
271
+ const pluginRoutes = await discoverPluginRoutes(activePlugins, config, { root, outDir, assetPrefix, site })
272
+
273
+ const islands: InspectIsland[] = [...islandPlan.targets.values()]
274
+ .map((target) => {
275
+ const analysis = graph.analyses.get(target.file)
276
+ const reason = target.local === undefined
277
+ ? analysis?.exports.get(target.exportName)?.reason
278
+ : analysis?.localIslands.get(target.local)?.reason
279
+ return {
280
+ exportName: target.local ?? target.exportName,
281
+ file: toSrcRel(target.file),
282
+ reason: reason ?? 'is interactive',
283
+ hydrate: target.defaultHydrate ?? 'load',
284
+ }
285
+ })
286
+ .sort((a, b) => a.file.localeCompare(b.file) || a.exportName.localeCompare(b.exportName))
287
+
288
+ const actions: InspectAction[] = buildActionEntries(actionsByFile, routesDir, toSrcRel)
289
+ .map(entry => ({
290
+ exportName: entry.exportName,
291
+ file: entry.file,
292
+ url: entry.url,
293
+ middlewares: entry.middlewares,
294
+ }))
295
+ .sort((a, b) => a.file.localeCompare(b.file) || a.exportName.localeCompare(b.exportName))
296
+
297
+ const plugins: InspectPlugin[] = activePlugins.map(plugin => ({
298
+ name: plugin.name,
299
+ ...(plugin.enforce !== undefined ? { enforce: plugin.enforce } : {}),
300
+ providesLocals: [...(plugin.providesLocals ?? [])],
301
+ readsLocals: [...(plugin.readsLocals ?? [])],
302
+ commands: Object.keys(plugin.commands ?? {}),
303
+ }))
304
+
305
+ return {
306
+ routes: [...fileRoutes, ...pluginRoutes],
307
+ statusPages,
308
+ paramMatchers,
309
+ islands,
310
+ actions,
311
+ plugins,
312
+ }
313
+ }
314
+
315
+ export function formatInspectReport(report: InspectReport): string {
316
+ const lines: string[] = []
317
+
318
+ lines.push(`Routes (${report.routes.length}):`)
319
+ if (report.routes.length === 0) {
320
+ lines.push(' (none)')
321
+ }
322
+ else {
323
+ for (const r of report.routes) {
324
+ const parts: string[] = [r.path]
325
+ if (r.methods !== undefined && r.methods.length > 0)
326
+ parts.push(r.methods.join(','))
327
+ parts.push(r.file ?? `(plugin: ${r.plugin})`)
328
+ if (r.groups !== undefined && r.groups.length > 0)
329
+ parts.push(`groups=[${r.groups.join(', ')}]`)
330
+ if (r.matchers !== undefined)
331
+ parts.push(`matchers=[${Object.entries(r.matchers).map(([k, v]) => `${k}=${v}`).join(', ')}]`)
332
+ if (r.optionalParams !== undefined && r.optionalParams.length > 0)
333
+ parts.push(`optional=[${r.optionalParams.join(', ')}]`)
334
+ if (r.load)
335
+ parts.push('load')
336
+ if (r.prerender)
337
+ parts.push('prerender')
338
+ if (r.cache !== undefined)
339
+ parts.push(`cache=${formatCacheSpec(r.cache)}`)
340
+ if (r.cacheable === true)
341
+ parts.push('cacheable')
342
+ if (r.layouts.length > 0)
343
+ parts.push(`layouts=[${r.layouts.join(', ')}]`)
344
+ if (r.middlewares.length > 0)
345
+ parts.push(`middlewares=[${r.middlewares.join(', ')}]`)
346
+ lines.push(` ${parts.join(' ')}`)
347
+ }
348
+ }
349
+
350
+ if (report.statusPages.length > 0) {
351
+ lines.push('', `Status Pages (${report.statusPages.length}):`)
352
+ for (const sp of report.statusPages) {
353
+ const parts: string[] = [sp.kind, sp.dirPattern, sp.file]
354
+ if (sp.layouts.length > 0)
355
+ parts.push(`layouts=[${sp.layouts.join(', ')}]`)
356
+ lines.push(` ${parts.join(' ')}`)
357
+ }
358
+ }
359
+
360
+ if (report.paramMatchers.length > 0) {
361
+ lines.push('', `Param Matchers (${report.paramMatchers.length}):`)
362
+ for (const matcher of report.paramMatchers)
363
+ lines.push(` ${matcher.name} ${matcher.file}`)
364
+ }
365
+
366
+ lines.push('', `Islands (${report.islands.length}):`)
367
+ if (report.islands.length === 0) {
368
+ lines.push(' (none)')
369
+ }
370
+ else {
371
+ for (const island of report.islands)
372
+ lines.push(` ${island.exportName} ${island.file} hydrate=${island.hydrate} ${island.reason}`)
373
+ }
374
+
375
+ lines.push('', `Actions (${report.actions.length}):`)
376
+ if (report.actions.length === 0) {
377
+ lines.push(' (none)')
378
+ }
379
+ else {
380
+ for (const a of report.actions) {
381
+ const mw = a.middlewares.length > 0 ? ` middlewares=[${a.middlewares.join(', ')}]` : ''
382
+ lines.push(` ${a.exportName} ${a.file} ${a.url}${mw}`)
383
+ }
384
+ }
385
+
386
+ lines.push('', `Plugins (${report.plugins.length}):`)
387
+ if (report.plugins.length === 0) {
388
+ lines.push(' (none)')
389
+ }
390
+ else {
391
+ report.plugins.forEach((p, idx) => {
392
+ const parts: string[] = [`${idx + 1}. ${p.name}`]
393
+ if (p.enforce !== undefined)
394
+ parts.push(`enforce=${p.enforce}`)
395
+ if (p.providesLocals.length > 0)
396
+ parts.push(`providesLocals=[${p.providesLocals.join(', ')}]`)
397
+ if (p.readsLocals.length > 0)
398
+ parts.push(`readsLocals=[${p.readsLocals.join(', ')}]`)
399
+ if (p.commands.length > 0)
400
+ parts.push(`commands=[${p.commands.join(', ')}]`)
401
+ lines.push(` ${parts.join(' ')}`)
402
+ })
403
+ }
404
+
405
+ return lines.join('\n')
406
+ }