prunelle 0.8.0 → 0.10.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 +68 -51
- package/package.json +7 -2
- package/src/a11y/declaration.ts +10 -17
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +94 -136
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +14 -6
- package/src/build/index.ts +23 -11
- package/src/build/island-promote.ts +42 -2
- package/src/build/islands.ts +63 -9
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +117 -1
- package/src/build/plugin-host.ts +13 -1
- package/src/build/prerender.ts +8 -3
- package/src/build/reach.ts +18 -4
- package/src/build/report.ts +1 -1
- package/src/build/resolve.ts +5 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +42 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +10 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +30 -105
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +49 -21
- package/src/cli/commands.ts +138 -16
- package/src/cli/docs.ts +21 -2
- package/src/cli/form-opaque-children.ts +40 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +22 -16
- package/src/compiler/cacheability-private.ts +13 -3
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +322 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-rules.ts +72 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +61 -93
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/dom-attrs.ts +178 -22
- package/src/compiler/dom.ts +31 -44
- package/src/compiler/emit.ts +17 -6
- package/src/compiler/expr-context.ts +260 -207
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-body.ts +263 -21
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +324 -343
- package/src/compiler/signal-reads.ts +142 -29
- package/src/compiler/spread-handlers.ts +25 -13
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +165 -121
- package/src/compiler/ssr.ts +28 -441
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/host-check.ts +2 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +5 -2
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/attrs.ts +93 -25
- package/src/dom/extras.ts +91 -50
- package/src/dom/field-marks.ts +32 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +44 -18
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/loop.ts +259 -188
- package/src/dom/prefetch.ts +135 -0
- package/src/dom/regions.ts +515 -0
- package/src/dom/swap.ts +246 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +44 -41
- package/src/eco/index.ts +8 -5
- package/src/href.ts +31 -0
- package/src/index.ts +12 -5
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +12 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +128 -10
- package/src/reactivity/graph.ts +244 -41
- package/src/reactivity/hmr.ts +101 -0
- package/src/reactivity/index.ts +243 -239
- package/src/reactivity/resource.ts +129 -0
- package/src/reactivity/seed.ts +141 -0
- package/src/reactivity/selector.ts +85 -47
- package/src/reactivity/server-seed.ts +202 -0
- package/src/reactivity/store.ts +331 -97
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-protect.ts +3 -0
- package/src/server/action-registry.ts +11 -9
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +97 -0
- package/src/server/compress.ts +55 -18
- package/src/server/consent.ts +21 -5
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +77 -8
- package/src/server/cors.ts +98 -0
- package/src/server/csp-report.ts +90 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +2 -2
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +41 -11
- package/src/server/http.ts +28 -11
- package/src/server/index.ts +122 -307
- package/src/server/loader.ts +2 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +66 -16
- package/src/server/plugin-route-shadow.ts +24 -0
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +49 -10
- package/src/server/region.ts +22 -2
- package/src/server/request-handler.ts +406 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +55 -8
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +53 -27
- package/src/server/router.ts +2 -1
- package/src/server/routing.ts +104 -45
- package/src/server/sanitize-html.ts +4 -2
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +16 -6
- package/src/server/served-file.ts +19 -14
- package/src/server/shared-store.ts +323 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +34 -12
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +50 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +174 -53
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +63 -58
- package/src/ssr/navigation.ts +161 -14
- package/src/ssr/region.ts +9 -3
- package/src/style.ts +12 -5
- package/src/test/browser.ts +53 -23
- package/src/test/build-reuse.ts +85 -0
- package/src/test/index.ts +51 -8
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/src/ts-plugin/diagnostics.ts +56 -18
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +4058 -2246
package/src/cli/check.ts
CHANGED
|
@@ -12,19 +12,23 @@ import { formatIslandValueWarnings } from '../build/island-promote'
|
|
|
12
12
|
import { nodeEnvWarning, renderProblems, serverNodeEnvReads } from '../build/render-rules'
|
|
13
13
|
import { analyzeIslands } from '../build/islands'
|
|
14
14
|
import { ancestorFiles, discoverRouteMatchers, fileToRoutePath, hasRouteHandlerExport, missingPathsProblem, normalizeRoutePattern, routeExportProblemLocation, routeFileProblem, SPECIAL_ROUTE_FILES } from '../build/routes'
|
|
15
|
+
import { writeRouteTypes } from '../build/route-types'
|
|
15
16
|
import { findUnknownStatusPages } from '../build/status-pages'
|
|
16
17
|
import { analyzeModule } from '../compiler/analyze'
|
|
17
18
|
import { findCachedRoutePrivateReads } from '../compiler/cacheability'
|
|
18
|
-
import { collectProjectComplianceWarnings, pluginSetsLang, shouldEmitWarning } from '../compiler/compliance'
|
|
19
|
+
import { collectProjectComplianceWarnings, pluginChecksTitle, pluginSetsLang, shouldEmitWarning } from '../compiler/compliance'
|
|
19
20
|
import { collectMistakes, PrunelleMistake, serverOnlyTagError } from '../compiler/mistakes'
|
|
20
21
|
import { DIAGNOSTIC_PREFIX_RE, formatDiagnostic, formatLoc } from '../compiler/shared'
|
|
21
22
|
import { createAppContext, loadConfig, resolvePlugins, runWithAppContext } from '../plugins/index'
|
|
22
23
|
import { collectRequirements } from '../plugins/requires'
|
|
23
24
|
import { normalizeConsentConfig } from '../server/consent'
|
|
25
|
+
import { cookieWarnings } from './check-consent'
|
|
24
26
|
import { checkAppForms } from './check-forms'
|
|
25
27
|
import { unresolvedImport } from './check-imports'
|
|
26
28
|
import { checkAppLinks } from './check-links'
|
|
27
|
-
import {
|
|
29
|
+
import { checkRegionTargets } from './check-regions'
|
|
30
|
+
import { unknownCacheTagWarnings } from './check-cache'
|
|
31
|
+
import { csrfOffWarnings, externalRedirectWarnings, htmlSinkWarnings, proxyWithoutSiteWarnings, publicDotfileWarnings, securityConfigWarnings } from './check-security'
|
|
28
32
|
|
|
29
33
|
/** Whether `prunelle check` typechecked the app, with which tool, or why it did not. */
|
|
30
34
|
export type TypecheckRun = { ran: true, tool: string } | { ran: false, reason: string }
|
|
@@ -69,6 +73,8 @@ export interface CheckDiagnostic {
|
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
const DIAGNOSTIC_RE = /^(.+?):(\d+):(\d+): (error|warning): ([\s\S]*)$/
|
|
76
|
+
// The `[pwa/manifest-missing]` tag a plugin's warning names its rule with.
|
|
77
|
+
const PLUGIN_RULE_RE = /\[([a-z0-9-]+\/[a-z0-9-]+)\]/
|
|
72
78
|
|
|
73
79
|
export function diagnosticData(text: string, severity: 'error' | 'warning'): CheckDiagnostic {
|
|
74
80
|
const m = DIAGNOSTIC_RE.exec(text)
|
|
@@ -184,9 +190,9 @@ function formatIslandIssue(issue: IslandIssue, root: string, sources: Map<string
|
|
|
184
190
|
}
|
|
185
191
|
}
|
|
186
192
|
|
|
187
|
-
// Each plugin's check(ctx) runs inside a real AppRuntimeContext; what it reports without a place lands on prunelle.config.ts.
|
|
188
|
-
async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root: string, routesDir: string, publicDir: string, outDir: string, assetPrefix: string, site: string | undefined, consentCategories: readonly string[] }, errors: string[], warnings: string[]): Promise<void> {
|
|
189
|
-
const { root, routesDir, publicDir, outDir, assetPrefix, site, consentCategories } = paths
|
|
193
|
+
// Each plugin's check(ctx) runs inside a real AppRuntimeContext; what it reports without a place lands on prunelle.config.ts, and a warning whose `[ns/rule]` tag `compliance.ignore` lists is dropped.
|
|
194
|
+
async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root: string, routesDir: string, publicDir: string, outDir: string, assetPrefix: string, site: string | undefined, consentCategories: readonly string[], store: string | undefined, ignore: readonly string[] }, errors: string[], warnings: string[]): Promise<void> {
|
|
195
|
+
const { root, routesDir, publicDir, outDir, assetPrefix, site, consentCategories, store, ignore } = paths
|
|
190
196
|
const appCtx = createAppContext({ root, outDir, publicDir: join(outDir, 'public'), assetPrefix, site, dev: false })
|
|
191
197
|
const placed = (message: string, severity: 'error' | 'warning'): string =>
|
|
192
198
|
DIAGNOSTIC_PREFIX_RE.test(message) ? message : formatDiagnostic('prunelle.config.ts:1:1', message, severity)
|
|
@@ -194,8 +200,13 @@ async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root
|
|
|
194
200
|
root,
|
|
195
201
|
routesDir,
|
|
196
202
|
publicDir,
|
|
203
|
+
site,
|
|
197
204
|
error: message => errors.push(placed(message, 'error')),
|
|
198
|
-
warn: message =>
|
|
205
|
+
warn: (message) => {
|
|
206
|
+
const rule = PLUGIN_RULE_RE.exec(message)?.[1]
|
|
207
|
+
if (rule === undefined || !ignore.includes(rule))
|
|
208
|
+
warnings.push(placed(message, 'warning'))
|
|
209
|
+
},
|
|
199
210
|
provide: appCtx.provide,
|
|
200
211
|
inject: appCtx.inject,
|
|
201
212
|
}
|
|
@@ -209,7 +220,7 @@ async function runPluginChecks(plugins: readonly PrunellePlugin[], paths: { root
|
|
|
209
220
|
errors.push(placed(`${plugin.name}: ${err instanceof Error ? err.message : String(err)}`, 'error'))
|
|
210
221
|
}
|
|
211
222
|
}
|
|
212
|
-
const { unmet, failed } = await runWithAppContext(appCtx, () => collectRequirements(plugins, { root, site, consentCategories }))
|
|
223
|
+
const { unmet, failed } = await runWithAppContext(appCtx, () => collectRequirements(plugins, { root, site, consentCategories, store }))
|
|
213
224
|
for (const line of unmet)
|
|
214
225
|
warnings.push(placed(`${line} (a production start refuses until it is set)`, 'warning'))
|
|
215
226
|
for (const line of failed)
|
|
@@ -228,6 +239,23 @@ function discoverProjectFiles(srcDir: string, routesDir: string, configFile: str
|
|
|
228
239
|
return [...fileSet].sort()
|
|
229
240
|
}
|
|
230
241
|
|
|
242
|
+
function removedImportWarning(imp: { source: string, specifiers: readonly { imported: string }[] }): string | undefined {
|
|
243
|
+
if (imp.source === '@prunellejs/auth') {
|
|
244
|
+
const removed = imp.specifiers.find(s => s.imported === 'createRateLimiter' || s.imported === 'RateLimiter')
|
|
245
|
+
if (removed !== undefined)
|
|
246
|
+
return `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\`.`
|
|
247
|
+
}
|
|
248
|
+
if (imp.source === '@prunellejs/cms' || imp.source.startsWith('@prunellejs/cms/'))
|
|
249
|
+
return 'prunelle check: @prunellejs/cms was removed: remove it from prunelle.config.ts and package.json, and edit Markdown files directly or load from a headless CMS via @prunellejs/content `load()`.'
|
|
250
|
+
if (imp.source === 'prunelle/config' && imp.specifiers.some(s => s.imported === 'a11y'))
|
|
251
|
+
return 'prunelle check: `a11y()` was removed from prunelle/config: `prunelle a11y` is now a built-in CLI command, so remove `a11y()` from prunelle.config.ts.'
|
|
252
|
+
if (imp.source === '@prunellejs/spa' && imp.specifiers.some(s => s.imported === 'regions'))
|
|
253
|
+
return 'prunelle check: `regions()` was removed from @prunellejs/spa: `<Region>` swapping is built into `prunelle` automatically on routes rendering `<Region>`, so remove `regions()` from prunelle.config.ts and import `refreshRegion` from `prunelle`.'
|
|
254
|
+
if (imp.source === '@prunellejs/spa/regions')
|
|
255
|
+
return 'prunelle check: `@prunellejs/spa/regions` was removed: import `refreshRegion` from `prunelle` instead.'
|
|
256
|
+
return undefined
|
|
257
|
+
}
|
|
258
|
+
|
|
231
259
|
export async function checkProject(rootDir: string, options: { skipTypecheck?: boolean } = {}): Promise<CheckResult> {
|
|
232
260
|
const root = resolve(rootDir)
|
|
233
261
|
const errors: string[] = []
|
|
@@ -289,11 +317,11 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
289
317
|
|
|
290
318
|
// Exact route discovery matching `prunelle build` (`walkRoutes` skips `_components/` dirs, `.d.ts`, `.test.ts`)
|
|
291
319
|
const routeFiles = existsSync(routesDir) ? walkRoutes(routesDir).sort() : []
|
|
292
|
-
|
|
293
|
-
errors.push(formatDiagnostic(`${relPosix(root, unknown.file)}:1:1`, `prunelle check: ${unknown.message}`))
|
|
320
|
+
errors.push(...findUnknownStatusPages(root, routeFiles).map(unknown => formatDiagnostic(`${relPosix(root, unknown.file)}:1:1`, `prunelle check: ${unknown.message}`)))
|
|
294
321
|
const routeFileSet = new Set(routeFiles)
|
|
295
322
|
const specialFiles = routeFiles.filter(f => SPECIAL_ROUTE_FILES.has(basename(f)))
|
|
296
323
|
const pageFiles = routeFiles.filter(f => !basename(f).startsWith('_') && analyses.has(f) && hasRouteHandlerExport(analyses.get(f)!))
|
|
324
|
+
writeRouteTypes(root, routesDir, pageFiles)
|
|
297
325
|
const matcherDiscovery = discoverRouteMatchers({
|
|
298
326
|
root,
|
|
299
327
|
routesDir,
|
|
@@ -331,11 +359,9 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
331
359
|
const unresolved = unresolvedImport(file, rel, imp.source, imp.specifiers)
|
|
332
360
|
if (unresolved !== undefined)
|
|
333
361
|
errors.push(formatDiagnostic(locOf(root, file, sources, imp.start), unresolved))
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
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'))
|
|
338
|
-
}
|
|
362
|
+
const removedWarning = removedImportWarning(imp)
|
|
363
|
+
if (removedWarning !== undefined)
|
|
364
|
+
warnings.push(formatDiagnostic(locOf(root, file, sources, imp.start), removedWarning, 'warning'))
|
|
339
365
|
}
|
|
340
366
|
if (file !== configFile) {
|
|
341
367
|
for (const offset of serverNodeEnvReads(analysis, islands, file))
|
|
@@ -385,24 +411,26 @@ export async function checkProject(rootDir: string, options: { skipTypecheck?: b
|
|
|
385
411
|
}
|
|
386
412
|
|
|
387
413
|
// 3d. French web law compliance checks (CSS third-party URLs, LCEN legal notice, RGAA accessibility statement)
|
|
388
|
-
warnings.push(...collectProjectComplianceWarnings({ root, srcDir, routesDir, publicDir, routeFiles, analyses, compliance, consentMaxAge: loadedConfig.consent?.maxAge, site, lang: loadedConfig.lang, langFromPlugin: pluginSetsLang(plugins) }))
|
|
414
|
+
warnings.push(...collectProjectComplianceWarnings({ root, srcDir, routesDir, publicDir, routeFiles, analyses, compliance, consentMaxAge: loadedConfig.consent?.maxAge, site, lang: loadedConfig.lang, langFromPlugin: pluginSetsLang(plugins), titleChecked: pluginChecksTitle(plugins) }))
|
|
389
415
|
|
|
390
416
|
// 3d. Form field / schema checks & public action protection warnings (#4, #5)
|
|
391
417
|
const formCheck = await checkAppForms({ root, routesDir, routeFiles, graph, sources, compliance })
|
|
392
418
|
errors.push(...formCheck.errors)
|
|
393
419
|
warnings.push(...formCheck.warnings)
|
|
394
420
|
|
|
395
|
-
warnings.push(...publicDotfileWarnings(publicDir, root))
|
|
396
|
-
warnings.push(...securityConfigWarnings(loadedConfig.security))
|
|
397
|
-
warnings.push(...proxyWithoutSiteWarnings(loadedConfig.trustProxy, site, compliance))
|
|
421
|
+
warnings.push(...publicDotfileWarnings(publicDir, root), ...securityConfigWarnings(loadedConfig.security), ...proxyWithoutSiteWarnings(loadedConfig.trustProxy, site, compliance))
|
|
398
422
|
warnings.push(...csrfOffWarnings(routeFiles, file => sourceOf(file, sources), (file, offset) => locOf(root, file, sources, offset), compliance))
|
|
399
423
|
warnings.push(...externalRedirectWarnings(files, file => sourceOf(file, sources), (file, offset) => locOf(root, file, sources, offset)))
|
|
424
|
+
warnings.push(...htmlSinkWarnings(files, file => sourceOf(file, sources), (file, offset) => locOf(root, file, sources, offset), loadedConfig.security, compliance))
|
|
425
|
+
warnings.push(...unknownCacheTagWarnings(files, file => sourceOf(file, sources), (file, offset) => locOf(root, file, sources, offset), new Set(routeFiles.flatMap(file => analyses.get(file)?.cache?.tags ?? []))))
|
|
426
|
+
warnings.push(...cookieWarnings(loadedConfig.consent !== undefined, files, file => sourceOf(file, sources), (file, offset) => locOf(root, file, sources, offset), compliance))
|
|
400
427
|
|
|
401
|
-
// 3e. Broken internal link checks (#3)
|
|
402
|
-
warnings.push(...await checkAppLinks({ root, routesDir, publicDir, assetPrefix, site, config: loadedConfig, plugins, routeFiles, analyses, sources }))
|
|
428
|
+
// 3e. Broken internal link & region target checks (#3, #379)
|
|
429
|
+
warnings.push(...await checkAppLinks({ root, routesDir, publicDir, assetPrefix, site, config: loadedConfig, plugins, routeFiles, analyses, sources, errors }))
|
|
430
|
+
errors.push(...checkRegionTargets({ graph, routesDir, pageFiles, locate: (file, offset) => locOf(root, file, sources, offset) }))
|
|
403
431
|
|
|
404
432
|
// 3f. Plugin check(ctx) hooks
|
|
405
|
-
await runPluginChecks(plugins, { root, routesDir, publicDir, outDir, assetPrefix, site, consentCategories }, errors, warnings)
|
|
433
|
+
await runPluginChecks(plugins, { root, routesDir, publicDir, outDir, assetPrefix, site, consentCategories, store: loadedConfig.store, ignore: compliance?.ignore ?? [] }, errors, warnings)
|
|
406
434
|
|
|
407
435
|
const typecheck = options.skipTypecheck === true ? { ran: false as const, reason: "skipped by --no-typecheck" } : runTypecheck(root, errors)
|
|
408
436
|
|
package/src/cli/commands.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { resolve } from 'node:path'
|
|
|
6
6
|
import { badUsage, Exit, fail, parse } from '@kaynooo/cli-kit'
|
|
7
7
|
import { parseByteSize } from '../build/byte-size'
|
|
8
8
|
|
|
9
|
-
const TEMPLATES = ['minimal', 'fullstack', 'blog', 'app'] as const
|
|
9
|
+
const TEMPLATES = ['minimal', 'fullstack', 'blog', 'app', 'plugin'] as const
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
const ROOT = { type: 'string', description: 'the app folder, when it is not the current one or the [dir] argument' } as const
|
|
@@ -52,9 +52,9 @@ function rootOf(cwd: string, root: string | undefined, dir: string | undefined):
|
|
|
52
52
|
|
|
53
53
|
function newCommand(cwd: string): Commands[string] {
|
|
54
54
|
return {
|
|
55
|
-
summary: 'create an app from a template',
|
|
55
|
+
summary: 'create an app or a plugin from a template',
|
|
56
56
|
run: async (args) => {
|
|
57
|
-
const { values, positionals: [dir] } = parse(args, 'prunelle new [options] <dir>: creates an app from a template', {
|
|
57
|
+
const { values, positionals: [dir] } = parse(args, 'prunelle new [options] <dir>: creates an app from a template, or a plugin package with --template plugin', {
|
|
58
58
|
template: { type: 'string', choices: TEMPLATES, description: 'the template (minimal)' },
|
|
59
59
|
force: { type: 'boolean', description: 'write into a folder that is not empty' },
|
|
60
60
|
root: ROOT,
|
|
@@ -66,7 +66,7 @@ function newCommand(cwd: string): Commands[string] {
|
|
|
66
66
|
for (const file of res.overwritten)
|
|
67
67
|
console.log(`prunelle new: overwrote ${file}`)
|
|
68
68
|
console.log(`Created Prunelle (${template}) project in ${res.root} (${res.files.length} files)`)
|
|
69
|
-
console.log(`\nNext steps:\n cd ${dir}\n bun install\n bun run dev`)
|
|
69
|
+
console.log(`\nNext steps:\n cd ${dir}\n bun install\n ${template === 'plugin' ? 'bun test' : 'bun run dev'}`)
|
|
70
70
|
return 0
|
|
71
71
|
},
|
|
72
72
|
}
|
|
@@ -97,6 +97,8 @@ function checkCommand(cwd: string): Commands[string] {
|
|
|
97
97
|
console.warn(warning)
|
|
98
98
|
for (const e of res.errors)
|
|
99
99
|
console.error(e)
|
|
100
|
+
const { rgaaCriteriaCovered, RGAA_CRITERIA_TOTAL } = await import('../compiler/compliance-rgaa-criteria')
|
|
101
|
+
console.log(`prunelle check: its RGAA rules partly cover ${rgaaCriteriaCovered()} of the ${RGAA_CRITERIA_TOTAL} RGAA 4.1 criteria, so a clean run does not make the site accessible: \`prunelle a11y\` audits the rendered pages, and a manual audit covers the rest.`)
|
|
100
102
|
const typecheck = res.typecheck.ran ? `typechecked with ${res.typecheck.tool}` : `no typecheck: ${res.typecheck.reason}`
|
|
101
103
|
if (failed) {
|
|
102
104
|
if (res.ok)
|
|
@@ -193,47 +195,165 @@ function buildCommand(cwd: string): Commands[string] {
|
|
|
193
195
|
}
|
|
194
196
|
}
|
|
195
197
|
|
|
198
|
+
function a11yCommand(cwd: string): Commands[string] {
|
|
199
|
+
return {
|
|
200
|
+
summary: 'audit rendered routes with axe-core + RGAA 4.1 and draft the accessibility declaration',
|
|
201
|
+
run: async (args) => {
|
|
202
|
+
const { values, positionals } = parse(args, 'prunelle a11y [options] [dest]: audits rendered routes with axe-core + RGAA 4.1 and drafts an accessibility declaration', {
|
|
203
|
+
'routes': { type: 'string', description: 'comma-separated routes to audit (e.g. /,/about)' },
|
|
204
|
+
'all-static': { type: 'boolean', description: 'include static non-dynamic HTML routes alongside prerendered routes' },
|
|
205
|
+
'json': { type: 'boolean', description: 'print the audit report as JSON on stdout' },
|
|
206
|
+
'draft': { type: 'string', optional: { bare: '' }, description: 'write an editable RGAA 4.1.2 accessibility declaration page (default: src/routes/accessibilite.tsx)' },
|
|
207
|
+
'force': { type: 'boolean', description: 'overwrite an existing declaration file when used with --draft' },
|
|
208
|
+
'out': { type: 'string', description: 'destination path for --draft (default: src/routes/accessibilite.tsx)' },
|
|
209
|
+
'audit-date': { type: 'string', description: 'day the manual RGAA audit ended (YYYY-MM-DD), written into --draft with --rate' },
|
|
210
|
+
'rate': { type: 'string', description: 'applicable RGAA criteria the manual audit found met, in percent: 100 is totally, 50 or more partially compliant' },
|
|
211
|
+
'status': { type: 'string', description: 'removed: the level now follows --audit-date and --rate' },
|
|
212
|
+
'org': { type: 'string', description: 'organization name written into --draft' },
|
|
213
|
+
'contact': { type: 'string', description: 'contact email written into --draft' },
|
|
214
|
+
'no-fail': { type: 'boolean', description: 'exit 0 even when accessibility violations are found' },
|
|
215
|
+
'root': ROOT,
|
|
216
|
+
}, {
|
|
217
|
+
positionals: ['[dest]'],
|
|
218
|
+
exits: [
|
|
219
|
+
[0, 'no accessibility violations found (or --draft / --no-fail)'],
|
|
220
|
+
[1, 'one or more accessibility violations found, or audit failed'],
|
|
221
|
+
USAGE_EXIT,
|
|
222
|
+
],
|
|
223
|
+
})
|
|
224
|
+
const rawRoutes = values.routes !== undefined ? values.routes.split(',').map(s => s.trim()).filter(Boolean) : undefined
|
|
225
|
+
if (values.routes !== undefined && (rawRoutes === undefined || rawRoutes.length === 0))
|
|
226
|
+
return badUsage('--routes requires at least one route path, e.g. --routes /,/about')
|
|
227
|
+
if (values.status !== undefined)
|
|
228
|
+
return badUsage('--status is gone: the compliance level follows the manual audit, so pass --audit-date YYYY-MM-DD and --rate <percent> (100 is totally, 50 or more partially compliant)')
|
|
229
|
+
if ((values['audit-date'] === undefined) !== (values.rate === undefined))
|
|
230
|
+
return badUsage('--audit-date and --rate go together: pass the day the manual RGAA audit ended and the percentage of criteria it found met')
|
|
231
|
+
const rawRate = values.rate?.trim()
|
|
232
|
+
const manualAudit = values['audit-date'] !== undefined && rawRate !== undefined
|
|
233
|
+
? { date: new Date(`${values['audit-date']}T00:00:00Z`), rate: rawRate === '' ? Number.NaN : Number(rawRate) }
|
|
234
|
+
: undefined
|
|
235
|
+
if (manualAudit !== undefined) {
|
|
236
|
+
// A day that does not exist (2026-02-30) rolls over to the next month instead of turning NaN, so it must round-trip.
|
|
237
|
+
if (Number.isNaN(manualAudit.date.getTime()) || manualAudit.date.toISOString().slice(0, 10) !== values['audit-date'])
|
|
238
|
+
return badUsage('--audit-date must be a valid YYYY-MM-DD date, e.g. --audit-date 2026-03-31')
|
|
239
|
+
if (!(manualAudit.rate >= 0 && manualAudit.rate <= 100))
|
|
240
|
+
return badUsage(`--rate must be a percentage from 0 to 100, got "${values.rate}"`)
|
|
241
|
+
}
|
|
242
|
+
const wantDraft = values.draft !== undefined
|
|
243
|
+
const draft = wantDraft
|
|
244
|
+
? (values.out ?? (values.draft !== '' ? values.draft : undefined) ?? positionals[0] ?? '')
|
|
245
|
+
: undefined
|
|
246
|
+
const { formatA11yReport, runA11y } = await import('../a11y/index')
|
|
247
|
+
const { report, drafted } = await failing('a11y', () => runA11y({
|
|
248
|
+
root: rootOf(cwd, values.root, undefined),
|
|
249
|
+
routes: rawRoutes,
|
|
250
|
+
includeAllStatic: values['all-static'] === true,
|
|
251
|
+
draft,
|
|
252
|
+
force: values.force === true,
|
|
253
|
+
audit: manualAudit,
|
|
254
|
+
organization: values.org,
|
|
255
|
+
contactEmail: values.contact,
|
|
256
|
+
}))
|
|
257
|
+
if (values.json === true) {
|
|
258
|
+
console.log(JSON.stringify(drafted !== undefined ? { ...report, declaration: { path: drafted.relativePath, status: drafted.status } } : report, null, 2))
|
|
259
|
+
return !report.ok && !wantDraft && values['no-fail'] !== true ? 1 : 0
|
|
260
|
+
}
|
|
261
|
+
console.log(formatA11yReport(report))
|
|
262
|
+
if (drafted !== undefined)
|
|
263
|
+
console.log(`prunelle a11y: drafted RGAA 4.1.2 accessibility declaration at ${drafted.relativePath} (${drafted.status})`)
|
|
264
|
+
if (!report.ok && !wantDraft && values['no-fail'] !== true)
|
|
265
|
+
return fail(`found ${report.totalViolations} accessibility violation${report.totalViolations === 1 ? '' : 's'}`, 1)
|
|
266
|
+
return 0
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
196
271
|
function ecoCommand(cwd: string): Commands[string] {
|
|
197
272
|
return {
|
|
198
|
-
summary: '
|
|
273
|
+
summary: 'report what prunelle saw of the RGESN eco-design criteria, and draft the declaration',
|
|
199
274
|
run: async (args) => {
|
|
200
|
-
const { values, positionals: [dir] } = parse(args, 'prunelle eco [options] [dir]: builds the app and
|
|
275
|
+
const { values, positionals: [dir] } = parse(args, 'prunelle eco [options] [dir]: builds the app and reports what it saw of the RGESN 2024 criteria, leaving every verdict to a person', {
|
|
201
276
|
declaration: { type: 'string', optional: { bare: '' }, description: 'write an editable RGESN 2024 eco-design declaration page (default: src/routes/ecoconception.tsx)' },
|
|
277
|
+
force: { type: 'boolean', description: 'overwrite an existing declaration file when used with --declaration' },
|
|
202
278
|
service: { type: 'string', description: 'the service\'s name, written into --declaration' },
|
|
203
279
|
org: { type: 'string', description: 'the entity running the evaluation, written into --declaration' },
|
|
204
280
|
contact: { type: 'string', description: 'the contact email, written into --declaration' },
|
|
205
281
|
root: ROOT,
|
|
206
|
-
}, { positionals: ['[dir]'], exits: [OK, [1, 'the build failed'], USAGE_EXIT] })
|
|
282
|
+
}, { positionals: ['[dir]'], exits: [OK, [1, 'the build failed, or the file --declaration would write exists without --force'], USAGE_EXIT] })
|
|
207
283
|
const { formatEcoResult, runEco } = await import('../eco/index')
|
|
208
|
-
const result = await failing('eco', () => runEco({ root: rootOf(cwd, values.root, dir), declaration: values.declaration, service: values.service, organization: values.org, contactEmail: values.contact }))
|
|
284
|
+
const result = await failing('eco', () => runEco({ root: rootOf(cwd, values.root, dir), declaration: values.declaration, force: values.force === true, service: values.service, organization: values.org, contactEmail: values.contact }))
|
|
209
285
|
console.log(formatEcoResult(result))
|
|
210
286
|
return 0
|
|
211
287
|
},
|
|
212
288
|
}
|
|
213
289
|
}
|
|
214
290
|
|
|
291
|
+
function rgpdCommand(cwd: string): Commands[string] {
|
|
292
|
+
return {
|
|
293
|
+
summary: 'list the personal data the app processes, and draft the privacy notice and the record of processing',
|
|
294
|
+
run: async (args) => {
|
|
295
|
+
const { values, positionals: [dir] } = parse(args, 'prunelle rgpd [options] [dir]: lists the personal data the plugins declare and the app\'s forms collect, and drafts the RGPD privacy notice and record of processing from it', {
|
|
296
|
+
draft: { type: 'string', optional: { bare: '' }, description: 'write the privacy notice page (default: src/routes/confidentialite.tsx) and registre-des-traitements.md' },
|
|
297
|
+
force: { type: 'boolean', description: 'overwrite files --draft finds already there' },
|
|
298
|
+
org: { type: 'string', description: 'the controller\'s name, written into --draft' },
|
|
299
|
+
contact: { type: 'string', description: 'the contact email for personal data, written into --draft' },
|
|
300
|
+
root: ROOT,
|
|
301
|
+
}, { positionals: ['[dir]'], exits: [OK, [1, 'the config failed to load, or a file --draft would write exists without --force'], USAGE_EXIT] })
|
|
302
|
+
const { formatRgpdResult, runRgpd } = await import('../rgpd/index')
|
|
303
|
+
const result = await failing('rgpd', () => runRgpd({ root: rootOf(cwd, values.root, dir), draft: values.draft, force: values.force === true, organization: values.org, contactEmail: values.contact }))
|
|
304
|
+
console.log(formatRgpdResult(result))
|
|
305
|
+
return 0
|
|
306
|
+
},
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
215
310
|
const SERVE_EXITS: ExitRow[] = [[0, 'the server started'], [1, 'the config or the server failed to load'], USAGE_EXIT]
|
|
216
311
|
|
|
217
312
|
function startCommand(cwd: string): Commands[string] {
|
|
218
313
|
return {
|
|
219
314
|
summary: 'serve the built app',
|
|
220
315
|
run: async (args) => {
|
|
221
|
-
const { values, positionals: [dir] } = parse(args, 'prunelle start [options] [dir]: serves the built app', {
|
|
316
|
+
const { values, positionals: [dir] } = parse(args, 'prunelle start [options] [dir]: serves the built app', {
|
|
317
|
+
port: PORT,
|
|
318
|
+
host: HOST,
|
|
319
|
+
workers: { type: 'string', description: 'how many processes serve the app on its port, a whole number or auto for one per CPU core (1, Linux only)' },
|
|
320
|
+
root: ROOT,
|
|
321
|
+
}, { positionals: ['[dir]'], exits: SERVE_EXITS })
|
|
222
322
|
const root = rootOf(cwd, values.root, dir)
|
|
223
323
|
process.env.NODE_ENV ??= 'production'
|
|
324
|
+
const { followPrimary, parseWorkers, reportListening, superviseWorkers, workerOf } = await import('../server/workers')
|
|
325
|
+
const worker = workerOf()
|
|
326
|
+
if (worker !== undefined)
|
|
327
|
+
followPrimary()
|
|
328
|
+
const count = worker === undefined && values.workers !== undefined ? parseWorkers(values.workers) ?? badUsage(`invalid --workers "${values.workers}": give how many processes serve the app, a whole number from 1 or auto`) : 1
|
|
329
|
+
if (count > 1 && process.platform !== 'linux')
|
|
330
|
+
return fail(`--workers shares one port between processes, and only Linux spreads connections across them`, 1, `on ${process.platform}, run one process per port behind a proxy`)
|
|
331
|
+
// The primary serves nothing, so it loads neither the config nor the app: each worker does.
|
|
332
|
+
if (count > 1)
|
|
333
|
+
return await superviseWorkers({ count, command: [process.execPath, ...process.execArgv, ...process.argv.slice(1)] }).exited
|
|
224
334
|
const { loadConfig } = await import('../plugins/index')
|
|
225
335
|
const config = await failing('start', async () => loadConfig(root))
|
|
226
336
|
const port = parsePort(values.port ?? (process.env.PORT || config.port), 3000)
|
|
227
337
|
const hostname = values.host ?? (process.env.HOST || '127.0.0.1')
|
|
338
|
+
if (worker !== undefined && port === 0)
|
|
339
|
+
return fail('--workers needs a fixed port, and port 0 gives each process its own', 1, 'set --port or PORT')
|
|
340
|
+
const { loopbackBindNotice } = await import('../server/security')
|
|
341
|
+
const notice = process.env.NODE_ENV === 'production' ? loopbackBindNotice(hostname, values.host !== undefined || Boolean(process.env.HOST)) : undefined
|
|
228
342
|
const { startServer } = await import('../server/start')
|
|
229
343
|
const { handleSignals } = await import('../server/lifecycle')
|
|
230
|
-
const { app, server } = await failing('start', async () => startServer({ root, port, hostname }))
|
|
344
|
+
const { app, server } = await failing('start', async () => startServer({ root, port, hostname, reusePort: worker !== undefined, quietReload: worker !== undefined && worker.index > 1 }))
|
|
231
345
|
handleSignals(app, server)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
346
|
+
if (worker !== undefined)
|
|
347
|
+
reportListening()
|
|
348
|
+
// The first worker speaks for the others.
|
|
349
|
+
if (worker !== undefined && worker.index > 1)
|
|
350
|
+
return 0
|
|
351
|
+
console.log(`prunelle server listening on http://${hostname}:${server.port}${worker === undefined ? '' : ` with ${worker.count} workers`}`)
|
|
235
352
|
if (notice !== undefined)
|
|
236
353
|
console.warn(notice)
|
|
354
|
+
const perProcess = worker === undefined ? [] : app.perProcessState?.() ?? []
|
|
355
|
+
if (worker !== undefined && perProcess.length > 0)
|
|
356
|
+
console.warn(`prunelle start: ${worker.count} processes serve this app with no \`store\`, so ${perProcess.join('; ')}: set \`store: 'data/app.db'\` in prunelle.config.ts to share them.`)
|
|
237
357
|
return 0
|
|
238
358
|
},
|
|
239
359
|
}
|
|
@@ -245,12 +365,12 @@ function devCommand(cwd: string): Commands[string] {
|
|
|
245
365
|
run: async (args) => {
|
|
246
366
|
const { values, positionals: [dir] } = parse(args, 'prunelle dev [options] [dir]: serves the app and rebuilds it when a file changes', { port: PORT, host: HOST, root: ROOT }, { positionals: ['[dir]'], exits: SERVE_EXITS })
|
|
247
367
|
const root = rootOf(cwd, values.root, dir)
|
|
248
|
-
const { loadConfig
|
|
368
|
+
const { loadConfig } = await import('../plugins/index')
|
|
249
369
|
const config = await failing('dev', async () => loadConfig(root, { dev: true }))
|
|
250
370
|
const port = parsePort(values.port ?? (process.env.PORT || config.port), 3000)
|
|
251
371
|
const hostname = values.host ?? (process.env.HOST || '127.0.0.1')
|
|
252
372
|
const { devSupervisor } = await import('../dev/supervisor')
|
|
253
|
-
const dev = await failing('dev', async () => devSupervisor({ root, port, hostname
|
|
373
|
+
const dev = await failing('dev', async () => devSupervisor({ root, port, hostname }))
|
|
254
374
|
for (const signal of ['SIGINT', 'SIGTERM'] as const)
|
|
255
375
|
process.once(signal, () => void dev.stop().finally(() => process.exit(0)))
|
|
256
376
|
return 0
|
|
@@ -262,7 +382,7 @@ function docsCommand(cwd: string): Commands[string] {
|
|
|
262
382
|
return {
|
|
263
383
|
summary: 'search llms.txt across prunelle and installed plugins',
|
|
264
384
|
run: async (args) => {
|
|
265
|
-
const { values, positionals } = parse(args, 'prunelle docs [options] <words...>: searches llms.txt of prunelle
|
|
385
|
+
const { values, positionals } = parse(args, 'prunelle docs [options] <words...>: searches llms.txt of prunelle, every installed @prunellejs/* package and every dependency of the app that ships one', {
|
|
266
386
|
json: { type: 'boolean', description: 'print { query, words, packages, matches } as JSON' },
|
|
267
387
|
limit: { type: 'string', description: 'maximum matching sections to print (default: 20)' },
|
|
268
388
|
root: ROOT,
|
|
@@ -342,7 +462,9 @@ export function builtinCommands(cwd: string): Commands {
|
|
|
342
462
|
mcp: mcpCommand(cwd),
|
|
343
463
|
dev: devCommand(cwd),
|
|
344
464
|
build: buildCommand(cwd),
|
|
465
|
+
a11y: a11yCommand(cwd),
|
|
345
466
|
eco: ecoCommand(cwd),
|
|
467
|
+
rgpd: rgpdCommand(cwd),
|
|
346
468
|
start: startCommand(cwd),
|
|
347
469
|
upgrade: upgradeCommand(cwd),
|
|
348
470
|
}
|
package/src/cli/docs.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `prunelle docs <words>`: discover and search installed `llms.txt` files for `prunelle
|
|
1
|
+
// `prunelle docs <words>`: discover and search installed `llms.txt` files for `prunelle`, `@prunellejs/*` packages and the app's other dependencies.
|
|
2
2
|
|
|
3
3
|
import { readdirSync, readFileSync, statSync } from 'node:fs'
|
|
4
4
|
import { dirname, join, resolve } from 'node:path'
|
|
@@ -119,11 +119,26 @@ function scanScopedPackages(
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
// A third-party plugin has no scope of its own, so it is found as a dependency the app declares; one it does not declare is a dependency's, whose docs it never asked for.
|
|
123
|
+
function declaredDependencies(root: string): string[] {
|
|
124
|
+
const pkgJsonPath = join(root, 'package.json')
|
|
125
|
+
if (!isFile(pkgJsonPath))
|
|
126
|
+
return []
|
|
127
|
+
try {
|
|
128
|
+
const parsed = JSON.parse(readFileSync(pkgJsonPath, 'utf8')) as { dependencies?: Record<string, string>, devDependencies?: Record<string, string> }
|
|
129
|
+
return [...Object.keys(parsed.dependencies ?? {}), ...Object.keys(parsed.devDependencies ?? {})]
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return []
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Discovers `llms.txt` files for `prunelle`, installed `@prunellejs/*` (and `@prunelle/*`) packages, and every dependency `rootDir`'s `package.json` declares, from `rootDir` up through ancestor `node_modules`. */
|
|
123
137
|
export function discoverLlmsDocs(rootDir: string): LlmsPackageDoc[] {
|
|
124
138
|
const root = resolve(rootDir)
|
|
125
139
|
const docs: LlmsPackageDoc[] = []
|
|
126
140
|
const seen = new Set<string>()
|
|
141
|
+
const dependencies = declaredDependencies(root)
|
|
127
142
|
|
|
128
143
|
let dir = root
|
|
129
144
|
while (true) {
|
|
@@ -132,6 +147,10 @@ export function discoverLlmsDocs(rootDir: string): LlmsPackageDoc[] {
|
|
|
132
147
|
if (!seen.has('prunelle'))
|
|
133
148
|
addPackageDoc(docs, seen, root, join(nodeModulesDir, 'prunelle'), 'prunelle')
|
|
134
149
|
scanScopedPackages(docs, seen, root, nodeModulesDir)
|
|
150
|
+
for (const name of dependencies) {
|
|
151
|
+
if (!seen.has(name))
|
|
152
|
+
addPackageDoc(docs, seen, root, join(nodeModulesDir, name), name)
|
|
153
|
+
}
|
|
135
154
|
}
|
|
136
155
|
const parent = dirname(dir)
|
|
137
156
|
if (parent === dir)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Which children of a form hide the controls they render from `prunelle check`'s field matching (#401).
|
|
2
|
+
import type { Node, Program } from 'oxc-parser'
|
|
3
|
+
import { walk } from '../compiler/ast'
|
|
4
|
+
import { unwrapTsExpr } from '../compiler/shared'
|
|
5
|
+
|
|
6
|
+
function containsJsx(node: Node): boolean {
|
|
7
|
+
let found = false
|
|
8
|
+
walk(node, (n) => {
|
|
9
|
+
if (n.type === 'JSXElement' || n.type === 'JSXFragment') found = true
|
|
10
|
+
return found ? false : undefined
|
|
11
|
+
})
|
|
12
|
+
return found
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const jsxBindingsByProgram = new WeakMap<Program, ReadonlySet<string>>()
|
|
16
|
+
|
|
17
|
+
/** The names a file binds to JSX: a variable holding an element, or a function returning one. */
|
|
18
|
+
function jsxBindings(program: Program): ReadonlySet<string> {
|
|
19
|
+
const cached = jsxBindingsByProgram.get(program)
|
|
20
|
+
if (cached !== undefined) return cached
|
|
21
|
+
const names = new Set<string>()
|
|
22
|
+
walk(program, (node) => {
|
|
23
|
+
if (node.type === 'VariableDeclarator' && node.id.type === 'Identifier' && node.init !== null && containsJsx(node.init)) names.add(node.id.name)
|
|
24
|
+
else if (node.type === 'FunctionDeclaration' && node.id !== null && node.body !== null && containsJsx(node.body)) names.add(node.id.name)
|
|
25
|
+
return undefined
|
|
26
|
+
})
|
|
27
|
+
jsxBindingsByProgram.set(program, names)
|
|
28
|
+
return names
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** A child like `{props.children}`, `{fields}` or `{renderFields()}`, `fields` and `renderFields` bound to JSX in the file: the check cannot see which controls it renders. Text such as `{errors.email}` or `{t('title')}` is not. */
|
|
32
|
+
export function hasOpaqueChild(children: readonly Node[], program: Program): boolean {
|
|
33
|
+
return children.some((child) => {
|
|
34
|
+
if (child.type !== 'JSXExpressionContainer' || child.expression.type === 'JSXEmptyExpression') return false
|
|
35
|
+
const expr = unwrapTsExpr(child.expression)
|
|
36
|
+
if (expr.type === 'Identifier') return expr.name === 'children' || jsxBindings(program).has(expr.name)
|
|
37
|
+
if (expr.type === 'MemberExpression') return !expr.computed && expr.property.type === 'Identifier' && expr.property.name === 'children'
|
|
38
|
+
return expr.type === 'CallExpression' && expr.callee.type === 'Identifier' && jsxBindings(program).has(expr.callee.name)
|
|
39
|
+
})
|
|
40
|
+
}
|
package/src/cli/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ function pluginCommands(cwd: string): (words: string[]) => Promise<Commands> {
|
|
|
38
38
|
root: { type: 'string', description: 'the app directory (default: the current one)' },
|
|
39
39
|
})
|
|
40
40
|
const taken = takeRoot(args, cwd)
|
|
41
|
-
await run(taken.rest, taken.root)
|
|
41
|
+
await run(taken.rest, taken.root, { store: config.store })
|
|
42
42
|
return 0
|
|
43
43
|
},
|
|
44
44
|
}
|
package/src/cli/inspect.ts
CHANGED
package/src/cli/mcp-tools.ts
CHANGED
|
@@ -240,7 +240,7 @@ export function listPrunelleTools(): McpToolDefinition[] {
|
|
|
240
240
|
},
|
|
241
241
|
{
|
|
242
242
|
name: 'docs',
|
|
243
|
-
description: 'Search `llms.txt` documentation across `prunelle
|
|
243
|
+
description: 'Search `llms.txt` documentation across `prunelle`, every installed `@prunellejs/*` package, and every dependency of the app that ships one.',
|
|
244
244
|
inputSchema: {
|
|
245
245
|
type: 'object',
|
|
246
246
|
properties: {
|
|
@@ -466,7 +466,7 @@ export async function callPrunelleTool(ctx: PrunelleMcpContext, name: string, ra
|
|
|
466
466
|
}
|
|
467
467
|
}
|
|
468
468
|
|
|
469
|
-
/** Lists every discovered `llms.txt` (`prunelle
|
|
469
|
+
/** Lists every discovered `llms.txt` (`prunelle`, installed `@prunellejs/*` packages and the app's dependencies) as an MCP resource. */
|
|
470
470
|
export function listPrunelleResources(root: string): McpResource[] {
|
|
471
471
|
return discoverLlmsDocs(root).map(doc => ({
|
|
472
472
|
uri: `${LLMS_URI_PREFIX}${doc.packageName}`,
|
package/src/cli/new.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// `prunelle new <name> [--template minimal|fullstack|blog|app] [--force]` project scaffolder: copies `templates/_shared` and `templates/<template
|
|
1
|
+
// `prunelle new <name> [--template minimal|fullstack|blog|app|plugin] [--force]` project scaffolder: copies `templates/_shared` and `templates/<template>`, or `templates/plugin` alone.
|
|
2
2
|
|
|
3
3
|
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
4
4
|
import { basename, dirname, join, resolve } from 'node:path'
|
|
@@ -6,7 +6,7 @@ import pkg from '../../package.json' with { type: 'json' }
|
|
|
6
6
|
import { DEFAULT_DECLARATION_PATH, draftAccessibilityStatement } from '../a11y/declaration'
|
|
7
7
|
import { isNotSourceDir, relPosix, walkFiles } from '../build/files'
|
|
8
8
|
|
|
9
|
-
export type ScaffoldTemplate = 'minimal' | 'fullstack' | 'blog' | 'app'
|
|
9
|
+
export type ScaffoldTemplate = 'minimal' | 'fullstack' | 'blog' | 'app' | 'plugin'
|
|
10
10
|
|
|
11
11
|
export interface ScaffoldOptions {
|
|
12
12
|
template?: ScaffoldTemplate | undefined
|
|
@@ -17,7 +17,7 @@ export interface ScaffoldOptions {
|
|
|
17
17
|
const TEMPLATES_DIR = join(import.meta.dir, '../../templates')
|
|
18
18
|
|
|
19
19
|
// npm leaves dotfiles like `.gitignore` out of a package, so the template stores them without the leading dot.
|
|
20
|
-
const RENAMED: Record<string, string> = { 'gitignore': '.gitignore', 'mcp.json': '.mcp.json' }
|
|
20
|
+
const RENAMED: Record<string, string> = { 'gitignore': '.gitignore', 'dockerignore': '.dockerignore', 'mcp.json': '.mcp.json' }
|
|
21
21
|
|
|
22
22
|
// What a fresh `git init` leaves in a folder: it does not make the folder one with work in it.
|
|
23
23
|
const FRESH_REPO_ENTRIES = new Set(['.git'])
|
|
@@ -33,10 +33,12 @@ export function scaffoldProject(targetDir: string, options: ScaffoldOptions = {}
|
|
|
33
33
|
|
|
34
34
|
const written: string[] = []
|
|
35
35
|
const overwritten: string[] = []
|
|
36
|
-
|
|
36
|
+
// A plugin is a package, not an app: it gets none of an app's pages, Docker files or accessibility statement.
|
|
37
|
+
const isPlugin = template === 'plugin'
|
|
38
|
+
for (const dir of isPlugin ? [join(TEMPLATES_DIR, template)] : [join(TEMPLATES_DIR, '_shared'), join(TEMPLATES_DIR, template)]) {
|
|
37
39
|
for (const abs of walkFiles(dir, { skipDir: isNotSourceDir, keep: entry => entry.isFile() })) {
|
|
38
40
|
const rel = RENAMED[relPosix(dir, abs)] ?? relPosix(dir, abs)
|
|
39
|
-
const text = readFileSync(abs, 'utf8').replaceAll('__APP_NAME__', name).replaceAll('__PRUNELLE_VERSION__', prunelleVersion)
|
|
41
|
+
const text = readFileSync(abs, 'utf8').replaceAll('__APP_NAME__', name).replaceAll('__PRUNELLE_VERSION__', prunelleVersion).replaceAll('__BUN_VERSION__', Bun.version)
|
|
40
42
|
if (existsSync(join(root, rel)))
|
|
41
43
|
overwritten.push(rel)
|
|
42
44
|
mkdirSync(dirname(join(root, rel)), { recursive: true })
|
|
@@ -44,6 +46,8 @@ export function scaffoldProject(targetDir: string, options: ScaffoldOptions = {}
|
|
|
44
46
|
written.push(rel)
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
if (isPlugin)
|
|
50
|
+
return { root, files: written, overwritten }
|
|
47
51
|
// Drafted rather than copied, so it is dated on the day the app is made and never drifts from what `prunelle a11y --draft` writes.
|
|
48
52
|
if (existsSync(join(root, DEFAULT_DECLARATION_PATH)))
|
|
49
53
|
overwritten.push(DEFAULT_DECLARATION_PATH)
|
package/src/cli/upgrade-names.ts
CHANGED
|
@@ -6,8 +6,13 @@ import { walk } from '../compiler/ast'
|
|
|
6
6
|
import { SourceEditor } from '../compiler/patch'
|
|
7
7
|
|
|
8
8
|
const KAY_SOURCE_RE = /^@kayjs\//
|
|
9
|
+
const PRUNELLE_SOURCE_RE = /^(?:prunelle(?:\/|$)|@prunellejs\/)/
|
|
9
10
|
const REF_TYPES_RE = /^(\s*\/\/\/\s*<reference\s+types=)(["'])([^"']+)\2(\s*\/>)/gm
|
|
10
11
|
|
|
12
|
+
const RENAMED_EXPORTS: Readonly<Record<string, string>> = {
|
|
13
|
+
UI_KUI_LAYER_SERVICE: 'UI_LAYER_SERVICE',
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
type Import = Extract<AstNode, { type: 'ImportDeclaration' }>
|
|
12
17
|
type Specifier = Extract<AstNode, { type: 'ImportSpecifier' }>
|
|
13
18
|
|
|
@@ -19,8 +24,11 @@ interface Binding {
|
|
|
19
24
|
pinned: boolean
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
/** What a name kay exported is called
|
|
27
|
+
/** What a name kay or an older prunelle exported is called now, or undefined when it kept its name. */
|
|
23
28
|
export function prunelleName(name: string): string | undefined {
|
|
29
|
+
const renamed = RENAMED_EXPORTS[name]
|
|
30
|
+
if (renamed !== undefined)
|
|
31
|
+
return renamed
|
|
24
32
|
const next = name.replace(/KAY/g, 'PRUNELLE').replace(/Kay/g, 'Prunelle').replace(/kay/g, 'prunelle')
|
|
25
33
|
return next === name ? undefined : next
|
|
26
34
|
}
|
|
@@ -42,6 +50,10 @@ function resolveAlias(spec: string, aliases?: ReadonlyMap<string, string>): stri
|
|
|
42
50
|
function hasKaySourceHint(code: string, aliases?: ReadonlyMap<string, string>): boolean {
|
|
43
51
|
if (code.includes('@kayjs/'))
|
|
44
52
|
return true
|
|
53
|
+
for (const name of Object.keys(RENAMED_EXPORTS)) {
|
|
54
|
+
if (code.includes(name))
|
|
55
|
+
return true
|
|
56
|
+
}
|
|
45
57
|
if (aliases === undefined || aliases.size === 0)
|
|
46
58
|
return false
|
|
47
59
|
for (const alias of aliases.keys()) {
|
|
@@ -71,7 +83,7 @@ export function renameKayNames(file: string, code: string, aliases?: ReadonlyMap
|
|
|
71
83
|
const skipped = new Set<number>()
|
|
72
84
|
const patchedSources = new Set<number>()
|
|
73
85
|
const fromKay = (source: { value?: unknown } | null | undefined): boolean =>
|
|
74
|
-
typeof source?.value === 'string' && (KAY_SOURCE_RE.test(source.value) || resolveAlias(source.value, aliases) !== undefined)
|
|
86
|
+
typeof source?.value === 'string' && (KAY_SOURCE_RE.test(source.value) || PRUNELLE_SOURCE_RE.test(source.value) || resolveAlias(source.value, aliases) !== undefined)
|
|
75
87
|
const rewriteSource = (source: { start: number, end: number, value?: unknown } | null | undefined): void => {
|
|
76
88
|
if (source === null || source === undefined || typeof source.value !== 'string' || patchedSources.has(source.start))
|
|
77
89
|
return
|