@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/src/upgrade.ts
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
|
*
|
|
@@ -52,15 +54,20 @@ import {
|
|
|
52
54
|
} from "./hooks-report.ts"
|
|
53
55
|
import { type AncestorPinSite, ancestorPins, declaresCli, PIN_SITES } from "./init-agents.ts"
|
|
54
56
|
import { codeUnitOrder } from "./internal/code-unit-order.ts"
|
|
57
|
+
import { gitIgnoredSync } from "./internal/git-ignored.ts"
|
|
55
58
|
import {
|
|
56
59
|
BUN_LOCK,
|
|
57
60
|
describeChange,
|
|
58
61
|
linkLockUpdate,
|
|
59
|
-
pruneLinkLocks,
|
|
60
62
|
type StaleLinkLock,
|
|
61
63
|
staleLinkLocks,
|
|
62
64
|
} from "./lock-links.ts"
|
|
63
|
-
import {
|
|
65
|
+
import {
|
|
66
|
+
type DependencyAdd,
|
|
67
|
+
getRecipe,
|
|
68
|
+
listRecipeVersions,
|
|
69
|
+
type UpgradeRecipe,
|
|
70
|
+
} from "./recipes/index.ts"
|
|
64
71
|
import { markerTarget } from "./rules/comment-markers.ts"
|
|
65
72
|
|
|
66
73
|
export interface UpgradeOptions {
|
|
@@ -115,6 +122,17 @@ export interface DependencyMoveChange {
|
|
|
115
122
|
readonly action: "renamed" | "removed"
|
|
116
123
|
}
|
|
117
124
|
|
|
125
|
+
/** A package added to a manifest because a source file beneath it imports an entry that needs it. */
|
|
126
|
+
export interface DependencyAddChange {
|
|
127
|
+
readonly file: string
|
|
128
|
+
readonly field: string
|
|
129
|
+
readonly name: string
|
|
130
|
+
readonly version: string
|
|
131
|
+
/** The first source file found importing that entry, and the specifier it uses. */
|
|
132
|
+
readonly importer: string
|
|
133
|
+
readonly specifier: string
|
|
134
|
+
}
|
|
135
|
+
|
|
118
136
|
/** An agent file whose MCP launch pins another `@nifrajs/cli`, re-pinned to the target. */
|
|
119
137
|
export interface AgentPinChange {
|
|
120
138
|
readonly file: string
|
|
@@ -141,6 +159,7 @@ export interface UpgradePlan {
|
|
|
141
159
|
readonly agentPins: readonly AgentPinChange[]
|
|
142
160
|
readonly dependencyMoves: readonly DependencyMoveChange[]
|
|
143
161
|
readonly importMoves: readonly ImportChange[]
|
|
162
|
+
readonly dependencyAdds: readonly DependencyAddChange[]
|
|
144
163
|
/** Pins refused because the target is BELOW the installed version (a rollback). Empty when allowed. */
|
|
145
164
|
readonly downgrades: readonly PinChange[]
|
|
146
165
|
/** Comments a release in the chain stopped honoring. Listed only, never rewritten. */
|
|
@@ -153,10 +172,9 @@ export interface UpgradePlan {
|
|
|
153
172
|
/** Other versions pinned outside package.json. Never edited. */
|
|
154
173
|
readonly strayPins: readonly StrayPin[]
|
|
155
174
|
/** `file:` entries of the project's bun.lock whose recorded dependencies the linked package.json
|
|
156
|
-
* (as this upgrade leaves it) no longer declares. Bun never refreshes them on its own.
|
|
175
|
+
* (as this upgrade leaves it) no longer declares. Bun 1.4.2 never refreshes them on its own. Never
|
|
176
|
+
* edited: an install that finds one missing re-resolves every package in the lock. */
|
|
157
177
|
readonly linkLocks: readonly StaleLinkLock[]
|
|
158
|
-
/** Whether `--write` dropped {@link linkLocks} from bun.lock, so `bun install` re-reads them. */
|
|
159
|
-
readonly lockPruned: boolean
|
|
160
178
|
readonly notes: readonly string[]
|
|
161
179
|
/** Releases on the way up that announce no behaviour change for the packages this project loads. */
|
|
162
180
|
readonly unaffected: readonly UnaffectedRelease[]
|
|
@@ -632,6 +650,138 @@ export function applyImportMoves(
|
|
|
632
650
|
}
|
|
633
651
|
|
|
634
652
|
const SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}"
|
|
653
|
+
// Svelte and Vue components import adapter entries too.
|
|
654
|
+
const ADD_SOURCE_GLOB = "**/*.{ts,tsx,mts,cts,js,jsx,mjs,cjs,svelte,vue}"
|
|
655
|
+
|
|
656
|
+
const IMPORTED_SPEC = (prefix: string): RegExp =>
|
|
657
|
+
new RegExp(
|
|
658
|
+
`(?:\\bfrom\\s*|\\bimport\\s*\\(\\s*|\\brequire\\s*\\(\\s*|\\bimport\\s+)(['"])(${escapeRegExp(prefix)}(?:/[^'"]*)?)\\1`,
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
/** The first specifier in `text` that names one of `imports` or a subpath of one. */
|
|
662
|
+
export function importedSpecifier(text: string, imports: readonly string[]): string | undefined {
|
|
663
|
+
for (const prefix of imports) {
|
|
664
|
+
const match = IMPORTED_SPEC(prefix).exec(text)
|
|
665
|
+
if (match !== null) return match[2]
|
|
666
|
+
}
|
|
667
|
+
return undefined
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const packageOf = (specifier: string): string =>
|
|
671
|
+
specifier
|
|
672
|
+
.split("/")
|
|
673
|
+
.slice(0, specifier.startsWith("@") ? 2 : 1)
|
|
674
|
+
.join("/")
|
|
675
|
+
|
|
676
|
+
const MEMBER = /("(?:[^"\\]|\\.)*")\s*:\s*"(?:[^"\\]|\\.)*"/g
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Add `"name": "version"` to the `field` object of a package.json text without reserializing it,
|
|
680
|
+
* creating the field at the end of the root when absent. The entry goes before the first larger name
|
|
681
|
+
* when the members are sorted, last otherwise.
|
|
682
|
+
*/
|
|
683
|
+
function insertDependencyEntry(text: string, field: string, name: string, version: string): string {
|
|
684
|
+
const entry = `${JSON.stringify(name)}: ${JSON.stringify(version)}`
|
|
685
|
+
const unit = /\n([ \t]+)"/.exec(text)?.[1] ?? " "
|
|
686
|
+
const range = objectRangeAt(text, [field])
|
|
687
|
+
if (range === undefined) {
|
|
688
|
+
const root = objectRangeAt(text, [])
|
|
689
|
+
if (root === undefined) return text
|
|
690
|
+
const body = text.slice(root.start, root.end)
|
|
691
|
+
const at = root.start + body.trimEnd().length
|
|
692
|
+
const comma = body.trim() === "" ? "" : ","
|
|
693
|
+
const close = /^[ \t]*\n/.test(text.slice(at)) ? "" : "\n"
|
|
694
|
+
const object = `${JSON.stringify(field)}: {\n${unit}${unit}${entry}\n${unit}}`
|
|
695
|
+
return `${text.slice(0, at)}${comma}\n${unit}${object}${close}${text.slice(at)}`
|
|
696
|
+
}
|
|
697
|
+
const body = text.slice(range.start, range.end)
|
|
698
|
+
const members = [...body.matchAll(MEMBER)]
|
|
699
|
+
const first = members[0]
|
|
700
|
+
const last = members.at(-1)
|
|
701
|
+
if (first === undefined || last === undefined) {
|
|
702
|
+
const lineStart = text.lastIndexOf("\n", range.start) + 1
|
|
703
|
+
const indent = /^[ \t]*/.exec(text.slice(lineStart))?.[0] ?? ""
|
|
704
|
+
return `${text.slice(0, range.start)}\n${indent}${unit}${entry}\n${indent}${text.slice(range.end)}`
|
|
705
|
+
}
|
|
706
|
+
const names = members.map((member): unknown => JSON.parse(member[1] ?? '""'))
|
|
707
|
+
const newline = body.lastIndexOf("\n", first.index)
|
|
708
|
+
const separator = newline === -1 ? " " : `\n${body.slice(newline + 1, first.index)}`
|
|
709
|
+
const sorted = names.every(
|
|
710
|
+
(current, index) =>
|
|
711
|
+
typeof current === "string" && (index === 0 || String(names[index - 1]) <= current),
|
|
712
|
+
)
|
|
713
|
+
const before = sorted ? members.find((_, index) => String(names[index]) > name) : undefined
|
|
714
|
+
const at = range.start + (before === undefined ? last.index + last[0].length : before.index)
|
|
715
|
+
const insert = before === undefined ? `,${separator}${entry}` : `${entry},${separator}`
|
|
716
|
+
return text.slice(0, at) + insert + text.slice(at)
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Add `rule.add` to a package.json text beside the first anchor it lists - the imported entry's own
|
|
721
|
+
* package, then each of `rule.beside` - in every field that anchor is in, with the anchor's range
|
|
722
|
+
* style; in `dependencies` when no anchor is listed. Undefined when the manifest already lists the
|
|
723
|
+
* package in any field, is that package, or the edit would not parse.
|
|
724
|
+
*/
|
|
725
|
+
export function addDependencyText(
|
|
726
|
+
text: string,
|
|
727
|
+
rule: DependencyAdd,
|
|
728
|
+
specifier: string,
|
|
729
|
+
version: string,
|
|
730
|
+
exact = false,
|
|
731
|
+
): { text: string; changes: Array<{ field: string; name: string; version: string }> } | undefined {
|
|
732
|
+
let parsed: unknown
|
|
733
|
+
try {
|
|
734
|
+
parsed = JSON.parse(text)
|
|
735
|
+
} catch {
|
|
736
|
+
return undefined
|
|
737
|
+
}
|
|
738
|
+
if (typeof parsed !== "object" || parsed === null) return undefined
|
|
739
|
+
const manifest: object = parsed
|
|
740
|
+
if (Reflect.get(manifest, "name") === rule.add) return undefined
|
|
741
|
+
const specIn = (from: object, field: string, name: string): string | undefined => {
|
|
742
|
+
const deps: unknown = Reflect.get(from, field)
|
|
743
|
+
if (typeof deps !== "object" || deps === null || !Object.hasOwn(deps, name)) return undefined
|
|
744
|
+
const spec: unknown = Reflect.get(deps, name)
|
|
745
|
+
return typeof spec === "string" ? spec : undefined
|
|
746
|
+
}
|
|
747
|
+
if (DEP_FIELDS.some((field) => specIn(manifest, field, rule.add) !== undefined)) return undefined
|
|
748
|
+
const fallback = exact ? version : `^${version}`
|
|
749
|
+
const rangeFor = (spec: string): string =>
|
|
750
|
+
rewriteVersionSpec(spec, version, exact) ?? (specVersion(spec) === version ? spec : fallback)
|
|
751
|
+
let placed: Array<{ field: string; name: string; version: string }> = []
|
|
752
|
+
for (const anchor of [packageOf(specifier), ...(rule.beside ?? [])]) {
|
|
753
|
+
placed = DEP_FIELDS.flatMap((field) => {
|
|
754
|
+
const spec = specIn(manifest, field, anchor)
|
|
755
|
+
return spec === undefined ? [] : [{ field, name: rule.add, version: rangeFor(spec) }]
|
|
756
|
+
})
|
|
757
|
+
if (placed.length > 0) break
|
|
758
|
+
}
|
|
759
|
+
if (placed.length === 0) placed = [{ field: "dependencies", name: rule.add, version: fallback }]
|
|
760
|
+
let out = text
|
|
761
|
+
for (const change of placed)
|
|
762
|
+
out = insertDependencyEntry(out, change.field, rule.add, change.version)
|
|
763
|
+
// The edit is textual; a result that does not parse, or lacks an entry, is never written.
|
|
764
|
+
let written: unknown
|
|
765
|
+
try {
|
|
766
|
+
written = JSON.parse(out)
|
|
767
|
+
} catch {
|
|
768
|
+
return undefined
|
|
769
|
+
}
|
|
770
|
+
if (typeof written !== "object" || written === null) return undefined
|
|
771
|
+
const result: object = written
|
|
772
|
+
if (placed.some((change) => specIn(result, change.field, rule.add) !== change.version))
|
|
773
|
+
return undefined
|
|
774
|
+
return { text: out, changes: placed }
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/** The package.json nearest above `file`, both relative to `cwd`; undefined when none is under it. */
|
|
778
|
+
function nearestManifest(cwd: string, file: string): string | undefined {
|
|
779
|
+
for (let dir = dirname(file); ; dir = dirname(dir)) {
|
|
780
|
+
const manifest = dir === "." ? "package.json" : `${dir}/package.json`
|
|
781
|
+
if (plainFileAt(cwd, manifest)) return manifest
|
|
782
|
+
if (dir === ".") return undefined
|
|
783
|
+
}
|
|
784
|
+
}
|
|
635
785
|
const IGNORED_DIRECTORIES = new Set(["node_modules", "dist", "build", ".git", "coverage", ".next"])
|
|
636
786
|
|
|
637
787
|
// Any directory on the path counts, the top-level one included (`dist/index.js`). Bun's glob yields
|
|
@@ -650,7 +800,9 @@ function scan(cwd: string, pattern: string, dot = false): string[] {
|
|
|
650
800
|
for (const path of glob.scanSync({ cwd, dot, followSymlinks: false })) {
|
|
651
801
|
if (!isIgnored(path)) out.push(path.replaceAll("\\", "/"))
|
|
652
802
|
}
|
|
653
|
-
|
|
803
|
+
// A gitignored copy (a backup, a generated app) is not the project: never edited, never reported.
|
|
804
|
+
const ignored = gitIgnoredSync(cwd, out)
|
|
805
|
+
return (ignored.size === 0 ? out : out.filter((path) => !ignored.has(path))).sort()
|
|
654
806
|
}
|
|
655
807
|
|
|
656
808
|
// The fixed version group: every package released together at one version.
|
|
@@ -1153,6 +1305,7 @@ export function chainRecipes(target: string, installed: string | null): ChainedR
|
|
|
1153
1305
|
pins: [...pins].map(([match, to]) => ({ match, to })),
|
|
1154
1306
|
dependencyMoves: recipes.flatMap((recipe) => recipe.dependencyMoves ?? []),
|
|
1155
1307
|
importMoves: recipes.flatMap((recipe) => recipe.importMoves),
|
|
1308
|
+
dependencyAdds: recipes.flatMap((recipe) => recipe.dependencyAdds ?? []),
|
|
1156
1309
|
retiredMarkers: recipes.flatMap((recipe) => recipe.retiredMarkers ?? []),
|
|
1157
1310
|
notes: recipes.flatMap((recipe) =>
|
|
1158
1311
|
(recipe.notes ?? []).map((note) => `${recipe.version}: ${note}`),
|
|
@@ -1174,6 +1327,7 @@ export function computeUpgrade(
|
|
|
1174
1327
|
const planned = new Map<string, string>()
|
|
1175
1328
|
const dependencyMoves: DependencyMoveChange[] = []
|
|
1176
1329
|
const importMoves: ImportChange[] = []
|
|
1330
|
+
const dependencyAdds: DependencyAddChange[] = []
|
|
1177
1331
|
const downgrades: PinChange[] = []
|
|
1178
1332
|
const retiredMarkers: RetiredMarkerSite[] = []
|
|
1179
1333
|
const linkedOutside = installedGroupPackages(cwd)
|
|
@@ -1195,20 +1349,8 @@ export function computeUpgrade(
|
|
|
1195
1349
|
}
|
|
1196
1350
|
}
|
|
1197
1351
|
|
|
1198
|
-
// Read against the manifests as this upgrade leaves them
|
|
1352
|
+
// Read against the manifests as this upgrade leaves them.
|
|
1199
1353
|
const linkLocks = plainFileAt(cwd, BUN_LOCK) ? staleLinkLocks(resolve(cwd), manifests) : []
|
|
1200
|
-
let lockPruned = false
|
|
1201
|
-
if (write && linkLocks.length > 0) {
|
|
1202
|
-
const lockPath = join(cwd, BUN_LOCK)
|
|
1203
|
-
const pruned = pruneLinkLocks(
|
|
1204
|
-
readFileSync(lockPath, "utf8"),
|
|
1205
|
-
linkLocks.map((entry) => entry.package),
|
|
1206
|
-
)
|
|
1207
|
-
if (pruned !== undefined) {
|
|
1208
|
-
writeFileSync(lockPath, pruned)
|
|
1209
|
-
lockPruned = true
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
1354
|
|
|
1213
1355
|
for (const { change, text, abs } of agentPinEdits(cwd, recipe.version, above)) {
|
|
1214
1356
|
agentPins.push(change)
|
|
@@ -1216,17 +1358,41 @@ export function computeUpgrade(
|
|
|
1216
1358
|
if (write) writeFileSync(abs, Buffer.from(text, "latin1"))
|
|
1217
1359
|
}
|
|
1218
1360
|
|
|
1361
|
+
const movedSources = new Map<string, string>()
|
|
1219
1362
|
if (recipe.importMoves.length > 0) {
|
|
1220
1363
|
for (const rel of scan(cwd, SOURCE_GLOB)) {
|
|
1221
1364
|
const abs = join(cwd, rel)
|
|
1222
1365
|
const text = readFileSync(abs, "utf8")
|
|
1223
1366
|
const result = applyImportMoves(text, recipe.importMoves)
|
|
1224
1367
|
if (result.changes.length === 0) continue
|
|
1368
|
+
movedSources.set(rel, result.text)
|
|
1225
1369
|
for (const change of result.changes) importMoves.push({ file: rel, ...change })
|
|
1226
1370
|
if (write) writeFileSync(abs, result.text)
|
|
1227
1371
|
}
|
|
1228
1372
|
}
|
|
1229
1373
|
|
|
1374
|
+
// Read the sources as the import moves leave them, and each manifest as the pins left it.
|
|
1375
|
+
const adds = recipe.dependencyAdds ?? []
|
|
1376
|
+
if (adds.length > 0) {
|
|
1377
|
+
for (const rel of scan(cwd, ADD_SOURCE_GLOB)) {
|
|
1378
|
+
const source = movedSources.get(rel) ?? readFileSync(join(cwd, rel), "utf8")
|
|
1379
|
+
for (const rule of adds) {
|
|
1380
|
+
const specifier = importedSpecifier(source, rule.imports)
|
|
1381
|
+
if (specifier === undefined) continue
|
|
1382
|
+
const file = nearestManifest(cwd, rel)
|
|
1383
|
+
if (file === undefined) continue
|
|
1384
|
+
const abs = resolve(cwd, file)
|
|
1385
|
+
const current = manifests.get(abs) ?? readFileSync(abs, "utf8")
|
|
1386
|
+
const added = addDependencyText(current, rule, specifier, recipe.version, exact)
|
|
1387
|
+
if (added === undefined) continue
|
|
1388
|
+
manifests.set(abs, added.text)
|
|
1389
|
+
for (const change of added.changes)
|
|
1390
|
+
dependencyAdds.push({ file, ...change, importer: rel, specifier })
|
|
1391
|
+
if (write) writeFileSync(abs, added.text)
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1230
1396
|
// Read after the import moves, so a listed line number is the one the file has after `--write`.
|
|
1231
1397
|
const retired = recipe.retiredMarkers ?? []
|
|
1232
1398
|
if (retired.length > 0) {
|
|
@@ -1254,13 +1420,13 @@ export function computeUpgrade(
|
|
|
1254
1420
|
agentPins,
|
|
1255
1421
|
dependencyMoves,
|
|
1256
1422
|
importMoves,
|
|
1423
|
+
dependencyAdds,
|
|
1257
1424
|
downgrades,
|
|
1258
1425
|
retiredMarkers,
|
|
1259
1426
|
linkedOutside,
|
|
1260
1427
|
linkedSkew: linkedSkew(cwd, recipe.version),
|
|
1261
1428
|
strayPins: strayPins(cwd, recipe.version, planned),
|
|
1262
1429
|
linkLocks,
|
|
1263
|
-
lockPruned,
|
|
1264
1430
|
notes: recipe.notes ?? [],
|
|
1265
1431
|
unaffected: unaffectedReleases(
|
|
1266
1432
|
"steps" in recipe && Array.isArray(recipe.steps) ? recipe.steps : [recipe.version],
|
|
@@ -1292,6 +1458,7 @@ function renderPlan(
|
|
|
1292
1458
|
plan.agentPins.length === 0 &&
|
|
1293
1459
|
plan.dependencyMoves.length === 0 &&
|
|
1294
1460
|
plan.importMoves.length === 0 &&
|
|
1461
|
+
plan.dependencyAdds.length === 0 &&
|
|
1295
1462
|
plan.retiredMarkers.length === 0 &&
|
|
1296
1463
|
plan.linkedOutside.length === 0 &&
|
|
1297
1464
|
plan.linkedSkew.length === 0 &&
|
|
@@ -1330,6 +1497,15 @@ function renderPlan(
|
|
|
1330
1497
|
for (const m of plan.importMoves) lines.push(` ${m.file} ${m.from} → ${m.to} (${m.count})`)
|
|
1331
1498
|
lines.push("")
|
|
1332
1499
|
}
|
|
1500
|
+
if (plan.dependencyAdds.length > 0) {
|
|
1501
|
+
lines.push(`${verb} ${plan.dependencyAdds.length} dependency addition(s):`)
|
|
1502
|
+
for (const add of plan.dependencyAdds) {
|
|
1503
|
+
lines.push(
|
|
1504
|
+
` ${add.file} ${add.field}: ${add.name}@${add.version} (${add.importer} imports ${add.specifier})`,
|
|
1505
|
+
)
|
|
1506
|
+
}
|
|
1507
|
+
lines.push("")
|
|
1508
|
+
}
|
|
1333
1509
|
if (plan.retiredMarkers.length > 0) {
|
|
1334
1510
|
lines.push(
|
|
1335
1511
|
`${plan.retiredMarkers.length} retired comment(s) that silence nothing now; nifra check reports what each covered:`,
|
|
@@ -1371,20 +1547,15 @@ function renderPlan(
|
|
|
1371
1547
|
}
|
|
1372
1548
|
if (plan.linkLocks.length > 0) {
|
|
1373
1549
|
lines.push(
|
|
1374
|
-
plan.
|
|
1375
|
-
? `Dropped ${plan.linkLocks.length} file: package(s) from bun.lock, whose recorded dependencies Bun never refreshes; \`bun install\` reads each linked package.json again:`
|
|
1376
|
-
: write
|
|
1377
|
-
? `bun.lock records stale dependencies for ${plan.linkLocks.length} file: package(s), which Bun never refreshes; run \`${linkLockUpdate(plan.linkLocks)}\`:`
|
|
1378
|
-
: `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:`,
|
|
1550
|
+
`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:`,
|
|
1379
1551
|
)
|
|
1380
1552
|
for (const entry of plan.linkLocks)
|
|
1381
1553
|
lines.push(
|
|
1382
1554
|
` ${entry.package} (file:${entry.path}) ${entry.changes.map(describeChange).join(", ")}`,
|
|
1383
1555
|
)
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
)
|
|
1556
|
+
lines.push(
|
|
1557
|
+
" Bun records each linked package.json as it is on disk, uncommitted edits included: review the bun.lock diff before committing it.",
|
|
1558
|
+
)
|
|
1388
1559
|
lines.push("")
|
|
1389
1560
|
}
|
|
1390
1561
|
for (const note of plan.notes) lines.push(`note: ${note}`)
|
|
@@ -1463,14 +1634,14 @@ const INSTALL_COMMANDS: readonly (readonly [lockfile: string, command: string])[
|
|
|
1463
1634
|
|
|
1464
1635
|
/**
|
|
1465
1636
|
* Whether the project needs an install before a check can judge the target: `--write` changed what
|
|
1466
|
-
* package.json declares
|
|
1467
|
-
* version. A link from outside the root is left out; installing here does not move it.
|
|
1637
|
+
* 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.
|
|
1468
1638
|
*/
|
|
1469
1639
|
export function pendingInstall(cwd: string, plan: UpgradePlan): PendingInstall | undefined {
|
|
1470
1640
|
const installed = installedGroupPackages(cwd)
|
|
1471
1641
|
.filter((entry) => entry.inside && entry.version !== plan.version)
|
|
1472
1642
|
.map(({ package: name, version }) => ({ package: name, version }))
|
|
1473
|
-
const edited =
|
|
1643
|
+
const edited =
|
|
1644
|
+
plan.pins.length > 0 || plan.dependencyMoves.length > 0 || plan.dependencyAdds.length > 0
|
|
1474
1645
|
if (!edited && installed.length === 0) return undefined
|
|
1475
1646
|
const command =
|
|
1476
1647
|
INSTALL_COMMANDS.find(([lockfile]) => existsSync(join(cwd, lockfile)))?.[1] ?? "bun install"
|
|
@@ -1615,6 +1786,28 @@ function newerCliCommand(version: string, options: UpgradeOptions): string {
|
|
|
1615
1786
|
}
|
|
1616
1787
|
|
|
1617
1788
|
/** CLI entry. Returns false (→ non-zero exit) on an unknown version, no project, or a failed verify. */
|
|
1789
|
+
/** The contracts.lock.json routes that send a body but whose request side guards nothing. A release
|
|
1790
|
+
* that reads a body schema the installed one could not has `nifra check` report each as newly
|
|
1791
|
+
* covered. Read routes and response sides are left out: most declare no schema there. */
|
|
1792
|
+
async function uncoveredContracts(cwd: string): Promise<string[]> {
|
|
1793
|
+
const { blindLockEntries, DEFAULT_CONTRACTS_LOCK, parseContractsLock } = await import(
|
|
1794
|
+
"./contracts.ts"
|
|
1795
|
+
)
|
|
1796
|
+
try {
|
|
1797
|
+
const text = readFileSync(join(cwd, DEFAULT_CONTRACTS_LOCK), "utf8")
|
|
1798
|
+
return (await blindLockEntries(parseContractsLock(JSON.parse(text))))
|
|
1799
|
+
.filter(
|
|
1800
|
+
(entry) => entry.sides.includes("request") && !/^(?:GET|HEAD|OPTIONS) /.test(entry.route),
|
|
1801
|
+
)
|
|
1802
|
+
.map((entry) => entry.route)
|
|
1803
|
+
} catch {
|
|
1804
|
+
return []
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
const uncoveredContractsNote = (routes: readonly string[]): string =>
|
|
1809
|
+
`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\`.`
|
|
1810
|
+
|
|
1618
1811
|
export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<boolean> {
|
|
1619
1812
|
const cliVersion = options.cliVersion ?? listRecipeVersions().at(-1) ?? "0.0.0"
|
|
1620
1813
|
const targets = upgradeTargets(cliVersion)
|
|
@@ -1726,9 +1919,11 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1726
1919
|
// Verify only makes sense once edits are on disk and installed. Default on after --write; opt out
|
|
1727
1920
|
// with --no-verify. An uninstalled upgrade passes, so `upgrade --write && bun install` chains.
|
|
1728
1921
|
const verify = write && options.verify !== false && pending === undefined
|
|
1922
|
+
const uncovered = await uncoveredContracts(cwd)
|
|
1729
1923
|
if (options.json) {
|
|
1730
1924
|
// The check result rides inside the one JSON document; its human report would break the stream.
|
|
1731
1925
|
const report: Record<string, unknown> = { ...plan, from, steps: recipe.steps, write }
|
|
1926
|
+
if (uncovered.length > 0) report.contractsUncovered = uncovered
|
|
1732
1927
|
if (hooks !== undefined) report.hooks = hooks
|
|
1733
1928
|
if (pending !== undefined) report.install = pending
|
|
1734
1929
|
let ok = true
|
|
@@ -1743,6 +1938,7 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1743
1938
|
return ok
|
|
1744
1939
|
}
|
|
1745
1940
|
console.log(renderPlan(plan, write, from, recipe.steps))
|
|
1941
|
+
if (uncovered.length > 0) console.log(uncoveredContractsNote(uncovered))
|
|
1746
1942
|
if (plan.linkedSkew.length > 0)
|
|
1747
1943
|
console.warn(`\n${renderLinkedSkew(recipe.version, plan.linkedSkew, cwd, true)}`)
|
|
1748
1944
|
if (hooks !== undefined) console.log(`\n${renderHookScope(hooks)}`)
|
package/src/version-drift.ts
CHANGED
|
@@ -74,7 +74,7 @@ export function collectVersionDrift(cwd: string, cliVersion?: string): VersionDr
|
|
|
74
74
|
continue
|
|
75
75
|
add(
|
|
76
76
|
recorded,
|
|
77
|
-
`recorded for ${entry.package} in bun.lock,
|
|
77
|
+
`recorded for ${entry.package} in bun.lock, stale until \`bun update ${entry.package}\` (NF-D003)`,
|
|
78
78
|
)
|
|
79
79
|
}
|
|
80
80
|
}
|