prunelle 0.1.1 → 0.6.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/llms.txt +130 -38
- package/package.json +8 -2
- package/src/a11y/declaration.ts +335 -0
- package/src/a11y/index.ts +446 -0
- package/src/a11y/rgaa-map.ts +184 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +80 -36
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +8 -4
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +11 -9
- package/src/build/ecoindex.ts +229 -0
- package/src/build/index.ts +174 -108
- package/src/build/islands.ts +2 -2
- package/src/build/manifest.ts +66 -5
- package/src/build/output.ts +2 -2
- package/src/build/plugin-host.ts +92 -33
- package/src/build/precompress.ts +15 -2
- package/src/build/prerender.ts +128 -46
- package/src/build/report.ts +23 -2
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static.ts +137 -39
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +561 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check.ts +75 -20
- package/src/cli/commands.ts +85 -4
- package/src/cli/docs.ts +402 -0
- package/src/cli/inspect.ts +103 -14
- package/src/cli/mcp-tools.ts +490 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +2 -2
- package/src/cli/render.ts +421 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +137 -16
- package/src/compiler/analyze.ts +42 -9
- package/src/compiler/browser-globals.ts +140 -17
- package/src/compiler/cacheability.ts +636 -0
- package/src/compiler/compliance-rgaa.ts +508 -0
- package/src/compiler/compliance.ts +241 -289
- 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/mistakes.ts +4 -1
- 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 +40 -12
- package/src/compiler/signal-reads.ts +6 -2
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +218 -87
- package/src/dev/error-log.ts +151 -0
- package/src/dev/index.ts +84 -34
- package/src/dev/open-editor.ts +204 -0
- package/src/dev/protocol.ts +1 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +42 -25
- package/src/dev/watchers.ts +47 -11
- package/src/dom/action.ts +43 -20
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +28 -12
- package/src/dom/index.ts +26 -8
- package/src/dom/island.ts +35 -28
- package/src/dom/loop.ts +10 -9
- package/src/plugins/config.ts +8 -7
- package/src/plugins/index.ts +2 -2
- package/src/plugins/load.ts +26 -7
- package/src/plugins/order.ts +38 -1
- package/src/plugins/public.ts +5 -2
- package/src/plugins/services.ts +81 -0
- package/src/plugins/types.ts +34 -0
- 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-protect.ts +198 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +82 -27
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +91 -9
- package/src/server/document.ts +25 -10
- package/src/server/errors.ts +303 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +131 -32
- package/src/server/index.ts +231 -261
- package/src/server/loader.ts +5 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +123 -88
- package/src/server/public.ts +3 -3
- package/src/server/rate-limit.ts +58 -35
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +423 -0
- package/src/server/route-table.ts +339 -8
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +196 -63
- package/src/server/security.ts +208 -32
- package/src/server/serve-handlers.ts +21 -7
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +61 -8
- package/src/server/stream.ts +41 -22
- package/src/ssr/context.ts +85 -3
- package/src/ssr/index.ts +130 -3
- package/src/ssr/region.ts +31 -19
- 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/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +5 -0
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/index.tsx +4 -0
- package/ts-plugin.cjs +4277 -0
package/src/cli/docs.ts
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
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 docs = discoverLlmsDocs(rootDir)
|
|
334
|
+
const packages = docs.map(doc => ({ name: doc.packageName, version: doc.version, file: doc.relFile }))
|
|
335
|
+
const words = query.trim().toLowerCase().split(WORD_SPLIT_RE).filter(Boolean)
|
|
336
|
+
if (words.length === 0)
|
|
337
|
+
return { query, words: [], packages, matches: [] }
|
|
338
|
+
|
|
339
|
+
const phrase = words.join(' ')
|
|
340
|
+
const matches: DocsMatch[] = []
|
|
341
|
+
|
|
342
|
+
for (const doc of docs) {
|
|
343
|
+
const pkgLower = doc.packageName.toLowerCase()
|
|
344
|
+
for (const section of parseSections(doc.content)) {
|
|
345
|
+
const headingLower = section.heading.toLowerCase()
|
|
346
|
+
const contentLower = section.content.toLowerCase()
|
|
347
|
+
const combined = `${pkgLower} ${headingLower} ${contentLower}`
|
|
348
|
+
if (!words.every(word => combined.includes(word)))
|
|
349
|
+
continue
|
|
350
|
+
|
|
351
|
+
const score = scoreSection(pkgLower, headingLower, contentLower, words, phrase)
|
|
352
|
+
matches.push({
|
|
353
|
+
packageName: doc.packageName,
|
|
354
|
+
version: doc.version,
|
|
355
|
+
file: doc.file,
|
|
356
|
+
relFile: doc.relFile,
|
|
357
|
+
heading: section.heading,
|
|
358
|
+
line: section.line,
|
|
359
|
+
score,
|
|
360
|
+
content: section.content,
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
matches.sort((a, b) => {
|
|
366
|
+
if (b.score !== a.score)
|
|
367
|
+
return b.score - a.score
|
|
368
|
+
const aCore = a.packageName === 'prunelle' ? 0 : 1
|
|
369
|
+
const bCore = b.packageName === 'prunelle' ? 0 : 1
|
|
370
|
+
if (aCore !== bCore)
|
|
371
|
+
return aCore - bCore
|
|
372
|
+
const byPkg = a.packageName.localeCompare(b.packageName)
|
|
373
|
+
if (byPkg !== 0)
|
|
374
|
+
return byPkg
|
|
375
|
+
return a.line - b.line
|
|
376
|
+
})
|
|
377
|
+
|
|
378
|
+
const limit = options?.limit ?? DEFAULT_LIMIT
|
|
379
|
+
const limited = limit >= 0 ? matches.slice(0, limit) : matches
|
|
380
|
+
return { query, words, packages, matches: limited }
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function formatPackageLabel(name: string, version: string | undefined): string {
|
|
384
|
+
return version !== undefined ? `${name}@${version}` : name
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/** Formats a `DocsSearchResult` for terminal output. */
|
|
388
|
+
export function formatDocsSearchResult(result: DocsSearchResult): string {
|
|
389
|
+
if (result.matches.length === 0) {
|
|
390
|
+
const pkgList = result.packages.length > 0
|
|
391
|
+
? result.packages.map(pkg => `${formatPackageLabel(pkg.name, pkg.version)} (${pkg.file})`).join(', ')
|
|
392
|
+
: '(none)'
|
|
393
|
+
if (result.words.length === 0)
|
|
394
|
+
return `No search words provided.\nAvailable packages (${result.packages.length}): ${pkgList}`
|
|
395
|
+
return `No docs matched "${result.query}".\nSearched packages (${result.packages.length}): ${pkgList}`
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
return result.matches.map((match) => {
|
|
399
|
+
const pkgLabel = formatPackageLabel(match.packageName, match.version)
|
|
400
|
+
return `=== ${pkgLabel} — ${match.heading} (${match.relFile}:${match.line}) ===\n${match.content}`
|
|
401
|
+
}).join('\n\n')
|
|
402
|
+
}
|
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>>
|
|
@@ -101,11 +124,10 @@ async function discoverPluginRoutes(
|
|
|
101
124
|
},
|
|
102
125
|
rateLimiter: () => ({ hit: () => 0 }),
|
|
103
126
|
rewrite: () => {},
|
|
104
|
-
provide:
|
|
105
|
-
|
|
106
|
-
},
|
|
107
|
-
inject: key => services.get(key.name) as never,
|
|
127
|
+
provide: appCtx.provide,
|
|
128
|
+
inject: appCtx.inject,
|
|
108
129
|
getBuildData: () => undefined,
|
|
130
|
+
healthCheck: () => {},
|
|
109
131
|
onShutdown: (fn) => {
|
|
110
132
|
shutdowns.push(fn)
|
|
111
133
|
},
|
|
@@ -184,7 +206,7 @@ export async function inspectProject(rootDir: string): Promise<InspectReport> {
|
|
|
184
206
|
const toSrcRel = (srcFile: string): string => relPosix(root, srcFile)
|
|
185
207
|
const islandKeys = new Map<string, string>([...islandPlan.targets.keys()].map(k => [k, k]))
|
|
186
208
|
|
|
187
|
-
const { routes: routeEntries } = buildRouteEntries({
|
|
209
|
+
const { routes: routeEntries, statusPages: statusPageEntries } = buildRouteEntries({
|
|
188
210
|
graph,
|
|
189
211
|
islands: islandPlan,
|
|
190
212
|
islandChunks: islandKeys,
|
|
@@ -192,35 +214,74 @@ export async function inspectProject(rootDir: string): Promise<InspectReport> {
|
|
|
192
214
|
islandCssUrl: new Map(),
|
|
193
215
|
routesDir,
|
|
194
216
|
pageFiles,
|
|
217
|
+
specialFiles,
|
|
195
218
|
pluginCssFiles: [],
|
|
196
219
|
isStatic: false,
|
|
220
|
+
autoPrerender: config.autoPrerender,
|
|
197
221
|
toOutRel: toSrcRel,
|
|
198
222
|
})
|
|
199
223
|
|
|
224
|
+
const { customFiles: customMatcherFiles } = discoverRouteMatchers({
|
|
225
|
+
root,
|
|
226
|
+
routesDir,
|
|
227
|
+
routeFiles: [...specialFiles, ...pageFiles],
|
|
228
|
+
loadAnalysis: file => graph.load(file),
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
const statusPages: InspectStatusPage[] = statusPageEntries
|
|
232
|
+
.map(sp => ({
|
|
233
|
+
kind: sp.kind,
|
|
234
|
+
dirPattern: sp.dirPattern,
|
|
235
|
+
file: sp.file,
|
|
236
|
+
layouts: sp.layouts,
|
|
237
|
+
...(sp.inGroup === true ? { inGroup: true } : {}),
|
|
238
|
+
}))
|
|
239
|
+
.sort((a, b) => a.dirPattern.localeCompare(b.dirPattern) || a.kind.localeCompare(b.kind))
|
|
240
|
+
|
|
241
|
+
const paramMatchers: InspectParamMatcher[] = [...customMatcherFiles.entries()]
|
|
242
|
+
.map(([name, file]) => ({ name, file: toSrcRel(file) }))
|
|
243
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
244
|
+
|
|
200
245
|
const fileRoutes: InspectRoute[] = routeEntries.map((entry, idx) => {
|
|
201
|
-
const
|
|
246
|
+
const pageFile = pageFiles[idx]!
|
|
247
|
+
const analysis = graph.analyses.get(pageFile)
|
|
202
248
|
const hasDefault = analysis?.exportedNames.includes('default') === true
|
|
203
249
|
const methods = analysis?.exportedNames.filter(name => HTTP_METHODS.has(name)) ?? []
|
|
250
|
+
const groups = routeGroupsOf(routesDir, pageFile)
|
|
251
|
+
const matcherRefs = extractPatternMatchers(entry.path)
|
|
252
|
+
const matchers = matcherRefs.length > 0 ? Object.fromEntries(matcherRefs.map(m => [m.param, m.matcher])) : undefined
|
|
253
|
+
const optionalParams = extractOptionalParams(entry.path)
|
|
204
254
|
return {
|
|
205
255
|
path: entry.path,
|
|
206
256
|
file: entry.file,
|
|
207
257
|
...(methods.length > 0 ? { methods } : {}),
|
|
258
|
+
...(groups.length > 0 ? { groups } : {}),
|
|
259
|
+
...(matchers !== undefined ? { matchers } : {}),
|
|
260
|
+
...(optionalParams.length > 0 ? { optionalParams } : {}),
|
|
208
261
|
layouts: hasDefault ? entry.layouts : [],
|
|
209
262
|
middlewares: entry.middlewares,
|
|
210
263
|
load: entry.hasLoad === true,
|
|
211
264
|
prerender: entry.prerender === true,
|
|
265
|
+
...(entry.cache !== undefined ? { cache: entry.cache } : {}),
|
|
266
|
+
...(entry.cacheable === true ? { cacheable: true } : {}),
|
|
212
267
|
}
|
|
213
268
|
})
|
|
214
269
|
|
|
215
270
|
const pluginRoutes = await discoverPluginRoutes(activePlugins, config, { root, outDir, assetPrefix, site })
|
|
216
271
|
|
|
217
272
|
const islands: InspectIsland[] = [...islandPlan.targets.values()]
|
|
218
|
-
.map(target =>
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
273
|
+
.map((target) => {
|
|
274
|
+
const analysis = graph.analyses.get(target.file)
|
|
275
|
+
const reason = target.local === undefined
|
|
276
|
+
? analysis?.exports.get(target.exportName)?.reason
|
|
277
|
+
: analysis?.localIslands.get(target.local)?.reason
|
|
278
|
+
return {
|
|
279
|
+
exportName: target.local ?? target.exportName,
|
|
280
|
+
file: toSrcRel(target.file),
|
|
281
|
+
reason: reason ?? 'is interactive',
|
|
282
|
+
hydrate: target.defaultHydrate ?? 'load',
|
|
283
|
+
}
|
|
284
|
+
})
|
|
224
285
|
.sort((a, b) => a.file.localeCompare(b.file) || a.exportName.localeCompare(b.exportName))
|
|
225
286
|
|
|
226
287
|
const actions: InspectAction[] = buildActionEntries(actionsByFile, routesDir, toSrcRel)
|
|
@@ -242,6 +303,8 @@ export async function inspectProject(rootDir: string): Promise<InspectReport> {
|
|
|
242
303
|
|
|
243
304
|
return {
|
|
244
305
|
routes: [...fileRoutes, ...pluginRoutes],
|
|
306
|
+
statusPages,
|
|
307
|
+
paramMatchers,
|
|
245
308
|
islands,
|
|
246
309
|
actions,
|
|
247
310
|
plugins,
|
|
@@ -261,10 +324,20 @@ export function formatInspectReport(report: InspectReport): string {
|
|
|
261
324
|
if (r.methods !== undefined && r.methods.length > 0)
|
|
262
325
|
parts.push(r.methods.join(','))
|
|
263
326
|
parts.push(r.file ?? `(plugin: ${r.plugin})`)
|
|
327
|
+
if (r.groups !== undefined && r.groups.length > 0)
|
|
328
|
+
parts.push(`groups=[${r.groups.join(', ')}]`)
|
|
329
|
+
if (r.matchers !== undefined)
|
|
330
|
+
parts.push(`matchers=[${Object.entries(r.matchers).map(([k, v]) => `${k}=${v}`).join(', ')}]`)
|
|
331
|
+
if (r.optionalParams !== undefined && r.optionalParams.length > 0)
|
|
332
|
+
parts.push(`optional=[${r.optionalParams.join(', ')}]`)
|
|
264
333
|
if (r.load)
|
|
265
334
|
parts.push('load')
|
|
266
335
|
if (r.prerender)
|
|
267
336
|
parts.push('prerender')
|
|
337
|
+
if (r.cache !== undefined)
|
|
338
|
+
parts.push(`cache=${formatCacheSpec(r.cache)}`)
|
|
339
|
+
if (r.cacheable === true)
|
|
340
|
+
parts.push('cacheable')
|
|
268
341
|
if (r.layouts.length > 0)
|
|
269
342
|
parts.push(`layouts=[${r.layouts.join(', ')}]`)
|
|
270
343
|
if (r.middlewares.length > 0)
|
|
@@ -273,6 +346,22 @@ export function formatInspectReport(report: InspectReport): string {
|
|
|
273
346
|
}
|
|
274
347
|
}
|
|
275
348
|
|
|
349
|
+
if (report.statusPages.length > 0) {
|
|
350
|
+
lines.push('', `Status Pages (${report.statusPages.length}):`)
|
|
351
|
+
for (const sp of report.statusPages) {
|
|
352
|
+
const parts: string[] = [sp.kind, sp.dirPattern, sp.file]
|
|
353
|
+
if (sp.layouts.length > 0)
|
|
354
|
+
parts.push(`layouts=[${sp.layouts.join(', ')}]`)
|
|
355
|
+
lines.push(` ${parts.join(' ')}`)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (report.paramMatchers.length > 0) {
|
|
360
|
+
lines.push('', `Param Matchers (${report.paramMatchers.length}):`)
|
|
361
|
+
for (const matcher of report.paramMatchers)
|
|
362
|
+
lines.push(` ${matcher.name} ${matcher.file}`)
|
|
363
|
+
}
|
|
364
|
+
|
|
276
365
|
lines.push('', `Islands (${report.islands.length}):`)
|
|
277
366
|
if (report.islands.length === 0) {
|
|
278
367
|
lines.push(' (none)')
|