@nifrajs/cli 5.1.0 → 5.2.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 +3211 -0
- package/README.md +3 -0
- package/dist/agent-files.d.ts +19 -11
- package/dist/agent-files.d.ts.map +1 -1
- package/dist/agent-files.js +26 -18
- package/dist/agent-files.js.map +1 -1
- package/dist/assure-hydration.d.ts.map +1 -1
- package/dist/assure-hydration.js +1 -0
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +14 -1
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +131 -45
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +5 -0
- package/dist/check-diagnostics.d.ts.map +1 -1
- package/dist/check-diagnostics.js +3 -0
- package/dist/check-diagnostics.js.map +1 -1
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +6 -3
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +52 -12
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +23 -12
- package/dist/cli.js.map +1 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +9 -5
- package/dist/command-catalog.js.map +1 -1
- package/dist/dev-bun-config.d.ts +6 -3
- package/dist/dev-bun-config.d.ts.map +1 -1
- package/dist/dev-bun-config.js +13 -10
- package/dist/dev-bun-config.js.map +1 -1
- package/dist/dev-feed-tool.d.ts +3 -2
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +26 -5
- package/dist/dev-feed-tool.js.map +1 -1
- package/dist/doctor.d.ts +15 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +79 -61
- package/dist/doctor.js.map +1 -1
- package/dist/i18n-check.d.ts +11 -1
- package/dist/i18n-check.d.ts.map +1 -1
- package/dist/i18n-check.js +170 -17
- package/dist/i18n-check.js.map +1 -1
- package/dist/init-agents.d.ts +46 -6
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +193 -31
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +9 -1
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +6 -0
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +106 -0
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/workspace-packages.d.ts +22 -0
- package/dist/internal/workspace-packages.d.ts.map +1 -0
- package/dist/internal/workspace-packages.js +215 -0
- package/dist/internal/workspace-packages.js.map +1 -0
- package/dist/load.d.ts +7 -2
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +11 -2
- package/dist/load.js.map +1 -1
- package/dist/lock-links.d.ts +42 -0
- package/dist/lock-links.d.ts.map +1 -0
- package/dist/lock-links.js +144 -0
- package/dist/lock-links.js.map +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +5 -2
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/migrate-layout.d.ts +2 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +434 -29
- package/dist/migrate-layout.js.map +1 -1
- package/dist/project-site.d.ts +7 -0
- package/dist/project-site.d.ts.map +1 -0
- package/dist/project-site.js +19 -0
- package/dist/project-site.js.map +1 -0
- package/dist/recipes/4.0.0.d.ts.map +1 -1
- package/dist/recipes/4.0.0.js +2 -0
- package/dist/recipes/4.0.0.js.map +1 -1
- package/dist/recipes/5.1.0.d.ts +9 -0
- package/dist/recipes/5.1.0.d.ts.map +1 -0
- package/dist/recipes/5.1.0.js +22 -0
- package/dist/recipes/5.1.0.js.map +1 -0
- package/dist/recipes/5.2.0.d.ts +10 -0
- package/dist/recipes/5.2.0.d.ts.map +1 -0
- package/dist/recipes/5.2.0.js +32 -0
- package/dist/recipes/5.2.0.js.map +1 -0
- package/dist/recipes/index.d.ts +3 -0
- package/dist/recipes/index.d.ts.map +1 -1
- package/dist/recipes/index.js +7 -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/rule-explain.d.ts +26 -0
- package/dist/rule-explain.d.ts.map +1 -0
- package/dist/rule-explain.js +49 -0
- package/dist/rule-explain.js.map +1 -0
- package/dist/rules/codes.d.ts +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/contract-visibility.d.ts.map +1 -1
- package/dist/rules/contract-visibility.js +93 -21
- package/dist/rules/contract-visibility.js.map +1 -1
- package/dist/rules/explanations.d.ts +14 -0
- package/dist/rules/explanations.d.ts.map +1 -0
- package/dist/rules/explanations.js +316 -0
- package/dist/rules/explanations.js.map +1 -0
- package/dist/rules/legacy.d.ts.map +1 -1
- package/dist/rules/legacy.js +24 -1
- package/dist/rules/legacy.js.map +1 -1
- package/dist/rules/merge-auth.d.ts +12 -0
- package/dist/rules/merge-auth.d.ts.map +1 -0
- package/dist/rules/merge-auth.js +52 -0
- package/dist/rules/merge-auth.js.map +1 -0
- package/dist/rules/pages.d.ts +27 -0
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +177 -2
- package/dist/rules/pages.js.map +1 -1
- package/dist/rules/routes.d.ts +3 -2
- package/dist/rules/routes.d.ts.map +1 -1
- package/dist/rules/routes.js +4 -3
- package/dist/rules/routes.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +3 -2
- package/dist/rules/zones.js.map +1 -1
- package/dist/typecheck-coverage.d.ts +11 -0
- package/dist/typecheck-coverage.d.ts.map +1 -1
- package/dist/typecheck-coverage.js +50 -7
- package/dist/typecheck-coverage.js.map +1 -1
- package/dist/upgrade.d.ts +37 -1
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +171 -20
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +2 -0
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +12 -1
- package/dist/version-drift.js.map +1 -1
- package/dist/web-app-options.d.ts +1 -1
- package/dist/web-app-options.d.ts.map +1 -1
- package/dist/web-app-options.js.map +1 -1
- package/docs/examples.json +19 -1
- package/docs/llms-full.txt +625 -130
- package/docs/types.json +396 -50
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +1 -0
- package/src/assure.ts +11 -1
- package/src/capabilities-tool.ts +159 -50
- package/src/check-diagnostics.ts +8 -0
- package/src/check-scan.ts +9 -3
- package/src/check.ts +67 -12
- package/src/cli.ts +24 -11
- package/src/command-catalog.ts +16 -8
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +40 -6
- package/src/doctor.ts +102 -66
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +221 -41
- package/src/internal/project-specifiers.ts +9 -1
- package/src/internal/source-facts.ts +124 -0
- package/src/internal/workspace-packages.ts +218 -0
- package/src/load.ts +19 -3
- package/src/lock-links.ts +173 -0
- package/src/mcp-exec.ts +5 -2
- package/src/mcp-http.ts +1 -1
- package/src/mcp-root.ts +14 -8
- package/src/migrate-layout.ts +495 -31
- package/src/project-site.ts +18 -0
- package/src/recipes/4.0.0.ts +2 -0
- package/src/recipes/5.1.0.ts +23 -0
- package/src/recipes/5.2.0.ts +33 -0
- package/src/recipes/index.ts +7 -0
- package/src/review.ts +2 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +2 -0
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/explanations.ts +329 -0
- package/src/rules/legacy.ts +24 -1
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +221 -2
- package/src/rules/routes.ts +4 -3
- package/src/rules/zones.ts +3 -2
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +227 -22
- package/src/verification-plan.ts +6 -0
- package/src/version-drift.ts +15 -0
- package/src/web-app-options.ts +9 -1
package/src/upgrade.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
statSync,
|
|
37
37
|
writeFileSync,
|
|
38
38
|
} from "node:fs"
|
|
39
|
-
import { dirname, join, relative, sep } from "node:path"
|
|
39
|
+
import { dirname, join, relative, resolve, sep } from "node:path"
|
|
40
40
|
import { fileURLToPath } from "node:url"
|
|
41
41
|
import type { ReflectedHookReport } from "@nifrajs/core/reflection"
|
|
42
42
|
import { Glob } from "bun"
|
|
@@ -48,7 +48,15 @@ import {
|
|
|
48
48
|
parseHookReport,
|
|
49
49
|
renderHookDiff,
|
|
50
50
|
} from "./hooks-report.ts"
|
|
51
|
-
import { PIN_SITES } from "./init-agents.ts"
|
|
51
|
+
import { type AncestorPinSite, ancestorPins, declaresCli, PIN_SITES } from "./init-agents.ts"
|
|
52
|
+
import {
|
|
53
|
+
BUN_LOCK,
|
|
54
|
+
describeChange,
|
|
55
|
+
linkLockUpdate,
|
|
56
|
+
pruneLinkLocks,
|
|
57
|
+
type StaleLinkLock,
|
|
58
|
+
staleLinkLocks,
|
|
59
|
+
} from "./lock-links.ts"
|
|
52
60
|
import { getRecipe, listRecipeVersions, type UpgradeRecipe } from "./recipes/index.ts"
|
|
53
61
|
import { markerTarget } from "./rules/comment-markers.ts"
|
|
54
62
|
|
|
@@ -74,6 +82,8 @@ export interface UpgradeOptions {
|
|
|
74
82
|
* change in which hooks run where is visible. Loads the backend. Default true; `--no-hooks` skips it.
|
|
75
83
|
*/
|
|
76
84
|
readonly hooks?: boolean
|
|
85
|
+
/** Proceed although a linked repository loads its own nifra at another version. Default false. */
|
|
86
|
+
readonly allowLinkedSkew?: boolean
|
|
77
87
|
}
|
|
78
88
|
|
|
79
89
|
export interface PinChange {
|
|
@@ -106,6 +116,8 @@ export interface AgentPinChange {
|
|
|
106
116
|
readonly file: string
|
|
107
117
|
/** The versions it pinned, in order of appearance. */
|
|
108
118
|
readonly from: readonly string[]
|
|
119
|
+
/** The target version, or `unpinned` when the project declares `@nifrajs/cli`: the launch then runs
|
|
120
|
+
* that install and never needs re-pinning. */
|
|
109
121
|
readonly to: string
|
|
110
122
|
}
|
|
111
123
|
|
|
@@ -131,8 +143,16 @@ export interface UpgradePlan {
|
|
|
131
143
|
readonly retiredMarkers: readonly RetiredMarkerSite[]
|
|
132
144
|
/** Installed group packages linked from outside the workspace root, at another version. Never edited. */
|
|
133
145
|
readonly linkedOutside: readonly LinkedGroupInstall[]
|
|
146
|
+
/** Repositories a `link:`/`file:` dependency points outside the root, each loading its own nifra at
|
|
147
|
+
* another version. Never edited; the upgrade refuses while any is listed. */
|
|
148
|
+
readonly linkedSkew: readonly LinkedSkew[]
|
|
134
149
|
/** Other versions pinned outside package.json. Never edited. */
|
|
135
150
|
readonly strayPins: readonly StrayPin[]
|
|
151
|
+
/** `file:` entries of the project's bun.lock whose recorded dependencies the linked package.json
|
|
152
|
+
* (as this upgrade leaves it) no longer declares. Bun never refreshes them on its own. */
|
|
153
|
+
readonly linkLocks: readonly StaleLinkLock[]
|
|
154
|
+
/** Whether `--write` dropped {@link linkLocks} from bun.lock, so `bun install` re-reads them. */
|
|
155
|
+
readonly lockPruned: boolean
|
|
136
156
|
readonly notes: readonly string[]
|
|
137
157
|
}
|
|
138
158
|
|
|
@@ -688,20 +708,34 @@ function plainFileAt(cwd: string, rel: string): boolean {
|
|
|
688
708
|
}
|
|
689
709
|
|
|
690
710
|
/**
|
|
691
|
-
* The MCP launch pin in each agent file at `cwd`,
|
|
692
|
-
*
|
|
711
|
+
* The MCP launch pin in each agent file at `cwd`, and in each file above it whose launches all serve
|
|
712
|
+
* it ({@link ancestorPins}), moved to `version`: the files and the edit of `nifra init-agents
|
|
713
|
+
* --sync-mcp`, so an agent launches the nifra the project installs once it does.
|
|
693
714
|
*/
|
|
694
715
|
function agentPinEdits(
|
|
695
716
|
cwd: string,
|
|
696
717
|
version: string,
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
718
|
+
above: readonly AncestorPinSite[],
|
|
719
|
+
): Array<{ readonly change: AgentPinChange; readonly text: string; readonly abs: string }> {
|
|
720
|
+
const target = declaresCli(cwd) ? null : version
|
|
721
|
+
const edits: Array<{ change: AgentPinChange; text: string; abs: string }> = []
|
|
722
|
+
const sites = [
|
|
723
|
+
...PIN_SITES.map((site) => ({ dir: cwd, file: site.path, path: site.path, site })),
|
|
724
|
+
...above.map((entry) => ({ ...entry, file: entry.site.path })),
|
|
725
|
+
]
|
|
726
|
+
for (const { dir, file, path, site } of sites) {
|
|
727
|
+
if (!plainFileAt(dir, file)) continue
|
|
728
|
+
const abs = join(dir, file)
|
|
729
|
+
// A launch above the project runs from that directory, which need not see the install: it stays pinned.
|
|
730
|
+
const to = dir === cwd ? target : version
|
|
701
731
|
// latin1 is one char per byte, so every byte outside a pin is written back as it was.
|
|
702
|
-
const scan = site.repin(readFileSync(
|
|
732
|
+
const scan = site.repin(readFileSync(abs, "latin1"), to)
|
|
703
733
|
if (scan.stale.length === 0) continue
|
|
704
|
-
edits.push({
|
|
734
|
+
edits.push({
|
|
735
|
+
change: { file: path, from: scan.stale, to: to ?? "unpinned" },
|
|
736
|
+
text: scan.text,
|
|
737
|
+
abs,
|
|
738
|
+
})
|
|
705
739
|
}
|
|
706
740
|
return edits
|
|
707
741
|
}
|
|
@@ -723,6 +757,68 @@ const packageVersionAt = (dir: string): string | undefined => {
|
|
|
723
757
|
}
|
|
724
758
|
}
|
|
725
759
|
|
|
760
|
+
/** A repository linked into the project that resolves nifra from its own `node_modules`. */
|
|
761
|
+
export interface LinkedSkew {
|
|
762
|
+
/** The dependency's name, as the manifest declares it. */
|
|
763
|
+
readonly package: string
|
|
764
|
+
/** The project-relative manifest that declares it. */
|
|
765
|
+
readonly declaredIn: string
|
|
766
|
+
/** The linked repository's real path. */
|
|
767
|
+
readonly path: string
|
|
768
|
+
/** Each fixed-group package it installs itself, at a version other than the target. */
|
|
769
|
+
readonly installs: readonly { readonly package: string; readonly version: string }[]
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Every `link:` or `file:` dependency whose installed folder resolves outside `cwd` and installs a
|
|
774
|
+
* fixed-group package of its own at a version other than `target`. Its imports resolve from its real
|
|
775
|
+
* path, so it keeps loading that copy after this project upgrades: a `server()` it builds can no longer
|
|
776
|
+
* be merged here, and single-copy never redirects across versions. A copy that resolves back inside
|
|
777
|
+
* `cwd` follows this project's install and is not counted.
|
|
778
|
+
*/
|
|
779
|
+
export function linkedSkew(cwd: string, target: string): readonly LinkedSkew[] {
|
|
780
|
+
let root: string
|
|
781
|
+
try {
|
|
782
|
+
root = realpathSync(cwd)
|
|
783
|
+
} catch {
|
|
784
|
+
root = cwd
|
|
785
|
+
}
|
|
786
|
+
const inside = (path: string): boolean => path === root || path.startsWith(root + sep)
|
|
787
|
+
const seen = new Set<string>()
|
|
788
|
+
const found: LinkedSkew[] = []
|
|
789
|
+
for (const rel of scan(cwd, "**/package.json")) {
|
|
790
|
+
let manifest: unknown
|
|
791
|
+
try {
|
|
792
|
+
manifest = JSON.parse(readFileSync(join(cwd, rel), "utf8"))
|
|
793
|
+
} catch {
|
|
794
|
+
continue
|
|
795
|
+
}
|
|
796
|
+
for (const field of DEP_FIELDS) {
|
|
797
|
+
const block: unknown = Reflect.get(Object(manifest), field)
|
|
798
|
+
if (typeof block !== "object" || block === null) continue
|
|
799
|
+
for (const [name, spec] of Object.entries(block)) {
|
|
800
|
+
if (typeof spec !== "string" || !/^(?:link|file):/.test(spec)) continue
|
|
801
|
+
let path: string | undefined
|
|
802
|
+
for (const base of [join(cwd, dirname(rel)), cwd]) {
|
|
803
|
+
try {
|
|
804
|
+
path = realpathSync(join(base, "node_modules", name))
|
|
805
|
+
break
|
|
806
|
+
} catch {
|
|
807
|
+
// Not installed beside this manifest: try the root's node_modules.
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
if (path === undefined || inside(path) || seen.has(path)) continue
|
|
811
|
+
seen.add(path)
|
|
812
|
+
const installs = installedGroupPackages(path)
|
|
813
|
+
.filter((entry) => !inside(entry.path) && entry.version !== target)
|
|
814
|
+
.map((entry) => ({ package: entry.package, version: entry.version }))
|
|
815
|
+
if (installs.length > 0) found.push({ package: name, declaredIn: rel, path, installs })
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return found
|
|
820
|
+
}
|
|
821
|
+
|
|
726
822
|
/**
|
|
727
823
|
* Every fixed-group package installed in `cwd/node_modules`, realpath-resolved so a linked repository
|
|
728
824
|
* reports its own version. `inside` is false for one that resolves outside the workspace root.
|
|
@@ -821,6 +917,7 @@ export function computeUpgrade(
|
|
|
821
917
|
write: boolean,
|
|
822
918
|
allowDowngrade = false,
|
|
823
919
|
exact = false,
|
|
920
|
+
above: readonly AncestorPinSite[] = [],
|
|
824
921
|
): UpgradePlan {
|
|
825
922
|
const pins: PinChange[] = []
|
|
826
923
|
const agentPins: AgentPinChange[] = []
|
|
@@ -833,6 +930,7 @@ export function computeUpgrade(
|
|
|
833
930
|
.filter((entry) => !entry.inside && entry.version !== recipe.version)
|
|
834
931
|
.map(({ package: name, path, version }) => ({ package: name, path, version }))
|
|
835
932
|
|
|
933
|
+
const manifests = new Map<string, string>()
|
|
836
934
|
if ((recipe.dependencyMoves?.length ?? 0) > 0 || recipe.pins.length > 0) {
|
|
837
935
|
for (const rel of scan(cwd, "**/package.json")) {
|
|
838
936
|
const abs = join(cwd, rel)
|
|
@@ -842,14 +940,30 @@ export function computeUpgrade(
|
|
|
842
940
|
const pinned = pinSweepText(moved.text, recipe.pins, allowDowngrade, exact)
|
|
843
941
|
for (const change of pinned.changes) pins.push({ file: rel, ...change })
|
|
844
942
|
for (const d of pinned.downgrades) downgrades.push({ file: rel, ...d })
|
|
943
|
+
if (pinned.text !== original) manifests.set(resolve(abs), pinned.text)
|
|
845
944
|
if (write && pinned.text !== original) writeFileSync(abs, pinned.text)
|
|
846
945
|
}
|
|
847
946
|
}
|
|
848
947
|
|
|
849
|
-
|
|
948
|
+
// Read against the manifests as this upgrade leaves them, so a dry run lists what --write drops.
|
|
949
|
+
const linkLocks = plainFileAt(cwd, BUN_LOCK) ? staleLinkLocks(resolve(cwd), manifests) : []
|
|
950
|
+
let lockPruned = false
|
|
951
|
+
if (write && linkLocks.length > 0) {
|
|
952
|
+
const lockPath = join(cwd, BUN_LOCK)
|
|
953
|
+
const pruned = pruneLinkLocks(
|
|
954
|
+
readFileSync(lockPath, "utf8"),
|
|
955
|
+
linkLocks.map((entry) => entry.package),
|
|
956
|
+
)
|
|
957
|
+
if (pruned !== undefined) {
|
|
958
|
+
writeFileSync(lockPath, pruned)
|
|
959
|
+
lockPruned = true
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
for (const { change, text, abs } of agentPinEdits(cwd, recipe.version, above)) {
|
|
850
964
|
agentPins.push(change)
|
|
851
965
|
planned.set(change.file, text)
|
|
852
|
-
if (write) writeFileSync(
|
|
966
|
+
if (write) writeFileSync(abs, Buffer.from(text, "latin1"))
|
|
853
967
|
}
|
|
854
968
|
|
|
855
969
|
if (recipe.importMoves.length > 0) {
|
|
@@ -893,7 +1007,10 @@ export function computeUpgrade(
|
|
|
893
1007
|
downgrades,
|
|
894
1008
|
retiredMarkers,
|
|
895
1009
|
linkedOutside,
|
|
1010
|
+
linkedSkew: linkedSkew(cwd, recipe.version),
|
|
896
1011
|
strayPins: strayPins(cwd, recipe.version, planned),
|
|
1012
|
+
linkLocks,
|
|
1013
|
+
lockPruned,
|
|
897
1014
|
notes: recipe.notes ?? [],
|
|
898
1015
|
}
|
|
899
1016
|
}
|
|
@@ -922,7 +1039,9 @@ function renderPlan(
|
|
|
922
1039
|
plan.importMoves.length === 0 &&
|
|
923
1040
|
plan.retiredMarkers.length === 0 &&
|
|
924
1041
|
plan.linkedOutside.length === 0 &&
|
|
925
|
-
plan.
|
|
1042
|
+
plan.linkedSkew.length === 0 &&
|
|
1043
|
+
plan.strayPins.length === 0 &&
|
|
1044
|
+
plan.linkLocks.length === 0
|
|
926
1045
|
) {
|
|
927
1046
|
lines.push("Already up to date - no changes.")
|
|
928
1047
|
return lines.join("\n")
|
|
@@ -995,12 +1114,54 @@ function renderPlan(
|
|
|
995
1114
|
}
|
|
996
1115
|
lines.push("")
|
|
997
1116
|
}
|
|
1117
|
+
if (plan.linkLocks.length > 0) {
|
|
1118
|
+
lines.push(
|
|
1119
|
+
plan.lockPruned
|
|
1120
|
+
? `Dropped ${plan.linkLocks.length} file: package(s) from bun.lock, whose recorded dependencies Bun never refreshes; \`bun install\` reads each linked package.json again:`
|
|
1121
|
+
: write
|
|
1122
|
+
? `bun.lock records stale dependencies for ${plan.linkLocks.length} file: package(s), which Bun never refreshes; run \`${linkLockUpdate(plan.linkLocks)}\`:`
|
|
1123
|
+
: `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:`,
|
|
1124
|
+
)
|
|
1125
|
+
for (const entry of plan.linkLocks)
|
|
1126
|
+
lines.push(
|
|
1127
|
+
` ${entry.package} (file:${entry.path}) ${entry.changes.map(describeChange).join(", ")}`,
|
|
1128
|
+
)
|
|
1129
|
+
if (plan.lockPruned)
|
|
1130
|
+
lines.push(
|
|
1131
|
+
" Run `bun install` before committing bun.lock: until it records these packages again, `bun install --frozen-lockfile` fails.",
|
|
1132
|
+
)
|
|
1133
|
+
lines.push("")
|
|
1134
|
+
}
|
|
998
1135
|
for (const note of plan.notes) lines.push(`note: ${note}`)
|
|
999
1136
|
if (!write) lines.push("\nRe-run with --write to apply, then nifra check verifies.")
|
|
1000
1137
|
return lines.join("\n").trimEnd()
|
|
1001
1138
|
}
|
|
1002
1139
|
|
|
1003
1140
|
/** Explain a refused rollback: which pins would roll back, why it's blocked, and the escape hatch. */
|
|
1141
|
+
/** The linked repositories to upgrade first, each with the commands that move it to `version`. */
|
|
1142
|
+
function renderLinkedSkew(
|
|
1143
|
+
version: string,
|
|
1144
|
+
skew: readonly LinkedSkew[],
|
|
1145
|
+
cwd: string,
|
|
1146
|
+
allowed: boolean,
|
|
1147
|
+
): string {
|
|
1148
|
+
const lines = [
|
|
1149
|
+
`${allowed ? "Allowed by --allow-linked-skew" : "Blocked"}: ${skew.length} linked repositor${skew.length === 1 ? "y loads" : "ies load"} its own nifra at another version. Its imports resolve from its own node_modules, so after this upgrade a server() it builds cannot be merge()d here ("merge() requires a server() from this copy of @nifrajs/core").`,
|
|
1150
|
+
]
|
|
1151
|
+
for (const entry of skew) {
|
|
1152
|
+
const at = relative(cwd, entry.path).split(sep).join("/") || "."
|
|
1153
|
+
lines.push(
|
|
1154
|
+
` ${entry.package} (${entry.declaredIn}) at ${at}: ${entry.installs.map((install) => `${install.package} ${install.version}`).join(", ")}`,
|
|
1155
|
+
` cd ${at} && nifra upgrade ${version} --write && bun install`,
|
|
1156
|
+
)
|
|
1157
|
+
}
|
|
1158
|
+
if (!allowed)
|
|
1159
|
+
lines.push(
|
|
1160
|
+
"Upgrade each one first, then run this again. --allow-linked-skew upgrades this project anyway.",
|
|
1161
|
+
)
|
|
1162
|
+
return lines.join("\n")
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1004
1165
|
function renderDowngradeRefusal(version: string, downgrades: readonly PinChange[]): string {
|
|
1005
1166
|
return [
|
|
1006
1167
|
`nifra upgrade → ${version}: refusing to DOWNGRADE ${downgrades.length} pin(s) below what's installed.`,
|
|
@@ -1090,6 +1251,33 @@ export function upgradeTargets(cliVersion: string): string[] {
|
|
|
1090
1251
|
return versions.sort(compareSemverSpec)
|
|
1091
1252
|
}
|
|
1092
1253
|
|
|
1254
|
+
/** Each target with the notes of every release after the installed one: what an app can observe
|
|
1255
|
+
* changing on the way up. Older releases are listed by version only. */
|
|
1256
|
+
function renderUpgradeList(
|
|
1257
|
+
targets: readonly string[],
|
|
1258
|
+
installed: string | null,
|
|
1259
|
+
notes: Readonly<Record<string, readonly string[]>>,
|
|
1260
|
+
): string {
|
|
1261
|
+
const lines = [
|
|
1262
|
+
installed === null
|
|
1263
|
+
? "available upgrade targets:"
|
|
1264
|
+
: `available upgrade targets (this project declares ${installed}):`,
|
|
1265
|
+
]
|
|
1266
|
+
for (const version of targets) {
|
|
1267
|
+
const ahead = installed === null || compareSemverSpec(version, installed) > 0
|
|
1268
|
+
lines.push(` ${version}${version === installed ? " (declared)" : ""}`)
|
|
1269
|
+
if (!ahead) continue
|
|
1270
|
+
const list = notes[version] ?? []
|
|
1271
|
+
if (list.length === 0) lines.push(" no change an app can observe")
|
|
1272
|
+
for (const note of list) lines.push(` - ${note}`)
|
|
1273
|
+
}
|
|
1274
|
+
lines.push(
|
|
1275
|
+
"",
|
|
1276
|
+
"A newer release upgrades with its own CLI: bunx @nifrajs/cli@<version> upgrade <version>",
|
|
1277
|
+
)
|
|
1278
|
+
return lines.join("\n")
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1093
1281
|
/** The command that runs `version`'s own CLI with the same flags. `version` is a validated release. */
|
|
1094
1282
|
function newerCliCommand(version: string, options: UpgradeOptions): string {
|
|
1095
1283
|
const flags = [
|
|
@@ -1108,13 +1296,11 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1108
1296
|
const cliVersion = options.cliVersion ?? listRecipeVersions().at(-1) ?? "0.0.0"
|
|
1109
1297
|
const targets = upgradeTargets(cliVersion)
|
|
1110
1298
|
if (options.list) {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
)
|
|
1117
|
-
}
|
|
1299
|
+
const installed = installedGroupVersion(cwd)
|
|
1300
|
+
const notes = Object.fromEntries(targets.map((v) => [v, getRecipe(v)?.notes ?? []]))
|
|
1301
|
+
if (options.json)
|
|
1302
|
+
console.log(JSON.stringify({ versions: targets, cliVersion, installed, notes }, null, 2))
|
|
1303
|
+
else console.log(renderUpgradeList(targets, installed, notes))
|
|
1118
1304
|
return true
|
|
1119
1305
|
}
|
|
1120
1306
|
|
|
@@ -1170,7 +1356,8 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1170
1356
|
const recipe = chainRecipes(version, from)
|
|
1171
1357
|
|
|
1172
1358
|
// Fail-closed on rollback: a dry pass writes nothing, so we can refuse before any package.json is touched.
|
|
1173
|
-
const
|
|
1359
|
+
const above = (await ancestorPins(cwd)).owned
|
|
1360
|
+
const preview = computeUpgrade(cwd, recipe, false, allowDowngrade, exact, above)
|
|
1174
1361
|
if (preview.downgrades.length > 0) {
|
|
1175
1362
|
if (options.json) {
|
|
1176
1363
|
console.log(
|
|
@@ -1185,10 +1372,26 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1185
1372
|
}
|
|
1186
1373
|
return false
|
|
1187
1374
|
}
|
|
1375
|
+
// Refused before anything is written: the linked repository fails at the first merge(), not here.
|
|
1376
|
+
if (preview.linkedSkew.length > 0 && options.allowLinkedSkew !== true) {
|
|
1377
|
+
if (options.json) {
|
|
1378
|
+
console.log(
|
|
1379
|
+
JSON.stringify(
|
|
1380
|
+
{ ...preview, from, steps: recipe.steps, write: false, refused: "linked-skew" },
|
|
1381
|
+
null,
|
|
1382
|
+
2,
|
|
1383
|
+
),
|
|
1384
|
+
)
|
|
1385
|
+
} else {
|
|
1386
|
+
if (!write) console.log(renderPlan(preview, false, from, recipe.steps))
|
|
1387
|
+
console.error(renderLinkedSkew(recipe.version, preview.linkedSkew, cwd, false))
|
|
1388
|
+
}
|
|
1389
|
+
return false
|
|
1390
|
+
}
|
|
1188
1391
|
|
|
1189
1392
|
const captureHooks = write && options.hooks !== false
|
|
1190
1393
|
const before = captureHooks ? await hookReportBefore(cwd) : undefined
|
|
1191
|
-
const plan = write ? computeUpgrade(cwd, recipe, true, allowDowngrade, exact) : preview
|
|
1394
|
+
const plan = write ? computeUpgrade(cwd, recipe, true, allowDowngrade, exact, above) : preview
|
|
1192
1395
|
const hooks = before === undefined ? undefined : await hookScopeAcross(cwd, before)
|
|
1193
1396
|
|
|
1194
1397
|
// Verify only makes sense once edits are on disk. Default on after --write; opt out with --no-verify.
|
|
@@ -1209,6 +1412,8 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1209
1412
|
return ok
|
|
1210
1413
|
}
|
|
1211
1414
|
console.log(renderPlan(plan, write, from, recipe.steps))
|
|
1415
|
+
if (plan.linkedSkew.length > 0)
|
|
1416
|
+
console.warn(`\n${renderLinkedSkew(recipe.version, plan.linkedSkew, cwd, true)}`)
|
|
1212
1417
|
if (hooks !== undefined) console.log(`\n${renderHookScope(hooks)}`)
|
|
1213
1418
|
|
|
1214
1419
|
if (verify) {
|
package/src/verification-plan.ts
CHANGED
|
@@ -67,6 +67,11 @@ const GATES = Object.freeze([
|
|
|
67
67
|
[["run", "check:sitemap"]],
|
|
68
68
|
"Run `bun run gen:sitemap` and review the generated sitemap.",
|
|
69
69
|
),
|
|
70
|
+
gate(
|
|
71
|
+
"site",
|
|
72
|
+
[["run", "check:site"]],
|
|
73
|
+
"Run `bun run check:site` and fix what the site's production build refuses; the release deploys that build after npm has the packages.",
|
|
74
|
+
),
|
|
70
75
|
gate(
|
|
71
76
|
"public-manifest",
|
|
72
77
|
[["run", "check:public-manifest"]],
|
|
@@ -232,6 +237,7 @@ const RELEASE_PLAN = Object.freeze([
|
|
|
232
237
|
"cli-isolation",
|
|
233
238
|
"corpus",
|
|
234
239
|
"sitemap",
|
|
240
|
+
"site",
|
|
235
241
|
"docs",
|
|
236
242
|
"public-boundary",
|
|
237
243
|
"public-manifest",
|
package/src/version-drift.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs"
|
|
2
2
|
import { join, sep } from "node:path"
|
|
3
|
+
import { bunLockDir, staleLinkLocks } from "./lock-links.ts"
|
|
3
4
|
import {
|
|
4
5
|
compareSemverSpec,
|
|
5
6
|
groupDeclaredNames,
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
installedGroupPackages,
|
|
8
9
|
isFixedGroup,
|
|
9
10
|
type LinkedGroupInstall,
|
|
11
|
+
specVersion,
|
|
10
12
|
} from "./upgrade.ts"
|
|
11
13
|
|
|
12
14
|
/** The fixed-group packages the package installed at `dir` depends on. */
|
|
@@ -64,6 +66,19 @@ export function collectVersionDrift(cwd: string, cliVersion?: string): VersionDr
|
|
|
64
66
|
if (!inside) linkedOutside.push({ package: name, path, version })
|
|
65
67
|
}
|
|
66
68
|
if (cliVersion !== undefined) add(cliVersion, "the running nifra CLI")
|
|
69
|
+
// A linked package's stale recorded pin is installed under that package, where the scan of
|
|
70
|
+
// node_modules above never looks; only an exact pin names the version that copy has.
|
|
71
|
+
const lockDir = bunLockDir(cwd)
|
|
72
|
+
for (const entry of lockDir === undefined ? [] : staleLinkLocks(lockDir)) {
|
|
73
|
+
for (const { name, recorded } of entry.changes) {
|
|
74
|
+
if (recorded === undefined || !isFixedGroup(name) || specVersion(recorded) !== recorded)
|
|
75
|
+
continue
|
|
76
|
+
add(
|
|
77
|
+
recorded,
|
|
78
|
+
`recorded for ${entry.package} in bun.lock, which Bun never refreshes (NF-D003)`,
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
67
82
|
if (sources.size < 2) return undefined
|
|
68
83
|
const versions = [...sources]
|
|
69
84
|
.sort(([a], [b]) => compareSemverSpec(a, b))
|
package/src/web-app-options.ts
CHANGED
|
@@ -11,7 +11,15 @@ import { FRAMEWORK_WEB_OPTIONS, type FrameworkWebOption, type NifraFramework } f
|
|
|
11
11
|
|
|
12
12
|
type FrameworkWebAppOptions = Pick<
|
|
13
13
|
CreateWebAppOptions,
|
|
14
|
-
|
|
14
|
+
| "use"
|
|
15
|
+
| "api"
|
|
16
|
+
| "apiPrefix"
|
|
17
|
+
| "apiStrip"
|
|
18
|
+
| "mounts"
|
|
19
|
+
| "csp"
|
|
20
|
+
| "nonce"
|
|
21
|
+
| "serverComponents"
|
|
22
|
+
| "i18n"
|
|
15
23
|
>
|
|
16
24
|
|
|
17
25
|
/** `use`, the backend as `api`, and every forwarded framework field the config sets. */
|