@nifrajs/cli 5.8.0 → 5.9.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 +134 -0
- package/dist/agent-files.d.ts +0 -22
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +3 -1
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +2 -10
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +3 -3
- package/dist/assure.js.map +1 -1
- package/dist/check-scan.d.ts +2 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +54 -86
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts +3 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +20 -23
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +42 -13
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +20 -30
- package/dist/command-catalog.js.map +1 -1
- package/dist/config-target.js +1 -1
- package/dist/config-target.js.map +1 -1
- package/dist/db-child.js +3 -10
- package/dist/db-child.js.map +1 -1
- package/dist/db-config.d.ts +2 -0
- package/dist/db-config.d.ts.map +1 -1
- package/dist/db-config.js +2 -0
- package/dist/db-config.js.map +1 -1
- package/dist/doctor.d.ts +14 -3
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +91 -6
- package/dist/doctor.js.map +1 -1
- package/dist/frontend-guidance.d.ts +19 -0
- package/dist/frontend-guidance.d.ts.map +1 -1
- package/dist/frontend-guidance.js +267 -23
- package/dist/frontend-guidance.js.map +1 -1
- package/dist/hand-built-manifest.d.ts.map +1 -1
- package/dist/hand-built-manifest.js +1 -1
- package/dist/hand-built-manifest.js.map +1 -1
- package/dist/internal/control-character.d.ts +3 -0
- package/dist/internal/control-character.d.ts.map +1 -0
- package/dist/internal/control-character.js +10 -0
- package/dist/internal/control-character.js.map +1 -0
- package/dist/internal/escape-regexp.d.ts +3 -0
- package/dist/internal/escape-regexp.d.ts.map +1 -0
- package/dist/internal/escape-regexp.js +5 -0
- package/dist/internal/escape-regexp.js.map +1 -0
- package/dist/internal/line-at.d.ts +3 -0
- package/dist/internal/line-at.d.ts.map +1 -0
- package/dist/internal/line-at.js +5 -0
- package/dist/internal/line-at.js.map +1 -0
- package/dist/internal/nifra-project.d.ts.map +1 -1
- package/dist/internal/nifra-project.js +35 -41
- package/dist/internal/nifra-project.js.map +1 -1
- package/dist/internal/posix-path.d.ts +3 -0
- package/dist/internal/posix-path.d.ts.map +1 -0
- package/dist/internal/posix-path.js +5 -0
- package/dist/internal/posix-path.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +3 -10
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/realpath-or-self.d.ts +3 -0
- package/dist/internal/realpath-or-self.d.ts.map +1 -0
- package/dist/internal/realpath-or-self.js +11 -0
- package/dist/internal/realpath-or-self.js.map +1 -0
- package/dist/internal/record.d.ts +3 -0
- package/dist/internal/record.d.ts.map +1 -0
- package/dist/internal/record.js +5 -0
- package/dist/internal/record.js.map +1 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +28 -25
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/introspect.d.ts +0 -22
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +11 -151
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts +2 -0
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +54 -64
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +6 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +7 -0
- package/dist/local-cli.d.ts.map +1 -1
- package/dist/local-cli.js +13 -0
- package/dist/local-cli.js.map +1 -1
- package/dist/mcp-docs-tools.d.ts +1 -1
- package/dist/mcp-docs-tools.d.ts.map +1 -1
- package/dist/mcp-docs-tools.js +46 -3
- package/dist/mcp-docs-tools.js.map +1 -1
- package/dist/mcp-http.d.ts +1 -1
- package/dist/mcp-http.js +2 -2
- package/dist/mcp-io.d.ts +16 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +63 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-isolate.d.ts.map +1 -1
- package/dist/mcp-isolate.js +2 -1
- package/dist/mcp-isolate.js.map +1 -1
- package/dist/mcp-project-child.d.ts.map +1 -1
- package/dist/mcp-project-child.js +5 -12
- package/dist/mcp-project-child.js.map +1 -1
- package/dist/mcp-render.d.ts.map +1 -1
- package/dist/mcp-render.js +9 -51
- package/dist/mcp-render.js.map +1 -1
- package/dist/mcp-root.js +1 -1
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp-run.d.ts.map +1 -1
- package/dist/mcp-run.js +3 -46
- package/dist/mcp-run.js.map +1 -1
- package/dist/mcp-ws.d.ts.map +1 -1
- package/dist/mcp-ws.js +2 -18
- package/dist/mcp-ws.js.map +1 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +36 -57
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +7 -7
- package/dist/output-schemas.js.map +1 -1
- package/dist/port.d.ts.map +1 -1
- package/dist/port.js +1 -2
- package/dist/port.js.map +1 -1
- package/dist/ppr-read-fix.js +2 -2
- package/dist/ppr-read-fix.js.map +1 -1
- package/dist/recipes/5.9.0.d.ts +10 -0
- package/dist/recipes/5.9.0.d.ts.map +1 -0
- package/dist/recipes/5.9.0.js +41 -0
- package/dist/recipes/5.9.0.js.map +1 -0
- package/dist/recipes/index.d.ts +5 -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 +9 -13
- package/dist/review.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +3 -9
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +3 -10
- package/dist/rules/data-guard.js.map +1 -1
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +41 -58
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +20 -27
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +206 -313
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -10
- package/dist/rules/zones.js.map +1 -1
- package/dist/runtime-differences.d.ts +62 -0
- package/dist/runtime-differences.d.ts.map +1 -0
- package/dist/runtime-differences.js +222 -0
- package/dist/runtime-differences.js.map +1 -0
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +43 -43
- package/dist/sdk.js.map +1 -1
- package/dist/smoke.d.ts.map +1 -1
- package/dist/smoke.js +4 -12
- package/dist/smoke.js.map +1 -1
- package/dist/source-rewrites.d.ts +27 -0
- package/dist/source-rewrites.d.ts.map +1 -0
- package/dist/source-rewrites.js +402 -0
- package/dist/source-rewrites.js.map +1 -0
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +1 -1
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/symptom-search.d.ts +5 -0
- package/dist/symptom-search.d.ts.map +1 -0
- package/dist/symptom-search.js +21 -0
- package/dist/symptom-search.js.map +1 -0
- package/dist/upgrade.d.ts +28 -3
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +153 -64
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +5 -3
- package/dist/verification-plan.js.map +1 -1
- package/docs/examples.json +32 -2
- package/docs/llms-full.txt +749 -95
- package/docs/types.json +300 -61
- package/package.json +11 -11
- package/src/agent-files.ts +4 -1
- package/src/assure-hydration.ts +2 -9
- package/src/assure.ts +3 -4
- package/src/check-scan.ts +65 -82
- package/src/check.ts +25 -23
- package/src/cli.ts +61 -13
- package/src/command-catalog.ts +22 -32
- package/src/config-target.ts +1 -1
- package/src/db-child.ts +3 -10
- package/src/db-config.ts +4 -0
- package/src/doctor.ts +128 -12
- package/src/frontend-guidance.ts +344 -25
- package/src/hand-built-manifest.ts +1 -2
- package/src/internal/control-character.ts +8 -0
- package/src/internal/escape-regexp.ts +4 -0
- package/src/internal/line-at.ts +4 -0
- package/src/internal/nifra-project.ts +39 -35
- package/src/internal/posix-path.ts +4 -0
- package/src/internal/project-specifiers.ts +3 -10
- package/src/internal/realpath-or-self.ts +10 -0
- package/src/internal/record.ts +4 -0
- package/src/internal/source-facts.ts +39 -29
- package/src/introspect.ts +16 -156
- package/src/levels-tool.ts +71 -78
- package/src/load.ts +6 -1
- package/src/local-cli.ts +12 -0
- package/src/mcp-docs-tools.ts +51 -3
- package/src/mcp-http.ts +2 -2
- package/src/mcp-io.ts +77 -0
- package/src/mcp-isolate.ts +2 -3
- package/src/mcp-project-child.ts +5 -14
- package/src/mcp-render.ts +11 -59
- package/src/mcp-root.ts +1 -1
- package/src/mcp-run.ts +5 -54
- package/src/mcp-ws.ts +2 -19
- package/src/migrate-layout.ts +52 -72
- package/src/output-schemas.ts +7 -8
- package/src/port.ts +1 -4
- package/src/ppr-read-fix.ts +2 -2
- package/src/recipes/5.9.0.ts +42 -0
- package/src/recipes/index.ts +7 -0
- package/src/review.ts +12 -15
- package/src/rules/contract-visibility.ts +3 -8
- package/src/rules/data-guard.ts +3 -10
- package/src/rules/pages.ts +47 -58
- package/src/rules/routes.ts +21 -27
- package/src/rules/security.ts +224 -255
- package/src/rules/zones.ts +3 -10
- package/src/runtime-differences.ts +302 -0
- package/src/sdk.ts +55 -58
- package/src/smoke.ts +4 -13
- package/src/source-rewrites.ts +463 -0
- package/src/stylex-migrate.ts +1 -3
- package/src/symptom-search.ts +27 -0
- package/src/upgrade.ts +194 -74
- package/src/verification-plan.ts +10 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nifrajs/cli",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.9.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.9.0",
|
|
74
|
+
"@nifrajs/core": "5.9.0",
|
|
75
|
+
"@nifrajs/agent-review": "5.9.0",
|
|
76
|
+
"@nifrajs/i18n": "5.9.0",
|
|
77
|
+
"@nifrajs/mcp": "5.9.0",
|
|
78
|
+
"@nifrajs/mcp-db": "5.9.0",
|
|
79
|
+
"@nifrajs/runner": "5.9.0",
|
|
80
|
+
"@nifrajs/schema": "5.9.0",
|
|
81
|
+
"@nifrajs/testing": "5.9.0",
|
|
82
|
+
"@nifrajs/web": "5.9.0"
|
|
83
83
|
},
|
|
84
84
|
"repository": {
|
|
85
85
|
"type": "git",
|
package/src/agent-files.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Generated by scripts/gen-vendored.ts - edit packages/create-nifra/src/agent-files.ts instead.
|
|
2
|
+
// Copied so `nifra init-agents` writes what a scaffold writes, without depending on create-nifra.
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* The canonical generators for the agent files an app ships. `AGENTS.md` is the single source of agent
|
|
3
6
|
* guidance; every other agent's file is a thin pointer to it, so no two copies can drift:
|
|
@@ -10,7 +13,7 @@
|
|
|
10
13
|
* .mcp.json, .cursor/mcp.json - the nifra MCP server, registered for Claude Code and Cursor
|
|
11
14
|
*
|
|
12
15
|
* `create-nifra` (scaffold time) and `@nifrajs/cli`'s `nifra init-agents` (retrofit an existing app) each
|
|
13
|
-
* ship this file byte-identical - `
|
|
16
|
+
* ship this file byte-identical - the CLI's is generated from this one (`scripts/gen-vendored.ts`) - so
|
|
14
17
|
* the generated files can never drift apart and neither package needs the other at runtime. It stays
|
|
15
18
|
* dependency-free (pure string + object generation) on purpose: `create-nifra` ships with no runtime deps.
|
|
16
19
|
*
|
package/src/assure-hydration.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
forwardTerminalSignals,
|
|
18
18
|
joinHeadTail,
|
|
19
19
|
OWN_PROCESS_GROUP,
|
|
20
|
+
protocolStdout,
|
|
20
21
|
readBoundedStream,
|
|
21
22
|
readHeadTail,
|
|
22
23
|
signalProcessGroup,
|
|
@@ -700,15 +701,7 @@ export async function runHydrationAssurance(
|
|
|
700
701
|
}
|
|
701
702
|
|
|
702
703
|
if (import.meta.main && process.argv.includes("--nifra-hydration-child")) {
|
|
703
|
-
|
|
704
|
-
// never reaches the answer channel.
|
|
705
|
-
const stdout = process.stdout.write.bind(process.stdout)
|
|
706
|
-
const toStderr = (...args: unknown[]): void => {
|
|
707
|
-
process.stderr.write(`${args.map((arg) => String(arg)).join(" ")}\n`)
|
|
708
|
-
}
|
|
709
|
-
console.log = toStderr
|
|
710
|
-
console.info = toStderr
|
|
711
|
-
console.debug = toStderr
|
|
704
|
+
const stdout = protocolStdout()
|
|
712
705
|
const token = (await readBoundedStream(Bun.stdin.stream(), 256)).text.trim()
|
|
713
706
|
const cwd = process.argv[2] ?? process.cwd()
|
|
714
707
|
const rawOptions = process.argv[4]
|
package/src/assure.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { pathToFileURL } from "node:url"
|
|
|
6
6
|
import type { AssuranceConfig, AssuranceReport, AssuredRoute } from "@nifrajs/core/assurance"
|
|
7
7
|
import { CONFIG_FILE, FRAMEWORK_FILE } from "./app-files.ts"
|
|
8
8
|
import type { Diagnostic } from "./diagnostics.ts"
|
|
9
|
+
import { toPosix } from "./internal/posix-path.ts"
|
|
9
10
|
import type { ProjectVerification } from "./verification.ts"
|
|
10
11
|
|
|
11
12
|
export interface AssureSink {
|
|
@@ -60,8 +61,6 @@ export function createMemoryAssureSink(): MemoryAssureSink {
|
|
|
60
61
|
|
|
61
62
|
export const DEFAULT_ASSURANCE_CONFIG = "nifra.assurance.ts"
|
|
62
63
|
|
|
63
|
-
const displayPath = (path: string): string => path.replaceAll("\\", "/")
|
|
64
|
-
|
|
65
64
|
function isConfig(value: unknown): value is AssuranceConfig {
|
|
66
65
|
if (typeof value !== "object" || value === null) return false
|
|
67
66
|
const candidate = value as Partial<AssuranceConfig>
|
|
@@ -79,7 +78,7 @@ export async function loadAssuranceConfig(
|
|
|
79
78
|
const path = resolve(cwd, configPath)
|
|
80
79
|
if (!existsSync(path)) {
|
|
81
80
|
throw new Error(
|
|
82
|
-
`[nifra] route assurance config not found: ${
|
|
81
|
+
`[nifra] route assurance config not found: ${toPosix(path)} - create ${DEFAULT_ASSURANCE_CONFIG} with a default defineAssuranceConfig({ source, policy }) export.`,
|
|
83
82
|
)
|
|
84
83
|
}
|
|
85
84
|
const specifier = pathToFileURL(path)
|
|
@@ -97,7 +96,7 @@ export async function loadAssuranceConfig(
|
|
|
97
96
|
}
|
|
98
97
|
if (!isConfig(loaded.default)) {
|
|
99
98
|
throw new Error(
|
|
100
|
-
`[nifra] ${
|
|
99
|
+
`[nifra] ${toPosix(path)} must default-export defineAssuranceConfig({ source, policy }).`,
|
|
101
100
|
)
|
|
102
101
|
}
|
|
103
102
|
return loaded.default
|
package/src/check-scan.ts
CHANGED
|
@@ -12,6 +12,9 @@ import { Glob } from "bun"
|
|
|
12
12
|
import type * as TSApi from "typescript"
|
|
13
13
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
14
14
|
import { gitIgnored } from "./internal/git-ignored.ts"
|
|
15
|
+
import { lineAt } from "./internal/line-at.ts"
|
|
16
|
+
import { toPosix } from "./internal/posix-path.ts"
|
|
17
|
+
import { realpathOrSelf } from "./internal/realpath-or-self.ts"
|
|
15
18
|
import { scriptKindOf } from "./internal/script-kind.ts"
|
|
16
19
|
import type { SourceFacts } from "./internal/source-facts.ts"
|
|
17
20
|
import {
|
|
@@ -79,7 +82,7 @@ const IGNORED = new RegExp(`${IGNORED_DIR.source}|${TEST_FILE.source}`)
|
|
|
79
82
|
|
|
80
83
|
/** Paths crossing the scanner boundary are project-relative identifiers, not filesystem paths. Keep
|
|
81
84
|
* them stable across runtimes so rules, diagnostics, ignore globs, and import chains have one shape. */
|
|
82
|
-
const normalizeProjectPath =
|
|
85
|
+
const normalizeProjectPath = toPosix
|
|
83
86
|
|
|
84
87
|
// Browser code by path, mirroring `@nifrajs/web/zones`: a suffix decides first, then the folder. A
|
|
85
88
|
// route's backend half (`x.backend.ts`), `backend/` and `*.fn.ts` run on the server only.
|
|
@@ -218,10 +221,6 @@ interface SimpleFetchCall {
|
|
|
218
221
|
readonly end: number
|
|
219
222
|
}
|
|
220
223
|
|
|
221
|
-
/** Line number (1-based) of a match index within `content`. */
|
|
222
|
-
const lineAt = (content: string, index: number): number =>
|
|
223
|
-
content.slice(0, index).split("\n").length
|
|
224
|
-
|
|
225
224
|
function parseQuotedLiteral(raw: string): string | undefined {
|
|
226
225
|
try {
|
|
227
226
|
return JSON.parse(raw) as string
|
|
@@ -253,59 +252,51 @@ function parseQuotedLiteral(raw: string): string | undefined {
|
|
|
253
252
|
}
|
|
254
253
|
}
|
|
255
254
|
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
/**
|
|
256
|
+
* Calls `visit` with each index from `from` whose character sits outside a string literal, until it
|
|
257
|
+
* returns true. Returns that index, `src.length` when the scan ran out, or -1 when it ran out inside a
|
|
258
|
+
* literal left open.
|
|
259
|
+
*/
|
|
260
|
+
function scanOutsideStrings(src: string, from: number, visit: (index: number) => boolean): number {
|
|
258
261
|
let quote: '"' | "'" | "`" | undefined
|
|
259
|
-
for (let i =
|
|
262
|
+
for (let i = from; i < src.length; i++) {
|
|
260
263
|
const c = src[i]
|
|
261
264
|
if (quote !== undefined) {
|
|
262
|
-
if (c === "\\")
|
|
263
|
-
|
|
264
|
-
continue
|
|
265
|
-
}
|
|
266
|
-
if (c === quote) quote = undefined
|
|
267
|
-
continue
|
|
268
|
-
}
|
|
269
|
-
if (c === '"' || c === "'" || c === "`") {
|
|
270
|
-
quote = c
|
|
265
|
+
if (c === "\\") i++
|
|
266
|
+
else if (c === quote) quote = undefined
|
|
271
267
|
continue
|
|
272
268
|
}
|
|
273
|
-
if (c === "
|
|
274
|
-
else if (
|
|
275
|
-
depth--
|
|
276
|
-
if (depth === 0) return i
|
|
277
|
-
}
|
|
269
|
+
if (c === '"' || c === "'" || c === "`") quote = c
|
|
270
|
+
else if (visit(i)) return i
|
|
278
271
|
}
|
|
279
|
-
return undefined
|
|
272
|
+
return quote === undefined ? src.length : -1
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function findMatchingParen(src: string, openIndex: number): number | undefined {
|
|
276
|
+
let depth = 0
|
|
277
|
+
const end = scanOutsideStrings(src, openIndex, (i) => {
|
|
278
|
+
if (src[i] === "(") depth++
|
|
279
|
+
else if (src[i] === ")") return --depth === 0
|
|
280
|
+
return false
|
|
281
|
+
})
|
|
282
|
+
return end >= 0 && end < src.length ? end : undefined
|
|
280
283
|
}
|
|
281
284
|
|
|
282
285
|
function splitTopLevelArgs(src: string): string[] | undefined {
|
|
283
286
|
const args: string[] = []
|
|
284
287
|
let start = 0
|
|
285
288
|
let depth = 0
|
|
286
|
-
|
|
287
|
-
for (let i = 0; i < src.length; i++) {
|
|
289
|
+
const end = scanOutsideStrings(src, 0, (i) => {
|
|
288
290
|
const c = src[i]
|
|
289
|
-
if (quote !== undefined) {
|
|
290
|
-
if (c === "\\") {
|
|
291
|
-
i++
|
|
292
|
-
continue
|
|
293
|
-
}
|
|
294
|
-
if (c === quote) quote = undefined
|
|
295
|
-
continue
|
|
296
|
-
}
|
|
297
|
-
if (c === '"' || c === "'" || c === "`") {
|
|
298
|
-
quote = c
|
|
299
|
-
continue
|
|
300
|
-
}
|
|
301
291
|
if (c === "(" || c === "{" || c === "[") depth++
|
|
302
292
|
else if (c === ")" || c === "}" || c === "]") depth--
|
|
303
293
|
else if (c === "," && depth === 0) {
|
|
304
294
|
args.push(src.slice(start, i).trim())
|
|
305
295
|
start = i + 1
|
|
306
296
|
}
|
|
307
|
-
|
|
308
|
-
|
|
297
|
+
return false
|
|
298
|
+
})
|
|
299
|
+
if (end < 0 || depth !== 0) return undefined
|
|
309
300
|
const tail = src.slice(start).trim()
|
|
310
301
|
if (tail !== "") args.push(tail)
|
|
311
302
|
return args
|
|
@@ -643,26 +634,14 @@ function matchesExternalMount(content: string, start: number, mounts: readonly s
|
|
|
643
634
|
|
|
644
635
|
function findTopLevelPropertyColon(src: string): number | undefined {
|
|
645
636
|
let depth = 0
|
|
646
|
-
|
|
647
|
-
for (let i = 0; i < src.length; i++) {
|
|
637
|
+
const end = scanOutsideStrings(src, 0, (i) => {
|
|
648
638
|
const c = src[i]
|
|
649
|
-
if (quote !== undefined) {
|
|
650
|
-
if (c === "\\") {
|
|
651
|
-
i++
|
|
652
|
-
continue
|
|
653
|
-
}
|
|
654
|
-
if (c === quote) quote = undefined
|
|
655
|
-
continue
|
|
656
|
-
}
|
|
657
|
-
if (c === '"' || c === "'" || c === "`") {
|
|
658
|
-
quote = c
|
|
659
|
-
continue
|
|
660
|
-
}
|
|
661
639
|
if (c === "(" || c === "{" || c === "[") depth++
|
|
662
640
|
else if (c === ")" || c === "}" || c === "]") depth--
|
|
663
|
-
else
|
|
664
|
-
|
|
665
|
-
|
|
641
|
+
else return c === ":" && depth === 0
|
|
642
|
+
return false
|
|
643
|
+
})
|
|
644
|
+
return end >= 0 && end < src.length ? end : undefined
|
|
666
645
|
}
|
|
667
646
|
|
|
668
647
|
function parseStaticPropertyName(raw: string): string | undefined {
|
|
@@ -711,18 +690,33 @@ export function scanFetchText(
|
|
|
711
690
|
file: string,
|
|
712
691
|
content: string,
|
|
713
692
|
externalMounts: readonly string[] = [],
|
|
693
|
+
): TypedClientFinding[] {
|
|
694
|
+
return ownPathCalls(file, content, GLOBAL_FETCH_CALL, externalMounts, (m) =>
|
|
695
|
+
hasLiteralNifraDataHeader(content, m.index + m[0].lastIndexOf("(")),
|
|
696
|
+
)
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* A finding for each `pattern` match in code whose first argument is a literal own-API path (`"/…"`,
|
|
701
|
+
* not `"//…"`), unless it falls under one of `externalMounts` or `skip` passes it.
|
|
702
|
+
*/
|
|
703
|
+
function ownPathCalls(
|
|
704
|
+
file: string,
|
|
705
|
+
content: string,
|
|
706
|
+
pattern: RegExp,
|
|
707
|
+
externalMounts: readonly string[],
|
|
708
|
+
skip?: (match: RegExpExecArray) => boolean,
|
|
714
709
|
): TypedClientFinding[] {
|
|
715
710
|
const out: TypedClientFinding[] = []
|
|
716
711
|
const lines = content.split("\n")
|
|
717
712
|
const code = codePositionMask(content)
|
|
718
|
-
|
|
719
|
-
for (let m =
|
|
713
|
+
pattern.lastIndex = 0
|
|
714
|
+
for (let m = pattern.exec(code); m !== null; m = pattern.exec(code)) {
|
|
720
715
|
const argument = firstArgumentIndex(content, m.index + m[0].length)
|
|
721
716
|
const quote = content[argument]
|
|
722
717
|
if (quote !== "'" && quote !== '"' && quote !== "`") continue
|
|
723
718
|
if (content[argument + 1] !== "/" || content[argument + 2] === "/") continue
|
|
724
|
-
|
|
725
|
-
if (hasLiteralNifraDataHeader(content, openParen)) continue
|
|
719
|
+
if (skip?.(m) === true) continue
|
|
726
720
|
if (externalMounts.length > 0 && matchesExternalMount(content, argument + 1, externalMounts))
|
|
727
721
|
continue
|
|
728
722
|
out.push(typedClientFinding(file, lines, lineAt(content, m.index)))
|
|
@@ -749,20 +743,7 @@ export function scanStreamText(
|
|
|
749
743
|
content: string,
|
|
750
744
|
externalMounts: readonly string[] = [],
|
|
751
745
|
): TypedClientFinding[] {
|
|
752
|
-
|
|
753
|
-
const lines = content.split("\n")
|
|
754
|
-
const code = codePositionMask(content)
|
|
755
|
-
STREAM_CONSTRUCT.lastIndex = 0
|
|
756
|
-
for (let m = STREAM_CONSTRUCT.exec(code); m !== null; m = STREAM_CONSTRUCT.exec(code)) {
|
|
757
|
-
const argument = firstArgumentIndex(content, m.index + m[0].length)
|
|
758
|
-
const quote = content[argument]
|
|
759
|
-
if (quote !== "'" && quote !== '"' && quote !== "`") continue
|
|
760
|
-
if (content[argument + 1] !== "/" || content[argument + 2] === "/") continue
|
|
761
|
-
if (externalMounts.length > 0 && matchesExternalMount(content, argument + 1, externalMounts))
|
|
762
|
-
continue
|
|
763
|
-
out.push(typedClientFinding(file, lines, lineAt(content, m.index)))
|
|
764
|
-
}
|
|
765
|
-
return out
|
|
746
|
+
return ownPathCalls(file, content, STREAM_CONSTRUCT, externalMounts)
|
|
766
747
|
}
|
|
767
748
|
|
|
768
749
|
/** Statically collect simple Nifra route registrations from source, without importing app code. */
|
|
@@ -2733,13 +2714,7 @@ const SQL_SOURCE_FILE = /\.[cm]?tsx?$/
|
|
|
2733
2714
|
* flagged - the pre-feature answer.
|
|
2734
2715
|
*/
|
|
2735
2716
|
export function createProjectSqlImports(cwd: string): SqlImports {
|
|
2736
|
-
const root = (()
|
|
2737
|
-
try {
|
|
2738
|
-
return realpathSync(resolve(cwd))
|
|
2739
|
-
} catch {
|
|
2740
|
-
return resolve(cwd)
|
|
2741
|
-
}
|
|
2742
|
-
})()
|
|
2717
|
+
const root = realpathOrSelf(resolve(cwd))
|
|
2743
2718
|
return createSqlImports((fromModule, specifier) => {
|
|
2744
2719
|
if (!isRelativeSpecifier(specifier)) return undefined
|
|
2745
2720
|
try {
|
|
@@ -3496,6 +3471,8 @@ export async function walkSource(
|
|
|
3496
3471
|
* files in a zone. A `.svelte`/`.vue` file is visited as {@link componentScripts}.
|
|
3497
3472
|
*/
|
|
3498
3473
|
readonly scripts?: boolean
|
|
3474
|
+
/** With `scripts`, every `.js` file too: in a library package, plain `.js` is its code, not tooling. */
|
|
3475
|
+
readonly library?: boolean
|
|
3499
3476
|
} = {},
|
|
3500
3477
|
): Promise<void> {
|
|
3501
3478
|
const skip = opts.includeTests === true ? IGNORED_DIR : IGNORED
|
|
@@ -3510,7 +3487,13 @@ export async function walkSource(
|
|
|
3510
3487
|
// A backslash is a filename character on POSIX; only Windows separators need normalizing.
|
|
3511
3488
|
const rel = sep === "\\" ? normalizeProjectPath(rawRel) : rawRel
|
|
3512
3489
|
// A `.js` file outside a zone is tooling (a bundler config, a script, a vendored asset), not app code.
|
|
3513
|
-
if (
|
|
3490
|
+
if (
|
|
3491
|
+
opts.library !== true &&
|
|
3492
|
+
PLAIN_SCRIPT_FILE.test(rel) &&
|
|
3493
|
+
!ZONE_DIRECTORY.test(rel) &&
|
|
3494
|
+
!ZONE_SUFFIX.test(rel)
|
|
3495
|
+
)
|
|
3496
|
+
continue
|
|
3514
3497
|
if (!skip.test(rel) && (opts.ignore === undefined || !opts.ignore(rel))) rels.push(rel)
|
|
3515
3498
|
}
|
|
3516
3499
|
const ignored = await gitIgnored(cwd, rels)
|
package/src/check.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* anything fails. Pure scanners (`scanFetchText`, `scanServerOnlyImports`) are unit-tested.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { existsSync, mkdtempSync, readFileSync,
|
|
19
|
+
import { existsSync, mkdtempSync, readFileSync, rmdirSync, rmSync } from "node:fs"
|
|
20
20
|
import { tmpdir } from "node:os"
|
|
21
21
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path"
|
|
22
22
|
import { declaredSide, specifierPackage } from "@nifrajs/web/zones"
|
|
@@ -32,10 +32,11 @@ import {
|
|
|
32
32
|
} from "./check-diagnostics.ts"
|
|
33
33
|
import { appDirs, clientModuleRoot } from "./client-module.ts"
|
|
34
34
|
import { checkContractsLock, DEFAULT_CONTRACTS_LOCK } from "./contracts.ts"
|
|
35
|
-
import { type Diagnostic, normalizeSeverity, toSarifLog } from "./diagnostics.ts"
|
|
35
|
+
import { type Diagnostic, diagnostic, normalizeSeverity, toSarifLog } from "./diagnostics.ts"
|
|
36
36
|
import { installedManifest } from "./internal/installed-package.ts"
|
|
37
37
|
import { createApiOnlyProbe, createNifraProjectProbe } from "./internal/nifra-project.ts"
|
|
38
38
|
import { createSpecifierResolver } from "./internal/project-specifiers.ts"
|
|
39
|
+
import { realpathOrSelf } from "./internal/realpath-or-self.ts"
|
|
39
40
|
import { createSourceFacts } from "./internal/source-facts.ts"
|
|
40
41
|
import { loadProjectTypeScript, type TypeScriptApi } from "./internal/typescript-import.ts"
|
|
41
42
|
import {
|
|
@@ -262,7 +263,7 @@ async function loadCheckConfig(
|
|
|
262
263
|
const raw = Array.isArray(parsed.externalMounts) ? parsed.externalMounts : []
|
|
263
264
|
const externalMounts = raw
|
|
264
265
|
.filter((m): m is string => typeof m === "string" && m.startsWith("/"))
|
|
265
|
-
.map((m) => m.replace(/\/\*+$/, "").replace(
|
|
266
|
+
.map((m) => m.replace(/\/\*+$/, "").replace(/(?<!\/)\/+$/, "") || "/")
|
|
266
267
|
const warnings: string[] = []
|
|
267
268
|
const rules: Record<string, RuleOverride> = {}
|
|
268
269
|
if (parsed.rules !== undefined) {
|
|
@@ -462,13 +463,7 @@ async function buildProjectScan(
|
|
|
462
463
|
// Resolved modules stay project-relative, as the scanned files are: the zone of a path is read
|
|
463
464
|
// from its folders, and a checkout under a folder named `backend/` must not make it all backend.
|
|
464
465
|
// The resolver answers with real paths, so the project root is read as one too.
|
|
465
|
-
const realCwd = (
|
|
466
|
-
try {
|
|
467
|
-
return realpathSync(cwd)
|
|
468
|
-
} catch {
|
|
469
|
-
return cwd
|
|
470
|
-
}
|
|
471
|
-
})()
|
|
466
|
+
const realCwd = realpathOrSelf(cwd)
|
|
472
467
|
const resolveSpecifier = createSpecifierResolver()
|
|
473
468
|
const sourceFacts =
|
|
474
469
|
sqlCompiler === undefined
|
|
@@ -792,6 +787,25 @@ function belowError(warnings: number, infos: number): string {
|
|
|
792
787
|
return parts.join(", ")
|
|
793
788
|
}
|
|
794
789
|
|
|
790
|
+
/** The check's findings as structured diagnostics: the collector's own, else each report entry mapped over. */
|
|
791
|
+
export function checkDiagnostics(result: CheckResult): readonly Diagnostic[] {
|
|
792
|
+
return (
|
|
793
|
+
result.structuredDiagnostics ??
|
|
794
|
+
result.diagnostics.map((value) =>
|
|
795
|
+
diagnostic({
|
|
796
|
+
code: value.code ?? value.rule,
|
|
797
|
+
severity: normalizeSeverity(value.severity),
|
|
798
|
+
message: value.message,
|
|
799
|
+
...(value.file === undefined ? {} : { file: value.file }),
|
|
800
|
+
...(value.line === undefined ? {} : { line: value.line }),
|
|
801
|
+
...(value.evidence === undefined ? {} : { evidence: value.evidence }),
|
|
802
|
+
...(value.fix === undefined ? {} : { fix: { recipe: value.fix } }),
|
|
803
|
+
...(value.verify === undefined ? {} : { verify: value.verify }),
|
|
804
|
+
}),
|
|
805
|
+
)
|
|
806
|
+
)
|
|
807
|
+
}
|
|
808
|
+
|
|
795
809
|
/** Run the full check; print a report (`--json` for machine output) and return whether it passed. */
|
|
796
810
|
export async function runCheck(
|
|
797
811
|
cwd: string,
|
|
@@ -807,19 +821,7 @@ export async function runCheck(
|
|
|
807
821
|
const verification = await collectProjectVerification(cwd, { lintsOnly: opts.lintsOnly ?? false })
|
|
808
822
|
const result = await verification.check()
|
|
809
823
|
if (opts.sarif) {
|
|
810
|
-
|
|
811
|
-
result.structuredDiagnostics ??
|
|
812
|
-
result.diagnostics.map((value) => ({
|
|
813
|
-
code: value.code ?? value.rule,
|
|
814
|
-
severity: normalizeSeverity(value.severity),
|
|
815
|
-
message: value.message,
|
|
816
|
-
...(value.file === undefined ? {} : { file: value.file }),
|
|
817
|
-
...(value.line === undefined ? {} : { line: value.line }),
|
|
818
|
-
...(value.evidence === undefined ? {} : { evidence: value.evidence }),
|
|
819
|
-
...(value.fix === undefined ? {} : { fix: { recipe: value.fix } }),
|
|
820
|
-
...(value.verify === undefined ? {} : { verify: value.verify }),
|
|
821
|
-
}))
|
|
822
|
-
console.log(JSON.stringify(toSarifLog(diagnostics), null, 2))
|
|
824
|
+
console.log(JSON.stringify(toSarifLog(checkDiagnostics(result)), null, 2))
|
|
823
825
|
return result.ok
|
|
824
826
|
}
|
|
825
827
|
if (opts.json) {
|
package/src/cli.ts
CHANGED
|
@@ -215,10 +215,15 @@ Usage:
|
|
|
215
215
|
nifra_explain (structured errors), nifra_inspect (request
|
|
216
216
|
traces), nifra_learn (guided build path).
|
|
217
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) -
|
|
218
|
+
nifra_types, nifra_learn, nifra_frontend, nifra_runtime, nifra_gallery) -
|
|
219
219
|
self-host on a VPS so any remote agent can learn nifra. Default :8787.
|
|
220
220
|
nifra learn [<step>] Print the guided build-an-app path (the human view of nifra_learn):
|
|
221
221
|
no arg for the step index, a number for one step's goal/do/verify.
|
|
222
|
+
nifra frontend [<adapter>] [<symptom>] [--json]
|
|
223
|
+
Print the frontend gotcha catalog (the human view of nifra_frontend).
|
|
224
|
+
nifra runtime [<runtime>] [<symptom>] [--json]
|
|
225
|
+
Print where Bun, Node, Deno and Workers differ (the human view of
|
|
226
|
+
nifra_runtime): cause, fix and how to verify, with measured versions.
|
|
222
227
|
nifra check [--json] [--sarif] [--lints-only]
|
|
223
228
|
Gate: typecheck + lints (hand-rolled fetch(), untyped client("…"),
|
|
224
229
|
backend code in browser code). Run as "done"; --json for agents;
|
|
@@ -349,7 +354,7 @@ set in the process environment is never overwritten by a file.
|
|
|
349
354
|
${renderCommandCatalogHelp()}`
|
|
350
355
|
|
|
351
356
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
352
|
-
const CLI_VERSION = "5.
|
|
357
|
+
const CLI_VERSION = "5.9.0"
|
|
353
358
|
|
|
354
359
|
// A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
|
|
355
360
|
const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
|
|
@@ -949,6 +954,7 @@ async function buildForTarget(
|
|
|
949
954
|
...(fw.cssCodeSplit !== undefined ? { cssCodeSplit: fw.cssCodeSplit } : {}),
|
|
950
955
|
...(fw.cssLoading !== undefined ? { cssLoading: fw.cssLoading } : {}),
|
|
951
956
|
...(fw.clientIp !== undefined ? { clientIp: fw.clientIp } : {}),
|
|
957
|
+
...(fw.selfHost !== undefined ? { selfHost: fw.selfHost } : {}),
|
|
952
958
|
live: fw.live?.clientEntry,
|
|
953
959
|
// Prerendering drives a built app: the static target is made of its pages, and a bun or node server
|
|
954
960
|
// answers its prerendered pages from their file. Not under Vite, whose server bundle may rely on
|
|
@@ -1170,6 +1176,36 @@ function exitIfHeldOpen(command: string): void {
|
|
|
1170
1176
|
/** Set on the copy of `nifra mcp` that serves without `.env` files, so it does not restart again. */
|
|
1171
1177
|
const MCP_WITHOUT_ENV_FILES = "NIFRA_MCP_WITHOUT_ENV_FILES"
|
|
1172
1178
|
|
|
1179
|
+
/** Parsed arguments for the project-independent `nifra frontend` command. */
|
|
1180
|
+
export interface FrontendCommandInput {
|
|
1181
|
+
readonly adapter?: string | undefined
|
|
1182
|
+
readonly symptom?: string | undefined
|
|
1183
|
+
readonly json: boolean
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
/** Parse frontend positionals separately from flags so `--json` never becomes a symptom. */
|
|
1187
|
+
export function frontendCommandInput(
|
|
1188
|
+
argv: readonly string[],
|
|
1189
|
+
parseAdapter: (value: string | undefined) => string | undefined,
|
|
1190
|
+
): FrontendCommandInput {
|
|
1191
|
+
const unknown = argv.find(
|
|
1192
|
+
(arg) => arg.startsWith("-") && arg !== "--json" && arg !== "--help" && arg !== "-h",
|
|
1193
|
+
)
|
|
1194
|
+
if (unknown !== undefined)
|
|
1195
|
+
throw new Error(`[nifra] unknown option: ${unknown} - see \`nifra help\``)
|
|
1196
|
+
const positional = argv.filter((arg) => !arg.startsWith("-"))
|
|
1197
|
+
const first = positional[0]
|
|
1198
|
+
const maybeAdapter = parseAdapter(first)
|
|
1199
|
+
const adapter = maybeAdapter === undefined ? undefined : first
|
|
1200
|
+
const symptom = (maybeAdapter === undefined ? positional : positional.slice(1)).join(" ")
|
|
1201
|
+
return {
|
|
1202
|
+
adapter,
|
|
1203
|
+
symptom: symptom.length > 0 ? symptom : undefined,
|
|
1204
|
+
json: argv.includes("--json"),
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
/** Dispatch a CLI invocation, including project-independent agent and documentation commands. */
|
|
1173
1209
|
async function main(): Promise<void> {
|
|
1174
1210
|
const { argv: rawArgv, files: envFiles } = takeEnvFileFlags(cliArgv())
|
|
1175
1211
|
// `nifra mcp` keeps none of the `.env` values Bun loaded at startup. Decided before the
|
|
@@ -1265,18 +1301,30 @@ async function main(): Promise<void> {
|
|
|
1265
1301
|
// Project-independent and static. `nifra frontend` for the index, `nifra frontend vue "lost reactivity"`
|
|
1266
1302
|
// to filter by adapter and/or symptom (either arg may be omitted; an adapter is recognized by name).
|
|
1267
1303
|
if (command === "frontend") {
|
|
1268
|
-
const { renderFrontendResult, parseAdapter } = await import(
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
const
|
|
1272
|
-
const symptom = (maybeAdapter === undefined ? argv.slice(1) : argv.slice(2))
|
|
1273
|
-
.filter((a) => !a.startsWith("-"))
|
|
1274
|
-
.join(" ")
|
|
1304
|
+
const { selectFrontendGuidance, renderFrontendResult, parseAdapter } = await import(
|
|
1305
|
+
"./frontend-guidance.ts"
|
|
1306
|
+
)
|
|
1307
|
+
const input = frontendCommandInput(argv.slice(1), parseAdapter)
|
|
1275
1308
|
console.log(
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1309
|
+
input.json
|
|
1310
|
+
? JSON.stringify(selectFrontendGuidance(input), null, 2)
|
|
1311
|
+
: renderFrontendResult(input),
|
|
1312
|
+
)
|
|
1313
|
+
return
|
|
1314
|
+
}
|
|
1315
|
+
// `runtime` prints the Bun/Node/Deno/Workers differences catalog (the human head of `nifra_runtime`).
|
|
1316
|
+
// Project-independent and static. `nifra runtime` for the index, `nifra runtime deno "path guard"` to
|
|
1317
|
+
// filter by runtime and/or symptom (either arg may be omitted; a runtime is recognized by name).
|
|
1318
|
+
if (command === "runtime") {
|
|
1319
|
+
const { selectRuntimeDifferences, renderRuntimeResult, parseRuntime } = await import(
|
|
1320
|
+
"./runtime-differences.ts"
|
|
1321
|
+
)
|
|
1322
|
+
const input = frontendCommandInput(argv.slice(1), parseRuntime)
|
|
1323
|
+
const query = { runtime: input.adapter, symptom: input.symptom }
|
|
1324
|
+
console.log(
|
|
1325
|
+
input.json
|
|
1326
|
+
? JSON.stringify(selectRuntimeDifferences(query), null, 2)
|
|
1327
|
+
: renderRuntimeResult(query),
|
|
1280
1328
|
)
|
|
1281
1329
|
return
|
|
1282
1330
|
}
|
package/src/command-catalog.ts
CHANGED
|
@@ -14,11 +14,11 @@ import type {
|
|
|
14
14
|
CapabilitySnapshotCommandResult,
|
|
15
15
|
} from "./capabilities-tool.ts"
|
|
16
16
|
import { cdnCheckSpec } from "./cdn-check.ts"
|
|
17
|
-
import { type CheckResult, renderCheckReport } from "./check.ts"
|
|
17
|
+
import { type CheckResult, checkDiagnostics, renderCheckReport } from "./check.ts"
|
|
18
18
|
import type { ContractsLock } from "./contracts.ts"
|
|
19
19
|
import { dbAuditSpec, dbQuerySpec, dbRoleSpec, dbSchemaSpec } from "./db-tool.ts"
|
|
20
20
|
import { errorsSpec, explainSpec, logsSpec } from "./dev-feed-tool.ts"
|
|
21
|
-
import {
|
|
21
|
+
import { toSarifLog } from "./diagnostics.ts"
|
|
22
22
|
import type { DoctorResult } from "./doctor.ts"
|
|
23
23
|
import { type I18nCheckOutput, i18nCheckPassed, renderI18nCheck } from "./i18n-check.ts"
|
|
24
24
|
import type { VerificationLevelsResult } from "./levels-tool.ts"
|
|
@@ -936,6 +936,17 @@ const SYNC_SCHEMA = input<SyncInput>(
|
|
|
936
936
|
},
|
|
937
937
|
)
|
|
938
938
|
|
|
939
|
+
/** What both sync commands answer, `{ ok, results }`, and their one flag. */
|
|
940
|
+
const syncOutput = <Output>(): CommandOutputContract<Output> =>
|
|
941
|
+
output({
|
|
942
|
+
type: "object",
|
|
943
|
+
properties: { ok: { type: "boolean" }, results: { type: "array" } },
|
|
944
|
+
required: ["ok", "results"],
|
|
945
|
+
})
|
|
946
|
+
const SYNC_ARGV: CommandArgvBinding<SyncInput> = {
|
|
947
|
+
flags: [{ name: "json", field: "json", type: "boolean" }],
|
|
948
|
+
}
|
|
949
|
+
|
|
939
950
|
const PROVE_SCHEMA = input<ProveInput>(
|
|
940
951
|
objectSchema({
|
|
941
952
|
files: { type: "array", items: { type: "string" } },
|
|
@@ -1043,25 +1054,9 @@ function backendAppFor(ctx: CommandCtx): Promise<IntrospectedApp> {
|
|
|
1043
1054
|
return import("./load.ts").then(({ loadBackendApp }) => loadBackendApp(ctx.cwd))
|
|
1044
1055
|
}
|
|
1045
1056
|
|
|
1046
|
-
function structuredDiagnostics(out: CheckCommandOutput): readonly Diagnostic[] {
|
|
1047
|
-
if (out.structuredDiagnostics !== undefined) return out.structuredDiagnostics
|
|
1048
|
-
return out.diagnostics.map((value) =>
|
|
1049
|
-
diagnostic({
|
|
1050
|
-
code: value.code ?? value.rule,
|
|
1051
|
-
severity: normalizeSeverity(value.severity),
|
|
1052
|
-
message: value.message,
|
|
1053
|
-
...(value.file === undefined ? {} : { file: value.file }),
|
|
1054
|
-
...(value.line === undefined ? {} : { line: value.line }),
|
|
1055
|
-
...(value.evidence === undefined ? {} : { evidence: value.evidence }),
|
|
1056
|
-
...(value.fix === undefined ? {} : { fix: { recipe: value.fix } }),
|
|
1057
|
-
...(value.verify === undefined ? {} : { verify: value.verify }),
|
|
1058
|
-
}),
|
|
1059
|
-
)
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
1057
|
function checkJson(out: CheckCommandOutput, input?: CheckInput): unknown {
|
|
1063
|
-
if (input?.sarif === true) return toSarifLog(
|
|
1064
|
-
return { ...out, diagnostics:
|
|
1058
|
+
if (input?.sarif === true) return toSarifLog(checkDiagnostics(out))
|
|
1059
|
+
return { ...out, diagnostics: checkDiagnostics(out) }
|
|
1065
1060
|
}
|
|
1066
1061
|
|
|
1067
1062
|
const checkSpec: CommandSpec<CheckInput, CheckCommandOutput> = {
|
|
@@ -1179,6 +1174,9 @@ const levelsSpec: CommandSpec<LevelsInput, LevelsCommandOutput> = {
|
|
|
1179
1174
|
...out.levels.flatMap((s) => [
|
|
1180
1175
|
`${s.ok ? "✓" : "✖"} L${s.level} ${s.name}`,
|
|
1181
1176
|
...s.reasons.map((r) => ` - ${r}`),
|
|
1177
|
+
...(s.setupWitnesses === undefined
|
|
1178
|
+
? []
|
|
1179
|
+
: [` witnesses from setup: ${s.setupWitnesses.join(", ")}`]),
|
|
1182
1180
|
]),
|
|
1183
1181
|
out.achieved < 0
|
|
1184
1182
|
? "[nifra] verification level: none (L0 failing)"
|
|
@@ -2021,14 +2019,10 @@ const syncManifestSpec: CommandSpec<SyncInput, SyncManifestCommandOutput> = {
|
|
|
2021
2019
|
name: "sync-manifest",
|
|
2022
2020
|
summary: "Regenerate generated server-manifest route tables without a full build.",
|
|
2023
2021
|
input: SYNC_SCHEMA,
|
|
2024
|
-
output:
|
|
2025
|
-
type: "object",
|
|
2026
|
-
properties: { ok: { type: "boolean" }, results: { type: "array" } },
|
|
2027
|
-
required: ["ok", "results"],
|
|
2028
|
-
}),
|
|
2022
|
+
output: syncOutput(),
|
|
2029
2023
|
transports: ["cli", "mcp"],
|
|
2030
2024
|
stability: "stable",
|
|
2031
|
-
argv:
|
|
2025
|
+
argv: SYNC_ARGV,
|
|
2032
2026
|
async run(_value, ctx) {
|
|
2033
2027
|
const results = await syncServerManifests(ctx.cwd)
|
|
2034
2028
|
return { ok: syncManifestsOk(results), results }
|
|
@@ -2041,14 +2035,10 @@ const syncRoutesSpec: CommandSpec<SyncInput, SyncCommandOutput> = {
|
|
|
2041
2035
|
name: "sync-routes",
|
|
2042
2036
|
summary: "Regenerate nifra-routes.d.ts so typed navigation follows route search schemas.",
|
|
2043
2037
|
input: SYNC_SCHEMA,
|
|
2044
|
-
output:
|
|
2045
|
-
type: "object",
|
|
2046
|
-
properties: { ok: { type: "boolean" }, results: { type: "array" } },
|
|
2047
|
-
required: ["ok", "results"],
|
|
2048
|
-
}),
|
|
2038
|
+
output: syncOutput(),
|
|
2049
2039
|
transports: ["cli", "mcp"],
|
|
2050
2040
|
stability: "stable",
|
|
2051
|
-
argv:
|
|
2041
|
+
argv: SYNC_ARGV,
|
|
2052
2042
|
async run(_value, ctx) {
|
|
2053
2043
|
const result = await (await import("./sync-routes.ts")).syncRouteTypes(ctx.cwd)
|
|
2054
2044
|
return { ok: true, results: result === null ? [] : [result] }
|