@nifrajs/cli 5.0.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 +10 -2
- 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 +5 -2
- package/dist/assure-hydration.js.map +1 -1
- package/dist/assure.d.ts +12 -2
- package/dist/assure.d.ts.map +1 -1
- package/dist/assure.js +73 -9
- package/dist/assure.js.map +1 -1
- package/dist/capabilities-tool.d.ts.map +1 -1
- package/dist/capabilities-tool.js +152 -49
- package/dist/capabilities-tool.js.map +1 -1
- package/dist/check-diagnostics.d.ts +7 -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 +8 -2
- package/dist/check-scan.d.ts.map +1 -1
- package/dist/check-scan.js +49 -13
- package/dist/check-scan.js.map +1 -1
- package/dist/check.d.ts.map +1 -1
- package/dist/check.js +91 -45
- package/dist/check.js.map +1 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +128 -59
- package/dist/cli.js.map +1 -1
- package/dist/client-module.d.ts +5 -3
- package/dist/client-module.d.ts.map +1 -1
- package/dist/client-module.js +34 -10
- package/dist/client-module.js.map +1 -1
- package/dist/command-catalog.d.ts +9 -1
- package/dist/command-catalog.d.ts.map +1 -1
- package/dist/command-catalog.js +75 -26
- 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 +19 -1
- package/dist/dev-feed-tool.d.ts.map +1 -1
- package/dist/dev-feed-tool.js +114 -0
- 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/fix-recipes.d.ts +2 -0
- package/dist/fix-recipes.d.ts.map +1 -1
- package/dist/fix-recipes.js +93 -12
- package/dist/fix-recipes.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 +60 -4
- package/dist/init-agents.d.ts.map +1 -1
- package/dist/init-agents.js +196 -33
- package/dist/init-agents.js.map +1 -1
- package/dist/internal/config-paths.d.ts +16 -0
- package/dist/internal/config-paths.d.ts.map +1 -0
- package/dist/internal/config-paths.js +124 -0
- package/dist/internal/config-paths.js.map +1 -0
- package/dist/internal/installed-package.d.ts +4 -0
- package/dist/internal/installed-package.d.ts.map +1 -0
- package/dist/internal/installed-package.js +17 -0
- package/dist/internal/installed-package.js.map +1 -0
- package/dist/internal/project-specifiers.d.ts +14 -1
- package/dist/internal/project-specifiers.d.ts.map +1 -1
- package/dist/internal/project-specifiers.js +63 -16
- package/dist/internal/project-specifiers.js.map +1 -1
- package/dist/internal/source-facts.d.ts +12 -1
- package/dist/internal/source-facts.d.ts.map +1 -1
- package/dist/internal/source-facts.js +117 -5
- package/dist/internal/source-facts.js.map +1 -1
- package/dist/internal/typescript-import.d.ts.map +1 -1
- package/dist/internal/typescript-import.js +5 -3
- package/dist/internal/typescript-import.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/introspect.d.ts +9 -0
- package/dist/introspect.d.ts.map +1 -1
- package/dist/introspect.js +32 -1
- package/dist/introspect.js.map +1 -1
- package/dist/levels-tool.d.ts.map +1 -1
- package/dist/levels-tool.js +5 -8
- package/dist/levels-tool.js.map +1 -1
- package/dist/load.d.ts +9 -4
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +32 -3
- 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-context.d.ts.map +1 -1
- package/dist/mcp-context.js +6 -21
- package/dist/mcp-context.js.map +1 -1
- package/dist/mcp-delegate.d.ts +2 -2
- package/dist/mcp-delegate.d.ts.map +1 -1
- package/dist/mcp-delegate.js +19 -7
- package/dist/mcp-delegate.js.map +1 -1
- package/dist/mcp-exec.d.ts +1 -0
- package/dist/mcp-exec.d.ts.map +1 -1
- package/dist/mcp-exec.js +13 -5
- package/dist/mcp-exec.js.map +1 -1
- package/dist/mcp-http.js +1 -1
- package/dist/mcp-io.d.ts +13 -0
- package/dist/mcp-io.d.ts.map +1 -1
- package/dist/mcp-io.js +23 -0
- package/dist/mcp-io.js.map +1 -1
- package/dist/mcp-path.d.ts +2 -1
- package/dist/mcp-path.d.ts.map +1 -1
- package/dist/mcp-path.js +9 -24
- package/dist/mcp-path.js.map +1 -1
- package/dist/mcp-root.d.ts +6 -4
- package/dist/mcp-root.d.ts.map +1 -1
- package/dist/mcp-root.js +12 -8
- package/dist/mcp-root.js.map +1 -1
- package/dist/mcp.d.ts.map +1 -1
- package/dist/mcp.js +40 -17
- package/dist/mcp.js.map +1 -1
- package/dist/migrate-layout.d.ts +41 -1
- package/dist/migrate-layout.d.ts.map +1 -1
- package/dist/migrate-layout.js +1729 -236
- package/dist/migrate-layout.js.map +1 -1
- package/dist/output-schemas.d.ts +34 -0
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +132 -21
- package/dist/output-schemas.js.map +1 -1
- package/dist/project-path.d.ts +6 -0
- package/dist/project-path.d.ts.map +1 -1
- package/dist/project-path.js +48 -14
- package/dist/project-path.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/release-verification.d.ts +5 -0
- package/dist/release-verification.d.ts.map +1 -1
- package/dist/release-verification.js +14 -0
- package/dist/release-verification.js.map +1 -1
- package/dist/review.d.ts.map +1 -1
- package/dist/review.js +7 -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 +5 -1
- package/dist/rules/codes.d.ts.map +1 -1
- package/dist/rules/codes.js +5 -1
- 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/data-guard.d.ts +6 -0
- package/dist/rules/data-guard.d.ts.map +1 -1
- package/dist/rules/data-guard.js +37 -0
- package/dist/rules/data-guard.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 +44 -2
- 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 +56 -3
- package/dist/rules/pages.d.ts.map +1 -1
- package/dist/rules/pages.js +412 -23
- 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/security.d.ts +3 -2
- package/dist/rules/security.d.ts.map +1 -1
- package/dist/rules/security.js +42 -11
- package/dist/rules/security.js.map +1 -1
- package/dist/rules/zones.d.ts.map +1 -1
- package/dist/rules/zones.js +34 -11
- package/dist/rules/zones.js.map +1 -1
- package/dist/stylex-migrate.d.ts.map +1 -1
- package/dist/stylex-migrate.js +127 -17
- package/dist/stylex-migrate.js.map +1 -1
- package/dist/test-tool.d.ts.map +1 -1
- package/dist/test-tool.js +3 -9
- package/dist/test-tool.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 +57 -6
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js +247 -19
- package/dist/upgrade.js.map +1 -1
- package/dist/verification-plan.d.ts.map +1 -1
- package/dist/verification-plan.js +7 -2
- package/dist/verification-plan.js.map +1 -1
- package/dist/version-drift.d.ts.map +1 -1
- package/dist/version-drift.js +66 -3
- 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 +21 -3
- package/docs/llms-full.txt +1083 -168
- package/docs/types.json +535 -112
- package/package.json +13 -12
- package/src/agent-files.ts +27 -17
- package/src/assure-hydration.ts +5 -1
- package/src/assure.ts +99 -11
- package/src/capabilities-tool.ts +188 -53
- package/src/check-diagnostics.ts +10 -0
- package/src/check-scan.ts +65 -12
- package/src/check.ts +122 -51
- package/src/cli.ts +127 -45
- package/src/client-module.ts +45 -9
- package/src/command-catalog.ts +92 -28
- package/src/dev-bun-config.ts +13 -9
- package/src/dev-feed-tool.ts +146 -1
- package/src/doctor.ts +102 -66
- package/src/fix-recipes.ts +101 -10
- package/src/i18n-check.ts +254 -18
- package/src/init-agents.ts +225 -44
- package/src/internal/config-paths.ts +154 -0
- package/src/internal/installed-package.ts +15 -0
- package/src/internal/project-specifiers.ts +78 -17
- package/src/internal/source-facts.ts +147 -5
- package/src/internal/typescript-import.ts +5 -3
- package/src/internal/workspace-packages.ts +218 -0
- package/src/introspect.ts +39 -1
- package/src/levels-tool.ts +7 -9
- package/src/load.ts +46 -4
- package/src/lock-links.ts +173 -0
- package/src/mcp-context.ts +5 -18
- package/src/mcp-delegate.ts +22 -10
- package/src/mcp-exec.ts +14 -4
- package/src/mcp-http.ts +1 -1
- package/src/mcp-io.ts +33 -0
- package/src/mcp-path.ts +8 -22
- package/src/mcp-root.ts +14 -8
- package/src/mcp.ts +48 -19
- package/src/migrate-layout.ts +1968 -245
- package/src/output-schemas.ts +179 -23
- package/src/project-path.ts +44 -13
- 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/release-verification.ts +20 -0
- package/src/review.ts +7 -0
- package/src/rule-explain.ts +75 -0
- package/src/rules/codes.ts +5 -1
- package/src/rules/contract-visibility.ts +118 -20
- package/src/rules/data-guard.ts +40 -0
- package/src/rules/explanations.ts +329 -0
- package/src/rules/legacy.ts +46 -2
- package/src/rules/merge-auth.ts +55 -0
- package/src/rules/pages.ts +486 -25
- package/src/rules/routes.ts +4 -3
- package/src/rules/security.ts +49 -11
- package/src/rules/zones.ts +33 -9
- package/src/stylex-migrate.ts +117 -17
- package/src/test-tool.ts +3 -9
- package/src/typecheck-coverage.ts +51 -6
- package/src/upgrade.ts +312 -19
- package/src/verification-plan.ts +15 -2
- package/src/version-drift.ts +68 -2
- package/src/web-app-options.ts +9 -1
package/src/upgrade.ts
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* 1. **pin sweep** - set every matching dependency to the target version across the workspace's
|
|
7
7
|
* package.json files, preserving the caret/tilde/exact style and skipping `workspace:`/`link:` specs.
|
|
8
|
-
* `overrides`, `resolutions` and `pnpm.overrides` are swept too, since they decide what installs
|
|
9
|
-
*
|
|
8
|
+
* `overrides`, `resolutions` and `pnpm.overrides` are swept too, since they decide what installs.
|
|
9
|
+
* The MCP launch pin in `.mcp.json`, `.cursor/mcp.json`, CLAUDE.md and AGENTS.md moves too, the
|
|
10
|
+
* edit `nifra init-agents --sync-mcp` makes; a version pinned anywhere else (a Dockerfile, a CI
|
|
11
|
+
* workflow, another lockfile) is listed only.
|
|
10
12
|
* 2. **dependency moves** - replace removed packages with their supported successor without
|
|
11
13
|
* reserializing package.json or leaving duplicate dependency keys.
|
|
12
14
|
* 3. **import moves** - rewrite exact import specifiers to their updated module paths.
|
|
@@ -26,6 +28,7 @@
|
|
|
26
28
|
|
|
27
29
|
import {
|
|
28
30
|
existsSync,
|
|
31
|
+
lstatSync,
|
|
29
32
|
mkdirSync,
|
|
30
33
|
readdirSync,
|
|
31
34
|
readFileSync,
|
|
@@ -33,7 +36,7 @@ import {
|
|
|
33
36
|
statSync,
|
|
34
37
|
writeFileSync,
|
|
35
38
|
} from "node:fs"
|
|
36
|
-
import { dirname, join, relative, sep } from "node:path"
|
|
39
|
+
import { dirname, join, relative, resolve, sep } from "node:path"
|
|
37
40
|
import { fileURLToPath } from "node:url"
|
|
38
41
|
import type { ReflectedHookReport } from "@nifrajs/core/reflection"
|
|
39
42
|
import { Glob } from "bun"
|
|
@@ -45,6 +48,15 @@ import {
|
|
|
45
48
|
parseHookReport,
|
|
46
49
|
renderHookDiff,
|
|
47
50
|
} from "./hooks-report.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"
|
|
48
60
|
import { getRecipe, listRecipeVersions, type UpgradeRecipe } from "./recipes/index.ts"
|
|
49
61
|
import { markerTarget } from "./rules/comment-markers.ts"
|
|
50
62
|
|
|
@@ -70,6 +82,8 @@ export interface UpgradeOptions {
|
|
|
70
82
|
* change in which hooks run where is visible. Loads the backend. Default true; `--no-hooks` skips it.
|
|
71
83
|
*/
|
|
72
84
|
readonly hooks?: boolean
|
|
85
|
+
/** Proceed although a linked repository loads its own nifra at another version. Default false. */
|
|
86
|
+
readonly allowLinkedSkew?: boolean
|
|
73
87
|
}
|
|
74
88
|
|
|
75
89
|
export interface PinChange {
|
|
@@ -97,6 +111,16 @@ export interface DependencyMoveChange {
|
|
|
97
111
|
readonly action: "renamed" | "removed"
|
|
98
112
|
}
|
|
99
113
|
|
|
114
|
+
/** An agent file whose MCP launch pins another `@nifrajs/cli`, re-pinned to the target. */
|
|
115
|
+
export interface AgentPinChange {
|
|
116
|
+
readonly file: string
|
|
117
|
+
/** The versions it pinned, in order of appearance. */
|
|
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. */
|
|
121
|
+
readonly to: string
|
|
122
|
+
}
|
|
123
|
+
|
|
100
124
|
/** A retired comment in the project, and the line it applied to before the release retired it. */
|
|
101
125
|
export interface RetiredMarkerSite {
|
|
102
126
|
readonly file: string
|
|
@@ -110,6 +134,7 @@ export interface RetiredMarkerSite {
|
|
|
110
134
|
export interface UpgradePlan {
|
|
111
135
|
readonly version: string
|
|
112
136
|
readonly pins: readonly PinChange[]
|
|
137
|
+
readonly agentPins: readonly AgentPinChange[]
|
|
113
138
|
readonly dependencyMoves: readonly DependencyMoveChange[]
|
|
114
139
|
readonly importMoves: readonly ImportChange[]
|
|
115
140
|
/** Pins refused because the target is BELOW the installed version (a rollback). Empty when allowed. */
|
|
@@ -118,8 +143,16 @@ export interface UpgradePlan {
|
|
|
118
143
|
readonly retiredMarkers: readonly RetiredMarkerSite[]
|
|
119
144
|
/** Installed group packages linked from outside the workspace root, at another version. Never edited. */
|
|
120
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[]
|
|
121
149
|
/** Other versions pinned outside package.json. Never edited. */
|
|
122
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
|
|
123
156
|
readonly notes: readonly string[]
|
|
124
157
|
}
|
|
125
158
|
|
|
@@ -540,7 +573,7 @@ function scan(cwd: string, pattern: string, dot = false): string[] {
|
|
|
540
573
|
}
|
|
541
574
|
|
|
542
575
|
// The fixed version group: every package released together at one version.
|
|
543
|
-
const isFixedGroup = (name: string): boolean =>
|
|
576
|
+
export const isFixedGroup = (name: string): boolean =>
|
|
544
577
|
name.startsWith("@nifrajs/") || name === "nifra" || name === "create-nifra"
|
|
545
578
|
|
|
546
579
|
const groupPins = (version: string): UpgradeRecipe["pins"] => [
|
|
@@ -549,6 +582,20 @@ const groupPins = (version: string): UpgradeRecipe["pins"] => [
|
|
|
549
582
|
{ match: "nifra", to: version },
|
|
550
583
|
]
|
|
551
584
|
|
|
585
|
+
/** Every fixed-group package a package.json under `cwd` names, whatever its spec. */
|
|
586
|
+
export function groupDeclaredNames(cwd: string): ReadonlySet<string> {
|
|
587
|
+
const names = new Set<string>()
|
|
588
|
+
for (const rel of scan(cwd, "**/package.json")) {
|
|
589
|
+
try {
|
|
590
|
+
const parsed = JSON.parse(readFileSync(join(cwd, rel), "utf8")) as Record<string, unknown>
|
|
591
|
+
for (const { target } of pinEntries(parsed)) if (isFixedGroup(target)) names.add(target)
|
|
592
|
+
} catch {
|
|
593
|
+
// Not JSON: it declares nothing.
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return names
|
|
597
|
+
}
|
|
598
|
+
|
|
552
599
|
/**
|
|
553
600
|
* Every fixed-group version the package.json files under `cwd` declare with a plain semver spec, each
|
|
554
601
|
* with the files that declare it. An override counts: it decides what installs. `workspace:`, `link:`
|
|
@@ -589,6 +636,7 @@ export interface StrayPin {
|
|
|
589
636
|
|
|
590
637
|
const STRAY_PIN_FILES = [
|
|
591
638
|
"**/{.mcp.json,mcp.json}",
|
|
639
|
+
"**/{AGENTS.md,CLAUDE.md}",
|
|
592
640
|
"**/{Dockerfile,Dockerfile.*,*.Dockerfile,*.dockerfile,Containerfile}",
|
|
593
641
|
"**/{docker-compose,compose}*.{yml,yaml}",
|
|
594
642
|
".github/workflows/*.{yml,yaml}",
|
|
@@ -601,10 +649,16 @@ const GROUP_PIN =
|
|
|
601
649
|
/(?<![\w.@/-])(@nifrajs\/[a-z0-9._-]+|create-nifra|nifra)@(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/g
|
|
602
650
|
|
|
603
651
|
/**
|
|
604
|
-
* Fixed-group versions other than `version` pinned where `nifra upgrade` does not edit: MCP configs
|
|
605
|
-
* container files, CI workflows, and lockfiles besides
|
|
652
|
+
* Fixed-group versions other than `version` pinned where `nifra upgrade` does not edit: MCP configs and
|
|
653
|
+
* agent guidance beyond the launch pin it moves, container files, CI workflows, and lockfiles besides
|
|
654
|
+
* the workspace's own (which install rewrites). `planned` holds a file's text after the upgrade's own
|
|
655
|
+
* edits, so a dry run lists what `--write` would leave.
|
|
606
656
|
*/
|
|
607
|
-
export function strayPins(
|
|
657
|
+
export function strayPins(
|
|
658
|
+
cwd: string,
|
|
659
|
+
version: string,
|
|
660
|
+
planned: ReadonlyMap<string, string> = new Map(),
|
|
661
|
+
): StrayPin[] {
|
|
608
662
|
const found: StrayPin[] = []
|
|
609
663
|
const files = new Set(STRAY_PIN_FILES.flatMap((pattern) => scan(cwd, pattern, true)))
|
|
610
664
|
for (const rel of [...files].sort()) {
|
|
@@ -613,7 +667,7 @@ export function strayPins(cwd: string, version: string): StrayPin[] {
|
|
|
613
667
|
let text: string
|
|
614
668
|
try {
|
|
615
669
|
if (statSync(join(cwd, rel)).size > 8_000_000) continue
|
|
616
|
-
text = readFileSync(join(cwd, rel), "utf8")
|
|
670
|
+
text = planned.get(rel) ?? readFileSync(join(cwd, rel), "utf8")
|
|
617
671
|
} catch {
|
|
618
672
|
continue
|
|
619
673
|
}
|
|
@@ -635,6 +689,57 @@ export function strayPins(cwd: string, version: string): StrayPin[] {
|
|
|
635
689
|
return found
|
|
636
690
|
}
|
|
637
691
|
|
|
692
|
+
/** Whether `rel` is a regular file under `cwd` reached through no symlink: the upgrade's write boundary. */
|
|
693
|
+
function plainFileAt(cwd: string, rel: string): boolean {
|
|
694
|
+
let path = cwd
|
|
695
|
+
const parts = rel.split("/")
|
|
696
|
+
for (const [index, part] of parts.entries()) {
|
|
697
|
+
path = join(path, part)
|
|
698
|
+
let stat: ReturnType<typeof lstatSync>
|
|
699
|
+
try {
|
|
700
|
+
stat = lstatSync(path)
|
|
701
|
+
} catch {
|
|
702
|
+
return false
|
|
703
|
+
}
|
|
704
|
+
if (stat.isSymbolicLink()) return false
|
|
705
|
+
if (index === parts.length - 1 ? !stat.isFile() : !stat.isDirectory()) return false
|
|
706
|
+
}
|
|
707
|
+
return true
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
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.
|
|
714
|
+
*/
|
|
715
|
+
function agentPinEdits(
|
|
716
|
+
cwd: string,
|
|
717
|
+
version: string,
|
|
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
|
|
731
|
+
// latin1 is one char per byte, so every byte outside a pin is written back as it was.
|
|
732
|
+
const scan = site.repin(readFileSync(abs, "latin1"), to)
|
|
733
|
+
if (scan.stale.length === 0) continue
|
|
734
|
+
edits.push({
|
|
735
|
+
change: { file: path, from: scan.stale, to: to ?? "unpinned" },
|
|
736
|
+
text: scan.text,
|
|
737
|
+
abs,
|
|
738
|
+
})
|
|
739
|
+
}
|
|
740
|
+
return edits
|
|
741
|
+
}
|
|
742
|
+
|
|
638
743
|
/** An installed fixed-group package, followed to its real location. */
|
|
639
744
|
export interface LinkedGroupInstall {
|
|
640
745
|
readonly package: string
|
|
@@ -652,6 +757,68 @@ const packageVersionAt = (dir: string): string | undefined => {
|
|
|
652
757
|
}
|
|
653
758
|
}
|
|
654
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
|
+
|
|
655
822
|
/**
|
|
656
823
|
* Every fixed-group package installed in `cwd/node_modules`, realpath-resolved so a linked repository
|
|
657
824
|
* reports its own version. `inside` is false for one that resolves outside the workspace root.
|
|
@@ -750,8 +917,11 @@ export function computeUpgrade(
|
|
|
750
917
|
write: boolean,
|
|
751
918
|
allowDowngrade = false,
|
|
752
919
|
exact = false,
|
|
920
|
+
above: readonly AncestorPinSite[] = [],
|
|
753
921
|
): UpgradePlan {
|
|
754
922
|
const pins: PinChange[] = []
|
|
923
|
+
const agentPins: AgentPinChange[] = []
|
|
924
|
+
const planned = new Map<string, string>()
|
|
755
925
|
const dependencyMoves: DependencyMoveChange[] = []
|
|
756
926
|
const importMoves: ImportChange[] = []
|
|
757
927
|
const downgrades: PinChange[] = []
|
|
@@ -760,6 +930,7 @@ export function computeUpgrade(
|
|
|
760
930
|
.filter((entry) => !entry.inside && entry.version !== recipe.version)
|
|
761
931
|
.map(({ package: name, path, version }) => ({ package: name, path, version }))
|
|
762
932
|
|
|
933
|
+
const manifests = new Map<string, string>()
|
|
763
934
|
if ((recipe.dependencyMoves?.length ?? 0) > 0 || recipe.pins.length > 0) {
|
|
764
935
|
for (const rel of scan(cwd, "**/package.json")) {
|
|
765
936
|
const abs = join(cwd, rel)
|
|
@@ -769,10 +940,32 @@ export function computeUpgrade(
|
|
|
769
940
|
const pinned = pinSweepText(moved.text, recipe.pins, allowDowngrade, exact)
|
|
770
941
|
for (const change of pinned.changes) pins.push({ file: rel, ...change })
|
|
771
942
|
for (const d of pinned.downgrades) downgrades.push({ file: rel, ...d })
|
|
943
|
+
if (pinned.text !== original) manifests.set(resolve(abs), pinned.text)
|
|
772
944
|
if (write && pinned.text !== original) writeFileSync(abs, pinned.text)
|
|
773
945
|
}
|
|
774
946
|
}
|
|
775
947
|
|
|
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)) {
|
|
964
|
+
agentPins.push(change)
|
|
965
|
+
planned.set(change.file, text)
|
|
966
|
+
if (write) writeFileSync(abs, Buffer.from(text, "latin1"))
|
|
967
|
+
}
|
|
968
|
+
|
|
776
969
|
if (recipe.importMoves.length > 0) {
|
|
777
970
|
for (const rel of scan(cwd, SOURCE_GLOB)) {
|
|
778
971
|
const abs = join(cwd, rel)
|
|
@@ -808,12 +1001,16 @@ export function computeUpgrade(
|
|
|
808
1001
|
return {
|
|
809
1002
|
version: recipe.version,
|
|
810
1003
|
pins,
|
|
1004
|
+
agentPins,
|
|
811
1005
|
dependencyMoves,
|
|
812
1006
|
importMoves,
|
|
813
1007
|
downgrades,
|
|
814
1008
|
retiredMarkers,
|
|
815
1009
|
linkedOutside,
|
|
816
|
-
|
|
1010
|
+
linkedSkew: linkedSkew(cwd, recipe.version),
|
|
1011
|
+
strayPins: strayPins(cwd, recipe.version, planned),
|
|
1012
|
+
linkLocks,
|
|
1013
|
+
lockPruned,
|
|
817
1014
|
notes: recipe.notes ?? [],
|
|
818
1015
|
}
|
|
819
1016
|
}
|
|
@@ -837,11 +1034,14 @@ function renderPlan(
|
|
|
837
1034
|
lines.push("")
|
|
838
1035
|
if (
|
|
839
1036
|
plan.pins.length === 0 &&
|
|
1037
|
+
plan.agentPins.length === 0 &&
|
|
840
1038
|
plan.dependencyMoves.length === 0 &&
|
|
841
1039
|
plan.importMoves.length === 0 &&
|
|
842
1040
|
plan.retiredMarkers.length === 0 &&
|
|
843
1041
|
plan.linkedOutside.length === 0 &&
|
|
844
|
-
plan.
|
|
1042
|
+
plan.linkedSkew.length === 0 &&
|
|
1043
|
+
plan.strayPins.length === 0 &&
|
|
1044
|
+
plan.linkLocks.length === 0
|
|
845
1045
|
) {
|
|
846
1046
|
lines.push("Already up to date - no changes.")
|
|
847
1047
|
return lines.join("\n")
|
|
@@ -862,6 +1062,13 @@ function renderPlan(
|
|
|
862
1062
|
for (const p of plan.pins) lines.push(` ${p.file} ${p.name}: ${p.from} → ${p.to}`)
|
|
863
1063
|
lines.push("")
|
|
864
1064
|
}
|
|
1065
|
+
if (plan.agentPins.length > 0) {
|
|
1066
|
+
lines.push(`${verb} ${plan.agentPins.length} MCP launch pin(s):`)
|
|
1067
|
+
for (const p of plan.agentPins)
|
|
1068
|
+
lines.push(` ${p.file} @nifrajs/cli: ${p.from.join(", ")} → ${p.to}`)
|
|
1069
|
+
if (write) lines.push(" Restart your agent so it launches the new nifra MCP server.")
|
|
1070
|
+
lines.push("")
|
|
1071
|
+
}
|
|
865
1072
|
if (plan.importMoves.length > 0) {
|
|
866
1073
|
const total = plan.importMoves.reduce((n, m) => n + m.count, 0)
|
|
867
1074
|
lines.push(`${verb} ${total} import move(s) across ${plan.importMoves.length} file(s):`)
|
|
@@ -907,12 +1114,54 @@ function renderPlan(
|
|
|
907
1114
|
}
|
|
908
1115
|
lines.push("")
|
|
909
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
|
+
}
|
|
910
1135
|
for (const note of plan.notes) lines.push(`note: ${note}`)
|
|
911
1136
|
if (!write) lines.push("\nRe-run with --write to apply, then nifra check verifies.")
|
|
912
1137
|
return lines.join("\n").trimEnd()
|
|
913
1138
|
}
|
|
914
1139
|
|
|
915
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
|
+
|
|
916
1165
|
function renderDowngradeRefusal(version: string, downgrades: readonly PinChange[]): string {
|
|
917
1166
|
return [
|
|
918
1167
|
`nifra upgrade → ${version}: refusing to DOWNGRADE ${downgrades.length} pin(s) below what's installed.`,
|
|
@@ -1002,6 +1251,33 @@ export function upgradeTargets(cliVersion: string): string[] {
|
|
|
1002
1251
|
return versions.sort(compareSemverSpec)
|
|
1003
1252
|
}
|
|
1004
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
|
+
|
|
1005
1281
|
/** The command that runs `version`'s own CLI with the same flags. `version` is a validated release. */
|
|
1006
1282
|
function newerCliCommand(version: string, options: UpgradeOptions): string {
|
|
1007
1283
|
const flags = [
|
|
@@ -1020,13 +1296,11 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1020
1296
|
const cliVersion = options.cliVersion ?? listRecipeVersions().at(-1) ?? "0.0.0"
|
|
1021
1297
|
const targets = upgradeTargets(cliVersion)
|
|
1022
1298
|
if (options.list) {
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
)
|
|
1029
|
-
}
|
|
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))
|
|
1030
1304
|
return true
|
|
1031
1305
|
}
|
|
1032
1306
|
|
|
@@ -1082,7 +1356,8 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1082
1356
|
const recipe = chainRecipes(version, from)
|
|
1083
1357
|
|
|
1084
1358
|
// Fail-closed on rollback: a dry pass writes nothing, so we can refuse before any package.json is touched.
|
|
1085
|
-
const
|
|
1359
|
+
const above = (await ancestorPins(cwd)).owned
|
|
1360
|
+
const preview = computeUpgrade(cwd, recipe, false, allowDowngrade, exact, above)
|
|
1086
1361
|
if (preview.downgrades.length > 0) {
|
|
1087
1362
|
if (options.json) {
|
|
1088
1363
|
console.log(
|
|
@@ -1097,10 +1372,26 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1097
1372
|
}
|
|
1098
1373
|
return false
|
|
1099
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
|
+
}
|
|
1100
1391
|
|
|
1101
1392
|
const captureHooks = write && options.hooks !== false
|
|
1102
1393
|
const before = captureHooks ? await hookReportBefore(cwd) : undefined
|
|
1103
|
-
const plan = write ? computeUpgrade(cwd, recipe, true, allowDowngrade, exact) : preview
|
|
1394
|
+
const plan = write ? computeUpgrade(cwd, recipe, true, allowDowngrade, exact, above) : preview
|
|
1104
1395
|
const hooks = before === undefined ? undefined : await hookScopeAcross(cwd, before)
|
|
1105
1396
|
|
|
1106
1397
|
// Verify only makes sense once edits are on disk. Default on after --write; opt out with --no-verify.
|
|
@@ -1121,6 +1412,8 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
|
|
|
1121
1412
|
return ok
|
|
1122
1413
|
}
|
|
1123
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)}`)
|
|
1124
1417
|
if (hooks !== undefined) console.log(`\n${renderHookScope(hooks)}`)
|
|
1125
1418
|
|
|
1126
1419
|
if (verify) {
|
package/src/verification-plan.ts
CHANGED
|
@@ -37,6 +37,11 @@ const GATES = Object.freeze([
|
|
|
37
37
|
"Run `bun run typecheck` and fix the reported TypeScript errors.",
|
|
38
38
|
),
|
|
39
39
|
gate("tests", [["run", "test"]], "Run `bun run test` and fix the first failing test."),
|
|
40
|
+
gate(
|
|
41
|
+
"rest-tests",
|
|
42
|
+
[["run", "test:rest"]],
|
|
43
|
+
"Run `bun run test:rest` and fix the first failing test.",
|
|
44
|
+
),
|
|
40
45
|
gate(
|
|
41
46
|
"docs",
|
|
42
47
|
[["run", "check:docs"]],
|
|
@@ -62,6 +67,11 @@ const GATES = Object.freeze([
|
|
|
62
67
|
[["run", "check:sitemap"]],
|
|
63
68
|
"Run `bun run gen:sitemap` and review the generated sitemap.",
|
|
64
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
|
+
),
|
|
65
75
|
gate(
|
|
66
76
|
"public-manifest",
|
|
67
77
|
[["run", "check:public-manifest"]],
|
|
@@ -216,15 +226,18 @@ const DEFAULT_PLAN = Object.freeze([
|
|
|
216
226
|
"changesets",
|
|
217
227
|
] as const)
|
|
218
228
|
|
|
229
|
+
// `coverage` fails on any failing test, so it is the release plan's run of the library suites;
|
|
230
|
+
// `rest-tests` runs the suites it leaves out, and `tests` would only repeat the two.
|
|
219
231
|
const RELEASE_PLAN = Object.freeze([
|
|
220
232
|
"build",
|
|
221
233
|
"lint",
|
|
222
234
|
"typecheck",
|
|
223
|
-
"tests",
|
|
224
|
-
"cli-isolation",
|
|
225
235
|
"coverage",
|
|
236
|
+
"rest-tests",
|
|
237
|
+
"cli-isolation",
|
|
226
238
|
"corpus",
|
|
227
239
|
"sitemap",
|
|
240
|
+
"site",
|
|
228
241
|
"docs",
|
|
229
242
|
"public-boundary",
|
|
230
243
|
"public-manifest",
|
package/src/version-drift.ts
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs"
|
|
2
|
+
import { join, sep } from "node:path"
|
|
3
|
+
import { bunLockDir, staleLinkLocks } from "./lock-links.ts"
|
|
1
4
|
import {
|
|
2
5
|
compareSemverSpec,
|
|
6
|
+
groupDeclaredNames,
|
|
3
7
|
groupPinVersions,
|
|
4
8
|
installedGroupPackages,
|
|
9
|
+
isFixedGroup,
|
|
5
10
|
type LinkedGroupInstall,
|
|
11
|
+
specVersion,
|
|
6
12
|
} from "./upgrade.ts"
|
|
7
13
|
|
|
14
|
+
/** The fixed-group packages the package installed at `dir` depends on. */
|
|
15
|
+
function groupDependenciesAt(dir: string): string[] {
|
|
16
|
+
try {
|
|
17
|
+
const manifest: unknown = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"))
|
|
18
|
+
if (typeof manifest !== "object" || manifest === null) return []
|
|
19
|
+
return ["dependencies", "peerDependencies", "optionalDependencies"].flatMap((field) => {
|
|
20
|
+
const deps: unknown = Reflect.get(manifest, field)
|
|
21
|
+
return typeof deps === "object" && deps !== null ? Object.keys(deps).filter(isFixedGroup) : []
|
|
22
|
+
})
|
|
23
|
+
} catch {
|
|
24
|
+
return []
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
8
28
|
/** One version of the fixed release group, and where the workspace carries it. */
|
|
9
29
|
export interface GroupVersion {
|
|
10
30
|
readonly version: string
|
|
@@ -35,11 +55,30 @@ export function collectVersionDrift(cwd: string, cliVersion?: string): VersionDr
|
|
|
35
55
|
for (const file of files) add(version, `pinned in ${file}`)
|
|
36
56
|
}
|
|
37
57
|
const linkedOutside: LinkedGroupInstall[] = []
|
|
38
|
-
|
|
58
|
+
const installs = installedGroupPackages(cwd)
|
|
59
|
+
// An install nothing declares, such as one an older install left behind, loads nowhere, and no
|
|
60
|
+
// upgrade re-pins it: counting it would report drift that never clears.
|
|
61
|
+
const declared = new Set(groupDeclaredNames(cwd))
|
|
62
|
+
for (const { path } of installs) for (const name of groupDependenciesAt(path)) declared.add(name)
|
|
63
|
+
for (const { package: name, path, version, inside } of installs) {
|
|
64
|
+
if (!declared.has(name)) continue
|
|
39
65
|
add(version, `installed ${name}${inside ? "" : ` (linked from ${path})`}`)
|
|
40
66
|
if (!inside) linkedOutside.push({ package: name, path, version })
|
|
41
67
|
}
|
|
42
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
|
+
}
|
|
43
82
|
if (sources.size < 2) return undefined
|
|
44
83
|
const versions = [...sources]
|
|
45
84
|
.sort(([a], [b]) => compareSemverSpec(a, b))
|
|
@@ -51,6 +90,33 @@ export function collectVersionDrift(cwd: string, cliVersion?: string): VersionDr
|
|
|
51
90
|
}
|
|
52
91
|
}
|
|
53
92
|
|
|
93
|
+
/** The install a package belongs to: the folder above its last `node_modules`, or the package itself. */
|
|
94
|
+
const installRoot = (path: string): string => {
|
|
95
|
+
const parts = path.split(sep)
|
|
96
|
+
const last = parts.lastIndexOf("node_modules")
|
|
97
|
+
return last <= 0 ? path : parts.slice(0, last).join(sep)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Linked installs, one phrase per install and version: a linked repository brings its whole group. */
|
|
101
|
+
function linkedGroups(installs: readonly LinkedGroupInstall[]): string[] {
|
|
102
|
+
const groups = new Map<string, LinkedGroupInstall[]>()
|
|
103
|
+
for (const install of installs) {
|
|
104
|
+
const key = `${installRoot(install.path)}\0${install.version}`
|
|
105
|
+
groups.set(key, [...(groups.get(key) ?? []), install])
|
|
106
|
+
}
|
|
107
|
+
return [...groups.values()].map((group) => {
|
|
108
|
+
const [first] = group
|
|
109
|
+
if (first === undefined) return ""
|
|
110
|
+
if (group.length === 1) return `${first.package} ${first.version} at ${first.path}`
|
|
111
|
+
const names = group.map((install) => install.package).sort()
|
|
112
|
+
const listed =
|
|
113
|
+
names.length > 3
|
|
114
|
+
? `${names.slice(0, 3).join(", ")} and ${names.length - 3} more`
|
|
115
|
+
: names.join(", ")
|
|
116
|
+
return `${group.length} packages at ${first.version} under ${installRoot(first.path)} (${listed})`
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
54
120
|
/** The advisory both `nifra doctor` and `nifra check` print. */
|
|
55
121
|
export function versionDriftMessage(drift: VersionDrift): string {
|
|
56
122
|
const listed = drift.versions
|
|
@@ -62,6 +128,6 @@ export function versionDriftMessage(drift: VersionDrift): string {
|
|
|
62
128
|
const linked =
|
|
63
129
|
drift.linkedOutside.length === 0
|
|
64
130
|
? ""
|
|
65
|
-
: ` It does not edit ${drift.linkedOutside
|
|
131
|
+
: ` It does not edit ${linkedGroups(drift.linkedOutside).join(", ")}, linked from outside the workspace root; upgrade that repository on its own.`
|
|
66
132
|
return `mixed nifra versions in this workspace: ${listed}. Run \`nifra upgrade ${drift.highest}\` (it runs each release's migration steps, then re-pins).${linked}`
|
|
67
133
|
}
|