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/check.ts
CHANGED
|
@@ -3,20 +3,24 @@
|
|
|
3
3
|
import type { IslandIssue } from '../build/islands'
|
|
4
4
|
import type { ModuleAnalysis } from '../compiler/analyze'
|
|
5
5
|
import type { ComplianceConfig } from '../compiler/compliance'
|
|
6
|
-
import type { CheckPluginContext, PrunellePlugin } from '../plugins/index'
|
|
6
|
+
import type { CheckPluginContext, PrunelleConfig, PrunellePlugin } from '../plugins/index'
|
|
7
7
|
import { existsSync, readFileSync } from 'node:fs'
|
|
8
8
|
import { basename, join, relative, resolve } from 'node:path'
|
|
9
9
|
import { isInNodeModules, isNotSourceDir, isTsFile, relPosix, walkFiles, walkRoutes } from '../build/files'
|
|
10
10
|
import { ModuleGraph } from '../build/graph'
|
|
11
11
|
import { nodeEnvWarning, renderProblems, serverNodeEnvReads } from '../build/render-rules'
|
|
12
12
|
import { analyzeIslands } from '../build/islands'
|
|
13
|
-
import { fileToRoutePath, hasRouteHandlerExport, missingPathsProblem, normalizeRoutePattern, routeExportProblemLocation, routeFileProblem, SPECIAL_ROUTE_FILES } from '../build/routes'
|
|
13
|
+
import { ancestorFiles, discoverRouteMatchers, fileToRoutePath, hasRouteHandlerExport, missingPathsProblem, normalizeRoutePattern, routeExportProblemLocation, routeFileProblem, SPECIAL_ROUTE_FILES } from '../build/routes'
|
|
14
|
+
import { findUnknownStatusPages } from '../build/status-pages'
|
|
14
15
|
import { analyzeModule } from '../compiler/analyze'
|
|
16
|
+
import { findCachedRoutePrivateReads } from '../compiler/cacheability'
|
|
15
17
|
import { collectProjectComplianceWarnings, shouldEmitWarning } from '../compiler/compliance'
|
|
16
18
|
import { collectMistakes, PrunelleMistake, serverOnlyTagError } from '../compiler/mistakes'
|
|
17
19
|
import { DIAGNOSTIC_PREFIX_RE, formatDiagnostic, formatLoc } from '../compiler/shared'
|
|
18
20
|
import { createAppContext, loadConfig, resolvePlugins, runWithAppContext } from '../plugins/index'
|
|
19
21
|
import { collectRequirements } from '../plugins/requires'
|
|
22
|
+
import { checkAppForms } from './check-forms'
|
|
23
|
+
import { checkAppLinks } from './check-links'
|
|
20
24
|
|
|
21
25
|
/** Whether `prunelle check` typechecked the app, with which tool, or why it did not. */
|
|
22
26
|
export type TypecheckRun = { ran: true, tool: string } | { ran: false, reason: string }
|
|
@@ -162,10 +166,13 @@ function formatIslandIssue(issue: IslandIssue, root: string, sources: Map<string
|
|
|
162
166
|
return formatDiagnostic(locOf(root, issue.file, sources, issue.offset), message)
|
|
163
167
|
}
|
|
164
168
|
case 'private-env': {
|
|
165
|
-
const
|
|
169
|
+
const isImportMeta = issue.envKind === 'process' && sources.get(issue.file)?.slice(issue.offset, issue.offset + 15).startsWith('import.meta') === true
|
|
170
|
+
const envName = issue.envKind === 'bun' ? 'Bun.env' : isImportMeta ? 'import.meta.env' : 'process.env'
|
|
166
171
|
const hint = issue.envKind === 'bun'
|
|
167
172
|
? 'Bun.env is server-only and is not inlined in browser bundles; use process.env.PUBLIC_* for build-time client values.'
|
|
168
|
-
:
|
|
173
|
+
: isImportMeta
|
|
174
|
+
? 'Only import.meta.env.PUBLIC_* and MODE/DEV/PROD reach the browser.'
|
|
175
|
+
: 'Only process.env.PUBLIC_* reaches the browser.'
|
|
169
176
|
return formatDiagnostic(locOf(root, issue.file, sources, issue.offset), `prunelle check: reads ${envName} and is reachable from the island in ${relPosix(root, issue.island)}. ${hint}`)
|
|
170
177
|
}
|
|
171
178
|
case 'compiler-mistake':
|
|
@@ -176,7 +183,7 @@ function formatIslandIssue(issue: IslandIssue, root: string, sources: Map<string
|
|
|
176
183
|
// Each plugin's check(ctx) runs inside a real AppRuntimeContext; what it reports without a place lands on prunelle.config.ts.
|
|
177
184
|
async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root: string, routesDir: string, outDir: string, assetPrefix: string, site: string | undefined }, errors: string[], warnings: string[]): Promise<void> {
|
|
178
185
|
const { root, routesDir, outDir, assetPrefix, site } = paths
|
|
179
|
-
const appCtx = createAppContext({ root, outDir, publicDir: join(outDir, 'public'), assetPrefix, dev: false })
|
|
186
|
+
const appCtx = createAppContext({ root, outDir, publicDir: join(outDir, 'public'), assetPrefix, site, dev: false })
|
|
180
187
|
const placed = (message: string, severity: 'error' | 'warning'): string =>
|
|
181
188
|
DIAGNOSTIC_PREFIX_RE.test(message) ? message : formatDiagnostic('prunelle.config.ts:1:1', message, severity)
|
|
182
189
|
const pluginCtx: CheckPluginContext = {
|
|
@@ -184,6 +191,8 @@ async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root
|
|
|
184
191
|
routesDir,
|
|
185
192
|
error: message => errors.push(placed(message, 'error')),
|
|
186
193
|
warn: message => warnings.push(placed(message, 'warning')),
|
|
194
|
+
provide: appCtx.provide,
|
|
195
|
+
inject: appCtx.inject,
|
|
187
196
|
}
|
|
188
197
|
for (const plugin of plugins) {
|
|
189
198
|
if (plugin.check === undefined)
|
|
@@ -203,6 +212,17 @@ async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root
|
|
|
203
212
|
}
|
|
204
213
|
|
|
205
214
|
|
|
215
|
+
function discoverProjectFiles(srcDir: string, routesDir: string, configFile: string): string[] {
|
|
216
|
+
const fileSet = new Set<string>()
|
|
217
|
+
if (existsSync(srcDir))
|
|
218
|
+
walkTsFiles(srcDir).forEach(f => fileSet.add(f))
|
|
219
|
+
if (existsSync(routesDir))
|
|
220
|
+
walkTsFiles(routesDir).forEach(f => fileSet.add(f))
|
|
221
|
+
if (existsSync(configFile))
|
|
222
|
+
fileSet.add(configFile)
|
|
223
|
+
return [...fileSet].sort()
|
|
224
|
+
}
|
|
225
|
+
|
|
206
226
|
export async function checkProject(rootDir: string, options: { skipTypecheck?: boolean } = {}): Promise<CheckResult> {
|
|
207
227
|
const root = resolve(rootDir)
|
|
208
228
|
const errors: string[] = []
|
|
@@ -210,12 +230,15 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
210
230
|
// 1. Validate prunelle.config.ts
|
|
211
231
|
let routesDir = resolve(root, 'src/routes')
|
|
212
232
|
let outDir = resolve(root, 'dist')
|
|
233
|
+
let publicDir = resolve(root, 'public')
|
|
213
234
|
let assetPrefix = '/_pru'
|
|
214
235
|
let site: string | undefined
|
|
215
236
|
let compliance: ComplianceConfig | undefined
|
|
237
|
+
let loadedConfig: PrunelleConfig = {}
|
|
216
238
|
let plugins: Awaited<ReturnType<typeof loadConfig>>['plugins'] = []
|
|
217
239
|
try {
|
|
218
240
|
const cfg = await loadConfig(root)
|
|
241
|
+
loadedConfig = cfg
|
|
219
242
|
plugins = resolvePlugins(cfg.plugins)
|
|
220
243
|
site = cfg.site
|
|
221
244
|
compliance = cfg.compliance
|
|
@@ -223,6 +246,8 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
223
246
|
routesDir = resolve(root, cfg.routesDir)
|
|
224
247
|
if (cfg.outDir !== undefined)
|
|
225
248
|
outDir = resolve(root, cfg.outDir)
|
|
249
|
+
if (cfg.publicDir !== undefined)
|
|
250
|
+
publicDir = resolve(root, cfg.publicDir)
|
|
226
251
|
if (cfg.assetPrefix !== undefined)
|
|
227
252
|
assetPrefix = cfg.assetPrefix.replace(/\/$/, '')
|
|
228
253
|
}
|
|
@@ -236,18 +261,10 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
236
261
|
errors.push(formatDiagnostic(`${relRoutes.replace(/\\/g, '/')}:1:1`, `prunelle check: missing routes directory: ${relRoutes}`))
|
|
237
262
|
}
|
|
238
263
|
|
|
239
|
-
// 3. Parse & run Prunelle static compiler analysis across src
|
|
264
|
+
// 3. Parse & run Prunelle static compiler analysis across src/, custom routesDir, and prunelle.config.ts
|
|
240
265
|
const srcDir = resolve(root, 'src')
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
for (const f of walkTsFiles(srcDir))
|
|
244
|
-
fileSet.add(f)
|
|
245
|
-
}
|
|
246
|
-
if (existsSync(routesDir)) {
|
|
247
|
-
for (const f of walkTsFiles(routesDir))
|
|
248
|
-
fileSet.add(f)
|
|
249
|
-
}
|
|
250
|
-
const files = [...fileSet].sort()
|
|
266
|
+
const configFile = resolve(root, 'prunelle.config.ts')
|
|
267
|
+
const files = discoverProjectFiles(srcDir, routesDir, configFile)
|
|
251
268
|
const graph = new ModuleGraph(root)
|
|
252
269
|
const { analyses } = graph
|
|
253
270
|
const sources = new Map<string, string>()
|
|
@@ -265,9 +282,19 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
265
282
|
|
|
266
283
|
// Exact route discovery matching `prunelle build` (`walkRoutes` skips `_components/` dirs, `.d.ts`, `.test.ts`)
|
|
267
284
|
const routeFiles = existsSync(routesDir) ? walkRoutes(routesDir).sort() : []
|
|
285
|
+
for (const unknown of findUnknownStatusPages(root, routeFiles))
|
|
286
|
+
errors.push(formatDiagnostic(`${relPosix(root, unknown.file)}:1:1`, `prunelle check: ${unknown.message}`))
|
|
268
287
|
const routeFileSet = new Set(routeFiles)
|
|
269
288
|
const specialFiles = routeFiles.filter(f => SPECIAL_ROUTE_FILES.has(basename(f)))
|
|
270
289
|
const pageFiles = routeFiles.filter(f => !basename(f).startsWith('_') && analyses.has(f) && hasRouteHandlerExport(analyses.get(f)!))
|
|
290
|
+
const matcherDiscovery = discoverRouteMatchers({
|
|
291
|
+
root,
|
|
292
|
+
routesDir,
|
|
293
|
+
routeFiles: [...specialFiles, ...pageFiles],
|
|
294
|
+
loadAnalysis: load,
|
|
295
|
+
})
|
|
296
|
+
for (const problem of matcherDiscovery.problems)
|
|
297
|
+
errors.push(formatDiagnostic(`${relPosix(root, problem.file)}:1:1`, `prunelle check: ${problem.message}`))
|
|
271
298
|
|
|
272
299
|
// 3a. Unified island planning, state-read promotion, special-file checks & reachability checks (shared with `prunelle build`)
|
|
273
300
|
const islands = analyzeIslands({
|
|
@@ -288,8 +315,17 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
288
315
|
if (isInNodeModules(file))
|
|
289
316
|
continue
|
|
290
317
|
const rel = relPosix(root, file)
|
|
291
|
-
for (const
|
|
292
|
-
|
|
318
|
+
for (const imp of analysis.imports) {
|
|
319
|
+
if (imp.source === '@prunellejs/auth') {
|
|
320
|
+
const removed = imp.specifiers.find(s => s.imported === 'createRateLimiter' || s.imported === 'RateLimiter')
|
|
321
|
+
if (removed !== undefined)
|
|
322
|
+
warnings.push(formatDiagnostic(locOf(root, file, sources, imp.start), `prunelle check: ${removed.imported} was removed from @prunellejs/auth in 0.2.0: use \`rateLimit\` on \`api.route()\`/\`action()\`, \`api.rateLimiter()\` in a plugin, or \`createRateLimitStore()\` from \`prunelle/server\`.`, 'warning'))
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (file !== configFile) {
|
|
326
|
+
for (const offset of serverNodeEnvReads(analysis, islands, file))
|
|
327
|
+
warnings.push(formatDiagnostic(locOf(root, file, sources, offset), nodeEnvWarning(rel), 'warning'))
|
|
328
|
+
}
|
|
293
329
|
|
|
294
330
|
if (file.endsWith('.tsx')) {
|
|
295
331
|
for (const problem of renderProblems(analysis, islands, file, rel, 'prunelle check'))
|
|
@@ -322,10 +358,29 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
322
358
|
}
|
|
323
359
|
}
|
|
324
360
|
|
|
325
|
-
// 3c.
|
|
361
|
+
// 3c. Cached route private-read guardrails (#6)
|
|
362
|
+
for (const problem of findCachedRoutePrivateReads({
|
|
363
|
+
graph,
|
|
364
|
+
pageFiles,
|
|
365
|
+
layoutsFor: file => ancestorFiles(routesDir, file, ['_layout.tsx']),
|
|
366
|
+
toRel: file => relPosix(root, file),
|
|
367
|
+
tool: 'prunelle check',
|
|
368
|
+
})) {
|
|
369
|
+
errors.push(formatDiagnostic(locOf(root, problem.file, sources, problem.offset), problem.message))
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// 3d. French web law compliance checks (CSS third-party URLs, LCEN legal notice, RGAA accessibility statement)
|
|
326
373
|
warnings.push(...collectProjectComplianceWarnings({ root, srcDir, routesDir, routeFiles, analyses, compliance, site }))
|
|
327
374
|
|
|
328
|
-
// 3d.
|
|
375
|
+
// 3d. Form field / schema checks & public action protection warnings (#4, #5)
|
|
376
|
+
const formCheck = await checkAppForms({ root, routesDir, routeFiles, graph, sources })
|
|
377
|
+
errors.push(...formCheck.errors)
|
|
378
|
+
warnings.push(...formCheck.warnings)
|
|
379
|
+
|
|
380
|
+
// 3e. Broken internal link checks (#3)
|
|
381
|
+
warnings.push(...await checkAppLinks({ root, routesDir, publicDir, assetPrefix, site, config: loadedConfig, plugins, routeFiles, analyses, sources }))
|
|
382
|
+
|
|
383
|
+
// 3f. Plugin check(ctx) hooks
|
|
329
384
|
await runPluginChecks(plugins, { root, routesDir, outDir, assetPrefix, site }, errors, warnings)
|
|
330
385
|
|
|
331
386
|
const typecheck = options.skipTypecheck === true ? { ran: false as const, reason: "skipped by --no-typecheck" } : runTypecheck(root, errors)
|
package/src/cli/commands.ts
CHANGED
|
@@ -123,13 +123,15 @@ function upgradeCommand(cwd: string): Commands[string] {
|
|
|
123
123
|
const res = upgradeProject(root)
|
|
124
124
|
for (const file of res.changed)
|
|
125
125
|
console.log(` ${file}`)
|
|
126
|
-
console.log(`prunelle upgrade rewrote ${res.changed.length}
|
|
127
|
-
|
|
126
|
+
console.log(`prunelle upgrade rewrote ${res.changed.length} file${res.changed.length === 1 ? '' : 's'}`)
|
|
127
|
+
// The dependencies moved: the first run for this app, which renames its cookies; a later run only fixes what an older prunelle left.
|
|
128
|
+
const moved = res.changed.some(file => file === 'package.json' || file.endsWith('/package.json'))
|
|
129
|
+
if (moved && values['no-install'] !== true) {
|
|
128
130
|
const install = Bun.spawnSync(['bun', 'install'], { cwd: root, stdout: 'inherit', stderr: 'inherit' })
|
|
129
131
|
if (install.exitCode !== 0)
|
|
130
132
|
return 1
|
|
131
133
|
}
|
|
132
|
-
if (
|
|
134
|
+
if (moved)
|
|
133
135
|
console.log('Signed-in users sign in again and visitors answer the cookie banner again: prunelle names its cookies pru_session and pru_consent.')
|
|
134
136
|
for (const line of res.manual)
|
|
135
137
|
console.error(line)
|
|
@@ -163,6 +165,7 @@ function buildCommand(cwd: string): Commands[string] {
|
|
|
163
165
|
run: async (args) => {
|
|
164
166
|
const { values, positionals: [dir] } = parse(args, 'prunelle build [options] [dir]: builds the app into dist/', {
|
|
165
167
|
'static': { type: 'boolean', description: 'export plain HTML files instead of a server' },
|
|
168
|
+
'auto-prerender': { type: 'boolean', description: 'prerender static pages that read nothing from the request or clock' },
|
|
166
169
|
'compile': { type: 'string', optional: { bare: '' }, description: 'also produce one binary, at [out] when given' },
|
|
167
170
|
'analyze': { type: 'boolean', description: 'list each island with why it is one' },
|
|
168
171
|
'json': { type: 'boolean', description: 'with --analyze, print the bundle report as JSON' },
|
|
@@ -176,7 +179,8 @@ function buildCommand(cwd: string): Commands[string] {
|
|
|
176
179
|
const analyzeJson = values.analyze === true && values.json === true
|
|
177
180
|
const { build } = await import('../build/index')
|
|
178
181
|
const t0 = performance.now()
|
|
179
|
-
const
|
|
182
|
+
const autoPrerender = values['auto-prerender'] === true ? true : undefined
|
|
183
|
+
const manifest = await failing('build', async () => build({ root: rootOf(cwd, values.root, dir), static: values.static === true, autoPrerender, compile, analyze: values.analyze === true, analyzeJson, maxJs }))
|
|
180
184
|
const ms = (performance.now() - t0).toFixed(1)
|
|
181
185
|
if (!analyzeJson)
|
|
182
186
|
console.log(`prunelle build done in ${ms} ms (${manifest.routes.length} routes, ${manifest.assets.length} client assets, ${manifest.actions.length} actions)`)
|
|
@@ -227,11 +231,88 @@ function devCommand(cwd: string): Commands[string] {
|
|
|
227
231
|
}
|
|
228
232
|
}
|
|
229
233
|
|
|
234
|
+
function docsCommand(cwd: string): Commands[string] {
|
|
235
|
+
return {
|
|
236
|
+
summary: 'search llms.txt across prunelle and installed plugins',
|
|
237
|
+
run: async (args) => {
|
|
238
|
+
const { values, positionals } = parse(args, 'prunelle docs [options] <words...>: searches llms.txt of prunelle and every installed @prunellejs/* package', {
|
|
239
|
+
json: { type: 'boolean', description: 'print { query, words, packages, matches } as JSON' },
|
|
240
|
+
limit: { type: 'string', description: 'maximum matching sections to print (default: 20)' },
|
|
241
|
+
root: ROOT,
|
|
242
|
+
}, { positionals: ['<words...>'], exits: [OK, [1, 'no matching section found'], USAGE_EXIT] })
|
|
243
|
+
const limit = values.limit === undefined ? undefined : Number(values.limit)
|
|
244
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit <= 0))
|
|
245
|
+
return badUsage(`invalid --limit "${values.limit}": give a positive integer`)
|
|
246
|
+
const query = positionals.join(' ').trim()
|
|
247
|
+
if (query === '')
|
|
248
|
+
return badUsage('give at least one search word, e.g. prunelle docs action')
|
|
249
|
+
const { formatDocsSearchResult, searchLlmsDocs } = await import('./docs')
|
|
250
|
+
const result = searchLlmsDocs(rootOf(cwd, values.root, undefined), query, { limit })
|
|
251
|
+
if (values.json === true) {
|
|
252
|
+
console.log(JSON.stringify(result, null, 2))
|
|
253
|
+
return result.matches.length > 0 ? 0 : 1
|
|
254
|
+
}
|
|
255
|
+
console.log(formatDocsSearchResult(result))
|
|
256
|
+
return result.matches.length > 0 ? 0 : 1
|
|
257
|
+
},
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function renderCommand(cwd: string): Commands[string] {
|
|
262
|
+
return {
|
|
263
|
+
summary: 'render a URL in-process without binding a port',
|
|
264
|
+
run: async (args) => {
|
|
265
|
+
const { values, positionals: [url] } = parse(args, 'prunelle render [options] <url>: builds or reuses a test build and prints the response with no port bound', {
|
|
266
|
+
method: { type: 'string', short: 'X', description: 'HTTP method (default: GET, or POST when --body is passed)' },
|
|
267
|
+
body: { type: 'string', short: 'd', description: 'request body string' },
|
|
268
|
+
header: { type: 'string', short: 'H', multiple: true, description: 'request header as "Name: Value" (repeatable)' },
|
|
269
|
+
cookie: { type: 'string', short: 'b', multiple: true, description: 'request cookie as "name=value" (repeatable)' },
|
|
270
|
+
include: { type: 'boolean', short: 'i', description: 'include HTTP status line and response headers before the body' },
|
|
271
|
+
fresh: { type: 'boolean', description: 'force a fresh build instead of reusing the cached render build' },
|
|
272
|
+
root: ROOT,
|
|
273
|
+
}, { positionals: ['<url>'], exits: [[0, 'response status is 2xx or 3xx'], [1, 'response status is 4xx/5xx or the render failed'], USAGE_EXIT] })
|
|
274
|
+
const { renderUrl, writeRenderResult } = await import('./render')
|
|
275
|
+
const result = await failing('render', () => renderUrl({
|
|
276
|
+
root: rootOf(cwd, values.root, undefined),
|
|
277
|
+
url: url!,
|
|
278
|
+
method: values.method,
|
|
279
|
+
body: values.body,
|
|
280
|
+
headers: values.header,
|
|
281
|
+
cookies: values.cookie,
|
|
282
|
+
includeHeaders: values.include === true,
|
|
283
|
+
fresh: values.fresh === true,
|
|
284
|
+
}))
|
|
285
|
+
writeRenderResult(result, values.include === true)
|
|
286
|
+
return result.ok ? 0 : 1
|
|
287
|
+
},
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function mcpCommand(cwd: string): Commands[string] {
|
|
292
|
+
return {
|
|
293
|
+
summary: 'run the Prunelle stdio MCP server for coding agents',
|
|
294
|
+
run: async (args) => {
|
|
295
|
+
const { values, positionals: [dir] } = parse(args, 'prunelle mcp [options] [dir]: runs a stdio MCP server exposing check, inspect, build analysis, render, docs, dev errors, and llms.txt resources', {
|
|
296
|
+
'allow-write': { type: 'boolean', description: 'allow MCP tools that write build output to disk' },
|
|
297
|
+
'root': ROOT,
|
|
298
|
+
}, { positionals: ['[dir]'], exits: [OK, [1, 'the MCP server exited with an error'], USAGE_EXIT] })
|
|
299
|
+
const { runPrunelleMcpStdio } = await import('./mcp')
|
|
300
|
+
return await failing('mcp', () => runPrunelleMcpStdio({
|
|
301
|
+
root: rootOf(cwd, values.root, dir),
|
|
302
|
+
allowWrite: values['allow-write'] === true,
|
|
303
|
+
}))
|
|
304
|
+
},
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
230
308
|
export function builtinCommands(cwd: string): Commands {
|
|
231
309
|
return {
|
|
232
310
|
new: newCommand(cwd),
|
|
233
311
|
check: checkCommand(cwd),
|
|
234
312
|
inspect: inspectCommand(cwd),
|
|
313
|
+
docs: docsCommand(cwd),
|
|
314
|
+
render: renderCommand(cwd),
|
|
315
|
+
mcp: mcpCommand(cwd),
|
|
235
316
|
dev: devCommand(cwd),
|
|
236
317
|
build: buildCommand(cwd),
|
|
237
318
|
start: startCommand(cwd),
|