@nifrajs/cli 5.6.0 → 5.8.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 +175 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +4 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts +6 -0
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +1 -30
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +35 -12
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +53 -5
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts +5 -0
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +18 -6
- package/dist/command-catalog.js.map +1 -1
- package/dist/contracts.d.ts +42 -4
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +288 -9
- package/dist/contracts.js.map +1 -1
- package/dist/doctor.d.ts +6 -4
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +20 -6
- package/dist/doctor.js.map +1 -1
- package/dist/internal/git-ignored.d.ts +12 -0
- package/dist/internal/git-ignored.d.ts.map +1 -0
- package/dist/internal/git-ignored.js +49 -0
- package/dist/internal/git-ignored.js.map +1 -0
- package/dist/internal/source-facts.d.ts +29 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +160 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/load.d.ts +4 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +10 -0
- package/dist/load.js.map +1 -1
- package/dist/local-cli.d.ts +15 -0
- package/dist/local-cli.d.ts.map +1 -0
- package/dist/local-cli.js +74 -0
- package/dist/local-cli.js.map +1 -0
- package/dist/lock-links.d.ts +0 -7
- package/dist/lock-links.d.ts.map +1 -1
- package/dist/lock-links.js +5 -44
- package/dist/lock-links.js.map +1 -1
- package/dist/mcp-delegate.d.ts +13 -5
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +24 -8
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/openapi-types.d.ts.map +1 -1
- package/dist/openapi-types.js +45 -2
- package/dist/openapi-types.js.map +1 -1
- package/dist/recipes/5.7.0.d.ts +12 -0
- package/dist/recipes/5.7.0.d.ts.map +1 -0
- package/dist/recipes/5.7.0.js +70 -0
- package/dist/recipes/5.7.0.js.map +1 -0
- package/dist/recipes/5.8.0.d.ts +9 -0
- package/dist/recipes/5.8.0.d.ts.map +1 -0
- package/dist/recipes/5.8.0.js +20 -0
- package/dist/recipes/5.8.0.js.map +1 -0
- package/dist/recipes/index.d.ts +13 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +4 -0
- package/dist/recipes/index.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +2 -0
- package/dist/review.js.map +1 -1
- package/dist/rules/codes.d.ts +2 -0
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +2 -0
- package/dist/rules/codes.js.map +1 -1
- package/dist/rules/explanations.d.ts.map +1 -1
- package/dist/rules/explanations.js +13 -3
- package/dist/rules/explanations.js.map +1 -1
- package/dist/rules/legacy.js +1 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/text-slot-boolean.d.ts +8 -0
- package/dist/rules/text-slot-boolean.d.ts.map +1 -0
- package/dist/rules/text-slot-boolean.js +57 -0
- package/dist/rules/text-slot-boolean.js.map +1 -0
- package/dist/rules/undeclared-response.d.ts +9 -0
- package/dist/rules/undeclared-response.d.ts.map +1 -0
- package/dist/rules/undeclared-response.js +93 -0
- package/dist/rules/undeclared-response.js.map +1 -0
- package/dist/upgrade.d.ts +34 -8
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +197 -25
- package/dist/upgrade.js.map +1 -1
- package/dist/version-drift.js +1 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +7 -1
- package/docs/llms-full.txt +441 -105
- package/docs/types.json +164 -43
- package/package.json +11 -11
- package/src/check-diagnostics.ts +4 -0
- package/src/check-scan.ts +1 -29
- package/src/check.ts +32 -10
- package/src/cli.ts +58 -5
- package/src/command-catalog.ts +23 -6
- package/src/contracts.ts +348 -14
- package/src/doctor.ts +28 -12
- package/src/internal/git-ignored.ts +47 -0
- package/src/internal/source-facts.ts +198 -0
- package/src/load.ts +16 -0
- package/src/local-cli.ts +83 -0
- package/src/lock-links.ts +5 -43
- package/src/mcp-delegate.ts +30 -9
- package/src/mcp-http.ts +1 -1
- package/src/openapi-types.ts +43 -2
- package/src/recipes/5.7.0.ts +72 -0
- package/src/recipes/5.8.0.ts +21 -0
- package/src/recipes/index.ts +18 -0
- package/src/review.ts +2 -0
- package/src/rules/codes.ts +2 -0
- package/src/rules/explanations.ts +13 -3
- package/src/rules/legacy.ts +1 -1
- package/src/rules/text-slot-boolean.ts +56 -0
- package/src/rules/undeclared-response.ts +92 -0
- package/src/upgrade.ts +229 -33
- package/src/version-drift.ts +1 -1
- package/src/web-app-options.ts +1 -0
package/dist/upgrade.js
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* 2. **dependency moves** - replace removed packages with their supported successor without
|
|
13
13
|
* reserializing package.json or leaving duplicate dependency keys.
|
|
14
14
|
* 3. **import moves** - rewrite exact import specifiers to their updated module paths.
|
|
15
|
-
* 4. **
|
|
15
|
+
* 4. **dependency adds** - add a package an imported entry needs to the manifest that imports it,
|
|
16
|
+
* beside the package the entry belongs to, when that manifest lists it nowhere.
|
|
17
|
+
* 5. **verify** - reuse the existing `nifra check` gate; no new verification surface. It reads the
|
|
16
18
|
* installed packages, so while the edited pins are not installed yet it is skipped with the
|
|
17
19
|
* install command to run first: a check then would judge the release being left.
|
|
18
20
|
*
|
|
@@ -34,8 +36,9 @@ import { Glob } from "bun";
|
|
|
34
36
|
import { collectHookReport, diffHookReports, HOOKS_BEFORE_UPGRADE_FILE, parseHookReport, renderHookDiff, } from "./hooks-report.js";
|
|
35
37
|
import { ancestorPins, declaresCli, PIN_SITES } from "./init-agents.js";
|
|
36
38
|
import { codeUnitOrder } from "./internal/code-unit-order.js";
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
+
import { gitIgnoredSync } from "./internal/git-ignored.js";
|
|
40
|
+
import { BUN_LOCK, describeChange, linkLockUpdate, staleLinkLocks, } from "./lock-links.js";
|
|
41
|
+
import { getRecipe, listRecipeVersions, } from "./recipes/index.js";
|
|
39
42
|
import { markerTarget } from "./rules/comment-markers.js";
|
|
40
43
|
const DEP_FIELDS = [
|
|
41
44
|
"dependencies",
|
|
@@ -453,6 +456,130 @@ export function applyImportMoves(text, moves) {
|
|
|
453
456
|
return { text: out, changes };
|
|
454
457
|
}
|
|
455
458
|
const SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}";
|
|
459
|
+
// Svelte and Vue components import adapter entries too.
|
|
460
|
+
const ADD_SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,svelte,vue}";
|
|
461
|
+
const IMPORTED_SPEC = (prefix) => new RegExp(`(?:\\bfrom\\s*|\\bimport\\s*\\(\\s*|\\brequire\\s*\\(\\s*|\\bimport\\s+)(['"])(${escapeRegExp(prefix)}(?:/[^'"]*)?)\\1`);
|
|
462
|
+
/** The first specifier in `text` that names one of `imports` or a subpath of one. */
|
|
463
|
+
export function importedSpecifier(text, imports) {
|
|
464
|
+
for (const prefix of imports) {
|
|
465
|
+
const match = IMPORTED_SPEC(prefix).exec(text);
|
|
466
|
+
if (match !== null)
|
|
467
|
+
return match[2];
|
|
468
|
+
}
|
|
469
|
+
return undefined;
|
|
470
|
+
}
|
|
471
|
+
const packageOf = (specifier) => specifier
|
|
472
|
+
.split("/")
|
|
473
|
+
.slice(0, specifier.startsWith("@") ? 2 : 1)
|
|
474
|
+
.join("/");
|
|
475
|
+
const MEMBER = /("(?:[^"\\]|\\.)*")\s*:\s*"(?:[^"\\]|\\.)*"/g;
|
|
476
|
+
/**
|
|
477
|
+
* Add `"name": "version"` to the `field` object of a package.json text without reserializing it,
|
|
478
|
+
* creating the field at the end of the root when absent. The entry goes before the first larger name
|
|
479
|
+
* when the members are sorted, last otherwise.
|
|
480
|
+
*/
|
|
481
|
+
function insertDependencyEntry(text, field, name, version) {
|
|
482
|
+
const entry = `${JSON.stringify(name)}: ${JSON.stringify(version)}`;
|
|
483
|
+
const unit = /\n([ \t]+)"/.exec(text)?.[1] ?? " ";
|
|
484
|
+
const range = objectRangeAt(text, [field]);
|
|
485
|
+
if (range === undefined) {
|
|
486
|
+
const root = objectRangeAt(text, []);
|
|
487
|
+
if (root === undefined)
|
|
488
|
+
return text;
|
|
489
|
+
const body = text.slice(root.start, root.end);
|
|
490
|
+
const at = root.start + body.trimEnd().length;
|
|
491
|
+
const comma = body.trim() === "" ? "" : ",";
|
|
492
|
+
const close = /^[ \t]*\n/.test(text.slice(at)) ? "" : "\n";
|
|
493
|
+
const object = `${JSON.stringify(field)}: {\n${unit}${unit}${entry}\n${unit}}`;
|
|
494
|
+
return `${text.slice(0, at)}${comma}\n${unit}${object}${close}${text.slice(at)}`;
|
|
495
|
+
}
|
|
496
|
+
const body = text.slice(range.start, range.end);
|
|
497
|
+
const members = [...body.matchAll(MEMBER)];
|
|
498
|
+
const first = members[0];
|
|
499
|
+
const last = members.at(-1);
|
|
500
|
+
if (first === undefined || last === undefined) {
|
|
501
|
+
const lineStart = text.lastIndexOf("\n", range.start) + 1;
|
|
502
|
+
const indent = /^[ \t]*/.exec(text.slice(lineStart))?.[0] ?? "";
|
|
503
|
+
return `${text.slice(0, range.start)}\n${indent}${unit}${entry}\n${indent}${text.slice(range.end)}`;
|
|
504
|
+
}
|
|
505
|
+
const names = members.map((member) => JSON.parse(member[1] ?? '""'));
|
|
506
|
+
const newline = body.lastIndexOf("\n", first.index);
|
|
507
|
+
const separator = newline === -1 ? " " : `\n${body.slice(newline + 1, first.index)}`;
|
|
508
|
+
const sorted = names.every((current, index) => typeof current === "string" && (index === 0 || String(names[index - 1]) <= current));
|
|
509
|
+
const before = sorted ? members.find((_, index) => String(names[index]) > name) : undefined;
|
|
510
|
+
const at = range.start + (before === undefined ? last.index + last[0].length : before.index);
|
|
511
|
+
const insert = before === undefined ? `,${separator}${entry}` : `${entry},${separator}`;
|
|
512
|
+
return text.slice(0, at) + insert + text.slice(at);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Add `rule.add` to a package.json text beside the first anchor it lists - the imported entry's own
|
|
516
|
+
* package, then each of `rule.beside` - in every field that anchor is in, with the anchor's range
|
|
517
|
+
* style; in `dependencies` when no anchor is listed. Undefined when the manifest already lists the
|
|
518
|
+
* package in any field, is that package, or the edit would not parse.
|
|
519
|
+
*/
|
|
520
|
+
export function addDependencyText(text, rule, specifier, version, exact = false) {
|
|
521
|
+
let parsed;
|
|
522
|
+
try {
|
|
523
|
+
parsed = JSON.parse(text);
|
|
524
|
+
}
|
|
525
|
+
catch {
|
|
526
|
+
return undefined;
|
|
527
|
+
}
|
|
528
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
529
|
+
return undefined;
|
|
530
|
+
const manifest = parsed;
|
|
531
|
+
if (Reflect.get(manifest, "name") === rule.add)
|
|
532
|
+
return undefined;
|
|
533
|
+
const specIn = (from, field, name) => {
|
|
534
|
+
const deps = Reflect.get(from, field);
|
|
535
|
+
if (typeof deps !== "object" || deps === null || !Object.hasOwn(deps, name))
|
|
536
|
+
return undefined;
|
|
537
|
+
const spec = Reflect.get(deps, name);
|
|
538
|
+
return typeof spec === "string" ? spec : undefined;
|
|
539
|
+
};
|
|
540
|
+
if (DEP_FIELDS.some((field) => specIn(manifest, field, rule.add) !== undefined))
|
|
541
|
+
return undefined;
|
|
542
|
+
const fallback = exact ? version : `^${version}`;
|
|
543
|
+
const rangeFor = (spec) => rewriteVersionSpec(spec, version, exact) ?? (specVersion(spec) === version ? spec : fallback);
|
|
544
|
+
let placed = [];
|
|
545
|
+
for (const anchor of [packageOf(specifier), ...(rule.beside ?? [])]) {
|
|
546
|
+
placed = DEP_FIELDS.flatMap((field) => {
|
|
547
|
+
const spec = specIn(manifest, field, anchor);
|
|
548
|
+
return spec === undefined ? [] : [{ field, name: rule.add, version: rangeFor(spec) }];
|
|
549
|
+
});
|
|
550
|
+
if (placed.length > 0)
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
if (placed.length === 0)
|
|
554
|
+
placed = [{ field: "dependencies", name: rule.add, version: fallback }];
|
|
555
|
+
let out = text;
|
|
556
|
+
for (const change of placed)
|
|
557
|
+
out = insertDependencyEntry(out, change.field, rule.add, change.version);
|
|
558
|
+
// The edit is textual; a result that does not parse, or lacks an entry, is never written.
|
|
559
|
+
let written;
|
|
560
|
+
try {
|
|
561
|
+
written = JSON.parse(out);
|
|
562
|
+
}
|
|
563
|
+
catch {
|
|
564
|
+
return undefined;
|
|
565
|
+
}
|
|
566
|
+
if (typeof written !== "object" || written === null)
|
|
567
|
+
return undefined;
|
|
568
|
+
const result = written;
|
|
569
|
+
if (placed.some((change) => specIn(result, change.field, rule.add) !== change.version))
|
|
570
|
+
return undefined;
|
|
571
|
+
return { text: out, changes: placed };
|
|
572
|
+
}
|
|
573
|
+
/** The package.json nearest above `file`, both relative to `cwd`; undefined when none is under it. */
|
|
574
|
+
function nearestManifest(cwd, file) {
|
|
575
|
+
for (let dir = dirname(file);; dir = dirname(dir)) {
|
|
576
|
+
const manifest = dir === "." ? "package.json" : `${dir}/package.json`;
|
|
577
|
+
if (plainFileAt(cwd, manifest))
|
|
578
|
+
return manifest;
|
|
579
|
+
if (dir === ".")
|
|
580
|
+
return undefined;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
456
583
|
const IGNORED_DIRECTORIES = new Set(["node_modules", "dist", "build", ".git", "coverage", ".next"]);
|
|
457
584
|
// Any directory on the path counts, the top-level one included (`dist/index.js`). Bun's glob yields
|
|
458
585
|
// `dist\index.js` on Windows.
|
|
@@ -469,7 +596,9 @@ function scan(cwd, pattern, dot = false) {
|
|
|
469
596
|
if (!isIgnored(path))
|
|
470
597
|
out.push(path.replaceAll("\\", "/"));
|
|
471
598
|
}
|
|
472
|
-
|
|
599
|
+
// A gitignored copy (a backup, a generated app) is not the project: never edited, never reported.
|
|
600
|
+
const ignored = gitIgnoredSync(cwd, out);
|
|
601
|
+
return (ignored.size === 0 ? out : out.filter((path) => !ignored.has(path))).sort();
|
|
473
602
|
}
|
|
474
603
|
// The fixed version group: every package released together at one version.
|
|
475
604
|
export const isFixedGroup = (name) => name.startsWith("@nifrajs/") || name === "nifra" || name === "create-nifra";
|
|
@@ -930,6 +1059,7 @@ export function chainRecipes(target, installed) {
|
|
|
930
1059
|
pins: [...pins].map(([match, to]) => ({ match, to })),
|
|
931
1060
|
dependencyMoves: recipes.flatMap((recipe) => recipe.dependencyMoves ?? []),
|
|
932
1061
|
importMoves: recipes.flatMap((recipe) => recipe.importMoves),
|
|
1062
|
+
dependencyAdds: recipes.flatMap((recipe) => recipe.dependencyAdds ?? []),
|
|
933
1063
|
retiredMarkers: recipes.flatMap((recipe) => recipe.retiredMarkers ?? []),
|
|
934
1064
|
notes: recipes.flatMap((recipe) => (recipe.notes ?? []).map((note) => `${recipe.version}: ${note}`)),
|
|
935
1065
|
};
|
|
@@ -941,6 +1071,7 @@ export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact
|
|
|
941
1071
|
const planned = new Map();
|
|
942
1072
|
const dependencyMoves = [];
|
|
943
1073
|
const importMoves = [];
|
|
1074
|
+
const dependencyAdds = [];
|
|
944
1075
|
const downgrades = [];
|
|
945
1076
|
const retiredMarkers = [];
|
|
946
1077
|
const linkedOutside = installedGroupPackages(cwd)
|
|
@@ -965,23 +1096,15 @@ export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact
|
|
|
965
1096
|
writeFileSync(abs, pinned.text);
|
|
966
1097
|
}
|
|
967
1098
|
}
|
|
968
|
-
// Read against the manifests as this upgrade leaves them
|
|
1099
|
+
// Read against the manifests as this upgrade leaves them.
|
|
969
1100
|
const linkLocks = plainFileAt(cwd, BUN_LOCK) ? staleLinkLocks(resolve(cwd), manifests) : [];
|
|
970
|
-
let lockPruned = false;
|
|
971
|
-
if (write && linkLocks.length > 0) {
|
|
972
|
-
const lockPath = join(cwd, BUN_LOCK);
|
|
973
|
-
const pruned = pruneLinkLocks(readFileSync(lockPath, "utf8"), linkLocks.map((entry) => entry.package));
|
|
974
|
-
if (pruned !== undefined) {
|
|
975
|
-
writeFileSync(lockPath, pruned);
|
|
976
|
-
lockPruned = true;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
1101
|
for (const { change, text, abs } of agentPinEdits(cwd, recipe.version, above)) {
|
|
980
1102
|
agentPins.push(change);
|
|
981
1103
|
planned.set(change.file, text);
|
|
982
1104
|
if (write)
|
|
983
1105
|
writeFileSync(abs, Buffer.from(text, "latin1"));
|
|
984
1106
|
}
|
|
1107
|
+
const movedSources = new Map();
|
|
985
1108
|
if (recipe.importMoves.length > 0) {
|
|
986
1109
|
for (const rel of scan(cwd, SOURCE_GLOB)) {
|
|
987
1110
|
const abs = join(cwd, rel);
|
|
@@ -989,12 +1112,38 @@ export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact
|
|
|
989
1112
|
const result = applyImportMoves(text, recipe.importMoves);
|
|
990
1113
|
if (result.changes.length === 0)
|
|
991
1114
|
continue;
|
|
1115
|
+
movedSources.set(rel, result.text);
|
|
992
1116
|
for (const change of result.changes)
|
|
993
1117
|
importMoves.push({ file: rel, ...change });
|
|
994
1118
|
if (write)
|
|
995
1119
|
writeFileSync(abs, result.text);
|
|
996
1120
|
}
|
|
997
1121
|
}
|
|
1122
|
+
// Read the sources as the import moves leave them, and each manifest as the pins left it.
|
|
1123
|
+
const adds = recipe.dependencyAdds ?? [];
|
|
1124
|
+
if (adds.length > 0) {
|
|
1125
|
+
for (const rel of scan(cwd, ADD_SOURCE_GLOB)) {
|
|
1126
|
+
const source = movedSources.get(rel) ?? readFileSync(join(cwd, rel), "utf8");
|
|
1127
|
+
for (const rule of adds) {
|
|
1128
|
+
const specifier = importedSpecifier(source, rule.imports);
|
|
1129
|
+
if (specifier === undefined)
|
|
1130
|
+
continue;
|
|
1131
|
+
const file = nearestManifest(cwd, rel);
|
|
1132
|
+
if (file === undefined)
|
|
1133
|
+
continue;
|
|
1134
|
+
const abs = resolve(cwd, file);
|
|
1135
|
+
const current = manifests.get(abs) ?? readFileSync(abs, "utf8");
|
|
1136
|
+
const added = addDependencyText(current, rule, specifier, recipe.version, exact);
|
|
1137
|
+
if (added === undefined)
|
|
1138
|
+
continue;
|
|
1139
|
+
manifests.set(abs, added.text);
|
|
1140
|
+
for (const change of added.changes)
|
|
1141
|
+
dependencyAdds.push({ file, ...change, importer: rel, specifier });
|
|
1142
|
+
if (write)
|
|
1143
|
+
writeFileSync(abs, added.text);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
998
1147
|
// Read after the import moves, so a listed line number is the one the file has after `--write`.
|
|
999
1148
|
const retired = recipe.retiredMarkers ?? [];
|
|
1000
1149
|
if (retired.length > 0) {
|
|
@@ -1022,13 +1171,13 @@ export function computeUpgrade(cwd, recipe, write, allowDowngrade = false, exact
|
|
|
1022
1171
|
agentPins,
|
|
1023
1172
|
dependencyMoves,
|
|
1024
1173
|
importMoves,
|
|
1174
|
+
dependencyAdds,
|
|
1025
1175
|
downgrades,
|
|
1026
1176
|
retiredMarkers,
|
|
1027
1177
|
linkedOutside,
|
|
1028
1178
|
linkedSkew: linkedSkew(cwd, recipe.version),
|
|
1029
1179
|
strayPins: strayPins(cwd, recipe.version, planned),
|
|
1030
1180
|
linkLocks,
|
|
1031
|
-
lockPruned,
|
|
1032
1181
|
notes: recipe.notes ?? [],
|
|
1033
1182
|
unaffected: unaffectedReleases("steps" in recipe && Array.isArray(recipe.steps) ? recipe.steps : [recipe.version], groupSurface(cwd)),
|
|
1034
1183
|
};
|
|
@@ -1049,6 +1198,7 @@ function renderPlan(plan, write, from, steps) {
|
|
|
1049
1198
|
plan.agentPins.length === 0 &&
|
|
1050
1199
|
plan.dependencyMoves.length === 0 &&
|
|
1051
1200
|
plan.importMoves.length === 0 &&
|
|
1201
|
+
plan.dependencyAdds.length === 0 &&
|
|
1052
1202
|
plan.retiredMarkers.length === 0 &&
|
|
1053
1203
|
plan.linkedOutside.length === 0 &&
|
|
1054
1204
|
plan.linkedSkew.length === 0 &&
|
|
@@ -1088,6 +1238,13 @@ function renderPlan(plan, write, from, steps) {
|
|
|
1088
1238
|
lines.push(` ${m.file} ${m.from} → ${m.to} (${m.count})`);
|
|
1089
1239
|
lines.push("");
|
|
1090
1240
|
}
|
|
1241
|
+
if (plan.dependencyAdds.length > 0) {
|
|
1242
|
+
lines.push(`${verb} ${plan.dependencyAdds.length} dependency addition(s):`);
|
|
1243
|
+
for (const add of plan.dependencyAdds) {
|
|
1244
|
+
lines.push(` ${add.file} ${add.field}: ${add.name}@${add.version} (${add.importer} imports ${add.specifier})`);
|
|
1245
|
+
}
|
|
1246
|
+
lines.push("");
|
|
1247
|
+
}
|
|
1091
1248
|
if (plan.retiredMarkers.length > 0) {
|
|
1092
1249
|
lines.push(`${plan.retiredMarkers.length} retired comment(s) that silence nothing now; nifra check reports what each covered:`);
|
|
1093
1250
|
for (const site of plan.retiredMarkers) {
|
|
@@ -1122,15 +1279,10 @@ function renderPlan(plan, write, from, steps) {
|
|
|
1122
1279
|
lines.push("");
|
|
1123
1280
|
}
|
|
1124
1281
|
if (plan.linkLocks.length > 0) {
|
|
1125
|
-
lines.push(plan.
|
|
1126
|
-
? `Dropped ${plan.linkLocks.length} file: package(s) from bun.lock, whose recorded dependencies Bun never refreshes; \`bun install\` reads each linked package.json again:`
|
|
1127
|
-
: write
|
|
1128
|
-
? `bun.lock records stale dependencies for ${plan.linkLocks.length} file: package(s), which Bun never refreshes; run \`${linkLockUpdate(plan.linkLocks)}\`:`
|
|
1129
|
-
: `bun.lock records stale dependencies for ${plan.linkLocks.length} file: package(s), which Bun never refreshes; --write drops them so \`bun install\` reads each linked package.json again:`);
|
|
1282
|
+
lines.push(`bun.lock records stale dependencies for ${plan.linkLocks.length} file: package(s). ${write ? "Left as it is" : "--write leaves it as it is"}; run \`${linkLockUpdate(plan.linkLocks)}\`, which refreshes those entries and keeps every other pin:`);
|
|
1130
1283
|
for (const entry of plan.linkLocks)
|
|
1131
1284
|
lines.push(` ${entry.package} (file:${entry.path}) ${entry.changes.map(describeChange).join(", ")}`);
|
|
1132
|
-
|
|
1133
|
-
lines.push(" Run `bun install` before committing bun.lock: until it records these packages again, `bun install --frozen-lockfile` fails.");
|
|
1285
|
+
lines.push(" Bun records each linked package.json as it is on disk, uncommitted edits included: review the bun.lock diff before committing it.");
|
|
1134
1286
|
lines.push("");
|
|
1135
1287
|
}
|
|
1136
1288
|
for (const note of plan.notes)
|
|
@@ -1179,14 +1331,13 @@ const INSTALL_COMMANDS = [
|
|
|
1179
1331
|
];
|
|
1180
1332
|
/**
|
|
1181
1333
|
* Whether the project needs an install before a check can judge the target: `--write` changed what
|
|
1182
|
-
* package.json declares
|
|
1183
|
-
* version. A link from outside the root is left out; installing here does not move it.
|
|
1334
|
+
* package.json declares, or node_modules holds a group package at another version. A link from outside the root is left out; installing here does not move it.
|
|
1184
1335
|
*/
|
|
1185
1336
|
export function pendingInstall(cwd, plan) {
|
|
1186
1337
|
const installed = installedGroupPackages(cwd)
|
|
1187
1338
|
.filter((entry) => entry.inside && entry.version !== plan.version)
|
|
1188
1339
|
.map(({ package: name, version }) => ({ package: name, version }));
|
|
1189
|
-
const edited = plan.pins.length > 0 || plan.dependencyMoves.length > 0 || plan.
|
|
1340
|
+
const edited = plan.pins.length > 0 || plan.dependencyMoves.length > 0 || plan.dependencyAdds.length > 0;
|
|
1190
1341
|
if (!edited && installed.length === 0)
|
|
1191
1342
|
return undefined;
|
|
1192
1343
|
const command = INSTALL_COMMANDS.find(([lockfile]) => existsSync(join(cwd, lockfile)))?.[1] ?? "bun install";
|
|
@@ -1314,6 +1465,22 @@ function newerCliCommand(version, options) {
|
|
|
1314
1465
|
return ["bunx", `@nifrajs/cli@${version}`, "upgrade", version, ...flags].join(" ");
|
|
1315
1466
|
}
|
|
1316
1467
|
/** CLI entry. Returns false (→ non-zero exit) on an unknown version, no project, or a failed verify. */
|
|
1468
|
+
/** The contracts.lock.json routes that send a body but whose request side guards nothing. A release
|
|
1469
|
+
* that reads a body schema the installed one could not has `nifra check` report each as newly
|
|
1470
|
+
* covered. Read routes and response sides are left out: most declare no schema there. */
|
|
1471
|
+
async function uncoveredContracts(cwd) {
|
|
1472
|
+
const { blindLockEntries, DEFAULT_CONTRACTS_LOCK, parseContractsLock } = await import("./contracts.js");
|
|
1473
|
+
try {
|
|
1474
|
+
const text = readFileSync(join(cwd, DEFAULT_CONTRACTS_LOCK), "utf8");
|
|
1475
|
+
return (await blindLockEntries(parseContractsLock(JSON.parse(text))))
|
|
1476
|
+
.filter((entry) => entry.sides.includes("request") && !/^(?:GET|HEAD|OPTIONS) /.test(entry.route))
|
|
1477
|
+
.map((entry) => entry.route);
|
|
1478
|
+
}
|
|
1479
|
+
catch {
|
|
1480
|
+
return [];
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
const uncoveredContractsNote = (routes) => `note: contracts.lock.json records no request schema for ${routes.slice(0, 3).join(", ")}${routes.length > 3 ? ` and ${routes.length - 3} more` : ""}. Where this release reads a schema the installed one could not, \`nifra check\` reports it as newly covered: review it, then run \`nifra contracts snapshot\`.`;
|
|
1317
1484
|
export async function runUpgrade(cwd, options) {
|
|
1318
1485
|
const cliVersion = options.cliVersion ?? listRecipeVersions().at(-1) ?? "0.0.0";
|
|
1319
1486
|
const targets = upgradeTargets(cliVersion);
|
|
@@ -1401,9 +1568,12 @@ export async function runUpgrade(cwd, options) {
|
|
|
1401
1568
|
// Verify only makes sense once edits are on disk and installed. Default on after --write; opt out
|
|
1402
1569
|
// with --no-verify. An uninstalled upgrade passes, so `upgrade --write && bun install` chains.
|
|
1403
1570
|
const verify = write && options.verify !== false && pending === undefined;
|
|
1571
|
+
const uncovered = await uncoveredContracts(cwd);
|
|
1404
1572
|
if (options.json) {
|
|
1405
1573
|
// The check result rides inside the one JSON document; its human report would break the stream.
|
|
1406
1574
|
const report = { ...plan, from, steps: recipe.steps, write };
|
|
1575
|
+
if (uncovered.length > 0)
|
|
1576
|
+
report.contractsUncovered = uncovered;
|
|
1407
1577
|
if (hooks !== undefined)
|
|
1408
1578
|
report.hooks = hooks;
|
|
1409
1579
|
if (pending !== undefined)
|
|
@@ -1420,6 +1590,8 @@ export async function runUpgrade(cwd, options) {
|
|
|
1420
1590
|
return ok;
|
|
1421
1591
|
}
|
|
1422
1592
|
console.log(renderPlan(plan, write, from, recipe.steps));
|
|
1593
|
+
if (uncovered.length > 0)
|
|
1594
|
+
console.log(uncoveredContractsNote(uncovered));
|
|
1423
1595
|
if (plan.linkedSkew.length > 0)
|
|
1424
1596
|
console.warn(`\n${renderLinkedSkew(recipe.version, plan.linkedSkew, cwd, true)}`);
|
|
1425
1597
|
if (hooks !== undefined)
|