@nifrajs/cli 5.6.0 → 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 +159 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +4 -0
- 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 +1 -30
- 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 +53 -5
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +5 -0
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +18 -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 +6 -4
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +20 -6
- package/dist/doctor.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/load.d.ts +4 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +10 -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-http.js +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/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 +2 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +2 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +2 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +2 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +13 -3
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/legacy.js +1 -1
- package/dist/rules/legacy.js.map +1 -1
- 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/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/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 +7 -1
- package/docs/llms-full.txt +441 -105
- package/docs/types.json +164 -43
- package/package.json +11 -11
- package/src/check-diagnostics.ts +4 -0
- package/src/check-scan.ts +1 -29
- package/src/check.ts +32 -10
- package/src/cli.ts +58 -5
- package/src/command-catalog.ts +23 -6
- package/src/contracts.ts +348 -14
- package/src/doctor.ts +28 -12
- package/src/internal/git-ignored.ts +47 -0
- package/src/internal/source-facts.ts +198 -0
- package/src/load.ts +16 -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-http.ts +1 -1
- package/src/openapi-types.ts +43 -2
- package/src/recipes/5.7.0.ts +72 -0
- package/src/recipes/index.ts +16 -0
- package/src/review.ts +2 -0
- package/src/rules/codes.ts +2 -0
- package/src/rules/explanations.ts +13 -3
- package/src/rules/legacy.ts +1 -1
- package/src/rules/text-slot-boolean.ts +56 -0
- package/src/rules/undeclared-response.ts +92 -0
- package/src/upgrade.ts +229 -33
- package/src/version-drift.ts +1 -1
- package/src/web-app-options.ts +1 -0
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/check-diagnostics.ts
CHANGED
|
@@ -36,6 +36,8 @@ import { routeRules } from "./rules/routes.ts"
|
|
|
36
36
|
import { secretRules } from "./rules/secrets.ts"
|
|
37
37
|
import { securityRules } from "./rules/security.ts"
|
|
38
38
|
import { swapRules } from "./rules/swap.ts"
|
|
39
|
+
import { textSlotBooleanRule } from "./rules/text-slot-boolean.ts"
|
|
40
|
+
import { undeclaredResponseRule } from "./rules/undeclared-response.ts"
|
|
39
41
|
import { zoneRules } from "./rules/zones.ts"
|
|
40
42
|
|
|
41
43
|
/** A single machine-readable check failure - the unit an agent (or CI) acts on. */
|
|
@@ -503,6 +505,8 @@ export async function collectCheckDiagnostics(
|
|
|
503
505
|
...pprRules,
|
|
504
506
|
mergeAuthGapRule,
|
|
505
507
|
routeStatementRule,
|
|
508
|
+
undeclaredResponseRule,
|
|
509
|
+
textSlotBooleanRule,
|
|
506
510
|
...zoneRules,
|
|
507
511
|
...dataGuardRules,
|
|
508
512
|
...secretRules,
|
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 {
|
|
@@ -3483,35 +3484,6 @@ const RAW_RESPONSE_EXPECTATION = ["NF-C007", "raw-response"]
|
|
|
3483
3484
|
* `includeTests` widens the surface to `*.test.ts`/`*.spec.ts`, which the default excludes. It exists
|
|
3484
3485
|
* for `nifra doctor`: `tsc` compiles tests, so a test importing a package no manifest declares is a
|
|
3485
3486
|
* build that a clean install cannot produce - the exact false confidence doctor is for. */
|
|
3486
|
-
/**
|
|
3487
|
-
* Paths git considers ignored under `cwd`, in ONE batched `git check-ignore` call - so `.gitignore`
|
|
3488
|
-
* (root + nested + the global excludesfile) is honoured, not just the built-in {@link IGNORED} list. This
|
|
3489
|
-
* is what keeps the scan out of generated/build trees that live under a repo but aren't source: a monorepo
|
|
3490
|
-
* that gitignores, say, `builder/projects/` (238 generated apps) would otherwise be walked in full - 40k+
|
|
3491
|
-
* findings, a 50 MB+ result that overwhelms the caller. Returns an EMPTY set when there's no git / not a
|
|
3492
|
-
* repo / git errors, so the scan simply degrades to the {@link IGNORED} regex - never throws, never blocks.
|
|
3493
|
-
*/
|
|
3494
|
-
async function gitIgnored(cwd: string, rels: readonly string[]): Promise<Set<string>> {
|
|
3495
|
-
if (rels.length === 0) return new Set()
|
|
3496
|
-
try {
|
|
3497
|
-
const proc = Bun.spawn(["git", "check-ignore", "--stdin", "-z"], {
|
|
3498
|
-
cwd,
|
|
3499
|
-
stdin: "pipe",
|
|
3500
|
-
stdout: "pipe",
|
|
3501
|
-
stderr: "ignore",
|
|
3502
|
-
})
|
|
3503
|
-
proc.stdin.write(`${rels.join("\0")}\0`)
|
|
3504
|
-
await proc.stdin.end()
|
|
3505
|
-
// -z keeps both directions literal: Git otherwise C-quotes Unicode/escapes on output and
|
|
3506
|
-
// interprets quoted input. Only matching paths are emitted; exit 1 means none matched.
|
|
3507
|
-
const out = await new Response(proc.stdout).text()
|
|
3508
|
-
await proc.exited
|
|
3509
|
-
return new Set(out.split("\0").filter((path) => path !== ""))
|
|
3510
|
-
} catch {
|
|
3511
|
-
return new Set()
|
|
3512
|
-
}
|
|
3513
|
-
}
|
|
3514
|
-
|
|
3515
3487
|
export async function walkSource(
|
|
3516
3488
|
cwd: string,
|
|
3517
3489
|
visit: (rel: string, content: string) => void,
|
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,
|
|
@@ -246,7 +253,7 @@ Usage:
|
|
|
246
253
|
skip and exits non-zero unless its verdict is green. --strict,
|
|
247
254
|
--hydration, --interact and --out imply --bundle.
|
|
248
255
|
nifra contracts snapshot [--out <file>] Write the deterministic route contract lock.
|
|
249
|
-
nifra contracts check [--json]
|
|
256
|
+
nifra contracts check [--out <file>] [--json] Check the current routes against the lock.
|
|
250
257
|
nifra replay <file> Replay a token-only verification metadata file.
|
|
251
258
|
nifra capabilities snapshot [--out <file>] [--config <file>]
|
|
252
259
|
Write the deterministic, token-only capability lockfile, but
|
|
@@ -289,7 +296,7 @@ Usage:
|
|
|
289
296
|
version, a rollback (--allow-downgrade overrides), or a
|
|
290
297
|
linked repository that loads its own nifra at another
|
|
291
298
|
version (--allow-linked-skew overrides). Deterministic +
|
|
292
|
-
idempotent.
|
|
299
|
+
idempotent. Leaves bun.lock alone.
|
|
293
300
|
nifra migrate layout [--write] [--zones] [--json]
|
|
294
301
|
Move an app onto the frontend/backend split: split each route
|
|
295
302
|
into x.tsx + x.backend.ts, fold _middleware.ts into
|
|
@@ -342,7 +349,7 @@ set in the process environment is never overwritten by a file.
|
|
|
342
349
|
${renderCommandCatalogHelp()}`
|
|
343
350
|
|
|
344
351
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
345
|
-
const CLI_VERSION = "5.
|
|
352
|
+
const CLI_VERSION = "5.7.0"
|
|
346
353
|
|
|
347
354
|
// A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
|
|
348
355
|
const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
|
|
@@ -393,6 +400,25 @@ export function formatCliError(err: unknown): string {
|
|
|
393
400
|
}
|
|
394
401
|
|
|
395
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
|
+
|
|
396
422
|
function reportFailure(err: unknown, argv: readonly string[]): void {
|
|
397
423
|
const message = formatCliError(err)
|
|
398
424
|
console.error(message)
|
|
@@ -1171,6 +1197,22 @@ async function main(): Promise<void> {
|
|
|
1171
1197
|
console.log(`nifra (@nifrajs/cli) ${CLI_VERSION}`)
|
|
1172
1198
|
return
|
|
1173
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
|
+
}
|
|
1174
1216
|
// `mcp` runs a long-lived stdio server and loads the project lazily per-tool - it must not go through
|
|
1175
1217
|
// the eager `loadApp` below (which would fail fast on a project that's API-only / not yet built).
|
|
1176
1218
|
if (command === "mcp") {
|
|
@@ -1246,12 +1288,23 @@ async function main(): Promise<void> {
|
|
|
1246
1288
|
}
|
|
1247
1289
|
const catalogSpec = findCommandSpec(dbSub === undefined ? command : `db-${dbSub}`)
|
|
1248
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
|
+
}
|
|
1249
1296
|
const markReflecting = installReflectionExitHint()
|
|
1250
1297
|
if (READ_ONLY_COMMANDS.has(command) || (command === "assure" && !assureBundleRequested(argv))) {
|
|
1251
1298
|
process.env[REFLECT_ENV] = command
|
|
1252
1299
|
}
|
|
1253
1300
|
try {
|
|
1254
|
-
|
|
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
|
+
}
|
|
1255
1308
|
markReflecting(command)
|
|
1256
1309
|
const output = await catalogSpec.run(input, { cwd: process.cwd(), cliVersion: CLI_VERSION })
|
|
1257
1310
|
markReflecting(undefined)
|
package/src/command-catalog.ts
CHANGED
|
@@ -527,6 +527,8 @@ interface RouteDiffCommandOutput extends DiffCommandOutput {
|
|
|
527
527
|
interface ContractsCommandOutput {
|
|
528
528
|
readonly ok: boolean
|
|
529
529
|
readonly lock?: ContractsLock
|
|
530
|
+
/** `snapshot`: each route whose declared schema the lock records as `null`. */
|
|
531
|
+
readonly unreflected?: readonly { readonly route: string; readonly parts: readonly string[] }[]
|
|
530
532
|
readonly diagnostics?: readonly unknown[]
|
|
531
533
|
readonly present?: boolean
|
|
532
534
|
readonly vacuous?: boolean
|
|
@@ -1989,14 +1991,29 @@ const contractsSpec: CommandSpec<ContractsInput, ContractsCommandOutput> = {
|
|
|
1989
1991
|
async run(value, ctx) {
|
|
1990
1992
|
const mod = await import("./contracts.ts")
|
|
1991
1993
|
if (value.action === "snapshot")
|
|
1992
|
-
return { ok: true,
|
|
1993
|
-
const result = await mod.checkContractsLock(ctx.cwd)
|
|
1994
|
+
return { ok: true, ...(await mod.snapshotContractsReport(ctx.cwd, value.out)) }
|
|
1995
|
+
const result = await mod.checkContractsLock(ctx.cwd, value.out)
|
|
1994
1996
|
return { ok: result.present && result.diagnostics.length === 0, ...result }
|
|
1995
1997
|
},
|
|
1996
|
-
render: (out) =>
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
1998
|
+
render: (out, input) => {
|
|
1999
|
+
const file = input?.out ?? "contracts.lock.json"
|
|
2000
|
+
if (input?.action === "snapshot")
|
|
2001
|
+
return [
|
|
2002
|
+
`✓ wrote ${file} (${Object.keys(out.lock?.routes ?? {}).length} routes)`,
|
|
2003
|
+
...(out.unreflected ?? []).map(
|
|
2004
|
+
(entry) =>
|
|
2005
|
+
` ⚠ ${entry.route}: ${entry.parts.join(", ")} declares a schema nifra cannot read, locked as null - a change to it goes unnoticed`,
|
|
2006
|
+
),
|
|
2007
|
+
]
|
|
2008
|
+
return [
|
|
2009
|
+
out.ok
|
|
2010
|
+
? "✓ contracts are current"
|
|
2011
|
+
: out.present === false
|
|
2012
|
+
? `✖ no ${file}: run \`nifra contracts snapshot\``
|
|
2013
|
+
: "✖ contract drift",
|
|
2014
|
+
...(out.diagnostics ?? []).map((d) => ` ${(d as { message: string }).message}`),
|
|
2015
|
+
]
|
|
2016
|
+
},
|
|
2000
2017
|
success: (out) => out.ok,
|
|
2001
2018
|
}
|
|
2002
2019
|
|