@nifrajs/cli 5.5.1 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +314 -0
- package/dist/cdn-check.d.ts +7 -6
- package/dist/cdn-check.d.ts.map +1 -1
- package/dist/cdn-check.js +13 -1
- package/dist/cdn-check.js.map +1 -1
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +9 -3
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +6 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +30 -32
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +35 -12
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +66 -9
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +19 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +111 -6
- package/dist/command-catalog.js.map +1 -1
- package/dist/contracts.d.ts +42 -4
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +288 -9
- package/dist/contracts.js.map +1 -1
- package/dist/doctor.d.ts +12 -2
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +67 -1
- package/dist/doctor.js.map +1 -1
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +27 -0
- package/dist/fix-recipes.js.map +1 -1
- package/dist/frontend-guidance.d.ts +1 -1
- package/dist/frontend-guidance.d.ts.map +1 -1
- package/dist/frontend-guidance.js +17 -8
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/internal/git-ignored.d.ts +12 -0
- package/dist/internal/git-ignored.d.ts.map +1 -0
- package/dist/internal/git-ignored.js +49 -0
- package/dist/internal/git-ignored.js.map +1 -0
- package/dist/internal/source-facts.d.ts +29 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +160 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/introspect.js +1 -1
- package/dist/introspect.js.map +1 -1
- package/dist/load.d.ts +7 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +18 -0
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +15 -0
- package/dist/local-cli.d.ts.map +1 -0
- package/dist/local-cli.js +74 -0
- package/dist/local-cli.js.map +1 -0
- package/dist/lock-links.d.ts +0 -7
- package/dist/lock-links.d.ts.map +1 -1
- package/dist/lock-links.js +5 -44
- package/dist/lock-links.js.map +1 -1
- package/dist/mcp-delegate.d.ts +13 -5
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +24 -8
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +57 -3
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.d.ts +2 -1
- package/dist/mcp-http.d.ts.map +1 -1
- package/dist/mcp-http.js +3 -2
- package/dist/mcp-http.js.map +1 -1
- package/dist/mcp-tool-meta.d.ts +21 -0
- package/dist/mcp-tool-meta.d.ts.map +1 -0
- package/dist/mcp-tool-meta.js +246 -0
- package/dist/mcp-tool-meta.js.map +1 -0
- package/dist/mcp.d.ts +3 -2
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +36 -98
- package/dist/mcp.js.map +1 -1
- package/dist/openapi-types.d.ts.map +1 -1
- package/dist/openapi-types.js +45 -2
- package/dist/openapi-types.js.map +1 -1
- package/dist/output-schemas.d.ts +8 -0
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +14 -0
- package/dist/output-schemas.js.map +1 -1
- package/dist/ppr-read-fix.d.ts +8 -0
- package/dist/ppr-read-fix.d.ts.map +1 -0
- package/dist/ppr-read-fix.js +356 -0
- package/dist/ppr-read-fix.js.map +1 -0
- package/dist/recipes/5.6.0.d.ts +10 -0
- package/dist/recipes/5.6.0.d.ts.map +1 -0
- package/dist/recipes/5.6.0.js +68 -0
- package/dist/recipes/5.6.0.js.map +1 -0
- package/dist/recipes/5.7.0.d.ts +12 -0
- package/dist/recipes/5.7.0.d.ts.map +1 -0
- package/dist/recipes/5.7.0.js +70 -0
- package/dist/recipes/5.7.0.js.map +1 -0
- package/dist/recipes/index.d.ts +13 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +4 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +9 -2
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +10 -3
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +11 -4
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +52 -16
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/islands.d.ts +91 -0
- package/dist/rules/islands.d.ts.map +1 -1
- package/dist/rules/islands.js +757 -3
- package/dist/rules/islands.js.map +1 -1
- package/dist/rules/legacy.js +1 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/ppr.d.ts +16 -0
- package/dist/rules/ppr.d.ts.map +1 -0
- package/dist/rules/ppr.js +114 -0
- package/dist/rules/ppr.js.map +1 -0
- package/dist/rules/swap.d.ts +7 -0
- package/dist/rules/swap.d.ts.map +1 -0
- package/dist/rules/swap.js +338 -0
- package/dist/rules/swap.js.map +1 -0
- package/dist/rules/text-slot-boolean.d.ts +8 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -0
- package/dist/rules/text-slot-boolean.js +57 -0
- package/dist/rules/text-slot-boolean.js.map +1 -0
- package/dist/rules/undeclared-response.d.ts +9 -0
- package/dist/rules/undeclared-response.d.ts.map +1 -0
- package/dist/rules/undeclared-response.js +93 -0
- package/dist/rules/undeclared-response.js.map +1 -0
- package/dist/scaffold-hole.d.ts +105 -0
- package/dist/scaffold-hole.d.ts.map +1 -0
- package/dist/scaffold-hole.js +688 -0
- package/dist/scaffold-hole.js.map +1 -0
- package/dist/scaffold.d.ts +5 -3
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +56 -46
- package/dist/scaffold.js.map +1 -1
- package/dist/upgrade.d.ts +34 -8
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +197 -25
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +12 -1
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.js +1 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +70 -10
- package/docs/llms-full.txt +3162 -1196
- package/docs/types.json +1473 -322
- package/package.json +11 -11
- package/src/cdn-check.ts +21 -7
- package/src/check-diagnostics.ts +9 -3
- package/src/check-scan.ts +35 -32
- package/src/check.ts +32 -10
- package/src/cli.ts +71 -9
- package/src/command-catalog.ts +149 -6
- package/src/contracts.ts +348 -14
- package/src/doctor.ts +62 -3
- package/src/fix-recipes.ts +28 -0
- package/src/frontend-guidance.ts +20 -8
- package/src/internal/git-ignored.ts +47 -0
- package/src/internal/source-facts.ts +198 -0
- package/src/introspect.ts +1 -1
- package/src/load.ts +29 -0
- package/src/local-cli.ts +83 -0
- package/src/lock-links.ts +5 -43
- package/src/mcp-delegate.ts +30 -9
- package/src/mcp-exec.ts +74 -3
- package/src/mcp-http.ts +3 -2
- package/src/mcp-tool-meta.ts +268 -0
- package/src/mcp.ts +35 -99
- package/src/openapi-types.ts +43 -2
- package/src/output-schemas.ts +28 -0
- package/src/ppr-read-fix.ts +426 -0
- package/src/recipes/5.6.0.ts +69 -0
- package/src/recipes/5.7.0.ts +72 -0
- package/src/recipes/index.ts +18 -0
- package/src/review.ts +9 -2
- package/src/rules/codes.ts +11 -4
- package/src/rules/explanations.ts +52 -16
- package/src/rules/islands.ts +875 -3
- package/src/rules/legacy.ts +1 -1
- package/src/rules/ppr.ts +143 -0
- package/src/rules/swap.ts +402 -0
- package/src/rules/text-slot-boolean.ts +56 -0
- package/src/rules/undeclared-response.ts +92 -0
- package/src/scaffold-hole.ts +880 -0
- package/src/scaffold.ts +60 -49
- package/src/upgrade.ts +229 -33
- package/src/verification-plan.ts +20 -1
- package/src/version-drift.ts +1 -1
- package/src/web-app-options.ts +2 -0
- package/dist/rules/nano.d.ts +0 -6
- package/dist/rules/nano.d.ts.map +0 -1
- package/dist/rules/nano.js +0 -273
- package/dist/rules/nano.js.map +0 -1
- package/src/rules/nano.ts +0 -307
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nifrajs/cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"description": "The nifra CLI - zero-config dev/build/start for a nifra app (`nifra dev`, `nifra build`, `nifra start`).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bun",
|
|
@@ -70,16 +70,16 @@
|
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@nifrajs/client": "5.
|
|
74
|
-
"@nifrajs/core": "5.
|
|
75
|
-
"@nifrajs/agent-review": "5.
|
|
76
|
-
"@nifrajs/i18n": "5.
|
|
77
|
-
"@nifrajs/mcp": "5.
|
|
78
|
-
"@nifrajs/mcp-db": "5.
|
|
79
|
-
"@nifrajs/runner": "5.
|
|
80
|
-
"@nifrajs/schema": "5.
|
|
81
|
-
"@nifrajs/testing": "5.
|
|
82
|
-
"@nifrajs/web": "5.
|
|
73
|
+
"@nifrajs/client": "5.7.0",
|
|
74
|
+
"@nifrajs/core": "5.7.0",
|
|
75
|
+
"@nifrajs/agent-review": "5.7.0",
|
|
76
|
+
"@nifrajs/i18n": "5.7.0",
|
|
77
|
+
"@nifrajs/mcp": "5.7.0",
|
|
78
|
+
"@nifrajs/mcp-db": "5.7.0",
|
|
79
|
+
"@nifrajs/runner": "5.7.0",
|
|
80
|
+
"@nifrajs/schema": "5.7.0",
|
|
81
|
+
"@nifrajs/testing": "5.7.0",
|
|
82
|
+
"@nifrajs/web": "5.7.0"
|
|
83
83
|
},
|
|
84
84
|
"repository": {
|
|
85
85
|
"type": "git",
|
package/src/cdn-check.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `nifra cdn-check <url>` - is a deployed page actually served by the CDN the way `withCdn` intends?
|
|
3
3
|
*
|
|
4
|
-
* Read-only: two GETs of the page
|
|
5
|
-
* the CDN from its status header, and fails when nifra's internal
|
|
6
|
-
* the CDN answers a navigation
|
|
7
|
-
* `Vary`, so it needs a rule that bypasses the cache for
|
|
8
|
-
* that fetches arbitrary URLs from this machine could
|
|
4
|
+
* Read-only: two GETs of the page, one shaped like a soft navigation (`x-nifra-data: 1`) and one like a
|
|
5
|
+
* slot swap (`x-nifra-swap`). It names the CDN from its status header, and fails when nifra's internal
|
|
6
|
+
* headers reach the visitor or when the CDN answers a navigation or swap request with the cached
|
|
7
|
+
* document (Cloudflare's zone cache ignores `Vary`, so it needs a rule that bypasses the cache for
|
|
8
|
+
* those headers). CLI only: an agent-facing tool that fetches arbitrary URLs from this machine could
|
|
9
|
+
* reach its private network.
|
|
9
10
|
*/
|
|
10
11
|
import type { CommandSpec } from "./command-catalog.ts"
|
|
11
12
|
|
|
@@ -17,7 +18,7 @@ export interface CdnCheckInput {
|
|
|
17
18
|
export type CdnName = "cloudflare" | "vercel" | "fastly" | "unknown"
|
|
18
19
|
|
|
19
20
|
export interface CdnCheckRequest {
|
|
20
|
-
readonly kind: "first" | "second" | "data"
|
|
21
|
+
readonly kind: "first" | "second" | "data" | "swap"
|
|
21
22
|
readonly status: number
|
|
22
23
|
readonly cache?: string | undefined
|
|
23
24
|
readonly age?: string | undefined
|
|
@@ -147,6 +148,9 @@ export async function runCdnCheck(
|
|
|
147
148
|
requests.push(summarize("second", second))
|
|
148
149
|
const data = await record({ "x-nifra-data": "1" })
|
|
149
150
|
requests.push(summarize("data", data))
|
|
151
|
+
// A slot no page renders: the app answers with the document, so only the cache status tells.
|
|
152
|
+
const swap = await record({ "x-nifra-swap": "nifra-cdn-check" })
|
|
153
|
+
requests.push(summarize("swap", swap))
|
|
150
154
|
|
|
151
155
|
for (const res of [first, second, data]) {
|
|
152
156
|
const leaked = INTERNAL.filter((name) => res.headers.has(name))
|
|
@@ -208,6 +212,16 @@ export async function runCdnCheck(
|
|
|
208
212
|
: "a soft navigation (x-nifra-data: 1) got the cached document instead of the page data; the CDN is not honoring Vary: x-nifra-data",
|
|
209
213
|
})
|
|
210
214
|
}
|
|
215
|
+
if (isHit(cacheStatus(cdn, swap.headers))) {
|
|
216
|
+
findings.push({
|
|
217
|
+
level: "fail",
|
|
218
|
+
code: "swap-served-from-cache",
|
|
219
|
+
message:
|
|
220
|
+
cdn === "cloudflare"
|
|
221
|
+
? "a slot swap (x-nifra-swap) was answered from cache. The zone cache ignores Vary: the Cache Rule that bypasses x-nifra-data must bypass requests with an x-nifra-swap header too"
|
|
222
|
+
: "a slot swap (x-nifra-swap) was answered from cache; the CDN must bypass its cache for requests carrying that header",
|
|
223
|
+
})
|
|
224
|
+
}
|
|
211
225
|
return { url: input.url, cdn, requests, findings }
|
|
212
226
|
}
|
|
213
227
|
|
|
@@ -226,7 +240,7 @@ function renderCdnCheck(out: CdnCheckOutput): readonly string[] {
|
|
|
226
240
|
export const cdnCheckSpec: CommandSpec<CdnCheckInput, CdnCheckOutput> = {
|
|
227
241
|
name: "cdn-check",
|
|
228
242
|
summary:
|
|
229
|
-
"Check a deployed page behind a CDN: is it served from cache, do internal or CDN-only headers reach the visitor, and
|
|
243
|
+
"Check a deployed page behind a CDN: is it served from cache, do internal or CDN-only headers reach the visitor, and do a soft navigation and a slot swap get their own answer rather than the cached document.",
|
|
230
244
|
input: {
|
|
231
245
|
jsonSchema: {
|
|
232
246
|
type: "object",
|
package/src/check-diagnostics.ts
CHANGED
|
@@ -29,12 +29,15 @@ import { islandRules } from "./rules/islands.ts"
|
|
|
29
29
|
import { retiredLayoutRule } from "./rules/layout.ts"
|
|
30
30
|
import { LEGACY_RULE_CODES, LEGACY_RULE_ORDER, legacyRules } from "./rules/legacy.ts"
|
|
31
31
|
import { mergeAuthGapRule } from "./rules/merge-auth.ts"
|
|
32
|
-
import { nanoRules } from "./rules/nano.ts"
|
|
33
32
|
import { pageRules } from "./rules/pages.ts"
|
|
33
|
+
import { pprRules } from "./rules/ppr.ts"
|
|
34
34
|
import { routeStatementRule } from "./rules/route-statement.ts"
|
|
35
35
|
import { routeRules } from "./rules/routes.ts"
|
|
36
36
|
import { secretRules } from "./rules/secrets.ts"
|
|
37
37
|
import { securityRules } from "./rules/security.ts"
|
|
38
|
+
import { swapRules } from "./rules/swap.ts"
|
|
39
|
+
import { textSlotBooleanRule } from "./rules/text-slot-boolean.ts"
|
|
40
|
+
import { undeclaredResponseRule } from "./rules/undeclared-response.ts"
|
|
38
41
|
import { zoneRules } from "./rules/zones.ts"
|
|
39
42
|
|
|
40
43
|
/** A single machine-readable check failure - the unit an agent (or CI) acts on. */
|
|
@@ -499,13 +502,16 @@ export async function collectCheckDiagnostics(
|
|
|
499
502
|
...routeRules,
|
|
500
503
|
contractVisibilityRule,
|
|
501
504
|
...pageRules,
|
|
505
|
+
...pprRules,
|
|
502
506
|
mergeAuthGapRule,
|
|
503
507
|
routeStatementRule,
|
|
508
|
+
undeclaredResponseRule,
|
|
509
|
+
textSlotBooleanRule,
|
|
504
510
|
...zoneRules,
|
|
505
511
|
...dataGuardRules,
|
|
506
512
|
...secretRules,
|
|
507
513
|
...islandRules,
|
|
508
|
-
...
|
|
514
|
+
...swapRules,
|
|
509
515
|
]
|
|
510
516
|
let registryDiagnostics: Diagnostic[] = []
|
|
511
517
|
let builtInsSucceeded = false
|
|
@@ -573,7 +579,7 @@ export async function collectCheckDiagnostics(
|
|
|
573
579
|
continue
|
|
574
580
|
}
|
|
575
581
|
// A structured informational contract note intentionally has no old human/legacy row. Every
|
|
576
|
-
// other non-legacy rule (security, route, island,
|
|
582
|
+
// other non-legacy rule (security, route, island, or an application pack) retains the
|
|
577
583
|
// existing fallback row keyed by its stable code.
|
|
578
584
|
if (knownLegacyCodes.has(item.code)) continue
|
|
579
585
|
compatibilityRows.push({
|
package/src/check-scan.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { isServerPackageSpecifier } from "@nifrajs/web/zones"
|
|
|
11
11
|
import { Glob } from "bun"
|
|
12
12
|
import type * as TSApi from "typescript"
|
|
13
13
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
14
|
+
import { gitIgnored } from "./internal/git-ignored.ts"
|
|
14
15
|
import { scriptKindOf } from "./internal/script-kind.ts"
|
|
15
16
|
import type { SourceFacts } from "./internal/source-facts.ts"
|
|
16
17
|
import {
|
|
@@ -2461,6 +2462,37 @@ function sqlMethod(ts: TypeScriptApi, call: TSApi.CallExpression): SqlSink | und
|
|
|
2461
2462
|
? { method, receiver: receiver?.getText() }
|
|
2462
2463
|
: undefined
|
|
2463
2464
|
const callee = call.expression
|
|
2465
|
+
// Svelte compiles this unbound rune; it is not a driver's raw-statement escape hatch.
|
|
2466
|
+
if (
|
|
2467
|
+
ts.isPropertyAccessExpression(callee) &&
|
|
2468
|
+
callee.name.text === "raw" &&
|
|
2469
|
+
ts.isIdentifier(callee.expression) &&
|
|
2470
|
+
callee.expression.text === "$state"
|
|
2471
|
+
) {
|
|
2472
|
+
const source = callee.getSourceFile()
|
|
2473
|
+
const imported = source.statements.some((statement) => {
|
|
2474
|
+
if (ts.isImportEqualsDeclaration(statement)) return statement.name.text === "$state"
|
|
2475
|
+
if (!ts.isImportDeclaration(statement)) return false
|
|
2476
|
+
const clause = statement.importClause
|
|
2477
|
+
const bindings = clause?.namedBindings
|
|
2478
|
+
return (
|
|
2479
|
+
clause?.name?.text === "$state" ||
|
|
2480
|
+
(bindings !== undefined &&
|
|
2481
|
+
(ts.isNamespaceImport(bindings)
|
|
2482
|
+
? bindings.name.text === "$state"
|
|
2483
|
+
: bindings.elements.some((binding) => binding.name.text === "$state")))
|
|
2484
|
+
)
|
|
2485
|
+
})
|
|
2486
|
+
let bound = imported || isShadowedAt(ts, callee.expression, "$state")
|
|
2487
|
+
for (
|
|
2488
|
+
let scope: TSApi.Node | undefined = callee.parent;
|
|
2489
|
+
scope !== undefined && !bound;
|
|
2490
|
+
scope = scope.parent
|
|
2491
|
+
) {
|
|
2492
|
+
bound = directBinding(ts, source, scope, "$state") !== undefined
|
|
2493
|
+
}
|
|
2494
|
+
if (/\.svelte(?:\.[jt]s)?$/.test(source.fileName) && !bound) return undefined
|
|
2495
|
+
}
|
|
2464
2496
|
if (ts.isIdentifier(callee)) return sink(callee.text, undefined)
|
|
2465
2497
|
if (ts.isPropertyAccessExpression(callee)) return sink(callee.name.text, callee.expression)
|
|
2466
2498
|
if (ts.isElementAccessExpression(callee) && ts.isStringLiteralLike(callee.argumentExpression)) {
|
|
@@ -3452,35 +3484,6 @@ const RAW_RESPONSE_EXPECTATION = ["NF-C007", "raw-response"]
|
|
|
3452
3484
|
* `includeTests` widens the surface to `*.test.ts`/`*.spec.ts`, which the default excludes. It exists
|
|
3453
3485
|
* for `nifra doctor`: `tsc` compiles tests, so a test importing a package no manifest declares is a
|
|
3454
3486
|
* build that a clean install cannot produce - the exact false confidence doctor is for. */
|
|
3455
|
-
/**
|
|
3456
|
-
* Paths git considers ignored under `cwd`, in ONE batched `git check-ignore` call - so `.gitignore`
|
|
3457
|
-
* (root + nested + the global excludesfile) is honoured, not just the built-in {@link IGNORED} list. This
|
|
3458
|
-
* is what keeps the scan out of generated/build trees that live under a repo but aren't source: a monorepo
|
|
3459
|
-
* that gitignores, say, `builder/projects/` (238 generated apps) would otherwise be walked in full - 40k+
|
|
3460
|
-
* findings, a 50 MB+ result that overwhelms the caller. Returns an EMPTY set when there's no git / not a
|
|
3461
|
-
* repo / git errors, so the scan simply degrades to the {@link IGNORED} regex - never throws, never blocks.
|
|
3462
|
-
*/
|
|
3463
|
-
async function gitIgnored(cwd: string, rels: readonly string[]): Promise<Set<string>> {
|
|
3464
|
-
if (rels.length === 0) return new Set()
|
|
3465
|
-
try {
|
|
3466
|
-
const proc = Bun.spawn(["git", "check-ignore", "--stdin", "-z"], {
|
|
3467
|
-
cwd,
|
|
3468
|
-
stdin: "pipe",
|
|
3469
|
-
stdout: "pipe",
|
|
3470
|
-
stderr: "ignore",
|
|
3471
|
-
})
|
|
3472
|
-
proc.stdin.write(`${rels.join("\0")}\0`)
|
|
3473
|
-
await proc.stdin.end()
|
|
3474
|
-
// -z keeps both directions literal: Git otherwise C-quotes Unicode/escapes on output and
|
|
3475
|
-
// interprets quoted input. Only matching paths are emitted; exit 1 means none matched.
|
|
3476
|
-
const out = await new Response(proc.stdout).text()
|
|
3477
|
-
await proc.exited
|
|
3478
|
-
return new Set(out.split("\0").filter((path) => path !== ""))
|
|
3479
|
-
} catch {
|
|
3480
|
-
return new Set()
|
|
3481
|
-
}
|
|
3482
|
-
}
|
|
3483
|
-
|
|
3484
3487
|
export async function walkSource(
|
|
3485
3488
|
cwd: string,
|
|
3486
3489
|
visit: (rel: string, content: string) => void,
|
|
@@ -3507,7 +3510,7 @@ export async function walkSource(
|
|
|
3507
3510
|
// A backslash is a filename character on POSIX; only Windows separators need normalizing.
|
|
3508
3511
|
const rel = sep === "\\" ? normalizeProjectPath(rawRel) : rawRel
|
|
3509
3512
|
// A `.js` file outside a zone is tooling (a bundler config, a script, a vendored asset), not app code.
|
|
3510
|
-
if (PLAIN_SCRIPT_FILE.test(rel) && !
|
|
3513
|
+
if (PLAIN_SCRIPT_FILE.test(rel) && !ZONE_DIRECTORY.test(rel) && !ZONE_SUFFIX.test(rel)) continue
|
|
3511
3514
|
if (!skip.test(rel) && (opts.ignore === undefined || !opts.ignore(rel))) rels.push(rel)
|
|
3512
3515
|
}
|
|
3513
3516
|
const ignored = await gitIgnored(cwd, rels)
|
|
@@ -3520,8 +3523,8 @@ export async function walkSource(
|
|
|
3520
3523
|
}
|
|
3521
3524
|
|
|
3522
3525
|
const PLAIN_SCRIPT_FILE = /\.[cm]?js$/
|
|
3523
|
-
const
|
|
3524
|
-
|
|
3526
|
+
const ZONE_DIRECTORY = /(?:^|\/)(?:routes|frontend|shared|backend)\//
|
|
3527
|
+
const ZONE_SUFFIX = /\.(?:frontend|shared|backend|fn)\.[^/]+$/
|
|
3525
3528
|
/** A single-file component: its `<script>` blocks are the code a build compiles. */
|
|
3526
3529
|
export const COMPONENT_FILE = /\.(?:svelte|vue)$/
|
|
3527
3530
|
|
package/src/check.ts
CHANGED
|
@@ -675,6 +675,8 @@ export function renderCheckReport(result: CheckResult): string[] {
|
|
|
675
675
|
if (deduplicated.length > 0) {
|
|
676
676
|
const packages = deduplicated.map((finding) => finding.package).join(", ")
|
|
677
677
|
lines.push(`• identity-sensitive duplicate installs handled by singleCopy: ${packages}`)
|
|
678
|
+
const unarmed = deduplicated.find((finding) => finding.unenforced !== undefined)
|
|
679
|
+
if (unarmed !== undefined) lines.push(` ${unarmed.remediation}`)
|
|
678
680
|
}
|
|
679
681
|
if (result.ruleOverrides !== undefined) {
|
|
680
682
|
const active = Object.entries(result.ruleOverrides).map(([rule, override]) => {
|
|
@@ -705,19 +707,39 @@ export function renderCheckReport(result: CheckResult): string[] {
|
|
|
705
707
|
: `✗ ${label}: ${errors}${rest === "" ? "" : ` (+${rest})`}`,
|
|
706
708
|
)
|
|
707
709
|
}
|
|
710
|
+
const fix = (suggestion: NonNullable<CheckDiagnostic["suggestion"]>, label: string): void => {
|
|
711
|
+
lines.push(` ${label}: ${suggestion.title}`)
|
|
712
|
+
if (suggestion.command !== undefined) {
|
|
713
|
+
lines.push(` command: ${suggestion.command.join(" ")}`)
|
|
714
|
+
}
|
|
715
|
+
if (suggestion.diff !== undefined) {
|
|
716
|
+
for (const line of suggestion.diff.split("\n")) lines.push(` ${line}`)
|
|
717
|
+
}
|
|
718
|
+
for (const step of suggestion.steps ?? []) lines.push(` - ${step}`)
|
|
719
|
+
}
|
|
720
|
+
// A fix several findings share prints once, after them: twenty raw responses are twenty
|
|
721
|
+
// locations and one recipe, not a hundred lines.
|
|
722
|
+
const keyOf = (d: CheckDiagnostic): string | undefined =>
|
|
723
|
+
d.suggestion === undefined ? undefined : JSON.stringify(d.suggestion)
|
|
724
|
+
const shared = new Map<
|
|
725
|
+
string,
|
|
726
|
+
{ suggestion: NonNullable<CheckDiagnostic["suggestion"]>; count: number }
|
|
727
|
+
>()
|
|
728
|
+
for (const d of ds) {
|
|
729
|
+
const key = keyOf(d)
|
|
730
|
+
if (key === undefined || d.suggestion === undefined) continue
|
|
731
|
+
const seen = shared.get(key)
|
|
732
|
+
if (seen === undefined) shared.set(key, { suggestion: d.suggestion, count: 1 })
|
|
733
|
+
else seen.count++
|
|
734
|
+
}
|
|
708
735
|
for (const d of ds) {
|
|
709
736
|
lines.push(` ${d.file ?? ""}${d.line ? `:${d.line}` : ""} ${d.message}`)
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
lines.push(` command: ${d.suggestion.command.join(" ")}`)
|
|
714
|
-
}
|
|
715
|
-
if (d.suggestion.diff !== undefined) {
|
|
716
|
-
for (const line of d.suggestion.diff.split("\n")) lines.push(` ${line}`)
|
|
717
|
-
}
|
|
718
|
-
for (const step of d.suggestion.steps ?? []) lines.push(` - ${step}`)
|
|
719
|
-
}
|
|
737
|
+
const key = keyOf(d)
|
|
738
|
+
if (d.suggestion !== undefined && key !== undefined && (shared.get(key)?.count ?? 0) === 1)
|
|
739
|
+
fix(d.suggestion, "fix")
|
|
720
740
|
}
|
|
741
|
+
for (const { suggestion, count } of shared.values())
|
|
742
|
+
if (count > 1) fix(suggestion, `fix (the ${count} above)`)
|
|
721
743
|
}
|
|
722
744
|
for (const [rule, label] of REPORT_SECTIONS) {
|
|
723
745
|
renderSection(
|
package/src/cli.ts
CHANGED
|
@@ -24,9 +24,16 @@ import { discoverRoutes } from "@nifrajs/web/fs"
|
|
|
24
24
|
import { formatShadowedPages, shadowedPages } from "@nifrajs/web/route-manifest"
|
|
25
25
|
import type { BunPlugin } from "bun"
|
|
26
26
|
import { adapterFile, BACKEND_APP_FILE } from "./app-files.ts"
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
bindCommandArgv,
|
|
29
|
+
type CommandSpec,
|
|
30
|
+
commandUsage,
|
|
31
|
+
findCommandSpec,
|
|
32
|
+
renderCommandCatalogHelp,
|
|
33
|
+
} from "./command-catalog.ts"
|
|
28
34
|
import { applyEnvFiles, forgetAutoLoadedEnv, REFLECT_ENV, takeEnvFileFlags } from "./env-file.ts"
|
|
29
35
|
import { FRAMEWORK_WEB_OPTIONS, type LoadedApp, loadApp, type NifraFramework } from "./load.ts"
|
|
36
|
+
import { PROJECT_COMMANDS, runThroughLocalCli } from "./local-cli.ts"
|
|
30
37
|
import { chooseBuildPipeline, describePipeline } from "./pipeline-guard.ts"
|
|
31
38
|
import {
|
|
32
39
|
frameworkMountPaths,
|
|
@@ -134,8 +141,8 @@ Usage:
|
|
|
134
141
|
to fix it.
|
|
135
142
|
nifra cdn-check <url> Check a deployed page behind a CDN: served from cache, no
|
|
136
143
|
internal or CDN-only headers reaching the visitor, and soft
|
|
137
|
-
navigations get
|
|
138
|
-
on a failure.
|
|
144
|
+
navigations and slot swaps get their own answer, not the
|
|
145
|
+
cached document. Exits 1 on a failure.
|
|
139
146
|
nifra db schema [<table>] The development database declared as \`devDatabase\` in
|
|
140
147
|
nifra.config.ts: tables, columns, keys, indexes.
|
|
141
148
|
nifra db query "<sql>" [--explain [--analyze]] One read-only SELECT (or its plan), in a fresh
|
|
@@ -207,7 +214,8 @@ Usage:
|
|
|
207
214
|
nifra_db_role (the declared dev database, read-only),
|
|
208
215
|
nifra_explain (structured errors), nifra_inspect (request
|
|
209
216
|
traces), nifra_learn (guided build path).
|
|
210
|
-
nifra docs-mcp [--port <n>] Serve the PUBLIC docs MCP over HTTP (nifra_docs
|
|
217
|
+
nifra docs-mcp [--port <n>] Serve the PUBLIC docs MCP over HTTP (nifra_docs, nifra_example,
|
|
218
|
+
nifra_types, nifra_learn, nifra_frontend, nifra_gallery) -
|
|
211
219
|
self-host on a VPS so any remote agent can learn nifra. Default :8787.
|
|
212
220
|
nifra learn [<step>] Print the guided build-an-app path (the human view of nifra_learn):
|
|
213
221
|
no arg for the step index, a number for one step's goal/do/verify.
|
|
@@ -245,7 +253,7 @@ Usage:
|
|
|
245
253
|
skip and exits non-zero unless its verdict is green. --strict,
|
|
246
254
|
--hydration, --interact and --out imply --bundle.
|
|
247
255
|
nifra contracts snapshot [--out <file>] Write the deterministic route contract lock.
|
|
248
|
-
nifra contracts check [--json]
|
|
256
|
+
nifra contracts check [--out <file>] [--json] Check the current routes against the lock.
|
|
249
257
|
nifra replay <file> Replay a token-only verification metadata file.
|
|
250
258
|
nifra capabilities snapshot [--out <file>] [--config <file>]
|
|
251
259
|
Write the deterministic, token-only capability lockfile, but
|
|
@@ -288,7 +296,7 @@ Usage:
|
|
|
288
296
|
version, a rollback (--allow-downgrade overrides), or a
|
|
289
297
|
linked repository that loads its own nifra at another
|
|
290
298
|
version (--allow-linked-skew overrides). Deterministic +
|
|
291
|
-
idempotent.
|
|
299
|
+
idempotent. Leaves bun.lock alone.
|
|
292
300
|
nifra migrate layout [--write] [--zones] [--json]
|
|
293
301
|
Move an app onto the frontend/backend split: split each route
|
|
294
302
|
into x.tsx + x.backend.ts, fold _middleware.ts into
|
|
@@ -296,6 +304,12 @@ Usage:
|
|
|
296
304
|
and zone the other modules into frontend/, backend/ or shared/
|
|
297
305
|
(--zones keeps them in place and lists them in package.json
|
|
298
306
|
"nifra.zones"). Dry-run by default; --write applies.
|
|
307
|
+
nifra scaffold hole <route> <name> [--shared] [--interactive] [--timeout <ms>] [--server] [--json]
|
|
308
|
+
Experimental: add a partially prerendered hole to a route whose
|
|
309
|
+
backend half exports shellLoader - its definition and <Hole> in
|
|
310
|
+
the page, its loader and output schema in the backend half. A
|
|
311
|
+
Vue or Svelte page gets the code to paste; --server writes a
|
|
312
|
+
React server component for the hole.
|
|
299
313
|
nifra types [--check] [--json] Generate each route's ./+types module under .nifra/types: its
|
|
300
314
|
params, the data its output schemas let through, and api typed
|
|
301
315
|
by backend/app.ts. dev, build and check refresh them too;
|
|
@@ -335,13 +349,12 @@ set in the process environment is never overwritten by a file.
|
|
|
335
349
|
${renderCommandCatalogHelp()}`
|
|
336
350
|
|
|
337
351
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
338
|
-
const CLI_VERSION = "5.
|
|
352
|
+
const CLI_VERSION = "5.7.0"
|
|
339
353
|
|
|
340
354
|
// A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
|
|
341
355
|
const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
|
|
342
356
|
const asBunPlugins = (v: readonly unknown[]): BunPlugin[] => v as BunPlugin[]
|
|
343
357
|
|
|
344
|
-
// biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Trusted application configuration supplies native Vite plugins; the pinned pipeline validates their hooks.
|
|
345
358
|
const asComponentPlugins = (
|
|
346
359
|
value: readonly unknown[],
|
|
347
360
|
): NonNullable<
|
|
@@ -387,6 +400,25 @@ export function formatCliError(err: unknown): string {
|
|
|
387
400
|
}
|
|
388
401
|
|
|
389
402
|
/** A failed command's message on stderr and, for a `--json` caller parsing stdout, as JSON there. */
|
|
403
|
+
/** One catalog command's usage: its lines from {@link HELP} when it has them, else the catalog's. */
|
|
404
|
+
export function commandHelp<Input, Output>(spec: CommandSpec<Input, Output>): string {
|
|
405
|
+
const name = spec.name.replace(/^db-/, "db ")
|
|
406
|
+
const lines: string[] = []
|
|
407
|
+
let inside = false
|
|
408
|
+
for (const line of HELP.split("\n")) {
|
|
409
|
+
if (line.startsWith(` nifra ${name} `) || line === ` nifra ${name}`) inside = true
|
|
410
|
+
else if (!inside || !/^ {3,}\S/.test(line)) {
|
|
411
|
+
// The first block is the hand-written one; the catalog's one-line summary repeats it below.
|
|
412
|
+
if (lines.length > 0) break
|
|
413
|
+
continue
|
|
414
|
+
}
|
|
415
|
+
lines.push(line)
|
|
416
|
+
}
|
|
417
|
+
if (lines.length > 0) return ["Usage:", ...lines].join("\n")
|
|
418
|
+
const usage = commandUsage(spec)
|
|
419
|
+
return `Usage:\n nifra ${name}${usage === "" ? "" : ` ${usage}`} ${spec.summary}`
|
|
420
|
+
}
|
|
421
|
+
|
|
390
422
|
function reportFailure(err: unknown, argv: readonly string[]): void {
|
|
391
423
|
const message = formatCliError(err)
|
|
392
424
|
console.error(message)
|
|
@@ -584,6 +616,7 @@ async function dev(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
584
616
|
...(fw.define ? { define: fw.define } : {}),
|
|
585
617
|
indicator: showsIndicator(flags, fw),
|
|
586
618
|
allowedHosts: fw.dev?.allowedHosts ?? [],
|
|
619
|
+
live: fw.live?.clientEntry,
|
|
587
620
|
createApp: (clientEntry, importQuery, dev) =>
|
|
588
621
|
createWebApp({
|
|
589
622
|
adapter: asAdapter(fw.adapter),
|
|
@@ -641,6 +674,7 @@ async function dev(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
641
674
|
port: flags.port,
|
|
642
675
|
...(flags.allowDuplicateIdentity ? { allowDuplicateIdentity: true } : {}),
|
|
643
676
|
indicator: showsIndicator(flags, fw),
|
|
677
|
+
live: fw.live?.clientEntry,
|
|
644
678
|
...(fw.conditions ? { conditions: fw.conditions } : {}),
|
|
645
679
|
...(fw.define ? { define: fw.define } : {}),
|
|
646
680
|
// `load` resolves route modules through VITE, not through Bun. That is what makes the Vite
|
|
@@ -915,6 +949,7 @@ async function buildForTarget(
|
|
|
915
949
|
...(fw.cssCodeSplit !== undefined ? { cssCodeSplit: fw.cssCodeSplit } : {}),
|
|
916
950
|
...(fw.cssLoading !== undefined ? { cssLoading: fw.cssLoading } : {}),
|
|
917
951
|
...(fw.clientIp !== undefined ? { clientIp: fw.clientIp } : {}),
|
|
952
|
+
live: fw.live?.clientEntry,
|
|
918
953
|
// Prerendering drives a built app: the static target is made of its pages, and a bun or node server
|
|
919
954
|
// answers its prerendered pages from their file. Not under Vite, whose server bundle may rely on
|
|
920
955
|
// transforms the prerender pass (Bun's runtime) does not apply: those pages keep rendering on demand.
|
|
@@ -1162,6 +1197,22 @@ async function main(): Promise<void> {
|
|
|
1162
1197
|
console.log(`nifra (@nifrajs/cli) ${CLI_VERSION}`)
|
|
1163
1198
|
return
|
|
1164
1199
|
}
|
|
1200
|
+
if (
|
|
1201
|
+
PROJECT_COMMANDS.has(command) &&
|
|
1202
|
+
!argv.includes("--help") &&
|
|
1203
|
+
!argv.includes("-h") &&
|
|
1204
|
+
!isBunDevReexecChild()
|
|
1205
|
+
) {
|
|
1206
|
+
const exitCode = await runThroughLocalCli({
|
|
1207
|
+
cwd: process.cwd(),
|
|
1208
|
+
version: CLI_VERSION,
|
|
1209
|
+
args: cliArgv(),
|
|
1210
|
+
})
|
|
1211
|
+
if (exitCode !== undefined) {
|
|
1212
|
+
process.exitCode = exitCode
|
|
1213
|
+
return
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1165
1216
|
// `mcp` runs a long-lived stdio server and loads the project lazily per-tool - it must not go through
|
|
1166
1217
|
// the eager `loadApp` below (which would fail fast on a project that's API-only / not yet built).
|
|
1167
1218
|
if (command === "mcp") {
|
|
@@ -1237,12 +1288,23 @@ async function main(): Promise<void> {
|
|
|
1237
1288
|
}
|
|
1238
1289
|
const catalogSpec = findCommandSpec(dbSub === undefined ? command : `db-${dbSub}`)
|
|
1239
1290
|
if (catalogSpec?.transports.includes("cli")) {
|
|
1291
|
+
const commandArgs = argv.slice(dbSub === undefined ? 1 : 2)
|
|
1292
|
+
if (commandArgs.includes("--help") || commandArgs.includes("-h")) {
|
|
1293
|
+
console.log(commandHelp(catalogSpec))
|
|
1294
|
+
return
|
|
1295
|
+
}
|
|
1240
1296
|
const markReflecting = installReflectionExitHint()
|
|
1241
1297
|
if (READ_ONLY_COMMANDS.has(command) || (command === "assure" && !assureBundleRequested(argv))) {
|
|
1242
1298
|
process.env[REFLECT_ENV] = command
|
|
1243
1299
|
}
|
|
1244
1300
|
try {
|
|
1245
|
-
|
|
1301
|
+
let input: unknown
|
|
1302
|
+
try {
|
|
1303
|
+
input = bindCommandArgv(catalogSpec, commandArgs)
|
|
1304
|
+
} catch (error) {
|
|
1305
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
1306
|
+
throw new Error(`[nifra] ${message}\n\n${commandHelp(catalogSpec)}`)
|
|
1307
|
+
}
|
|
1246
1308
|
markReflecting(command)
|
|
1247
1309
|
const output = await catalogSpec.run(input, { cwd: process.cwd(), cliVersion: CLI_VERSION })
|
|
1248
1310
|
markReflecting(undefined)
|