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.
- package/LICENSE +21 -0
- package/llms.txt +137 -40
- package/package.json +11 -2
- package/src/a11y/declaration.ts +369 -0
- package/src/a11y/index.ts +466 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +88 -40
- 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 +230 -0
- package/src/build/files.ts +6 -0
- package/src/build/first-load.ts +83 -11
- package/src/build/graph.ts +29 -39
- package/src/build/index.ts +218 -113
- package/src/build/island-promote.ts +229 -0
- package/src/build/islands.ts +11 -203
- package/src/build/manifest.ts +56 -116
- package/src/build/output.ts +2 -2
- package/src/build/plugin-host.ts +113 -41
- package/src/build/precompress.ts +16 -3
- package/src/build/prerender.ts +173 -38
- package/src/build/reach.ts +136 -0
- package/src/build/render-rules.ts +2 -2
- package/src/build/report.ts +42 -5
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static-headers.ts +93 -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 +610 -0
- package/src/cli/check-imports.ts +25 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +107 -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 -18
- package/src/compiler/analyze.ts +68 -14
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability.ts +636 -0
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +614 -0
- package/src/compiler/compliance-urls.ts +145 -0
- package/src/compiler/compliance.ts +355 -351
- 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 +167 -57
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/mistakes.ts +23 -2
- package/src/compiler/props-body.ts +52 -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/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 +26 -0
- package/src/dev/index.ts +91 -34
- package/src/dev/open-editor.ts +208 -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 +29 -14
- package/src/dom/index.ts +39 -10
- package/src/dom/island.ts +54 -35
- package/src/dom/loop.ts +33 -23
- package/src/eco/declaration.ts +257 -0
- package/src/eco/index.ts +65 -0
- package/src/index.ts +2 -2
- package/src/jsx-runtime.ts +2 -2
- package/src/plugins/config.ts +8 -7
- package/src/plugins/context.ts +16 -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 +45 -13
- 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 +56 -117
- 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 +305 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +177 -38
- package/src/server/index.ts +264 -272
- package/src/server/loader.ts +11 -2
- 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 +445 -0
- package/src/server/route-table.ts +344 -9
- 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 +277 -50
- package/src/server/serve-handlers.ts +31 -7
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +87 -11
- package/src/server/stream.ts +68 -27
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +105 -7
- package/src/ssr/index.ts +148 -3
- package/src/ssr/navigation.ts +2 -2
- package/src/ssr/region.ts +31 -19
- package/src/style.ts +32 -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
package/src/cli/docs.ts
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// `prunelle docs <words>`: discover and search installed `llms.txt` files for `prunelle` and `@prunellejs/*` packages.
|
|
2
|
+
|
|
3
|
+
import { readdirSync, readFileSync, statSync } from 'node:fs'
|
|
4
|
+
import { dirname, join, resolve } from 'node:path'
|
|
5
|
+
import { relPosix } from '../build/files'
|
|
6
|
+
|
|
7
|
+
const HEADING_RE = /^(#{1,3})\s+(.+?)\s*$/
|
|
8
|
+
const BOLD_BULLET_RE = /^- \*\*(.+?)\*\*/
|
|
9
|
+
const FENCE_RE = /^\s*```/
|
|
10
|
+
const WORD_SPLIT_RE = /\s+/
|
|
11
|
+
const SCOPED_PACKAGE_DIRS = ['@prunellejs', '@prunelle'] as const
|
|
12
|
+
const DEFAULT_LIMIT = 20
|
|
13
|
+
|
|
14
|
+
export interface LlmsPackageDoc {
|
|
15
|
+
packageName: string
|
|
16
|
+
version: string | undefined
|
|
17
|
+
file: string
|
|
18
|
+
relFile: string
|
|
19
|
+
content: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DocsMatch {
|
|
23
|
+
packageName: string
|
|
24
|
+
version: string | undefined
|
|
25
|
+
file: string
|
|
26
|
+
relFile: string
|
|
27
|
+
heading: string
|
|
28
|
+
line: number
|
|
29
|
+
score: number
|
|
30
|
+
content: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface DocsSearchResult {
|
|
34
|
+
query: string
|
|
35
|
+
words: string[]
|
|
36
|
+
packages: { name: string, version: string | undefined, file: string }[]
|
|
37
|
+
matches: DocsMatch[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface ParsedSection {
|
|
41
|
+
heading: string
|
|
42
|
+
line: number
|
|
43
|
+
content: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface HeadingBlock {
|
|
47
|
+
heading: string
|
|
48
|
+
line: number
|
|
49
|
+
lines: { num: number, text: string }[]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isFile(path: string): boolean {
|
|
53
|
+
const st = statSync(path, { throwIfNoEntry: false })
|
|
54
|
+
return st !== undefined && st.isFile()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isDirectory(path: string): boolean {
|
|
58
|
+
const st = statSync(path, { throwIfNoEntry: false })
|
|
59
|
+
return st !== undefined && st.isDirectory()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function readPackageMeta(pkgDir: string, fallbackName: string): { name: string, version: string | undefined } {
|
|
63
|
+
const pkgJsonPath = join(pkgDir, 'package.json')
|
|
64
|
+
if (!isFile(pkgJsonPath))
|
|
65
|
+
return { name: fallbackName, version: undefined }
|
|
66
|
+
try {
|
|
67
|
+
const parsed = JSON.parse(readFileSync(pkgJsonPath, 'utf8')) as { name?: unknown, version?: unknown }
|
|
68
|
+
const name = typeof parsed.name === 'string' && parsed.name.length > 0 ? parsed.name : fallbackName
|
|
69
|
+
const version = typeof parsed.version === 'string' && parsed.version.length > 0 ? parsed.version : undefined
|
|
70
|
+
return { name, version }
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return { name: fallbackName, version: undefined }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function addPackageDoc(
|
|
78
|
+
docs: LlmsPackageDoc[],
|
|
79
|
+
seen: Set<string>,
|
|
80
|
+
root: string,
|
|
81
|
+
pkgDir: string,
|
|
82
|
+
fallbackName: string,
|
|
83
|
+
): void {
|
|
84
|
+
const llmsPath = join(pkgDir, 'llms.txt')
|
|
85
|
+
if (!isFile(llmsPath))
|
|
86
|
+
return
|
|
87
|
+
const meta = readPackageMeta(pkgDir, fallbackName)
|
|
88
|
+
if (seen.has(meta.name))
|
|
89
|
+
return
|
|
90
|
+
seen.add(meta.name)
|
|
91
|
+
docs.push({
|
|
92
|
+
packageName: meta.name,
|
|
93
|
+
version: meta.version,
|
|
94
|
+
file: llmsPath,
|
|
95
|
+
relFile: relPosix(root, llmsPath),
|
|
96
|
+
content: readFileSync(llmsPath, 'utf8'),
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function scanScopedPackages(
|
|
101
|
+
docs: LlmsPackageDoc[],
|
|
102
|
+
seen: Set<string>,
|
|
103
|
+
root: string,
|
|
104
|
+
nodeModulesDir: string,
|
|
105
|
+
): void {
|
|
106
|
+
for (const scope of SCOPED_PACKAGE_DIRS) {
|
|
107
|
+
const scopeDir = join(nodeModulesDir, scope)
|
|
108
|
+
if (!isDirectory(scopeDir))
|
|
109
|
+
continue
|
|
110
|
+
let entries: string[]
|
|
111
|
+
try {
|
|
112
|
+
entries = readdirSync(scopeDir)
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
continue
|
|
116
|
+
}
|
|
117
|
+
for (const entry of entries)
|
|
118
|
+
addPackageDoc(docs, seen, root, join(scopeDir, entry), `${scope}/${entry}`)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Discovers `llms.txt` files for `prunelle` and installed `@prunellejs/*` (and `@prunelle/*`) packages from `rootDir` up through ancestor `node_modules`. */
|
|
123
|
+
export function discoverLlmsDocs(rootDir: string): LlmsPackageDoc[] {
|
|
124
|
+
const root = resolve(rootDir)
|
|
125
|
+
const docs: LlmsPackageDoc[] = []
|
|
126
|
+
const seen = new Set<string>()
|
|
127
|
+
|
|
128
|
+
let dir = root
|
|
129
|
+
while (true) {
|
|
130
|
+
const nodeModulesDir = join(dir, 'node_modules')
|
|
131
|
+
if (isDirectory(nodeModulesDir)) {
|
|
132
|
+
if (!seen.has('prunelle'))
|
|
133
|
+
addPackageDoc(docs, seen, root, join(nodeModulesDir, 'prunelle'), 'prunelle')
|
|
134
|
+
scanScopedPackages(docs, seen, root, nodeModulesDir)
|
|
135
|
+
}
|
|
136
|
+
const parent = dirname(dir)
|
|
137
|
+
if (parent === dir)
|
|
138
|
+
break
|
|
139
|
+
dir = parent
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!seen.has('prunelle'))
|
|
143
|
+
addPackageDoc(docs, seen, root, resolve(import.meta.dir, '../..'), 'prunelle')
|
|
144
|
+
|
|
145
|
+
docs.sort((a, b) => {
|
|
146
|
+
if (a.packageName === 'prunelle' && b.packageName !== 'prunelle')
|
|
147
|
+
return -1
|
|
148
|
+
if (b.packageName === 'prunelle' && a.packageName !== 'prunelle')
|
|
149
|
+
return 1
|
|
150
|
+
return a.packageName.localeCompare(b.packageName)
|
|
151
|
+
})
|
|
152
|
+
return docs
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function splitHeadingBlocks(content: string): HeadingBlock[] {
|
|
156
|
+
const rawLines = content.split(/\r?\n/)
|
|
157
|
+
const blocks: HeadingBlock[] = []
|
|
158
|
+
let current: HeadingBlock | undefined
|
|
159
|
+
let inFence = false
|
|
160
|
+
|
|
161
|
+
for (let i = 0; i < rawLines.length; i++) {
|
|
162
|
+
const text = rawLines[i]!
|
|
163
|
+
const num = i + 1
|
|
164
|
+
if (FENCE_RE.test(text))
|
|
165
|
+
inFence = !inFence
|
|
166
|
+
|
|
167
|
+
if (!inFence) {
|
|
168
|
+
const headingMatch = HEADING_RE.exec(text)
|
|
169
|
+
if (headingMatch !== null) {
|
|
170
|
+
current = { heading: headingMatch[2]!.trim(), line: num, lines: [] }
|
|
171
|
+
blocks.push(current)
|
|
172
|
+
continue
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (current === undefined) {
|
|
177
|
+
current = { heading: 'Overview', line: num, lines: [] }
|
|
178
|
+
blocks.push(current)
|
|
179
|
+
}
|
|
180
|
+
current.lines.push({ num, text })
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return blocks
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function flushLines(heading: string, line: number, lines: readonly { num: number, text: string }[], out: ParsedSection[]): void {
|
|
187
|
+
const text = lines.map(l => l.text).join('\n').trim()
|
|
188
|
+
if (text.length > 0)
|
|
189
|
+
out.push({ heading, line, content: text })
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function splitBlockSections(block: HeadingBlock): ParsedSection[] {
|
|
193
|
+
const hasBoldBullet = (() => {
|
|
194
|
+
let inFence = false
|
|
195
|
+
for (const l of block.lines) {
|
|
196
|
+
if (FENCE_RE.test(l.text))
|
|
197
|
+
inFence = !inFence
|
|
198
|
+
else if (!inFence && BOLD_BULLET_RE.test(l.text))
|
|
199
|
+
return true
|
|
200
|
+
}
|
|
201
|
+
return false
|
|
202
|
+
})()
|
|
203
|
+
|
|
204
|
+
if (!hasBoldBullet) {
|
|
205
|
+
const out: ParsedSection[] = []
|
|
206
|
+
flushLines(block.heading, block.line, block.lines, out)
|
|
207
|
+
return out
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const sections: ParsedSection[] = []
|
|
211
|
+
let activeBullet: { heading: string, line: number, lines: { num: number, text: string }[] } | undefined
|
|
212
|
+
let generalLines: { num: number, text: string }[] = []
|
|
213
|
+
let generalLine = block.line
|
|
214
|
+
let inFence = false
|
|
215
|
+
|
|
216
|
+
const flushActiveBullet = (): void => {
|
|
217
|
+
if (activeBullet !== undefined) {
|
|
218
|
+
flushLines(activeBullet.heading, activeBullet.line, activeBullet.lines, sections)
|
|
219
|
+
activeBullet = undefined
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const flushGeneral = (): void => {
|
|
224
|
+
if (generalLines.length > 0) {
|
|
225
|
+
flushLines(block.heading, generalLine, generalLines, sections)
|
|
226
|
+
generalLines = []
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
for (const entry of block.lines) {
|
|
231
|
+
if (FENCE_RE.test(entry.text))
|
|
232
|
+
inFence = !inFence
|
|
233
|
+
|
|
234
|
+
if (!inFence) {
|
|
235
|
+
const bulletMatch = BOLD_BULLET_RE.exec(entry.text)
|
|
236
|
+
if (bulletMatch !== null) {
|
|
237
|
+
flushGeneral()
|
|
238
|
+
flushActiveBullet()
|
|
239
|
+
activeBullet = {
|
|
240
|
+
heading: `${block.heading} > ${bulletMatch[1]!.trim()}`,
|
|
241
|
+
line: entry.num,
|
|
242
|
+
lines: [entry],
|
|
243
|
+
}
|
|
244
|
+
continue
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (activeBullet !== undefined) {
|
|
248
|
+
if (entry.text.trim() === '' || entry.text.startsWith(' ') || entry.text.startsWith('\t')) {
|
|
249
|
+
activeBullet.lines.push(entry)
|
|
250
|
+
continue
|
|
251
|
+
}
|
|
252
|
+
flushActiveBullet()
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else if (activeBullet !== undefined) {
|
|
256
|
+
activeBullet.lines.push(entry)
|
|
257
|
+
continue
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (generalLines.length === 0)
|
|
261
|
+
generalLine = entry.num
|
|
262
|
+
generalLines.push(entry)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
flushActiveBullet()
|
|
266
|
+
flushGeneral()
|
|
267
|
+
return sections
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function parseSections(content: string): ParsedSection[] {
|
|
271
|
+
const blocks = splitHeadingBlocks(content)
|
|
272
|
+
const sections: ParsedSection[] = []
|
|
273
|
+
for (const block of blocks) {
|
|
274
|
+
for (const section of splitBlockSections(block))
|
|
275
|
+
sections.push(section)
|
|
276
|
+
}
|
|
277
|
+
return sections
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function countOccurrences(haystack: string, needle: string, maxCount: number): number {
|
|
281
|
+
let count = 0
|
|
282
|
+
let pos = 0
|
|
283
|
+
while (count < maxCount) {
|
|
284
|
+
const idx = haystack.indexOf(needle, pos)
|
|
285
|
+
if (idx === -1)
|
|
286
|
+
break
|
|
287
|
+
count++
|
|
288
|
+
pos = idx + needle.length
|
|
289
|
+
}
|
|
290
|
+
return count
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function escapeRegExp(text: string): string {
|
|
294
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function scoreSection(
|
|
298
|
+
pkgLower: string,
|
|
299
|
+
headingLower: string,
|
|
300
|
+
contentLower: string,
|
|
301
|
+
words: readonly string[],
|
|
302
|
+
phrase: string,
|
|
303
|
+
): number {
|
|
304
|
+
let score = 0
|
|
305
|
+
if (headingLower.includes(phrase))
|
|
306
|
+
score += 30
|
|
307
|
+
if (pkgLower.includes(phrase))
|
|
308
|
+
score += 25
|
|
309
|
+
if (contentLower.includes(phrase))
|
|
310
|
+
score += 10
|
|
311
|
+
|
|
312
|
+
for (const word of words) {
|
|
313
|
+
const wordBoundary = new RegExp(`(?:^|[^a-z0-9])${escapeRegExp(word)}(?:$|[^a-z0-9])`)
|
|
314
|
+
if (pkgLower.includes(word))
|
|
315
|
+
score += wordBoundary.test(pkgLower) ? 25 : 15
|
|
316
|
+
if (headingLower.includes(word))
|
|
317
|
+
score += wordBoundary.test(headingLower) ? 25 : 20
|
|
318
|
+
const bodyHits = countOccurrences(contentLower, word, 10)
|
|
319
|
+
score += bodyHits * 2
|
|
320
|
+
if (bodyHits > 0 && wordBoundary.test(contentLower))
|
|
321
|
+
score += 3
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return score
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** Searches installed `llms.txt` docs for every whitespace-separated word in `query` (case-insensitive AND). */
|
|
328
|
+
export function searchLlmsDocs(
|
|
329
|
+
rootDir: string,
|
|
330
|
+
query: string,
|
|
331
|
+
options?: { limit?: number | undefined },
|
|
332
|
+
): DocsSearchResult {
|
|
333
|
+
const limit = options?.limit ?? DEFAULT_LIMIT
|
|
334
|
+
if (!Number.isInteger(limit) || limit <= 0)
|
|
335
|
+
throw new Error(`prunelle docs: invalid limit ${limit}: give a positive integer`)
|
|
336
|
+
const docs = discoverLlmsDocs(rootDir)
|
|
337
|
+
const packages = docs.map(doc => ({ name: doc.packageName, version: doc.version, file: doc.relFile }))
|
|
338
|
+
const words = query.trim().toLowerCase().split(WORD_SPLIT_RE).filter(Boolean)
|
|
339
|
+
if (words.length === 0)
|
|
340
|
+
return { query, words: [], packages, matches: [] }
|
|
341
|
+
|
|
342
|
+
const phrase = words.join(' ')
|
|
343
|
+
const matches: DocsMatch[] = []
|
|
344
|
+
|
|
345
|
+
for (const doc of docs) {
|
|
346
|
+
const pkgLower = doc.packageName.toLowerCase()
|
|
347
|
+
for (const section of parseSections(doc.content)) {
|
|
348
|
+
const headingLower = section.heading.toLowerCase()
|
|
349
|
+
const contentLower = section.content.toLowerCase()
|
|
350
|
+
const combined = `${pkgLower} ${headingLower} ${contentLower}`
|
|
351
|
+
if (!words.every(word => combined.includes(word)))
|
|
352
|
+
continue
|
|
353
|
+
|
|
354
|
+
const score = scoreSection(pkgLower, headingLower, contentLower, words, phrase)
|
|
355
|
+
matches.push({
|
|
356
|
+
packageName: doc.packageName,
|
|
357
|
+
version: doc.version,
|
|
358
|
+
file: doc.file,
|
|
359
|
+
relFile: doc.relFile,
|
|
360
|
+
heading: section.heading,
|
|
361
|
+
line: section.line,
|
|
362
|
+
score,
|
|
363
|
+
content: section.content,
|
|
364
|
+
})
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
matches.sort((a, b) => {
|
|
369
|
+
if (b.score !== a.score)
|
|
370
|
+
return b.score - a.score
|
|
371
|
+
const aCore = a.packageName === 'prunelle' ? 0 : 1
|
|
372
|
+
const bCore = b.packageName === 'prunelle' ? 0 : 1
|
|
373
|
+
if (aCore !== bCore)
|
|
374
|
+
return aCore - bCore
|
|
375
|
+
const byPkg = a.packageName.localeCompare(b.packageName)
|
|
376
|
+
if (byPkg !== 0)
|
|
377
|
+
return byPkg
|
|
378
|
+
return a.line - b.line
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
return { query, words, packages, matches: matches.slice(0, limit) }
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function formatPackageLabel(name: string, version: string | undefined): string {
|
|
385
|
+
return version !== undefined ? `${name}@${version}` : name
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** Formats a `DocsSearchResult` for terminal output. */
|
|
389
|
+
export function formatDocsSearchResult(result: DocsSearchResult): string {
|
|
390
|
+
if (result.matches.length === 0) {
|
|
391
|
+
const pkgList = result.packages.length > 0
|
|
392
|
+
? result.packages.map(pkg => `${formatPackageLabel(pkg.name, pkg.version)} (${pkg.file})`).join(', ')
|
|
393
|
+
: '(none)'
|
|
394
|
+
if (result.words.length === 0)
|
|
395
|
+
return `No search words provided.\nAvailable packages (${result.packages.length}): ${pkgList}`
|
|
396
|
+
return `No docs matched "${result.query}".\nSearched packages (${result.packages.length}): ${pkgList}`
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return result.matches.map((match) => {
|
|
400
|
+
const pkgLabel = formatPackageLabel(match.packageName, match.version)
|
|
401
|
+
return `=== ${pkgLabel} — ${match.heading} (${match.relFile}:${match.line}) ===\n${match.content}`
|
|
402
|
+
}).join('\n\n')
|
|
403
|
+
}
|
package/src/cli/inspect.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
// `prunelle inspect [dir] [--json]`: fast static report of routes, islands, actions, and active plugins without running a full bundle.
|
|
2
2
|
|
|
3
3
|
import type { ActionsByFile } from '../build/islands'
|
|
4
|
+
import type { StatusPageKind } from '../build/manifest'
|
|
4
5
|
import type { PrunelleConfig, PrunellePlugin, ServerPluginAPI } from '../plugins/index'
|
|
6
|
+
import type { RouteCacheSpec } from '../server/route-cache'
|
|
5
7
|
import { existsSync } from 'node:fs'
|
|
6
8
|
import { basename, join, resolve } from 'node:path'
|
|
7
9
|
import { relPosix, walkRoutes } from '../build/files'
|
|
8
10
|
import { ModuleGraph } from '../build/graph'
|
|
9
11
|
import { analyzeIslands } from '../build/islands'
|
|
10
12
|
import { buildActionEntries, buildRouteEntries } from '../build/manifest'
|
|
11
|
-
import { hasRouteHandlerExport, SPECIAL_ROUTE_FILES } from '../build/routes'
|
|
13
|
+
import { discoverRouteMatchers, hasRouteHandlerExport, routeGroupsOf, SPECIAL_ROUTE_FILES } from '../build/routes'
|
|
12
14
|
import { createAppContext, loadConfig, pickRuntimeConfig, resolvePlugins, runWithAppContext } from '../plugins/index'
|
|
13
15
|
import { actionHash } from '../server/action'
|
|
16
|
+
import { extractOptionalParams, extractPatternMatchers } from '../server/param-matchers'
|
|
17
|
+
import { formatCacheSpec } from '../server/route-cache'
|
|
14
18
|
|
|
15
19
|
const HTTP_METHODS = new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS'])
|
|
16
20
|
|
|
@@ -19,10 +23,15 @@ export interface InspectRoute {
|
|
|
19
23
|
file?: string | undefined
|
|
20
24
|
plugin?: string | undefined
|
|
21
25
|
methods?: string[] | undefined
|
|
26
|
+
groups?: string[] | undefined
|
|
27
|
+
matchers?: Record<string, string> | undefined
|
|
28
|
+
optionalParams?: string[] | undefined
|
|
22
29
|
layouts: string[]
|
|
23
30
|
middlewares: string[]
|
|
24
31
|
load: boolean
|
|
25
32
|
prerender: boolean
|
|
33
|
+
cache?: RouteCacheSpec | undefined
|
|
34
|
+
cacheable?: boolean | undefined
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
export interface InspectIsland {
|
|
@@ -47,8 +56,23 @@ export interface InspectPlugin {
|
|
|
47
56
|
commands: string[]
|
|
48
57
|
}
|
|
49
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
|
+
|
|
50
72
|
export interface InspectReport {
|
|
51
73
|
routes: InspectRoute[]
|
|
74
|
+
statusPages: InspectStatusPage[]
|
|
75
|
+
paramMatchers: InspectParamMatcher[]
|
|
52
76
|
islands: InspectIsland[]
|
|
53
77
|
actions: InspectAction[]
|
|
54
78
|
plugins: InspectPlugin[]
|
|
@@ -70,7 +94,6 @@ async function discoverPluginRoutes(
|
|
|
70
94
|
dev: false,
|
|
71
95
|
nodeEnv: 'production',
|
|
72
96
|
})
|
|
73
|
-
const services = new Map<string, unknown>()
|
|
74
97
|
const shutdowns: (() => void | Promise<void>)[] = []
|
|
75
98
|
const routes: InspectRoute[] = []
|
|
76
99
|
const runtimeConfig = pickRuntimeConfig(config) as Readonly<Record<string, unknown>>
|
|
@@ -87,6 +110,7 @@ async function discoverPluginRoutes(
|
|
|
87
110
|
assetPrefix,
|
|
88
111
|
site,
|
|
89
112
|
dev: false,
|
|
113
|
+
devExposed: false,
|
|
90
114
|
trustProxy: config.trustProxy ?? false,
|
|
91
115
|
trustedOrigins: config.trustedOrigins ?? [],
|
|
92
116
|
config: runtimeConfig,
|
|
@@ -99,13 +123,12 @@ async function discoverPluginRoutes(
|
|
|
99
123
|
else if (!methods.includes(upper))
|
|
100
124
|
methods.push(upper)
|
|
101
125
|
},
|
|
102
|
-
rateLimiter: () => ({ hit: () => 0 }),
|
|
126
|
+
rateLimiter: () => ({ hit: () => 0, peek: () => 0 }),
|
|
103
127
|
rewrite: () => {},
|
|
104
|
-
provide:
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
inject: key => services.get(key.name) as never,
|
|
128
|
+
provide: appCtx.provide,
|
|
129
|
+
inject: appCtx.inject,
|
|
108
130
|
getBuildData: () => undefined,
|
|
131
|
+
healthCheck: () => {},
|
|
109
132
|
onShutdown: (fn) => {
|
|
110
133
|
shutdowns.push(fn)
|
|
111
134
|
},
|
|
@@ -184,7 +207,7 @@ export async function inspectProject(rootDir: string): Promise<InspectReport> {
|
|
|
184
207
|
const toSrcRel = (srcFile: string): string => relPosix(root, srcFile)
|
|
185
208
|
const islandKeys = new Map<string, string>([...islandPlan.targets.keys()].map(k => [k, k]))
|
|
186
209
|
|
|
187
|
-
const { routes: routeEntries } = buildRouteEntries({
|
|
210
|
+
const { routes: routeEntries, statusPages: statusPageEntries } = buildRouteEntries({
|
|
188
211
|
graph,
|
|
189
212
|
islands: islandPlan,
|
|
190
213
|
islandChunks: islandKeys,
|
|
@@ -192,35 +215,74 @@ export async function inspectProject(rootDir: string): Promise<InspectReport> {
|
|
|
192
215
|
islandCssUrl: new Map(),
|
|
193
216
|
routesDir,
|
|
194
217
|
pageFiles,
|
|
218
|
+
specialFiles,
|
|
195
219
|
pluginCssFiles: [],
|
|
196
220
|
isStatic: false,
|
|
221
|
+
autoPrerender: config.autoPrerender,
|
|
197
222
|
toOutRel: toSrcRel,
|
|
198
223
|
})
|
|
199
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
|
+
|
|
200
246
|
const fileRoutes: InspectRoute[] = routeEntries.map((entry, idx) => {
|
|
201
|
-
const
|
|
247
|
+
const pageFile = pageFiles[idx]!
|
|
248
|
+
const analysis = graph.analyses.get(pageFile)
|
|
202
249
|
const hasDefault = analysis?.exportedNames.includes('default') === true
|
|
203
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)
|
|
204
255
|
return {
|
|
205
256
|
path: entry.path,
|
|
206
257
|
file: entry.file,
|
|
207
258
|
...(methods.length > 0 ? { methods } : {}),
|
|
259
|
+
...(groups.length > 0 ? { groups } : {}),
|
|
260
|
+
...(matchers !== undefined ? { matchers } : {}),
|
|
261
|
+
...(optionalParams.length > 0 ? { optionalParams } : {}),
|
|
208
262
|
layouts: hasDefault ? entry.layouts : [],
|
|
209
263
|
middlewares: entry.middlewares,
|
|
210
264
|
load: entry.hasLoad === true,
|
|
211
265
|
prerender: entry.prerender === true,
|
|
266
|
+
...(entry.cache !== undefined ? { cache: entry.cache } : {}),
|
|
267
|
+
...(entry.cacheable === true ? { cacheable: true } : {}),
|
|
212
268
|
}
|
|
213
269
|
})
|
|
214
270
|
|
|
215
271
|
const pluginRoutes = await discoverPluginRoutes(activePlugins, config, { root, outDir, assetPrefix, site })
|
|
216
272
|
|
|
217
273
|
const islands: InspectIsland[] = [...islandPlan.targets.values()]
|
|
218
|
-
.map(target =>
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
+
})
|
|
224
286
|
.sort((a, b) => a.file.localeCompare(b.file) || a.exportName.localeCompare(b.exportName))
|
|
225
287
|
|
|
226
288
|
const actions: InspectAction[] = buildActionEntries(actionsByFile, routesDir, toSrcRel)
|
|
@@ -242,6 +304,8 @@ export async function inspectProject(rootDir: string): Promise<InspectReport> {
|
|
|
242
304
|
|
|
243
305
|
return {
|
|
244
306
|
routes: [...fileRoutes, ...pluginRoutes],
|
|
307
|
+
statusPages,
|
|
308
|
+
paramMatchers,
|
|
245
309
|
islands,
|
|
246
310
|
actions,
|
|
247
311
|
plugins,
|
|
@@ -261,10 +325,20 @@ export function formatInspectReport(report: InspectReport): string {
|
|
|
261
325
|
if (r.methods !== undefined && r.methods.length > 0)
|
|
262
326
|
parts.push(r.methods.join(','))
|
|
263
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(', ')}]`)
|
|
264
334
|
if (r.load)
|
|
265
335
|
parts.push('load')
|
|
266
336
|
if (r.prerender)
|
|
267
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')
|
|
268
342
|
if (r.layouts.length > 0)
|
|
269
343
|
parts.push(`layouts=[${r.layouts.join(', ')}]`)
|
|
270
344
|
if (r.middlewares.length > 0)
|
|
@@ -273,6 +347,22 @@ export function formatInspectReport(report: InspectReport): string {
|
|
|
273
347
|
}
|
|
274
348
|
}
|
|
275
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
|
+
|
|
276
366
|
lines.push('', `Islands (${report.islands.length}):`)
|
|
277
367
|
if (report.islands.length === 0) {
|
|
278
368
|
lines.push(' (none)')
|