@nifrajs/cli 5.1.0 → 5.3.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 +3313 -0
- package/README.md +3 -0
- package/dist/agent-files.d.ts +19 -11
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +26 -18
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +7 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +14 -1
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +131 -45
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +5 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +5 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +9 -3
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +61 -21
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +55 -15
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +37 -18
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +9 -5
- package/dist/command-catalog.js.map +1 -1
- package/dist/db-tool.d.ts.map +1 -1
- package/dist/db-tool.js +2 -1
- package/dist/db-tool.js.map +1 -1
- package/dist/dev-bun-config.d.ts +6 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +13 -10
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +3 -2
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +26 -5
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +15 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +79 -61
- package/dist/doctor.js.map +1 -1
- package/dist/env-file.d.ts.map +1 -1
- package/dist/env-file.js +41 -8
- package/dist/env-file.js.map +1 -1
- package/dist/i18n-check.d.ts +11 -1
- package/dist/i18n-check.d.ts.map +1 -1
- package/dist/i18n-check.js +170 -17
- package/dist/i18n-check.js.map +1 -1
- package/dist/init-agents.d.ts +46 -6
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +193 -31
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +9 -1
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +22 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +322 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/workspace-packages.d.ts +22 -0
- package/dist/internal/workspace-packages.d.ts.map +1 -0
- package/dist/internal/workspace-packages.js +215 -0
- package/dist/internal/workspace-packages.js.map +1 -0
- package/dist/load.d.ts +7 -2
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +11 -2
- package/dist/load.js.map +1 -1
- package/dist/lock-links.d.ts +42 -0
- package/dist/lock-links.d.ts.map +1 -0
- package/dist/lock-links.js +144 -0
- package/dist/lock-links.js.map +1 -0
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +16 -5
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +23 -3
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +59 -12
- 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-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/migrate-layout.d.ts +2 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +435 -29
- package/dist/migrate-layout.js.map +1 -1
- package/dist/project-site.d.ts +7 -0
- package/dist/project-site.d.ts.map +1 -0
- package/dist/project-site.js +19 -0
- package/dist/project-site.js.map +1 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -1
- package/dist/recipes/4.0.0.js +2 -0
- package/dist/recipes/4.0.0.js.map +1 -1
- package/dist/recipes/5.1.0.d.ts +9 -0
- package/dist/recipes/5.1.0.d.ts.map +1 -0
- package/dist/recipes/5.1.0.js +22 -0
- package/dist/recipes/5.1.0.js.map +1 -0
- package/dist/recipes/5.2.0.d.ts +10 -0
- package/dist/recipes/5.2.0.d.ts.map +1 -0
- package/dist/recipes/5.2.0.js +32 -0
- package/dist/recipes/5.2.0.js.map +1 -0
- package/dist/recipes/5.3.0.d.ts +11 -0
- package/dist/recipes/5.3.0.d.ts.map +1 -0
- package/dist/recipes/5.3.0.js +35 -0
- package/dist/recipes/5.3.0.js.map +1 -0
- package/dist/recipes/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +9 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +4 -0
- package/dist/review.js.map +1 -1
- package/dist/rule-explain.d.ts +26 -0
- package/dist/rule-explain.d.ts.map +1 -0
- package/dist/rule-explain.js +49 -0
- package/dist/rule-explain.js.map +1 -0
- package/dist/rules/codes.d.ts +4 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +4 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +93 -21
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/explanations.d.ts +14 -0
- package/dist/rules/explanations.d.ts.map +1 -0
- package/dist/rules/explanations.js +326 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +24 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/merge-auth.d.ts +12 -0
- package/dist/rules/merge-auth.d.ts.map +1 -0
- package/dist/rules/merge-auth.js +52 -0
- package/dist/rules/merge-auth.js.map +1 -0
- package/dist/rules/pages.d.ts +51 -0
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +293 -2
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/route-statement.d.ts +10 -0
- package/dist/rules/route-statement.d.ts.map +1 -0
- package/dist/rules/route-statement.js +150 -0
- package/dist/rules/route-statement.js.map +1 -0
- package/dist/rules/routes.d.ts +3 -2
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +4 -3
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -2
- package/dist/rules/zones.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +11 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +50 -7
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +80 -11
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +332 -65
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +2 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +12 -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 +19 -1
- package/docs/llms-full.txt +716 -138
- package/docs/types.json +516 -74
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +8 -1
- package/src/assure.ts +11 -1
- package/src/capabilities-tool.ts +159 -50
- package/src/check-diagnostics.ts +10 -0
- package/src/check-scan.ts +64 -19
- package/src/check.ts +75 -15
- package/src/cli.ts +38 -17
- package/src/command-catalog.ts +16 -8
- package/src/db-tool.ts +2 -0
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +40 -6
- package/src/doctor.ts +102 -66
- package/src/env-file.ts +42 -7
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +221 -41
- package/src/internal/project-specifiers.ts +9 -1
- package/src/internal/source-facts.ts +397 -0
- package/src/internal/workspace-packages.ts +218 -0
- package/src/load.ts +19 -3
- package/src/lock-links.ts +173 -0
- package/src/mcp-exec.ts +18 -4
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +72 -12
- package/src/mcp-isolate.ts +2 -0
- package/src/mcp-root.ts +14 -8
- package/src/migrate-layout.ts +496 -31
- package/src/project-site.ts +18 -0
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.1.0.ts +23 -0
- package/src/recipes/5.2.0.ts +33 -0
- package/src/recipes/5.3.0.ts +36 -0
- package/src/recipes/index.ts +9 -0
- package/src/review.ts +4 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +4 -0
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/explanations.ts +339 -0
- package/src/rules/legacy.ts +24 -1
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +381 -2
- package/src/rules/route-statement.ts +170 -0
- package/src/rules/routes.ts +4 -3
- package/src/rules/zones.ts +3 -2
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +430 -70
- package/src/verification-plan.ts +6 -0
- package/src/version-drift.ts +15 -0
- package/src/web-app-options.ts +9 -1
package/src/check.ts
CHANGED
|
@@ -38,13 +38,18 @@ import { createApiOnlyProbe, createNifraProjectProbe } from "./internal/nifra-pr
|
|
|
38
38
|
import { createSpecifierResolver } from "./internal/project-specifiers.ts"
|
|
39
39
|
import { createSourceFacts } from "./internal/source-facts.ts"
|
|
40
40
|
import { loadProjectTypeScript, type TypeScriptApi } from "./internal/typescript-import.ts"
|
|
41
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
forwardTerminalSignals,
|
|
43
|
+
OWN_PROCESS_GROUP,
|
|
44
|
+
signalProcessGroup,
|
|
45
|
+
stopGroupAndWait,
|
|
46
|
+
} from "./mcp-io.ts"
|
|
42
47
|
// Type-only: `pipeline-report.ts` imports this module's source scanners, so a value import here would
|
|
43
48
|
// close a cycle. Doctor is what actually runs the collector (see the `pipeline` rule below).
|
|
44
49
|
import type { ContractCheckFacts, ProjectFactsSeed } from "./project-facts.ts"
|
|
45
50
|
import { RULE_CODES } from "./rules/codes.ts"
|
|
46
51
|
import { sourceIndex } from "./rules/index.ts"
|
|
47
|
-
import { filesOutsideProgram, splitListedFiles } from "./typecheck-coverage.ts"
|
|
52
|
+
import { filesOutsideProgram, splitListedFiles, typecheckProjects } from "./typecheck-coverage.ts"
|
|
48
53
|
|
|
49
54
|
export type {
|
|
50
55
|
CheckAnalysisInput,
|
|
@@ -124,10 +129,24 @@ function resolveTscBin(cwd: string): string | undefined {
|
|
|
124
129
|
}
|
|
125
130
|
}
|
|
126
131
|
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Run the project's own `tsc --noEmit` over each tsconfig `typecheckProjects` names, one program at a
|
|
134
|
+
* time, if TypeScript and a tsconfig are present. Never auto-installs.
|
|
135
|
+
*/
|
|
136
|
+
async function typecheck(
|
|
137
|
+
cwd: string,
|
|
138
|
+
signal?: AbortSignal,
|
|
139
|
+
configured?: readonly string[],
|
|
140
|
+
): Promise<TypecheckResult> {
|
|
141
|
+
const projects = typecheckProjects(cwd, configured)
|
|
142
|
+
if (projects.missing.length > 0) {
|
|
143
|
+
return {
|
|
144
|
+
ran: true,
|
|
145
|
+
ok: false,
|
|
146
|
+
output: `nifra.check.json "tsconfigs" names ${projects.missing.map((path) => `"${path}"`).join(", ")}, which does not exist`,
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (projects.paths.length === 0)
|
|
131
150
|
return { ran: false, ok: true, missingTsconfig: true, note: "no tsconfig.json" }
|
|
132
151
|
// Routes import their generated `./+types` modules; bring them up to date before tsc reads them.
|
|
133
152
|
const { refreshRouteTypes } = await import("./route-types.ts")
|
|
@@ -141,11 +160,28 @@ async function typecheck(cwd: string, signal?: AbortSignal): Promise<TypecheckRe
|
|
|
141
160
|
note: "typescript not installed (run: bun add -d typescript)",
|
|
142
161
|
}
|
|
143
162
|
}
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
163
|
+
const runs: TypecheckResult[] = []
|
|
164
|
+
for (const tsconfig of projects.paths) {
|
|
165
|
+
let run = await runTsc(cwd, tscBin, tsconfig, true, signal)
|
|
166
|
+
// A compiler that rejects `--listFiles` still gets its typecheck; only the coverage check is lost.
|
|
167
|
+
if (!run.ok && !run.cancelled && /TS50(?:23|25)\b[^\n]*listFiles/.test(run.output ?? ""))
|
|
168
|
+
run = await runTsc(cwd, tscBin, tsconfig, false, signal)
|
|
169
|
+
if (run.cancelled === true) return run
|
|
170
|
+
runs.push(run)
|
|
171
|
+
}
|
|
172
|
+
const [only] = runs
|
|
173
|
+
if (runs.length === 1 && only !== undefined) return only
|
|
174
|
+
// A file two programs both hold reports each error twice; keep one copy of each diagnostic block.
|
|
175
|
+
const blocks = new Set(
|
|
176
|
+
runs.flatMap((run) => (run.output ?? "").split(/\n(?=\S)/).filter((block) => block !== "")),
|
|
177
|
+
)
|
|
178
|
+
const programFiles = [...new Set(runs.flatMap((run) => run.programFiles ?? []))]
|
|
179
|
+
const merged: TypecheckResult = {
|
|
180
|
+
ran: true,
|
|
181
|
+
ok: runs.every((run) => run.ok),
|
|
182
|
+
output: [...blocks].join("\n"),
|
|
183
|
+
}
|
|
184
|
+
return programFiles.length > 0 ? { ...merged, programFiles } : merged
|
|
149
185
|
}
|
|
150
186
|
|
|
151
187
|
async function runTsc(
|
|
@@ -178,7 +214,7 @@ async function runTsc(
|
|
|
178
214
|
stop()
|
|
179
215
|
}
|
|
180
216
|
signal?.addEventListener("abort", abort, { once: true })
|
|
181
|
-
const releaseSignals = forwardTerminalSignals(
|
|
217
|
+
const releaseSignals = forwardTerminalSignals(() => stopGroupAndWait(proc))
|
|
182
218
|
let out = ""
|
|
183
219
|
let err = ""
|
|
184
220
|
let code: number | null = null
|
|
@@ -221,6 +257,7 @@ async function loadCheckConfig(
|
|
|
221
257
|
const parsed = JSON.parse(await Bun.file(path).text()) as {
|
|
222
258
|
externalMounts?: unknown
|
|
223
259
|
rules?: unknown
|
|
260
|
+
tsconfigs?: unknown
|
|
224
261
|
}
|
|
225
262
|
const raw = Array.isArray(parsed.externalMounts) ? parsed.externalMounts : []
|
|
226
263
|
const externalMounts = raw
|
|
@@ -273,7 +310,25 @@ async function loadCheckConfig(
|
|
|
273
310
|
}
|
|
274
311
|
}
|
|
275
312
|
}
|
|
276
|
-
|
|
313
|
+
let tsconfigs: readonly string[] | undefined
|
|
314
|
+
if (parsed.tsconfigs !== undefined) {
|
|
315
|
+
if (
|
|
316
|
+
Array.isArray(parsed.tsconfigs) &&
|
|
317
|
+
parsed.tsconfigs.length > 0 &&
|
|
318
|
+
parsed.tsconfigs.every(
|
|
319
|
+
(entry): entry is string =>
|
|
320
|
+
typeof entry === "string" && entry.endsWith(".json") && !isAbsolute(entry),
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
tsconfigs = parsed.tsconfigs
|
|
324
|
+
else
|
|
325
|
+
warnings.push(
|
|
326
|
+
'`tsconfigs` must be a non-empty array of tsconfig paths relative to the project, such as ["tsconfig.json"] - ignored',
|
|
327
|
+
)
|
|
328
|
+
}
|
|
329
|
+
const config: CheckConfig =
|
|
330
|
+
tsconfigs === undefined ? { externalMounts, rules } : { externalMounts, rules, tsconfigs }
|
|
331
|
+
return { config, warnings }
|
|
277
332
|
} catch (error) {
|
|
278
333
|
return {
|
|
279
334
|
config: empty,
|
|
@@ -369,7 +424,7 @@ async function buildProjectScan(
|
|
|
369
424
|
const [typecheckRun, _, doctor, manifestDrift, contracts] = await Promise.all([
|
|
370
425
|
opts.lintsOnly
|
|
371
426
|
? Promise.resolve<TypecheckResult>({ ran: false, ok: true, note: "lints-only mode" })
|
|
372
|
-
: typecheck(cwd, opts.signal),
|
|
427
|
+
: typecheck(cwd, opts.signal, checkConfig.tsconfigs),
|
|
373
428
|
walkSource(
|
|
374
429
|
cwd,
|
|
375
430
|
(rel, content) => {
|
|
@@ -429,7 +484,7 @@ async function buildProjectScan(
|
|
|
429
484
|
for (const { file, content } of sourceFiles) {
|
|
430
485
|
staticRoutes.push(...scanStaticRouteText(file, content, sourceFacts, project))
|
|
431
486
|
routePaths.push(...scanUnresolvedRoutePaths(file, content, project, sourceFacts))
|
|
432
|
-
responseRoutes.push(...scanResponseRoutes(file, content, sourceFacts))
|
|
487
|
+
responseRoutes.push(...scanResponseRoutes(file, content, sourceFacts, project))
|
|
433
488
|
if (sqlCompiler !== undefined)
|
|
434
489
|
interpolatedSql.push(...scanSqlSites(file, content, sqlCompiler, sqlImports))
|
|
435
490
|
}
|
|
@@ -607,6 +662,11 @@ export function renderCheckReport(result: CheckResult): string[] {
|
|
|
607
662
|
`• intentional external mounts (not typed-client checked): ${result.externalMounts.join(", ")}`,
|
|
608
663
|
)
|
|
609
664
|
}
|
|
665
|
+
if (result.tsconfigs !== undefined) {
|
|
666
|
+
lines.push(
|
|
667
|
+
`• typecheck programs (nifra.check.json "tsconfigs"): ${result.tsconfigs.join(", ")}`,
|
|
668
|
+
)
|
|
669
|
+
}
|
|
610
670
|
for (const gap of result.knownGaps ?? []) {
|
|
611
671
|
lines.push(`• known gap, not capability-analyzed: ${gap.path} - ${gap.reason}`)
|
|
612
672
|
}
|
package/src/cli.ts
CHANGED
|
@@ -129,6 +129,8 @@ Usage:
|
|
|
129
129
|
nifra explain [<message>] [--stack <s>] [--name <n>] A structured diagnostic for an error: its
|
|
130
130
|
code, the frame in your source, and the cause and fix when
|
|
131
131
|
nifra knows them. No message: the dev server's latest error.
|
|
132
|
+
A rule code (NF-C007): what that check rule reports and how
|
|
133
|
+
to fix it.
|
|
132
134
|
nifra cdn-check <url> Check a deployed page behind a CDN: served from cache, no
|
|
133
135
|
internal or CDN-only headers reaching the visitor, and soft
|
|
134
136
|
navigations get page data, not the cached document. Exits 1
|
|
@@ -143,7 +145,8 @@ Usage:
|
|
|
143
145
|
nifra build [--out <dir>] [--report] Emit a complete deploy directory.
|
|
144
146
|
[--target <t>] Target a FULL deploy dir for <t>:
|
|
145
147
|
bun | node | deno | cloudflare | vercel | static. Packages
|
|
146
|
-
buildClient + buildServer (+ prerender for static
|
|
148
|
+
buildClient + buildServer (+ prerender for static, bun and
|
|
149
|
+
node, whose server answers those pages from file) so an app
|
|
147
150
|
no longer hand-writes build-<target>.ts + _worker.ts +
|
|
148
151
|
_routes.json. The server entry is generated from your
|
|
149
152
|
backend/framework.ts (adapter) + backend/app.ts + routes/.
|
|
@@ -180,12 +183,16 @@ Usage:
|
|
|
180
183
|
structure" sections. No-clobber by default (skips a file you've
|
|
181
184
|
customized); --force overwrites the owned files. AGENTS.md is
|
|
182
185
|
only appended to, never overwritten.
|
|
183
|
-
nifra init-agents --sync-mcp [--json]
|
|
186
|
+
nifra init-agents --sync-mcp [--json] Move an existing app's MCP launch to the nifra the project
|
|
184
187
|
installs: rewrites only the @nifrajs/cli@x.y.z version in
|
|
185
188
|
.mcp.json, .cursor/mcp.json, CLAUDE.md and AGENTS.md's MCP
|
|
186
|
-
section - every other byte stays as it is
|
|
189
|
+
section - every other byte stays as it is - and drops it
|
|
190
|
+
when the project declares @nifrajs/cli, so the launch runs
|
|
191
|
+
that install from then on. Creates nothing.
|
|
187
192
|
At a workspace root with one nifra member, the two registries'
|
|
188
|
-
launch also names that member (\`mcp app\`).
|
|
193
|
+
launch also names that member (\`mcp app\`). Run in a member,
|
|
194
|
+
it also re-pins the files above it, up to the repository
|
|
195
|
+
root, whose every nifra launch serves that member.
|
|
189
196
|
nifra mcp [dir] Start an MCP server (stdio) exposing this project to a coding
|
|
190
197
|
agent. The project root is [dir] when given, else resolved from
|
|
191
198
|
cwd (marker walk-up + the client's MCP roots); tools refuse
|
|
@@ -269,13 +276,18 @@ Usage:
|
|
|
269
276
|
nifra upgrade <version> Upgrade to <version>, running every release recipe between the
|
|
270
277
|
[--write] [--no-verify] installed version and it, oldest first: move removed packages,
|
|
271
278
|
[--list] [--json] apply exact imports, pin every matching dependency (keeping
|
|
272
|
-
[--exact] ^/~, or exact with --exact
|
|
273
|
-
|
|
274
|
-
[--
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
+
[--exact] ^/~, or exact with --exact; a peer range only when it
|
|
280
|
+
excludes the target), then verify with nifra check.
|
|
281
|
+
[--allow-downgrade] Dry-run by default; --write applies, then verifies (--no-verify
|
|
282
|
+
[--allow-linked-skew] to skip) and prints how hook scope changed (--no-hooks to skip)
|
|
283
|
+
[--no-hooks] once the target is installed, else prints the install command
|
|
284
|
+
to run first. --list shows the targets with each newer
|
|
285
|
+
release's notes. A version newer than this CLI prints the
|
|
286
|
+
command for that release's CLI. Fail-closed on an unknown
|
|
287
|
+
version, a rollback (--allow-downgrade overrides), or a
|
|
288
|
+
linked repository that loads its own nifra at another
|
|
289
|
+
version (--allow-linked-skew overrides). Deterministic +
|
|
290
|
+
idempotent.
|
|
279
291
|
nifra migrate layout [--write] [--zones] [--json]
|
|
280
292
|
Move an app onto the frontend/backend split: split each route
|
|
281
293
|
into x.tsx + x.backend.ts, fold _middleware.ts into
|
|
@@ -303,8 +315,9 @@ Usage:
|
|
|
303
315
|
[--json] [--strict] placeholder + tag parity, plural cases, script purity,
|
|
304
316
|
untranslated messages. IMPORTS the entry (default: the first
|
|
305
317
|
i18n.ts in ., lib/, src/, src/lib/, app/), which exports
|
|
306
|
-
\`locales\` + \`catalogs\` (+ optional \`ignore\`)
|
|
307
|
-
|
|
318
|
+
\`locales\` + \`catalogs\` (+ optional \`ignore\`), or a
|
|
319
|
+
\`copy\` from defineCopy(), whose tables it finds in the
|
|
320
|
+
source. Exits 1 on errors; --strict also on warnings.
|
|
308
321
|
|
|
309
322
|
Reads nifra.config.ts (adapter + clientModule + plugins; or backend/framework.ts), backend/app.ts
|
|
310
323
|
(optional), and routes/ from the current directory. Run from your project root.
|
|
@@ -321,7 +334,7 @@ set in the process environment is never overwritten by a file.
|
|
|
321
334
|
${renderCommandCatalogHelp()}`
|
|
322
335
|
|
|
323
336
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
324
|
-
const CLI_VERSION = "5.
|
|
337
|
+
const CLI_VERSION = "5.3.0"
|
|
325
338
|
|
|
326
339
|
// A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
|
|
327
340
|
const asAdapter = (v: unknown): RenderAdapter => v as RenderAdapter
|
|
@@ -444,6 +457,7 @@ async function dev(app: LoadedApp, flags: Flags): Promise<void> {
|
|
|
444
457
|
app.cwd,
|
|
445
458
|
app.configPath,
|
|
446
459
|
app.framework.define,
|
|
460
|
+
app.framework.publicEnvPrefix,
|
|
447
461
|
)
|
|
448
462
|
// Bun 1.4 on Windows may discard the script-relative portion of argv when `--config` is
|
|
449
463
|
// present. Keep a second, authenticated copy of the user vector in the child's environment so
|
|
@@ -900,8 +914,12 @@ async function buildForTarget(
|
|
|
900
914
|
...(fw.cssCodeSplit !== undefined ? { cssCodeSplit: fw.cssCodeSplit } : {}),
|
|
901
915
|
...(fw.cssLoading !== undefined ? { cssLoading: fw.cssLoading } : {}),
|
|
902
916
|
...(fw.clientIp !== undefined ? { clientIp: fw.clientIp } : {}),
|
|
903
|
-
//
|
|
904
|
-
|
|
917
|
+
// Prerendering drives a built app: the static target is made of its pages, and a bun or node server
|
|
918
|
+
// answers its prerendered pages from their file. Not under Vite, whose server bundle may rely on
|
|
919
|
+
// transforms the prerender pass (Bun's runtime) does not apply: those pages keep rendering on demand.
|
|
920
|
+
...(target === "static" || (!useVite && (target === "bun" || target === "node"))
|
|
921
|
+
? { prerenderApp: await buildPrerenderApp(app) }
|
|
922
|
+
: {}),
|
|
905
923
|
})
|
|
906
924
|
// A production build must not certify itself green while a workspace-linked dependency ships a dist
|
|
907
925
|
// artifact older than (or absent next to) its source: the `bun`->src condition let this compile read
|
|
@@ -915,7 +933,7 @@ async function buildForTarget(
|
|
|
915
933
|
if (flags.report) console.log(`\n${renderSizeReport(result.size)}`)
|
|
916
934
|
}
|
|
917
935
|
|
|
918
|
-
/** Build the app FACTORY for the `static`
|
|
936
|
+
/** Build the app FACTORY for the prerender pass of the `static`, `bun` and `node` targets. Registers the
|
|
919
937
|
* framework's SSR Bun plugins (so `.vue`/`.svelte`/Solid routes import) once, then return a factory that
|
|
920
938
|
* `createWebApp`s the app for the client build's manifest. The client entry MUST be the real content-hashed
|
|
921
939
|
* bundle (`client.entry`) - it's the hydration `<script src>` the prerendered HTML emits, so a placeholder
|
|
@@ -936,6 +954,7 @@ async function buildPrerenderApp(
|
|
|
936
954
|
...(client.routes ? { routePreload: client.routes } : {}),
|
|
937
955
|
...(client.css ? { styles: client.css } : {}),
|
|
938
956
|
...(client.routeStyles ? { routeStyles: client.routeStyles } : {}),
|
|
957
|
+
...(client.copyChunks ? { copyChunks: client.copyChunks } : {}),
|
|
939
958
|
...(client.cssLoading !== undefined ? { cssLoading: client.cssLoading } : {}),
|
|
940
959
|
})
|
|
941
960
|
}
|
|
@@ -945,6 +964,7 @@ interface BuiltManifest {
|
|
|
945
964
|
readonly routes?: Readonly<Record<string, readonly string[]>>
|
|
946
965
|
readonly css?: readonly string[]
|
|
947
966
|
readonly routeStyles?: Readonly<Record<string, readonly string[]>>
|
|
967
|
+
readonly copyChunks?: Readonly<Record<string, string>>
|
|
948
968
|
readonly cssLoading?: CssLoadingMode
|
|
949
969
|
}
|
|
950
970
|
|
|
@@ -1323,6 +1343,7 @@ async function main(): Promise<void> {
|
|
|
1323
1343
|
verify: !argv.includes("--no-verify"),
|
|
1324
1344
|
hooks: !argv.includes("--no-hooks"),
|
|
1325
1345
|
allowDowngrade: argv.includes("--allow-downgrade"),
|
|
1346
|
+
allowLinkedSkew: argv.includes("--allow-linked-skew"),
|
|
1326
1347
|
exact: argv.includes("--exact"),
|
|
1327
1348
|
cliVersion: CLI_VERSION,
|
|
1328
1349
|
})
|
package/src/command-catalog.ts
CHANGED
|
@@ -1382,6 +1382,9 @@ const openApiSpec: CommandSpec<OpenApiInput, OpenApiCommandOutput> = {
|
|
|
1382
1382
|
json: (out) => (out.format === "json" ? JSON.parse(out.text) : out.text),
|
|
1383
1383
|
}
|
|
1384
1384
|
|
|
1385
|
+
// `render` cannot load doctor.ts, so each run's report is built beside its result.
|
|
1386
|
+
const doctorReports = new WeakMap<DoctorResult, readonly string[]>()
|
|
1387
|
+
|
|
1385
1388
|
const doctorSpec: CommandSpec<DoctorInput, DoctorResult> = {
|
|
1386
1389
|
name: "doctor",
|
|
1387
1390
|
summary: "Find undeclared imports, duplicate identity installs, and pipeline readiness drift.",
|
|
@@ -1409,14 +1412,18 @@ const doctorSpec: CommandSpec<DoctorInput, DoctorResult> = {
|
|
|
1409
1412
|
...(value.strict === undefined ? {} : { strict: value.strict }),
|
|
1410
1413
|
...(ctx.cliVersion === undefined ? {} : { cliVersion: ctx.cliVersion }),
|
|
1411
1414
|
}
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
+
const result =
|
|
1416
|
+
value.autoFix === true
|
|
1417
|
+
? await mod.applyDoctorAutoFix(ctx.cwd, options)
|
|
1418
|
+
: await mod.collectDoctorResult(ctx.cwd, options)
|
|
1419
|
+
doctorReports.set(result, mod.doctorReport(result, ctx.cliVersion))
|
|
1420
|
+
return result
|
|
1415
1421
|
},
|
|
1416
|
-
render: (out) =>
|
|
1417
|
-
out
|
|
1418
|
-
|
|
1419
|
-
|
|
1422
|
+
render: (out) =>
|
|
1423
|
+
doctorReports.get(out) ?? [
|
|
1424
|
+
out.ok ? "✓ doctor passed" : "✖ doctor found issues",
|
|
1425
|
+
...out.findings.map((f) => ` ${f.file}:${f.line} ${f.package}`),
|
|
1426
|
+
],
|
|
1420
1427
|
success: (out) => out.ok,
|
|
1421
1428
|
}
|
|
1422
1429
|
|
|
@@ -1570,7 +1577,8 @@ const migrateSpec: CommandSpec<MigrateInput, MigrateCommandOutput> = {
|
|
|
1570
1577
|
),
|
|
1571
1578
|
...out.issues.map((issue) => ` ⚠ ${issue.file}: ${issue.reason}`),
|
|
1572
1579
|
...out.followUps.map(
|
|
1573
|
-
(step) =>
|
|
1580
|
+
(step) =>
|
|
1581
|
+
` next ${step.file}: ${step.reason}${step.command === undefined ? "" : ` - \`${step.command}\``}`,
|
|
1574
1582
|
),
|
|
1575
1583
|
...(out.write ? [] : [" dry run: pass --write to apply"]),
|
|
1576
1584
|
]
|
package/src/db-tool.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
readBoundedLines,
|
|
39
39
|
readBoundedStream,
|
|
40
40
|
signalProcessGroup,
|
|
41
|
+
stopGroupOnExit,
|
|
41
42
|
} from "./mcp-io.ts"
|
|
42
43
|
|
|
43
44
|
/** Added to the declared `timeoutMs` before the subprocess is killed. */
|
|
@@ -138,6 +139,7 @@ export async function runDbChild(
|
|
|
138
139
|
stderr: "pipe",
|
|
139
140
|
detached: OWN_PROCESS_GROUP,
|
|
140
141
|
})
|
|
142
|
+
stopGroupOnExit(proc)
|
|
141
143
|
let killedFor: "startup" | "deadline" | "cancel" | undefined
|
|
142
144
|
const kill = (reason: NonNullable<typeof killedFor>): void => {
|
|
143
145
|
if (killedFor !== undefined) return
|
package/src/dev-bun-config.ts
CHANGED
|
@@ -221,12 +221,16 @@ function relativeSpecifier(fromDir: string, target: string): string {
|
|
|
221
221
|
* `singleCopy` is whether `package.json` declares `"nifra": { "singleCopy": [...] }`. The declared
|
|
222
222
|
* resolver then runs where `buildClient` runs it, after the zone guard; an app that also lists
|
|
223
223
|
* `singleCopyPlugin()` in `clientPlugins` gets its own instance in that place, once.
|
|
224
|
+
*
|
|
225
|
+
* `publicEnvPrefix` is the value `loadApp` resolved across both configs, written in as a literal:
|
|
226
|
+
* importing it from `configPath` would miss one set only in `backend/framework.ts`.
|
|
224
227
|
*/
|
|
225
228
|
export function renderBoundaryPluginModule(
|
|
226
229
|
configPath?: string,
|
|
227
230
|
pluginDir?: string,
|
|
228
231
|
servePlugins: readonly string[] = [],
|
|
229
232
|
singleCopy = false,
|
|
233
|
+
publicEnvPrefix?: string,
|
|
230
234
|
): string {
|
|
231
235
|
const appImport =
|
|
232
236
|
configPath !== undefined && pluginDir !== undefined
|
|
@@ -264,22 +268,18 @@ export function renderBoundaryPluginModule(
|
|
|
264
268
|
}
|
|
265
269
|
`
|
|
266
270
|
return `// Generated by \`nifra dev\` (Bun pipeline) - do not edit. Regenerated on every dev start.
|
|
267
|
-
import { serverFnStubPlugin, zoneGuardPlugin } from "@nifrajs/web/build"
|
|
271
|
+
import { importGlobPlugin, serverFnStubPlugin, zoneGuardPlugin } from "@nifrajs/web/build"
|
|
268
272
|
import { reserveDevSpecifiers } from "@nifrajs/web/internal/dev-reserved"
|
|
269
273
|
import { cssModulesBunPlugin } from "@nifrajs/web/plugins/css-modules"
|
|
270
274
|
${singleCopy ? 'import { singleCopyPlugin } from "@nifrajs/core/single-copy"\n' : ""}${appImport}
|
|
271
275
|
// This module lives at <app>/.nifra/dev-bun/, so the app root is two directories up.
|
|
272
276
|
const appRoot = Bun.fileURLToPath(new URL("../../", import.meta.url))
|
|
273
277
|
const zones = zoneGuardPlugin({
|
|
274
|
-
appRoot,${
|
|
275
|
-
appImport === ""
|
|
276
|
-
? ""
|
|
277
|
-
: `
|
|
278
|
-
...(typeof appConfig.publicEnvPrefix === "string" ? { publicEnvPrefix: appConfig.publicEnvPrefix } : {}),`
|
|
279
|
-
}
|
|
278
|
+
appRoot,${publicEnvPrefix === undefined ? "" : `\n publicEnvPrefix: ${JSON.stringify(publicEnvPrefix)},`}
|
|
280
279
|
})
|
|
281
280
|
const fn = serverFnStubPlugin()
|
|
282
281
|
const cssModules = cssModulesBunPlugin("dom")
|
|
282
|
+
const globs = importGlobPlugin({ root: appRoot })
|
|
283
283
|
|
|
284
284
|
export default {
|
|
285
285
|
name: "nifra-dev-boundary",
|
|
@@ -292,7 +292,9 @@ ${singleCopy ? appPluginsSetup : ""} // Boundary first: an app plugin must ne
|
|
|
292
292
|
zones.setup(guarded)
|
|
293
293
|
${singleCopySetup} fn.setup(guarded)
|
|
294
294
|
cssModules.setup(guarded)
|
|
295
|
-
${appSetup}${serveSetup}
|
|
295
|
+
${appSetup}${serveSetup} // Last, as in buildClient: a module another plugin loads is that plugin's.
|
|
296
|
+
globs.setup(guarded)
|
|
297
|
+
},
|
|
296
298
|
}
|
|
297
299
|
`
|
|
298
300
|
}
|
|
@@ -308,11 +310,12 @@ const TOKEN_FILE = "launch-token"
|
|
|
308
310
|
/** Write the generated config for an app; returns the bunfig path to re-exec with and the fresh
|
|
309
311
|
* launch token to pass in the child's environment. `configPath` (the app's `nifra.config.ts` /
|
|
310
312
|
* `backend/framework.ts`) is what lets the app's own `clientPlugins` reach Bun's dev-server
|
|
311
|
-
* bundler; `define`
|
|
313
|
+
* bundler; `define` and `publicEnvPrefix` are the loaded config's own. */
|
|
312
314
|
export async function writeBunDevConfig(
|
|
313
315
|
appRoot: string,
|
|
314
316
|
configPath?: string,
|
|
315
317
|
define?: Readonly<Record<string, string>>,
|
|
318
|
+
publicEnvPrefix?: string,
|
|
316
319
|
): Promise<BunDevConfig> {
|
|
317
320
|
const dir = resolve(appRoot, ".nifra", "dev-bun")
|
|
318
321
|
mkdirSync(dir, { recursive: true })
|
|
@@ -328,6 +331,7 @@ export async function writeBunDevConfig(
|
|
|
328
331
|
dir,
|
|
329
332
|
userServePlugins(user, appRoot),
|
|
330
333
|
readSingleCopyDeclaration(appRoot) !== undefined,
|
|
334
|
+
publicEnvPrefix,
|
|
331
335
|
),
|
|
332
336
|
)
|
|
333
337
|
const bunfigPath = resolve(dir, "bunfig.toml")
|
package/src/dev-feed-tool.ts
CHANGED
|
@@ -18,6 +18,13 @@ import type {
|
|
|
18
18
|
import type { Diagnostic } from "@nifrajs/web/diagnostic"
|
|
19
19
|
import type { CommandCtx, CommandSpec } from "./command-catalog.ts"
|
|
20
20
|
import type { DevServerLookup, LiveDevServer } from "./dev-server-client.ts"
|
|
21
|
+
import {
|
|
22
|
+
isRuleExplanation,
|
|
23
|
+
RULE_CODE_SHAPE,
|
|
24
|
+
type RuleExplainOutput,
|
|
25
|
+
renderRuleExplanation,
|
|
26
|
+
type UnknownRuleOutput,
|
|
27
|
+
} from "./rule-explain.ts"
|
|
21
28
|
|
|
22
29
|
const CATEGORIES: readonly DevErrorCategory[] = [
|
|
23
30
|
"ssr",
|
|
@@ -802,22 +809,30 @@ export interface ExplainInput {
|
|
|
802
809
|
readonly json?: boolean | undefined
|
|
803
810
|
}
|
|
804
811
|
|
|
805
|
-
/** A diagnostic,
|
|
812
|
+
/** A diagnostic, a rule code's catalog entry, or why there was nothing to explain. */
|
|
806
813
|
export type ExplainOutput =
|
|
807
814
|
| (Diagnostic & { readonly entry?: object; readonly note?: string })
|
|
815
|
+
| RuleExplainOutput
|
|
816
|
+
| UnknownRuleOutput
|
|
808
817
|
| { code: "NIFRA_NONE"; message: string }
|
|
809
818
|
|
|
810
|
-
const
|
|
819
|
+
const isRuleOutput = (out: ExplainOutput): out is RuleExplainOutput =>
|
|
820
|
+
"kind" in out && out.kind === "rule"
|
|
821
|
+
const explained = (out: ExplainOutput): out is Diagnostic =>
|
|
822
|
+
out.code !== "NIFRA_NONE" && out.code !== "NIFRA_UNKNOWN_RULE" && !isRuleOutput(out)
|
|
811
823
|
|
|
812
824
|
export const explainSpec: CommandSpec<ExplainInput, ExplainOutput> = {
|
|
813
825
|
name: "explain",
|
|
814
826
|
summary:
|
|
815
|
-
"Turn an error into a structured diagnostic: its code, the frame in your source with a codeframe, and the cause and fix when nifra recognises it. With no message, the running dev server's latest error.",
|
|
827
|
+
"Turn an error into a structured diagnostic: its code, the frame in your source with a codeframe, and the cause and fix when nifra recognises it. With no message, the running dev server's latest error. A rule code such as NF-C007 explains that rule.",
|
|
816
828
|
input: {
|
|
817
829
|
jsonSchema: {
|
|
818
830
|
type: "object",
|
|
819
831
|
properties: {
|
|
820
|
-
error: {
|
|
832
|
+
error: {
|
|
833
|
+
type: "string",
|
|
834
|
+
description: "The error message to explain, or a rule code such as NF-C007.",
|
|
835
|
+
},
|
|
821
836
|
stack: {
|
|
822
837
|
type: "string",
|
|
823
838
|
description: "Its stack trace, for the codeframe and source frame.",
|
|
@@ -849,7 +864,17 @@ export const explainSpec: CommandSpec<ExplainInput, ExplainOutput> = {
|
|
|
849
864
|
required: ["code", "message"],
|
|
850
865
|
},
|
|
851
866
|
parse: (value) => {
|
|
867
|
+
if (isRuleExplanation(value)) return value
|
|
852
868
|
if (isDiagnostic(value)) return value
|
|
869
|
+
if (
|
|
870
|
+
typeof value === "object" &&
|
|
871
|
+
value !== null &&
|
|
872
|
+
"code" in value &&
|
|
873
|
+
value.code === "NIFRA_UNKNOWN_RULE" &&
|
|
874
|
+
"message" in value &&
|
|
875
|
+
typeof value.message === "string"
|
|
876
|
+
)
|
|
877
|
+
return { code: "NIFRA_UNKNOWN_RULE", message: value.message }
|
|
853
878
|
if (
|
|
854
879
|
typeof value === "object" &&
|
|
855
880
|
value !== null &&
|
|
@@ -859,7 +884,9 @@ export const explainSpec: CommandSpec<ExplainInput, ExplainOutput> = {
|
|
|
859
884
|
typeof value.message === "string"
|
|
860
885
|
)
|
|
861
886
|
return { code: "NIFRA_NONE", message: value.message }
|
|
862
|
-
throw new TypeError(
|
|
887
|
+
throw new TypeError(
|
|
888
|
+
"explain output must be a diagnostic, a rule explanation, NIFRA_UNKNOWN_RULE or NIFRA_NONE",
|
|
889
|
+
)
|
|
863
890
|
},
|
|
864
891
|
},
|
|
865
892
|
transports: ["cli"],
|
|
@@ -875,6 +902,11 @@ export const explainSpec: CommandSpec<ExplainInput, ExplainOutput> = {
|
|
|
875
902
|
],
|
|
876
903
|
},
|
|
877
904
|
async run(input, ctx) {
|
|
905
|
+
const code = input.error?.trim()
|
|
906
|
+
if (input.stack === undefined && code !== undefined && RULE_CODE_SHAPE.test(code)) {
|
|
907
|
+
const { explainRule } = await import("./rule-explain.ts")
|
|
908
|
+
return explainRule(code)
|
|
909
|
+
}
|
|
878
910
|
const root = resolve(ctx.cwd, input.dir ?? ".")
|
|
879
911
|
if (input.error === undefined && input.stack === undefined) {
|
|
880
912
|
return explainLatest(root, input.port, ctx.signal)
|
|
@@ -888,6 +920,7 @@ export const explainSpec: CommandSpec<ExplainInput, ExplainOutput> = {
|
|
|
888
920
|
return buildDiagnostic(error, { root, showSource: explainSourceGate(root) })
|
|
889
921
|
},
|
|
890
922
|
render: (out) => {
|
|
923
|
+
if (isRuleOutput(out)) return renderRuleExplanation(out)
|
|
891
924
|
if (!explained(out)) return [out.message]
|
|
892
925
|
const at = topFrame(out)
|
|
893
926
|
return [
|
|
@@ -900,7 +933,8 @@ export const explainSpec: CommandSpec<ExplainInput, ExplainOutput> = {
|
|
|
900
933
|
...(out.fix === undefined ? [] : [` fix: ${out.fix}`]),
|
|
901
934
|
]
|
|
902
935
|
},
|
|
903
|
-
exitCode: (out) =>
|
|
936
|
+
exitCode: (out) =>
|
|
937
|
+
explained(out) || isRuleOutput(out) ? 0 : out.code === "NIFRA_UNKNOWN_RULE" ? 1 : 2,
|
|
904
938
|
json: (out) => out,
|
|
905
939
|
}
|
|
906
940
|
|