@nifrajs/cli 2.13.0 → 2.14.1
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/dist/capabilities-tool.d.ts +54 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +146 -18
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check.d.ts +11 -11
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +234 -43
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +11 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +91 -413
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +244 -0
- package/dist/command-catalog.d.ts.map +1 -0
- package/dist/command-catalog.js +1014 -0
- package/dist/command-catalog.js.map +1 -0
- package/dist/contracts.d.ts +9 -0
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +22 -6
- package/dist/contracts.js.map +1 -1
- package/dist/doctor.d.ts +13 -0
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +18 -2
- package/dist/doctor.js.map +1 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +22 -5
- package/dist/load.js.map +1 -1
- package/dist/manifest-tool.d.ts +15 -1
- package/dist/manifest-tool.d.ts.map +1 -1
- package/dist/manifest-tool.js +23 -9
- package/dist/manifest-tool.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp.d.ts +8 -0
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +59 -349
- package/dist/mcp.js.map +1 -1
- package/dist/project-facts.d.ts +40 -0
- package/dist/project-facts.d.ts.map +1 -0
- package/dist/project-facts.js +36 -0
- package/dist/project-facts.js.map +1 -0
- package/dist/rules/comment-markers.d.ts +8 -0
- package/dist/rules/comment-markers.d.ts.map +1 -1
- package/dist/rules/comment-markers.js +36 -0
- package/dist/rules/comment-markers.js.map +1 -1
- package/dist/rules/index.d.ts +2 -3
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js.map +1 -1
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +12 -14
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/security.js +14 -14
- package/dist/rules/security.js.map +1 -1
- package/docs/types.json +27 -14
- package/package.json +9 -9
- package/src/capabilities-tool.ts +229 -21
- package/src/check.ts +285 -59
- package/src/cli.ts +100 -404
- package/src/command-catalog.ts +1415 -0
- package/src/contracts.ts +28 -7
- package/src/doctor.ts +35 -4
- package/src/load.ts +25 -6
- package/src/manifest-tool.ts +43 -12
- package/src/mcp-http.ts +1 -1
- package/src/mcp.ts +82 -414
- package/src/project-facts.ts +86 -0
- package/src/rules/comment-markers.ts +36 -0
- package/src/rules/index.ts +3 -4
- package/src/rules/routes.ts +13 -14
- package/src/rules/security.ts +14 -14
package/dist/cli.js
CHANGED
|
@@ -17,12 +17,12 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
17
17
|
*
|
|
18
18
|
* Bun-only (it runs the framework's TS + Bun plugins directly). The *output* runs anywhere.
|
|
19
19
|
*/
|
|
20
|
-
import { existsSync } from "node:fs";
|
|
20
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
21
21
|
import { resolve } from "node:path";
|
|
22
22
|
import { inProcessClient } from "@nifrajs/client";
|
|
23
23
|
import { createWebApp, DEFAULT_DEV_PORT, } from "@nifrajs/web";
|
|
24
24
|
import { discoverRoutes } from "@nifrajs/web/fs";
|
|
25
|
-
import {
|
|
25
|
+
import { bindCommandArgv, findCommandSpec, renderCommandCatalogHelp } from "./command-catalog.js";
|
|
26
26
|
import { loadApp } from "./load.js";
|
|
27
27
|
import { chooseBuildPipeline, describePipeline } from "./pipeline-guard.js";
|
|
28
28
|
const HELP = `nifra - zero-config dev/build/start for a nifra app
|
|
@@ -36,6 +36,10 @@ Usage:
|
|
|
36
36
|
preserved), no Vite in the process. CSS Modules, plain CSS,
|
|
37
37
|
Tailwind and the app's own \`clientPlugins\`/\`serverPlugins\` run
|
|
38
38
|
through the same Bun transforms production uses.
|
|
39
|
+
[--allow-duplicate-identity] Downgrade the Vite dev server's identity-parity check to a
|
|
40
|
+
loud warning instead of a hard failure, so a duplicate React/
|
|
41
|
+
adapter copy from a linked sibling repo doesn't take dev down
|
|
42
|
+
while you fix the resolution. Dev only - \`nifra build\` still fails.
|
|
39
43
|
nifra build [--out <dir>] [--report] Emit a complete deploy directory.
|
|
40
44
|
[--target <t>] Target a FULL deploy dir for <t>:
|
|
41
45
|
bun | node | deno | cf-pages | vercel | static. Packages
|
|
@@ -106,11 +110,13 @@ Usage:
|
|
|
106
110
|
closed. Exits non-zero on any breaking change - run it in CI.
|
|
107
111
|
nifra sdk --lang <python|go> [--out <file>]
|
|
108
112
|
Generate a deterministic non-TypeScript SDK from backend.ts.
|
|
109
|
-
nifra assure [--config <file>] [--json]
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
nifra assure [--config <file>] [--json] Route-assurance report. Human table by default; --json emits
|
|
114
|
+
the {ok, routes, findings} report for agents.
|
|
115
|
+
nifra assure --bundle [--json] [--strict] [--out <file>] [--hydration] [--interact]
|
|
116
|
+
Emit one structured assurance {version, gates, verdict} bundle
|
|
117
|
+
(always JSON). Records every applicable gate as pass, fail, or
|
|
118
|
+
skip and exits non-zero unless its verdict is green. --strict,
|
|
119
|
+
--hydration, --interact and --out imply --bundle.
|
|
114
120
|
nifra contracts snapshot [--out <file>] Write the deterministic route contract lock.
|
|
115
121
|
nifra contracts check [--json] Check the current routes against contracts.lock.json.
|
|
116
122
|
nifra replay <file> Replay a token-only verification metadata file.
|
|
@@ -120,6 +126,8 @@ Usage:
|
|
|
120
126
|
nifra capabilities check [--lockfile <file>] [--config <file>] [--json]
|
|
121
127
|
CI gate: fail on raw effect-import bypasses, declaration/evidence
|
|
122
128
|
drift, unsafe GET/HEAD writes, idempotency gaps, or lockfile drift.
|
|
129
|
+
nifra capabilities explain <METHOD> <path> [--config <file>] [--json]
|
|
130
|
+
Explain one route's declared capability tokens and static provenance.
|
|
123
131
|
nifra manifest emit [--out <file>] [--config <file>] [--sign <key-ref>]
|
|
124
132
|
Emit a deterministic route trust artifact after assurance passes;
|
|
125
133
|
optionally write an Ed25519 signature via the configured KMS signer.
|
|
@@ -157,9 +165,11 @@ Reads nifra.config.ts (adapter + clientModule + plugins; or framework.ts), backe
|
|
|
157
165
|
routes/ from the current directory. Run from your project root.
|
|
158
166
|
|
|
159
167
|
Port: \`dev\` and \`start\` share the default ${DEFAULT_DEV_PORT}. Override with \`--port <n>\` (alias \`-p\`) or the
|
|
160
|
-
\`PORT\` env var (\`--port\` wins over \`PORT\`, which wins over the default)
|
|
168
|
+
\`PORT\` env var (\`--port\` wins over \`PORT\`, which wins over the default).
|
|
169
|
+
|
|
170
|
+
${renderCommandCatalogHelp()}`;
|
|
161
171
|
// Kept in lockstep with packages/cli/package.json by check:publish's version-consistency gate.
|
|
162
|
-
const CLI_VERSION = "2.
|
|
172
|
+
const CLI_VERSION = "2.14.1";
|
|
163
173
|
// A render adapter + nifra server are opaque to the CLI (it just forwards them); cast at the seam.
|
|
164
174
|
const asAdapter = (v) => v;
|
|
165
175
|
const asBunPlugins = (v) => v;
|
|
@@ -354,6 +364,7 @@ async function dev(app, flags) {
|
|
|
354
364
|
...(fw.publicEnvPrefix !== undefined ? { publicEnvPrefix: fw.publicEnvPrefix } : {}),
|
|
355
365
|
poll: flags.poll,
|
|
356
366
|
port: flags.port,
|
|
367
|
+
...(flags.allowDuplicateIdentity ? { allowDuplicateIdentity: true } : {}),
|
|
357
368
|
...(fw.conditions ? { conditions: fw.conditions } : {}),
|
|
358
369
|
...(fw.define ? { define: fw.define } : {}),
|
|
359
370
|
// `load` resolves route modules through VITE, not through Bun. That is what makes the Vite
|
|
@@ -403,6 +414,34 @@ export async function assertUseIsEdgeExported(use, configPath, frameworkFile) {
|
|
|
403
414
|
" - Define `use` in framework.ts and re-export it from nifra.config.ts " +
|
|
404
415
|
'(`export { use } from "./framework.ts"`) so `nifra dev` sees it too.');
|
|
405
416
|
}
|
|
417
|
+
/**
|
|
418
|
+
* A production build must not ship a workspace-linked package whose `default`-condition artifact is
|
|
419
|
+
* missing or older than its source. The `"bun": "./src"` / `"default": "./dist"` split means Bun (this
|
|
420
|
+
* build, the tests) reads live source while the deployed app and any node consumer read `dist/` - so a
|
|
421
|
+
* green `nifra build` can bundle stale or absent dist and the drift never shows in a diff. The doctor
|
|
422
|
+
* reports the same skew as an advisory during development; at build time it is a hard failure, because
|
|
423
|
+
* this is the artifact that ships. No-op outside a workspace: tarball-installed deps cannot drift.
|
|
424
|
+
*/
|
|
425
|
+
async function assertFreshWorkspaceDists(cwd) {
|
|
426
|
+
const pkgPath = resolve(cwd, "package.json");
|
|
427
|
+
if (!existsSync(pkgPath))
|
|
428
|
+
return;
|
|
429
|
+
let rootPackage;
|
|
430
|
+
try {
|
|
431
|
+
rootPackage = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
432
|
+
}
|
|
433
|
+
catch {
|
|
434
|
+
return; // an unreadable/!JSON package.json is a separate problem; don't mask it as a stale-dist failure
|
|
435
|
+
}
|
|
436
|
+
const { collectStaleWorkspaceDists } = await import("./doctor.js");
|
|
437
|
+
const stale = await collectStaleWorkspaceDists(cwd, rootPackage);
|
|
438
|
+
if (stale.length === 0)
|
|
439
|
+
return;
|
|
440
|
+
const lines = stale.map((f) => f.missing
|
|
441
|
+
? ` ${f.package}: ${f.distFile} was never built (source ${f.sourceFile})`
|
|
442
|
+
: ` ${f.package}: ${f.distFile} is ${f.behindSeconds}s behind ${f.sourceFile}`);
|
|
443
|
+
throw new Error(`[nifra] build blocked: ${stale.length} workspace-linked package(s) ship a stale or missing dist artifact, so the deployed app would serve code this build did not produce:\n${lines.join("\n")}\nBuild the offending package(s) (\`bun run build\` in each) so every export target exists and is at least as new as its source, then rebuild.`);
|
|
444
|
+
}
|
|
406
445
|
async function buildForTarget(app, target, flags) {
|
|
407
446
|
const { isBuildTarget, renderSizeReport, BUILD_TARGETS } = await import("@nifrajs/web/build");
|
|
408
447
|
if (!isBuildTarget(target)) {
|
|
@@ -460,6 +499,11 @@ async function buildForTarget(app, target, flags) {
|
|
|
460
499
|
// The static target needs a built app to drive prerendering - only build it when targeting static.
|
|
461
500
|
...(target === "static" ? { prerenderApp: await buildPrerenderApp(app) } : {}),
|
|
462
501
|
});
|
|
502
|
+
// A production build must not certify itself green while a workspace-linked dependency ships a dist
|
|
503
|
+
// artifact older than (or absent next to) its source: the `bun`->src condition let this compile read
|
|
504
|
+
// live source, but the deployed app and every node consumer read `dist/`. Gate here, after the compile
|
|
505
|
+
// proved the source is buildable, so the failure names the package to rebuild rather than a bundle error.
|
|
506
|
+
await assertFreshWorkspaceDists(cwd);
|
|
463
507
|
console.log(`nifra build (${target}, ${decision.pipeline}) → ${result.run}`);
|
|
464
508
|
// The pipeline is stated on every build, not only the surprising ones - an auto-selected Vite build
|
|
465
509
|
// must never look like the default, and a default Bun build must not leave the question open either.
|
|
@@ -515,6 +559,7 @@ export function parseFlags(args) {
|
|
|
515
559
|
let report = false;
|
|
516
560
|
let vite = false;
|
|
517
561
|
let bun = false;
|
|
562
|
+
let allowDuplicateIdentity = false;
|
|
518
563
|
for (let i = 0; i < args.length; i++) {
|
|
519
564
|
const a = args[i];
|
|
520
565
|
if ((a === "--port" || a === "-p") && args[i + 1])
|
|
@@ -531,11 +576,26 @@ export function parseFlags(args) {
|
|
|
531
576
|
vite = true;
|
|
532
577
|
else if (a === "--bun")
|
|
533
578
|
bun = true;
|
|
579
|
+
else if (a === "--allow-duplicate-identity")
|
|
580
|
+
allowDuplicateIdentity = true;
|
|
534
581
|
}
|
|
535
582
|
if (!Number.isFinite(port) || port < 0 || port > 65535) {
|
|
536
583
|
throw new Error(`[nifra] invalid --port: ${port}`);
|
|
537
584
|
}
|
|
538
|
-
return { port, out, poll, target, report, vite, bun };
|
|
585
|
+
return { port, out, poll, target, report, vite, bun, allowDuplicateIdentity };
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* `assure` uses the structured-bundle lane only when explicitly asked. A bare `--json` is NOT a
|
|
589
|
+
* request for the bundle - it keeps the legacy `{ ok, routes, findings }` report machine-readable, so a
|
|
590
|
+
* pre-bundle consumer is never silently handed the `{ gates, verdict }` shape. `--bundle` (or a
|
|
591
|
+
* bundle-only flag) opts in; `--bundle --json` still yields the bundle, which is always JSON.
|
|
592
|
+
*/
|
|
593
|
+
export function assureBundleRequested(argv) {
|
|
594
|
+
return (argv.includes("--bundle") ||
|
|
595
|
+
argv.includes("--strict") ||
|
|
596
|
+
argv.includes("--hydration") ||
|
|
597
|
+
argv.includes("--interact") ||
|
|
598
|
+
argv.includes("--out"));
|
|
539
599
|
}
|
|
540
600
|
async function main() {
|
|
541
601
|
const argv = Bun.argv.slice(2);
|
|
@@ -579,16 +639,27 @@ async function main() {
|
|
|
579
639
|
console.log(renderLearnResult(stepArg !== undefined && /^\d+$/.test(stepArg) ? Number(stepArg) : undefined));
|
|
580
640
|
return;
|
|
581
641
|
}
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
642
|
+
const catalogSpec = command === undefined ? undefined : findCommandSpec(command);
|
|
643
|
+
if (catalogSpec?.transports.includes("cli")) {
|
|
644
|
+
try {
|
|
645
|
+
const input = bindCommandArgv(catalogSpec, argv.slice(1));
|
|
646
|
+
const output = await catalogSpec.run(input, { cwd: process.cwd(), cliVersion: CLI_VERSION });
|
|
647
|
+
const asRecord = output;
|
|
648
|
+
const wantsJson = asRecord.json === true || argv.includes("--json");
|
|
649
|
+
if (wantsJson) {
|
|
650
|
+
const value = catalogSpec.json?.(output, input) ?? output;
|
|
651
|
+
console.log(typeof value === "string" ? value : JSON.stringify(value, null, 2));
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
console.log(catalogSpec.render(output, input).join("\n"));
|
|
655
|
+
}
|
|
656
|
+
if (catalogSpec.success !== undefined && !catalogSpec.success(output, input))
|
|
657
|
+
process.exitCode = 1;
|
|
658
|
+
}
|
|
659
|
+
catch (err) {
|
|
660
|
+
console.error(formatCliError(err));
|
|
591
661
|
process.exitCode = 1;
|
|
662
|
+
}
|
|
592
663
|
return;
|
|
593
664
|
}
|
|
594
665
|
if (command === "verify") {
|
|
@@ -601,30 +672,6 @@ async function main() {
|
|
|
601
672
|
process.exitCode = 1;
|
|
602
673
|
return;
|
|
603
674
|
}
|
|
604
|
-
if (command === "fix") {
|
|
605
|
-
const codeIndex = argv.indexOf("--code");
|
|
606
|
-
const code = codeIndex === -1 ? undefined : argv[codeIndex + 1];
|
|
607
|
-
try {
|
|
608
|
-
const { collectCheckResult } = await import("./check.js");
|
|
609
|
-
const { applyDiagnosticRecipe } = await import("./fix-recipes.js");
|
|
610
|
-
const result = await collectCheckResult(process.cwd(), { lintsOnly: true });
|
|
611
|
-
const changed = [];
|
|
612
|
-
for (const diagnostic of result.structuredDiagnostics ?? []) {
|
|
613
|
-
if (code !== undefined && diagnostic.code !== code)
|
|
614
|
-
continue;
|
|
615
|
-
changed.push(...(await applyDiagnosticRecipe(process.cwd(), diagnostic)));
|
|
616
|
-
}
|
|
617
|
-
const final = await collectCheckResult(process.cwd(), { lintsOnly: true });
|
|
618
|
-
console.log(JSON.stringify({ changed, diagnostics: final.structuredDiagnostics ?? [] }, null, 2));
|
|
619
|
-
if (final.ok === false)
|
|
620
|
-
process.exitCode = 1;
|
|
621
|
-
}
|
|
622
|
-
catch (err) {
|
|
623
|
-
console.error(formatCliError(err));
|
|
624
|
-
process.exitCode = 1;
|
|
625
|
-
}
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
675
|
// `init-agents` retrofits the agent-discovery files (.mcp.json, CLAUDE.md, …) into the cwd. It's a
|
|
629
676
|
// pure file-writing command independent of the app loading, so dispatch it before the eager `loadApp`
|
|
630
677
|
// (an existing app might be API-only or not yet built). It always succeeds unless a write throws.
|
|
@@ -636,77 +683,6 @@ async function main() {
|
|
|
636
683
|
});
|
|
637
684
|
return;
|
|
638
685
|
}
|
|
639
|
-
// `sync-manifest` rewrites a committed web `server-manifest.ts` from the current `routes/` tree, without
|
|
640
|
-
// a full build. Pure fs/text (re-scan routes, preserve baked client assets), so - like `check` - dispatch
|
|
641
|
-
// it before the eager `loadApp`.
|
|
642
|
-
if (command === "sync-manifest") {
|
|
643
|
-
const { runSyncManifest } = await import("./sync-manifest.js");
|
|
644
|
-
if (!(await runSyncManifest(process.cwd())))
|
|
645
|
-
process.exitCode = 1;
|
|
646
|
-
return;
|
|
647
|
-
}
|
|
648
|
-
// `sync-routes` regenerates the route-search types `.d.ts` (typed `navigate({ to, search })`) from
|
|
649
|
-
// `routes/`. Pure fs/text (needs only the route tree, not `framework.ts`), so dispatch before `loadApp`.
|
|
650
|
-
if (command === "sync-routes") {
|
|
651
|
-
const { runSyncRoutes } = await import("./sync-routes.js");
|
|
652
|
-
if (!(await runSyncRoutes(process.cwd())))
|
|
653
|
-
process.exitCode = 1;
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
// `doctor` is a pure cwd check (imports vs declared deps) - like `check`, dispatch before `loadApp`
|
|
657
|
-
// so it runs on an API-only / not-yet-built project.
|
|
658
|
-
if (command === "doctor") {
|
|
659
|
-
const { runDoctor } = await import("./doctor.js");
|
|
660
|
-
const targetIdx = argv.indexOf("--target");
|
|
661
|
-
const target = targetIdx !== -1 ? argv[targetIdx + 1] : undefined;
|
|
662
|
-
if (targetIdx !== -1 && (target === undefined || target.startsWith("-"))) {
|
|
663
|
-
console.error("[nifra] --target needs a value: bun | node | deno | cf-pages | vercel");
|
|
664
|
-
process.exitCode = 1;
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
if (!(await runDoctor(process.cwd(), {
|
|
668
|
-
json: argv.includes("--json"),
|
|
669
|
-
autoFix: argv.includes("--auto-fix") || argv.includes("--fix"),
|
|
670
|
-
strict: argv.includes("--strict"),
|
|
671
|
-
...(target === undefined ? {} : { target }),
|
|
672
|
-
})))
|
|
673
|
-
process.exitCode = 1;
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
// `snapshot` / `diff` load ONLY backend.ts (the API contract) - like `check`, they must run on an
|
|
677
|
-
// API-only project, so they dispatch before the eager `loadApp`.
|
|
678
|
-
if (command === "snapshot") {
|
|
679
|
-
const { runSnapshot } = await import("./diff-tool.js");
|
|
680
|
-
const outIdx = argv.indexOf("--out");
|
|
681
|
-
const out = outIdx !== -1 ? argv[outIdx + 1] : undefined;
|
|
682
|
-
if (outIdx !== -1 && (out === undefined || out.startsWith("-"))) {
|
|
683
|
-
console.error("[nifra] --out needs a file path");
|
|
684
|
-
process.exitCode = 1;
|
|
685
|
-
return;
|
|
686
|
-
}
|
|
687
|
-
try {
|
|
688
|
-
await runSnapshot(process.cwd(), out !== undefined ? { out } : {});
|
|
689
|
-
}
|
|
690
|
-
catch (err) {
|
|
691
|
-
console.error(formatCliError(err));
|
|
692
|
-
process.exitCode = 1;
|
|
693
|
-
}
|
|
694
|
-
return;
|
|
695
|
-
}
|
|
696
|
-
if (command === "diff") {
|
|
697
|
-
const { runDiff, DEFAULT_SNAPSHOT_FILE } = await import("./diff-tool.js");
|
|
698
|
-
const baseline = argv.slice(1).find((arg) => !arg.startsWith("-")) ?? DEFAULT_SNAPSHOT_FILE;
|
|
699
|
-
try {
|
|
700
|
-
if (!(await runDiff(process.cwd(), baseline, { json: argv.includes("--json") }))) {
|
|
701
|
-
process.exitCode = 1;
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
catch (err) {
|
|
705
|
-
console.error(formatCliError(err));
|
|
706
|
-
process.exitCode = 1;
|
|
707
|
-
}
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
686
|
if (command === "sdk") {
|
|
711
687
|
const languageIndex = argv.indexOf("--lang");
|
|
712
688
|
const language = languageIndex === -1 ? undefined : argv[languageIndex + 1];
|
|
@@ -732,241 +708,6 @@ async function main() {
|
|
|
732
708
|
}
|
|
733
709
|
return;
|
|
734
710
|
}
|
|
735
|
-
// Route assurance intentionally loads only its explicit config (which imports the backend it audits),
|
|
736
|
-
// not the full SSR app. Like snapshot/diff, this works for API-only projects.
|
|
737
|
-
if (command === "assure") {
|
|
738
|
-
const { runAssurance } = await import("./assure.js");
|
|
739
|
-
const configIdx = argv.indexOf("--config");
|
|
740
|
-
const config = configIdx !== -1 ? argv[configIdx + 1] : undefined;
|
|
741
|
-
if (configIdx !== -1 && (config === undefined || config.startsWith("-"))) {
|
|
742
|
-
console.error("[nifra] --config needs a file path");
|
|
743
|
-
process.exitCode = 1;
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
try {
|
|
747
|
-
if (!(await runAssurance(process.cwd(), {
|
|
748
|
-
json: argv.includes("--json"),
|
|
749
|
-
bundle: argv.includes("--json") ||
|
|
750
|
-
argv.includes("--strict") ||
|
|
751
|
-
argv.includes("--hydration") ||
|
|
752
|
-
argv.includes("--interact") ||
|
|
753
|
-
argv.includes("--out"),
|
|
754
|
-
strict: argv.includes("--strict"),
|
|
755
|
-
hydration: argv.includes("--hydration"),
|
|
756
|
-
interact: argv.includes("--interact"),
|
|
757
|
-
...(argv.includes("--out") ? { out: argv[argv.indexOf("--out") + 1] } : {}),
|
|
758
|
-
...(config !== undefined ? { config } : {}),
|
|
759
|
-
})))
|
|
760
|
-
process.exitCode = 1;
|
|
761
|
-
}
|
|
762
|
-
catch (err) {
|
|
763
|
-
console.error(formatCliError(err));
|
|
764
|
-
process.exitCode = 1;
|
|
765
|
-
}
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
if (command === "contracts") {
|
|
769
|
-
const action = argv[1];
|
|
770
|
-
const outIndex = argv.indexOf("--out");
|
|
771
|
-
const out = outIndex === -1 ? undefined : argv[outIndex + 1];
|
|
772
|
-
try {
|
|
773
|
-
const { checkContractsLock, snapshotContracts } = await import("./contracts.js");
|
|
774
|
-
if (action === "snapshot") {
|
|
775
|
-
const lock = await snapshotContracts(process.cwd(), out);
|
|
776
|
-
if (argv.includes("--json"))
|
|
777
|
-
console.log(JSON.stringify(lock, null, 2));
|
|
778
|
-
else
|
|
779
|
-
console.log(`[nifra] wrote ${Object.keys(lock.routes).length} contract digests`);
|
|
780
|
-
}
|
|
781
|
-
else if (action === "check") {
|
|
782
|
-
const result = await checkContractsLock(process.cwd());
|
|
783
|
-
const output = { ok: result.present && result.diagnostics.length === 0, ...result };
|
|
784
|
-
console.log(JSON.stringify(output, null, 2));
|
|
785
|
-
if (!output.ok)
|
|
786
|
-
process.exitCode = 1;
|
|
787
|
-
}
|
|
788
|
-
else {
|
|
789
|
-
console.error("[nifra] contracts needs snapshot or check");
|
|
790
|
-
process.exitCode = 1;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
catch (err) {
|
|
794
|
-
console.error(formatCliError(err));
|
|
795
|
-
process.exitCode = 1;
|
|
796
|
-
}
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
if (command === "replay") {
|
|
800
|
-
const file = argv[1];
|
|
801
|
-
if (file === undefined || file.startsWith("-")) {
|
|
802
|
-
console.error("[nifra] replay needs a file path");
|
|
803
|
-
process.exitCode = 1;
|
|
804
|
-
return;
|
|
805
|
-
}
|
|
806
|
-
try {
|
|
807
|
-
const { runReplay } = await import("./replay.js");
|
|
808
|
-
const result = await runReplay(process.cwd(), file);
|
|
809
|
-
console.log(JSON.stringify(result, null, 2));
|
|
810
|
-
if (!result.ok)
|
|
811
|
-
process.exitCode = 1;
|
|
812
|
-
}
|
|
813
|
-
catch (err) {
|
|
814
|
-
console.error(formatCliError(err));
|
|
815
|
-
process.exitCode = 1;
|
|
816
|
-
}
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
if (command === "capabilities") {
|
|
820
|
-
const action = argv[1];
|
|
821
|
-
const valueAfter = (flag) => {
|
|
822
|
-
const index = argv.indexOf(flag);
|
|
823
|
-
const value = index === -1 ? undefined : argv[index + 1];
|
|
824
|
-
if (index !== -1 && (value === undefined || value.startsWith("-"))) {
|
|
825
|
-
throw new Error(`[nifra] ${flag} needs a file path`);
|
|
826
|
-
}
|
|
827
|
-
return value;
|
|
828
|
-
};
|
|
829
|
-
try {
|
|
830
|
-
const { runCapabilityCheck, runCapabilitySnapshot } = await import("./capabilities-tool.js");
|
|
831
|
-
const config = valueAfter("--config");
|
|
832
|
-
if (action === "snapshot") {
|
|
833
|
-
const out = valueAfter("--out");
|
|
834
|
-
if (!(await runCapabilitySnapshot(process.cwd(), {
|
|
835
|
-
...(config !== undefined ? { config } : {}),
|
|
836
|
-
...(out !== undefined ? { out } : {}),
|
|
837
|
-
})))
|
|
838
|
-
process.exitCode = 1;
|
|
839
|
-
}
|
|
840
|
-
else if (action === "check") {
|
|
841
|
-
const lockfile = valueAfter("--lockfile");
|
|
842
|
-
if (!(await runCapabilityCheck(process.cwd(), {
|
|
843
|
-
...(config !== undefined ? { config } : {}),
|
|
844
|
-
...(lockfile !== undefined ? { lockfile } : {}),
|
|
845
|
-
json: argv.includes("--json"),
|
|
846
|
-
})))
|
|
847
|
-
process.exitCode = 1;
|
|
848
|
-
}
|
|
849
|
-
else {
|
|
850
|
-
throw new Error("[nifra] capabilities needs `snapshot` or `check`");
|
|
851
|
-
}
|
|
852
|
-
}
|
|
853
|
-
catch (err) {
|
|
854
|
-
console.error(formatCliError(err));
|
|
855
|
-
process.exitCode = 1;
|
|
856
|
-
}
|
|
857
|
-
return;
|
|
858
|
-
}
|
|
859
|
-
if (command === "manifest") {
|
|
860
|
-
const action = argv[1];
|
|
861
|
-
const valueAfter = (flag) => {
|
|
862
|
-
const index = argv.indexOf(flag);
|
|
863
|
-
const value = index === -1 ? undefined : argv[index + 1];
|
|
864
|
-
if (index !== -1 && (value === undefined || value.startsWith("-"))) {
|
|
865
|
-
throw new Error(`[nifra] ${flag} needs a value`);
|
|
866
|
-
}
|
|
867
|
-
return value;
|
|
868
|
-
};
|
|
869
|
-
try {
|
|
870
|
-
const { runManifestDiff, runManifestEmit } = await import("./manifest-tool.js");
|
|
871
|
-
if (action === "emit") {
|
|
872
|
-
const config = valueAfter("--config");
|
|
873
|
-
const out = valueAfter("--out");
|
|
874
|
-
const sign = valueAfter("--sign");
|
|
875
|
-
if (!(await runManifestEmit(process.cwd(), {
|
|
876
|
-
...(config !== undefined ? { config } : {}),
|
|
877
|
-
...(out !== undefined ? { out } : {}),
|
|
878
|
-
...(sign !== undefined ? { sign } : {}),
|
|
879
|
-
})))
|
|
880
|
-
process.exitCode = 1;
|
|
881
|
-
}
|
|
882
|
-
else if (action === "diff") {
|
|
883
|
-
const paths = argv.slice(2).filter((arg) => !arg.startsWith("-"));
|
|
884
|
-
if (paths.length !== 2)
|
|
885
|
-
throw new Error("[nifra] manifest diff needs <before> <after>");
|
|
886
|
-
if (!(await runManifestDiff(process.cwd(), paths[0], paths[1], {
|
|
887
|
-
json: argv.includes("--json"),
|
|
888
|
-
})))
|
|
889
|
-
process.exitCode = 1;
|
|
890
|
-
}
|
|
891
|
-
else {
|
|
892
|
-
throw new Error("[nifra] manifest needs `emit` or `diff`");
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
catch (err) {
|
|
896
|
-
console.error(formatCliError(err));
|
|
897
|
-
process.exitCode = 1;
|
|
898
|
-
}
|
|
899
|
-
return;
|
|
900
|
-
}
|
|
901
|
-
if (command === "levels") {
|
|
902
|
-
const valueAfter = (flag) => {
|
|
903
|
-
const index = argv.indexOf(flag);
|
|
904
|
-
const value = index === -1 ? undefined : argv[index + 1];
|
|
905
|
-
if (index !== -1 && (value === undefined || value.startsWith("-"))) {
|
|
906
|
-
throw new Error(`[nifra] ${flag} needs a value`);
|
|
907
|
-
}
|
|
908
|
-
return value;
|
|
909
|
-
};
|
|
910
|
-
try {
|
|
911
|
-
const { runLevels } = await import("./levels-tool.js");
|
|
912
|
-
const config = valueAfter("--config");
|
|
913
|
-
const minRaw = valueAfter("--min");
|
|
914
|
-
const min = minRaw === undefined ? undefined : Number(minRaw);
|
|
915
|
-
if (min !== undefined && (!Number.isInteger(min) || min < 0 || min > 4)) {
|
|
916
|
-
throw new Error("[nifra] --min must be an integer level between 0 and 4");
|
|
917
|
-
}
|
|
918
|
-
if (!(await runLevels(process.cwd(), {
|
|
919
|
-
json: argv.includes("--json"),
|
|
920
|
-
...(config !== undefined ? { config } : {}),
|
|
921
|
-
...(min !== undefined ? { min } : {}),
|
|
922
|
-
})))
|
|
923
|
-
process.exitCode = 1;
|
|
924
|
-
}
|
|
925
|
-
catch (err) {
|
|
926
|
-
console.error(formatCliError(err));
|
|
927
|
-
process.exitCode = 1;
|
|
928
|
-
}
|
|
929
|
-
return;
|
|
930
|
-
}
|
|
931
|
-
if (command === "prove") {
|
|
932
|
-
const valueAfter = (flag) => {
|
|
933
|
-
const index = argv.indexOf(flag);
|
|
934
|
-
const value = index === -1 ? undefined : argv[index + 1];
|
|
935
|
-
if (index !== -1 && (value === undefined || value.startsWith("-"))) {
|
|
936
|
-
throw new Error(`[nifra] ${flag} needs a value`);
|
|
937
|
-
}
|
|
938
|
-
return value;
|
|
939
|
-
};
|
|
940
|
-
try {
|
|
941
|
-
const minRaw = valueAfter("--min");
|
|
942
|
-
const min = minRaw === undefined ? undefined : Number(minRaw);
|
|
943
|
-
if (min !== undefined && (!Number.isInteger(min) || min < 0 || min > 4)) {
|
|
944
|
-
throw new Error("[nifra] --min must be an integer level between 0 and 4");
|
|
945
|
-
}
|
|
946
|
-
const changedFiles = [];
|
|
947
|
-
for (let index = 0; index < argv.length; index++) {
|
|
948
|
-
if (argv[index] !== "--file")
|
|
949
|
-
continue;
|
|
950
|
-
const file = argv[index + 1];
|
|
951
|
-
if (file === undefined || file.startsWith("-"))
|
|
952
|
-
throw new Error("[nifra] --file needs a path");
|
|
953
|
-
changedFiles.push(file);
|
|
954
|
-
index++;
|
|
955
|
-
}
|
|
956
|
-
const { runWorkGraph } = await import("./work-graph.js");
|
|
957
|
-
if (!(await runWorkGraph(process.cwd(), {
|
|
958
|
-
json: argv.includes("--json"),
|
|
959
|
-
...(changedFiles.length === 0 ? {} : { changedFiles }),
|
|
960
|
-
...(min === undefined ? {} : { minLevel: min }),
|
|
961
|
-
})))
|
|
962
|
-
process.exitCode = 1;
|
|
963
|
-
}
|
|
964
|
-
catch (err) {
|
|
965
|
-
console.error(formatCliError(err));
|
|
966
|
-
process.exitCode = 1;
|
|
967
|
-
}
|
|
968
|
-
return;
|
|
969
|
-
}
|
|
970
711
|
// `upgrade` is a pure cwd file-transformer (package.json pins + import moves) driven by a per-release
|
|
971
712
|
// recipe, then verified with `nifra check`. Dispatch before the eager `loadApp` - it must run on any
|
|
972
713
|
// repo (API-only, not built, or mid-upgrade with edits that don't yet typecheck under dry-run).
|
|
@@ -993,36 +734,7 @@ async function main() {
|
|
|
993
734
|
}
|
|
994
735
|
// `port` is a pure cwd-based portability linter (scans source, doesn't run the app) - like `check`/
|
|
995
736
|
// `doctor`, dispatch before the eager `loadApp` so it runs on an API-only / not-yet-built project.
|
|
996
|
-
if (command
|
|
997
|
-
const { runPort } = await import("./port.js");
|
|
998
|
-
const targetIdx = argv.indexOf("--target");
|
|
999
|
-
const target = targetIdx !== -1 ? argv[targetIdx + 1] : undefined;
|
|
1000
|
-
if (targetIdx !== -1 && (target === undefined || target.startsWith("-"))) {
|
|
1001
|
-
console.error("[nifra] --target needs a value: bun | node | deno | cf-pages | vercel");
|
|
1002
|
-
process.exitCode = 1;
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
|
-
try {
|
|
1006
|
-
const passed = await runPort(process.cwd(), {
|
|
1007
|
-
...(target !== undefined ? { target } : {}),
|
|
1008
|
-
json: argv.includes("--json"),
|
|
1009
|
-
ci: argv.includes("--ci"),
|
|
1010
|
-
strict: argv.includes("--strict"),
|
|
1011
|
-
});
|
|
1012
|
-
if (!passed)
|
|
1013
|
-
process.exitCode = 1;
|
|
1014
|
-
}
|
|
1015
|
-
catch (err) {
|
|
1016
|
-
console.error(formatCliError(err));
|
|
1017
|
-
process.exitCode = 1;
|
|
1018
|
-
}
|
|
1019
|
-
return;
|
|
1020
|
-
}
|
|
1021
|
-
if (command !== "dev" &&
|
|
1022
|
-
command !== "build" &&
|
|
1023
|
-
command !== "start" &&
|
|
1024
|
-
command !== "context" &&
|
|
1025
|
-
command !== "routes") {
|
|
737
|
+
if (command !== "dev" && command !== "build" && command !== "start") {
|
|
1026
738
|
console.error(`[nifra] unknown command: ${command}\n`);
|
|
1027
739
|
console.error(HELP);
|
|
1028
740
|
process.exitCode = 1;
|
|
@@ -1034,40 +746,6 @@ async function main() {
|
|
|
1034
746
|
await dev(app, flags);
|
|
1035
747
|
else if (command === "build")
|
|
1036
748
|
await buildForTarget(app, flags.target, flags);
|
|
1037
|
-
else if (command === "context")
|
|
1038
|
-
console.log(describeProject(app));
|
|
1039
|
-
else if (command === "routes") {
|
|
1040
|
-
if (argv.includes("--graph")) {
|
|
1041
|
-
console.log(await describeRouteGraph(app, { json: argv.includes("--json") }));
|
|
1042
|
-
}
|
|
1043
|
-
else if (argv.includes("--modes")) {
|
|
1044
|
-
// `--modes` answers a different question than the default table: not "what URLs exist" but "how
|
|
1045
|
-
// does each render, and can the target I'm about to deploy to actually honour that". Resolves
|
|
1046
|
-
// against `--target` when given, so a `static` build's server-needing route fails here, in one
|
|
1047
|
-
// place, instead of 404ing in production.
|
|
1048
|
-
const { buildRouteManifest, renderRouteManifest } = await import("@nifrajs/web/route-manifest");
|
|
1049
|
-
const manifest = discoverRoutes(app.routesDir);
|
|
1050
|
-
// `flags.target` defaults to "bun" for `build`; here an EXPLICIT `--target` is what opts into
|
|
1051
|
-
// gating, so read it from argv rather than inheriting the build default (which would silently gate
|
|
1052
|
-
// every `nifra routes --modes` against bun).
|
|
1053
|
-
const targetIdx = argv.indexOf("--target");
|
|
1054
|
-
const target = targetIdx !== -1 ? argv[targetIdx + 1] : undefined;
|
|
1055
|
-
const routeManifest = await buildRouteManifest(manifest, {
|
|
1056
|
-
...(target !== undefined ? { target } : {}),
|
|
1057
|
-
});
|
|
1058
|
-
if (argv.includes("--json"))
|
|
1059
|
-
console.log(JSON.stringify(routeManifest, null, 2));
|
|
1060
|
-
else
|
|
1061
|
-
console.log(renderRouteManifest(routeManifest));
|
|
1062
|
-
// A target that cannot honour a route is a build-breaking fact, not a note: exit non-zero so the
|
|
1063
|
-
// same command in CI gates the deploy it is warning about.
|
|
1064
|
-
if (routeManifest.conflicts.length > 0)
|
|
1065
|
-
process.exitCode = 1;
|
|
1066
|
-
}
|
|
1067
|
-
else {
|
|
1068
|
-
console.log(await describeRoutes(app, { json: argv.includes("--json") }));
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
749
|
else
|
|
1072
750
|
await start(app, flags);
|
|
1073
751
|
}
|