@nifrajs/cli 5.3.0 → 5.5.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.
Files changed (109) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/README.md +2 -1
  3. package/dist/check-scan.d.ts +6 -0
  4. package/dist/check-scan.d.ts.map +1 -1
  5. package/dist/check-scan.js +10 -10
  6. package/dist/check-scan.js.map +1 -1
  7. package/dist/check.d.ts.map +1 -1
  8. package/dist/check.js +1 -0
  9. package/dist/check.js.map +1 -1
  10. package/dist/cli.d.ts.map +1 -1
  11. package/dist/cli.js +6 -5
  12. package/dist/cli.js.map +1 -1
  13. package/dist/docs-search.d.ts +10 -1
  14. package/dist/docs-search.d.ts.map +1 -1
  15. package/dist/docs-search.js +86 -9
  16. package/dist/docs-search.js.map +1 -1
  17. package/dist/doctor.d.ts.map +1 -1
  18. package/dist/doctor.js +49 -4
  19. package/dist/doctor.js.map +1 -1
  20. package/dist/load.d.ts +4 -1
  21. package/dist/load.d.ts.map +1 -1
  22. package/dist/load.js +8 -0
  23. package/dist/load.js.map +1 -1
  24. package/dist/lock-links.d.ts.map +1 -1
  25. package/dist/lock-links.js +3 -1
  26. package/dist/lock-links.js.map +1 -1
  27. package/dist/mcp-http.js +1 -1
  28. package/dist/recipes/5.4.0.d.ts +10 -0
  29. package/dist/recipes/5.4.0.d.ts.map +1 -0
  30. package/dist/recipes/5.4.0.js +27 -0
  31. package/dist/recipes/5.4.0.js.map +1 -0
  32. package/dist/recipes/5.5.0.d.ts +9 -0
  33. package/dist/recipes/5.5.0.d.ts.map +1 -0
  34. package/dist/recipes/5.5.0.js +31 -0
  35. package/dist/recipes/5.5.0.js.map +1 -0
  36. package/dist/recipes/index.d.ts +7 -0
  37. package/dist/recipes/index.d.ts.map +1 -1
  38. package/dist/recipes/index.js +4 -0
  39. package/dist/recipes/index.js.map +1 -1
  40. package/dist/release-verification.d.ts +20 -0
  41. package/dist/release-verification.d.ts.map +1 -1
  42. package/dist/release-verification.js +62 -13
  43. package/dist/release-verification.js.map +1 -1
  44. package/dist/review.d.ts.map +1 -1
  45. package/dist/review.js +2 -0
  46. package/dist/review.js.map +1 -1
  47. package/dist/rules/codes.d.ts +2 -0
  48. package/dist/rules/codes.d.ts.map +1 -1
  49. package/dist/rules/codes.js +2 -0
  50. package/dist/rules/codes.js.map +1 -1
  51. package/dist/rules/explanations.d.ts.map +1 -1
  52. package/dist/rules/explanations.js +12 -2
  53. package/dist/rules/explanations.js.map +1 -1
  54. package/dist/rules/legacy.d.ts.map +1 -1
  55. package/dist/rules/legacy.js +63 -19
  56. package/dist/rules/legacy.js.map +1 -1
  57. package/dist/rules/security.d.ts +6 -0
  58. package/dist/rules/security.d.ts.map +1 -1
  59. package/dist/rules/security.js +152 -2
  60. package/dist/rules/security.js.map +1 -1
  61. package/dist/rules/zones.d.ts.map +1 -1
  62. package/dist/rules/zones.js +43 -1
  63. package/dist/rules/zones.js.map +1 -1
  64. package/dist/smoke.d.ts +17 -1
  65. package/dist/smoke.d.ts.map +1 -1
  66. package/dist/smoke.js +49 -0
  67. package/dist/smoke.js.map +1 -1
  68. package/dist/upgrade.d.ts +40 -12
  69. package/dist/upgrade.d.ts.map +1 -1
  70. package/dist/upgrade.js +182 -17
  71. package/dist/upgrade.js.map +1 -1
  72. package/dist/verification-plan.d.ts +4 -0
  73. package/dist/verification-plan.d.ts.map +1 -1
  74. package/dist/verification-plan.js +48 -0
  75. package/dist/verification-plan.js.map +1 -1
  76. package/dist/version-drift.d.ts +2 -1
  77. package/dist/version-drift.d.ts.map +1 -1
  78. package/dist/version-drift.js +11 -26
  79. package/dist/version-drift.js.map +1 -1
  80. package/dist/web-app-options.d.ts +1 -1
  81. package/dist/web-app-options.d.ts.map +1 -1
  82. package/dist/web-app-options.js.map +1 -1
  83. package/docs/examples.json +14 -2
  84. package/docs/llms-full.txt +759 -199
  85. package/docs/types.json +258 -44
  86. package/package.json +11 -11
  87. package/src/check-scan.ts +10 -12
  88. package/src/check.ts +1 -0
  89. package/src/cli.ts +6 -5
  90. package/src/docs-search.ts +90 -10
  91. package/src/doctor.ts +60 -4
  92. package/src/load.ts +13 -0
  93. package/src/lock-links.ts +3 -1
  94. package/src/mcp-http.ts +1 -1
  95. package/src/recipes/5.4.0.ts +28 -0
  96. package/src/recipes/5.5.0.ts +32 -0
  97. package/src/recipes/index.ts +11 -0
  98. package/src/release-verification.ts +88 -12
  99. package/src/review.ts +2 -0
  100. package/src/rules/codes.ts +2 -0
  101. package/src/rules/explanations.ts +12 -2
  102. package/src/rules/legacy.ts +75 -20
  103. package/src/rules/security.ts +171 -2
  104. package/src/rules/zones.ts +44 -1
  105. package/src/smoke.ts +70 -0
  106. package/src/upgrade.ts +199 -21
  107. package/src/verification-plan.ts +51 -0
  108. package/src/version-drift.ts +18 -26
  109. package/src/web-app-options.ts +1 -0
@@ -22,7 +22,7 @@ import {
22
22
  ZoneConfigError,
23
23
  } from "@nifrajs/web/zones"
24
24
  import { CONFIG_FILE, FRAMEWORK_FILE } from "../app-files.ts"
25
- import { COMPONENT_FILE, importSites, stripComments } from "../check-scan.ts"
25
+ import { COMPONENT_FILE, importSites, isServerOnlySink, stripComments } from "../check-scan.ts"
26
26
  import { appDirs, clientModuleRoot } from "../client-module.ts"
27
27
  import { componentCheckReceipts } from "../component-check.ts"
28
28
  import { type Diagnostic, diagnostic } from "../diagnostics.ts"
@@ -242,6 +242,47 @@ export const zoneImportRule: CheckRule = {
242
242
  follow({ file: name, app, zone: "error" })
243
243
  }
244
244
 
245
+ /**
246
+ * What backend code that imports frontend module `target` can do about it. The module may be
247
+ * declared shared in place when what it imports and reads is shared-safe, which is exactly what
248
+ * the shared rules then hold it to; otherwise the first import or read that stops it is named.
249
+ */
250
+ const shareRemedy = (target: string, targetName: string, app: string): string => {
251
+ const content = ctx.sources.read(targetName)
252
+ if (content === undefined) return ""
253
+ let blocker: string | undefined
254
+ for (const { specifier } of importSites(content, targetName, facts)) {
255
+ // By name first, as NF-C004 judges shared code: an alias resolving it to a project file
256
+ // does not stop that rule from refusing it.
257
+ if (isServerOnlySink(specifier)) {
258
+ blocker = `it imports ${specifier}, a server package`
259
+ break
260
+ }
261
+ const resolved = resolveSpecifier(target, specifier)
262
+ if (resolved !== undefined) {
263
+ const zone = classifierFor(app).classify(resolved, specifier).zone
264
+ if (zone === "error" || !importAllowed("shared", zone))
265
+ blocker = `it imports ${display(ctx.root, resolved)} (${zone === "error" ? "in no zone" : `${zone} code`})`
266
+ }
267
+ if (blocker !== undefined) break
268
+ }
269
+ const reads =
270
+ blocker === undefined
271
+ ? privateEnvReads(targetName, content, publicPrefix(ctx.root, app))
272
+ : []
273
+ if (reads.length > 0) blocker = `it reads ${reads[0]}, which the browser may not`
274
+ if (blocker !== undefined)
275
+ return `. ${targetName} cannot be shared as it is: ${blocker}; move what both sides need into shared/`
276
+ const inApp = app === "" ? targetName : targetName.slice(app.length + 1)
277
+ const dot = inApp.lastIndexOf(".")
278
+ const renamed =
279
+ dot === -1 ? `${inApp}.shared` : `${inApp.slice(0, dot)}.shared${inApp.slice(dot)}`
280
+ return (
281
+ `. ${targetName} imports only shared code and packages, so it can be shared where it is: ` +
282
+ `rename it ${renamed.slice(renamed.lastIndexOf("/") + 1)}, or list "${inApp}" under ` +
283
+ `"nifra": { "zones": { "shared": [...] } } in ${app === "" ? "" : `${app}/`}package.json`
284
+ )
285
+ }
245
286
  // An undeclared package is one fact, however many files import it.
246
287
  const reportedPackages = new Set<string>()
247
288
  // An array iterator reads the length on every step, so files `follow` appends are visited too.
@@ -285,6 +326,8 @@ export const zoneImportRule: CheckRule = {
285
326
  (from === "shared" && !importAllowed(from, to.zone) && !BACKEND.has(to.zone)))
286
327
  ) {
287
328
  message = importRuleMessage(file, from, targetName, to.zone)
329
+ if (SERVER.has(from) && to.zone === "frontend" && to.entry === undefined)
330
+ message += shareRemedy(target, targetName, app)
288
331
  } else continue
289
332
  if (!inWebApp(app)) message = withApiKindHint(message)
290
333
  findings.push(
package/src/smoke.ts CHANGED
@@ -30,6 +30,17 @@ export interface SmokeSsrCheck {
30
30
  readonly expectedHeaders?: Readonly<Record<string, string>>
31
31
  }
32
32
 
33
+ /** One host's surface under a host policy: what it must render and load, and what it must refuse. */
34
+ export interface SmokeHostCheck {
35
+ readonly id: string
36
+ /** The Host header every request of this check sends. */
37
+ readonly host: string
38
+ /** Pages that must render on `host`; every file each references must answer 200 there too. */
39
+ readonly pages: readonly string[]
40
+ /** Paths `host` must answer 404 for. */
41
+ readonly refused?: readonly string[]
42
+ }
43
+
33
44
  export interface SmokeHookContext {
34
45
  readonly app: SmokeApp
35
46
  readonly origin: string
@@ -56,6 +67,12 @@ export interface SmokeFixture {
56
67
  readonly securityHeaders?: readonly SmokeRequestCheck[]
57
68
  /** Optional callback/guard witnesses; credentials stay inside the fixture. */
58
69
  readonly authCallbacks?: readonly SmokeRequestCheck[]
70
+ /**
71
+ * Per-host surfaces, for an app with a host policy. A page a gate serves while refusing its bundle
72
+ * or stylesheet still answers 200, so each page's referenced files (scripts and their imports,
73
+ * stylesheets and their `url()`s, icons) are fetched on the same host and must answer 200 too.
74
+ */
75
+ readonly hosts?: readonly SmokeHostCheck[]
59
76
  /** Optional response-contract laboratory hook. Its result is summarized without payloads. */
60
77
  readonly contract?: (
61
78
  context: SmokeHookContext,
@@ -79,6 +96,7 @@ export interface SmokeCheckResult {
79
96
  | "not-found"
80
97
  | "headers"
81
98
  | "auth"
99
+ | "hosts"
82
100
  | "contract"
83
101
  | "hydration"
84
102
  readonly message?: string
@@ -212,6 +230,26 @@ function smokeSsrError(value: unknown): string | undefined {
212
230
  return undefined
213
231
  }
214
232
 
233
+ function hostCheckError(value: unknown, label: string): string | undefined {
234
+ if (!isRecord(value)) return `${label} must be an object`
235
+ if (typeof value.id !== "string" || !/^[A-Za-z0-9._-]{1,80}$/.test(value.id))
236
+ return `${label}.id must be a short safe identifier`
237
+ if (typeof value.host !== "string" || !/^[A-Za-z0-9.-]{1,253}(:\d{1,5})?$/.test(value.host))
238
+ return `${label}.host must be a host name`
239
+ if (
240
+ !Array.isArray(value.pages) ||
241
+ value.pages.length === 0 ||
242
+ !value.pages.every(validRelativePath)
243
+ )
244
+ return `${label}.pages must list local absolute paths`
245
+ if (
246
+ value.refused !== undefined &&
247
+ (!Array.isArray(value.refused) || !value.refused.every(validRelativePath))
248
+ )
249
+ return `${label}.refused must list local absolute paths`
250
+ return undefined
251
+ }
252
+
215
253
  function fixtureError(fixture: unknown, inProcess: boolean): string | undefined {
216
254
  if (!isRecord(fixture)) return "fixture must export an object"
217
255
  const app = fixture.app
@@ -257,6 +295,13 @@ function fixtureError(fixture: unknown, inProcess: boolean): string | undefined
257
295
  if (error !== undefined) return error
258
296
  }
259
297
  }
298
+ if (fixture.hosts !== undefined) {
299
+ if (!Array.isArray(fixture.hosts)) return "hosts must be an array"
300
+ for (let index = 0; index < fixture.hosts.length; index++) {
301
+ const error = hostCheckError(fixture.hosts[index], `hosts[${index}]`)
302
+ if (error !== undefined) return error
303
+ }
304
+ }
260
305
  if (fixture.contract !== undefined && typeof fixture.contract !== "function")
261
306
  return "contract must be a function"
262
307
  if (fixture.hydration !== undefined && typeof fixture.hydration !== "function")
@@ -518,6 +563,31 @@ export async function runSmoke(
518
563
  }
519
564
  if (fixture.authCallbacks === undefined) add("auth", "auth-callbacks", "skip")
520
565
 
566
+ if (fixture.hosts !== undefined && fixture.hosts.length > 0) {
567
+ // Bun-only and heavy, so loaded only by a fixture that declares hosts.
568
+ const { checkHostReach } = await import("@nifrajs/web/build")
569
+ for (const check of fixture.hosts) {
570
+ try {
571
+ const report = await checkHostReach({
572
+ host: check.host,
573
+ pages: check.pages,
574
+ refused: check.refused ?? [],
575
+ fetch: (path, host) =>
576
+ fetchRequest({ id: check.id, path, headers: { host }, expectedStatus: 200 }),
577
+ })
578
+ const shown = report.failures
579
+ .slice(0, 3)
580
+ .map((f) => `${f.path} ${f.status}${f.from === undefined ? "" : ` (from ${f.from})`}`)
581
+ const message = report.truncated
582
+ ? "too many referenced files to check"
583
+ : `${report.failures.length} failed: ${shown.join(", ")}`
584
+ add("hosts", check.id, report.ok ? "pass" : "fail", report.ok ? undefined : message)
585
+ } catch {
586
+ add("hosts", check.id, "fail", "host check request failed")
587
+ }
588
+ }
589
+ }
590
+
521
591
  if (fixture.contract === undefined) {
522
592
  add("contract", "response-contract", "skip")
523
593
  } else {
package/src/upgrade.ts CHANGED
@@ -38,7 +38,7 @@ import {
38
38
  statSync,
39
39
  writeFileSync,
40
40
  } from "node:fs"
41
- import { dirname, join, relative, resolve, sep } from "node:path"
41
+ import { basename, dirname, join, relative, resolve, sep } from "node:path"
42
42
  import { fileURLToPath } from "node:url"
43
43
  import type { ReflectedHookReport } from "@nifrajs/core/reflection"
44
44
  import { Glob } from "bun"
@@ -51,6 +51,7 @@ import {
51
51
  renderHookDiff,
52
52
  } from "./hooks-report.ts"
53
53
  import { type AncestorPinSite, ancestorPins, declaresCli, PIN_SITES } from "./init-agents.ts"
54
+ import { codeUnitOrder } from "./internal/code-unit-order.ts"
54
55
  import {
55
56
  BUN_LOCK,
56
57
  describeChange,
@@ -157,6 +158,8 @@ export interface UpgradePlan {
157
158
  /** Whether `--write` dropped {@link linkLocks} from bun.lock, so `bun install` re-reads them. */
158
159
  readonly lockPruned: boolean
159
160
  readonly notes: readonly string[]
161
+ /** Releases on the way up that announce no behaviour change for the packages this project loads. */
162
+ readonly unaffected: readonly UnaffectedRelease[]
160
163
  }
161
164
 
162
165
  const DEP_FIELDS = [
@@ -674,6 +677,78 @@ export function groupDeclaredNames(cwd: string): ReadonlySet<string> {
674
677
  return names
675
678
  }
676
679
 
680
+ /** The fixed-group packages the package installed at `dir` depends on. */
681
+ export function groupDependenciesAt(dir: string): string[] {
682
+ try {
683
+ const manifest: unknown = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"))
684
+ if (typeof manifest !== "object" || manifest === null) return []
685
+ return ["dependencies", "peerDependencies", "optionalDependencies"].flatMap((field) => {
686
+ const deps: unknown = Reflect.get(manifest, field)
687
+ return typeof deps === "object" && deps !== null ? Object.keys(deps).filter(isFixedGroup) : []
688
+ })
689
+ } catch {
690
+ return []
691
+ }
692
+ }
693
+
694
+ // Tools: what they depend on is not loaded by the app, so a release that changes what one does
695
+ // names the tool itself in `affects`.
696
+ const GROUP_TOOLS: ReadonlySet<string> = new Set(["@nifrajs/cli", "nifra", "create-nifra"])
697
+
698
+ /**
699
+ * The fixed-group packages this project loads: every one a package.json under `cwd` names, and what
700
+ * those depend on, followed through their installed manifests. `undefined` when a package to follow
701
+ * is not installed at the root, since what it loads is then unknown.
702
+ */
703
+ export function groupSurface(cwd: string): ReadonlySet<string> | undefined {
704
+ const surface = new Set(groupDeclaredNames(cwd))
705
+ const queue = [...surface]
706
+ for (let name = queue.shift(); name !== undefined; name = queue.shift()) {
707
+ if (GROUP_TOOLS.has(name)) continue
708
+ let dir: string
709
+ try {
710
+ dir = realpathSync(join(cwd, "node_modules", name))
711
+ } catch {
712
+ return undefined
713
+ }
714
+ for (const dep of groupDependenciesAt(dir)) {
715
+ if (surface.has(dep)) continue
716
+ surface.add(dep)
717
+ queue.push(dep)
718
+ }
719
+ }
720
+ return surface
721
+ }
722
+
723
+ /** A release whose recipe names what it changes, none of which this project loads. */
724
+ export interface UnaffectedRelease {
725
+ readonly version: string
726
+ readonly affects: readonly string[]
727
+ }
728
+
729
+ /**
730
+ * The `versions` whose recipe lists the packages its behaviour changes touch ({@link
731
+ * UpgradeRecipe.affects}) and none is in `surface`. A recipe without the list, or an unknown surface,
732
+ * is never reported unaffected.
733
+ */
734
+ export function unaffectedReleases(
735
+ versions: readonly string[],
736
+ surface: ReadonlySet<string> | undefined,
737
+ ): readonly UnaffectedRelease[] {
738
+ if (surface === undefined) return []
739
+ return versions.flatMap((version) => {
740
+ const affects = getRecipe(version)?.affects
741
+ if (affects === undefined || affects.some((name) => surface.has(name))) return []
742
+ return [{ version, affects }]
743
+ })
744
+ }
745
+
746
+ function unaffectedLine(release: UnaffectedRelease): string {
747
+ return release.affects.length === 0
748
+ ? `${release.version} announces no behaviour change`
749
+ : `${release.version} changes only ${release.affects.join(", ")}, which this project does not load: no announced behaviour change for it`
750
+ }
751
+
677
752
  /**
678
753
  * Every fixed-group version the package.json files under `cwd` declare with a plain semver spec, each
679
754
  * with the files that declare it. An override counts: it decides what installs. A peer range does
@@ -840,26 +915,94 @@ const packageVersionAt = (dir: string): string | undefined => {
840
915
  }
841
916
  }
842
917
 
843
- /** A repository linked into the project that resolves nifra from its own `node_modules`. */
918
+ /** A package linked into the project that resolves nifra from outside it. */
844
919
  export interface LinkedSkew {
845
920
  /** The dependency's name, as the manifest declares it. */
846
921
  readonly package: string
847
922
  /** The project-relative manifest that declares it. */
848
923
  readonly declaredIn: string
849
- /** The linked repository's real path. */
924
+ /** The linked package's real path. */
850
925
  readonly path: string
851
- /** Each fixed-group package it installs itself, at a version other than the target. */
852
- readonly installs: readonly { readonly package: string; readonly version: string }[]
926
+ /** Each fixed-group package it loads (for {@link linkedSkew}, at a version other than the
927
+ * target), at its real path. */
928
+ readonly installs: readonly LinkedGroupInstall[]
929
+ }
930
+
931
+ /** The install a package belongs to: the folder above its last `node_modules`, or the package itself. */
932
+ export const installRootOf = (path: string): string => {
933
+ const parts = path.split(sep)
934
+ const last = parts.lastIndexOf("node_modules")
935
+ return last <= 0 ? path : parts.slice(0, last).join(sep)
936
+ }
937
+
938
+ /** `name` as Node and Bun resolve it from `dir`: the first `node_modules/<name>` walking up to the root. */
939
+ export function resolvePackageFrom(dir: string, name: string): string | undefined {
940
+ for (let at = dir; ; ) {
941
+ if (basename(at) !== "node_modules") {
942
+ try {
943
+ return realpathSync(join(at, "node_modules", name))
944
+ } catch {
945
+ // Not installed here: Node and Bun look in the parent's node_modules next.
946
+ }
947
+ }
948
+ const parent = dirname(at)
949
+ if (parent === at) return undefined
950
+ at = parent
951
+ }
853
952
  }
854
953
 
954
+ const RUNTIME_FIELDS = ["dependencies", "peerDependencies", "optionalDependencies"] as const
955
+
855
956
  /**
856
- * Every `link:` or `file:` dependency whose installed folder resolves outside `cwd` and installs a
857
- * fixed-group package of its own at a version other than `target`. Its imports resolve from its real
858
- * path, so it keeps loading that copy after this project upgrades: a `server()` it builds can no longer
859
- * be merged here, and single-copy never redirects across versions. A copy that resolves back inside
860
- * `cwd` follows this project's install and is not counted.
957
+ * Every fixed-group package the package at `dir` loads, each resolved from the real path of the package
958
+ * that imports it: its own runtime dependencies, whatever its own `node_modules` holds, and the same
959
+ * through each source package it depends on (a workspace sibling or another link, never a registry
960
+ * install). A workspace member reads a hoisted copy from the workspace root, not its own folder.
861
961
  */
862
- export function linkedSkew(cwd: string, target: string): readonly LinkedSkew[] {
962
+ function resolvedGroupPackages(dir: string): LinkedGroupInstall[] {
963
+ const found = new Map<string, LinkedGroupInstall>()
964
+ const visited = new Set<string>()
965
+ const visit = (at: string): void => {
966
+ if (visited.has(at)) return
967
+ visited.add(at)
968
+ let manifest: unknown
969
+ try {
970
+ manifest = JSON.parse(readFileSync(join(at, "package.json"), "utf8"))
971
+ } catch {
972
+ return
973
+ }
974
+ const names = new Set(installedGroupPackages(at).map((install) => install.package))
975
+ const sources: string[] = []
976
+ for (const field of RUNTIME_FIELDS) {
977
+ const block: unknown = Reflect.get(Object(manifest), field)
978
+ if (typeof block !== "object" || block === null) continue
979
+ for (const name of Object.keys(block)) {
980
+ if (isFixedGroup(name)) names.add(name)
981
+ else sources.push(name)
982
+ }
983
+ }
984
+ for (const name of names) {
985
+ const path = resolvePackageFrom(at, name)
986
+ const version = path === undefined ? undefined : packageVersionAt(path)
987
+ if (path !== undefined && version !== undefined && !found.has(path))
988
+ found.set(path, { package: name, path, version })
989
+ }
990
+ for (const name of sources) {
991
+ const path = resolvePackageFrom(at, name)
992
+ if (path !== undefined && !path.split(sep).includes("node_modules")) visit(path)
993
+ }
994
+ }
995
+ visit(dir)
996
+ return [...found.values()]
997
+ }
998
+
999
+ /**
1000
+ * Every `link:` or `file:` dependency whose installed folder resolves outside `cwd` and loads
1001
+ * fixed-group packages from outside it, with those copies ({@link resolvedGroupPackages}). Its imports
1002
+ * resolve from its real path, so it loads its own copy whatever this project installs. A copy that
1003
+ * resolves back inside `cwd` follows this project's install and is not counted.
1004
+ */
1005
+ export function linkedRepositories(cwd: string): readonly LinkedSkew[] {
863
1006
  let root: string
864
1007
  try {
865
1008
  root = realpathSync(cwd)
@@ -892,9 +1035,9 @@ export function linkedSkew(cwd: string, target: string): readonly LinkedSkew[] {
892
1035
  }
893
1036
  if (path === undefined || inside(path) || seen.has(path)) continue
894
1037
  seen.add(path)
895
- const installs = installedGroupPackages(path)
896
- .filter((entry) => !inside(entry.path) && entry.version !== target)
897
- .map((entry) => ({ package: entry.package, version: entry.version }))
1038
+ const installs = resolvedGroupPackages(path)
1039
+ .filter((entry) => !inside(entry.path))
1040
+ .sort((a, b) => codeUnitOrder(a.package, b.package) || codeUnitOrder(a.path, b.path))
898
1041
  if (installs.length > 0) found.push({ package: name, declaredIn: rel, path, installs })
899
1042
  }
900
1043
  }
@@ -902,6 +1045,18 @@ export function linkedSkew(cwd: string, target: string): readonly LinkedSkew[] {
902
1045
  return found
903
1046
  }
904
1047
 
1048
+ /**
1049
+ * The {@link linkedRepositories} that install a fixed-group package at a version other than `target`:
1050
+ * they keep loading that copy after this project upgrades, so a `server()` one builds can no longer be
1051
+ * merged here, and single-copy never redirects across versions.
1052
+ */
1053
+ export function linkedSkew(cwd: string, target: string): readonly LinkedSkew[] {
1054
+ return linkedRepositories(cwd).flatMap((repo) => {
1055
+ const installs = repo.installs.filter((entry) => entry.version !== target)
1056
+ return installs.length === 0 ? [] : [{ ...repo, installs }]
1057
+ })
1058
+ }
1059
+
905
1060
  /**
906
1061
  * Every fixed-group package installed in `cwd/node_modules`, realpath-resolved so a linked repository
907
1062
  * reports its own version. `inside` is false for one that resolves outside the workspace root.
@@ -1107,6 +1262,10 @@ export function computeUpgrade(
1107
1262
  linkLocks,
1108
1263
  lockPruned,
1109
1264
  notes: recipe.notes ?? [],
1265
+ unaffected: unaffectedReleases(
1266
+ "steps" in recipe && Array.isArray(recipe.steps) ? recipe.steps : [recipe.version],
1267
+ groupSurface(cwd),
1268
+ ),
1110
1269
  }
1111
1270
  }
1112
1271
 
@@ -1126,6 +1285,7 @@ function renderPlan(
1126
1285
  : `From ${from}, applying the ${steps.join(", ")} recipe${steps.length === 1 ? "" : "s"}.`,
1127
1286
  )
1128
1287
  }
1288
+ for (const release of plan.unaffected) lines.push(unaffectedLine(release))
1129
1289
  lines.push("")
1130
1290
  if (
1131
1291
  plan.pins.length === 0 &&
@@ -1240,14 +1400,25 @@ function renderLinkedSkew(
1240
1400
  cwd: string,
1241
1401
  allowed: boolean,
1242
1402
  ): string {
1403
+ const display = (path: string): string => relative(cwd, path).split(sep).join("/") || "."
1404
+ // A hoisted workspace member loads the copy at its workspace root, so the upgrade runs there.
1405
+ const roots = [
1406
+ ...new Set(
1407
+ skew.flatMap((entry) => entry.installs.map((install) => installRootOf(install.path))),
1408
+ ),
1409
+ ].sort(codeUnitOrder)
1243
1410
  const lines = [
1244
- `${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").`,
1411
+ `${allowed ? "Allowed by --allow-linked-skew" : "Blocked"}: ${roots.length} linked repositor${roots.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").`,
1245
1412
  ]
1246
1413
  for (const entry of skew) {
1247
- const at = relative(cwd, entry.path).split(sep).join("/") || "."
1248
1414
  lines.push(
1249
- ` ${entry.package} (${entry.declaredIn}) at ${at}: ${entry.installs.map((install) => `${install.package} ${install.version}`).join(", ")}`,
1250
- ` cd ${at} && nifra upgrade ${version} --write && bun install`,
1415
+ ` ${entry.package} (${entry.declaredIn}) at ${display(entry.path)}: ${entry.installs.map((install) => `${install.package} ${install.version}`).join(", ")}`,
1416
+ )
1417
+ }
1418
+ for (const root of roots) {
1419
+ const at = display(root)
1420
+ lines.push(
1421
+ ` cd ${/^[\w./-]+$/.test(at) ? at : JSON.stringify(at)} && nifra upgrade ${version} --write && bun install`,
1251
1422
  )
1252
1423
  }
1253
1424
  if (!allowed)
@@ -1406,6 +1577,7 @@ function renderUpgradeList(
1406
1577
  targets: readonly string[],
1407
1578
  installed: string | null,
1408
1579
  notes: Readonly<Record<string, readonly string[]>>,
1580
+ unaffected: readonly UnaffectedRelease[] = [],
1409
1581
  ): string {
1410
1582
  const lines = [
1411
1583
  installed === null
@@ -1416,6 +1588,8 @@ function renderUpgradeList(
1416
1588
  const ahead = installed === null || compareSemverSpec(version, installed) > 0
1417
1589
  lines.push(` ${version}${version === installed ? " (declared)" : ""}`)
1418
1590
  if (!ahead) continue
1591
+ const quiet = unaffected.find((release) => release.version === version)
1592
+ if (quiet !== undefined) lines.push(` ${unaffectedLine(quiet)}`)
1419
1593
  const list = notes[version] ?? []
1420
1594
  if (list.length === 0) lines.push(" no change an app can observe")
1421
1595
  for (const note of list) lines.push(` - ${note}`)
@@ -1447,9 +1621,13 @@ export async function runUpgrade(cwd: string, options: UpgradeOptions): Promise<
1447
1621
  if (options.list) {
1448
1622
  const installed = installedGroupVersion(cwd)
1449
1623
  const notes = Object.fromEntries(targets.map((v) => [v, getRecipe(v)?.notes ?? []]))
1450
- if (options.json)
1451
- console.log(JSON.stringify({ versions: targets, cliVersion, installed, notes }, null, 2))
1452
- else console.log(renderUpgradeList(targets, installed, notes))
1624
+ const ahead = targets.filter((v) => installed === null || compareSemverSpec(v, installed) > 0)
1625
+ const unaffected = unaffectedReleases(ahead, groupSurface(cwd))
1626
+ if (options.json) {
1627
+ console.log(
1628
+ JSON.stringify({ versions: targets, cliVersion, installed, notes, unaffected }, null, 2),
1629
+ )
1630
+ } else console.log(renderUpgradeList(targets, installed, notes, unaffected))
1453
1631
  return true
1454
1632
  }
1455
1633
 
@@ -262,6 +262,57 @@ const RELEASE_PLAN = Object.freeze([
262
262
  "changesets",
263
263
  ] as const)
264
264
 
265
+ /**
266
+ * The release plan as groups CI runs in parallel jobs. Each job starts from a clean checkout, so every
267
+ * group begins with `build`; every other release gate belongs to exactly one group.
268
+ */
269
+ const RELEASE_GROUPS: Readonly<Record<string, readonly string[]>> = Object.freeze({
270
+ core: [
271
+ "build",
272
+ "lint",
273
+ "typecheck",
274
+ "coverage",
275
+ "rest-tests",
276
+ "cli-isolation",
277
+ "verification-parity",
278
+ "changesets",
279
+ ],
280
+ artifacts: [
281
+ "build",
282
+ "corpus",
283
+ "sitemap",
284
+ "site",
285
+ "docs",
286
+ "public-boundary",
287
+ "public-manifest",
288
+ "plugin-manifest",
289
+ "size",
290
+ "core-performance",
291
+ "middleware-performance",
292
+ "output-guard-performance",
293
+ "edge-startup",
294
+ ],
295
+ packages: ["build", "publish", "consumer", "cold-start"],
296
+ runtimes: ["build", "cross-runtime-deno", "cross-runtime-node", "workerd"],
297
+ pipelines: ["build", "pipeline-parity", "leak-matrix"],
298
+ "server-components": [
299
+ "build",
300
+ "server-components",
301
+ "server-components-performance",
302
+ "server-components-contracts",
303
+ ],
304
+ })
305
+
306
+ /** The names of the release plan's CI groups. */
307
+ export function releaseGroupNames(): readonly string[] {
308
+ return Object.keys(RELEASE_GROUPS)
309
+ }
310
+
311
+ /** The release gates one CI group runs, or undefined for a name that is not a group. */
312
+ export function releaseGroupGateIds(name: string): readonly string[] | undefined {
313
+ return Object.hasOwn(RELEASE_GROUPS, name) ? RELEASE_GROUPS[name] : undefined
314
+ }
315
+
265
316
  const gateById = new Map(GATES.map((entry) => [entry.id, entry]))
266
317
 
267
318
  const planIds = (mode: VerificationPlanMode): readonly string[] =>
@@ -1,30 +1,17 @@
1
- import { readFileSync } from "node:fs"
2
- import { join, sep } from "node:path"
3
1
  import { bunLockDir, staleLinkLocks } from "./lock-links.ts"
4
2
  import {
5
3
  compareSemverSpec,
6
4
  groupDeclaredNames,
5
+ groupDependenciesAt,
7
6
  groupPinVersions,
8
7
  installedGroupPackages,
8
+ installRootOf,
9
9
  isFixedGroup,
10
10
  type LinkedGroupInstall,
11
+ linkedRepositories,
11
12
  specVersion,
12
13
  } from "./upgrade.ts"
13
14
 
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
-
28
15
  /** One version of the fixed release group, and where the workspace carries it. */
29
16
  export interface GroupVersion {
30
17
  readonly version: string
@@ -34,7 +21,8 @@ export interface GroupVersion {
34
21
  /**
35
22
  * More than one version of the fixed release group (`@nifrajs/*`, `nifra`, `create-nifra`) in one
36
23
  * workspace. Read only: package.json pins, installed packages (followed to their real location, so a
37
- * linked repo reports its own version) and the running CLI. Nothing is spawned.
24
+ * linked repo reports its own version), the copies a `link:`/`file:` repository installs for itself,
25
+ * and the running CLI. Nothing is spawned.
38
26
  */
39
27
  export interface VersionDrift {
40
28
  /** Oldest first. */
@@ -65,6 +53,17 @@ export function collectVersionDrift(cwd: string, cliVersion?: string): VersionDr
65
53
  add(version, `installed ${name}${inside ? "" : ` (linked from ${path})`}`)
66
54
  if (!inside) linkedOutside.push({ package: name, path, version })
67
55
  }
56
+ // A repository linked in from outside loads nifra from its own node_modules, which the scan above
57
+ // never reads: two live-linked repos can each pin one version and still run two.
58
+ for (const repo of linkedRepositories(cwd)) {
59
+ for (const install of repo.installs) {
60
+ add(
61
+ install.version,
62
+ `installed ${install.package} by ${repo.package} (linked from ${repo.path}), which loads its own copy`,
63
+ )
64
+ linkedOutside.push(install)
65
+ }
66
+ }
68
67
  if (cliVersion !== undefined) add(cliVersion, "the running nifra CLI")
69
68
  // A linked package's stale recorded pin is installed under that package, where the scan of
70
69
  // node_modules above never looks; only an exact pin names the version that copy has.
@@ -90,18 +89,11 @@ export function collectVersionDrift(cwd: string, cliVersion?: string): VersionDr
90
89
  }
91
90
  }
92
91
 
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
92
  /** Linked installs, one phrase per install and version: a linked repository brings its whole group. */
101
93
  function linkedGroups(installs: readonly LinkedGroupInstall[]): string[] {
102
94
  const groups = new Map<string, LinkedGroupInstall[]>()
103
95
  for (const install of installs) {
104
- const key = `${installRoot(install.path)}\0${install.version}`
96
+ const key = `${installRootOf(install.path)}\0${install.version}`
105
97
  groups.set(key, [...(groups.get(key) ?? []), install])
106
98
  }
107
99
  return [...groups.values()].map((group) => {
@@ -113,7 +105,7 @@ function linkedGroups(installs: readonly LinkedGroupInstall[]): string[] {
113
105
  names.length > 3
114
106
  ? `${names.slice(0, 3).join(", ")} and ${names.length - 3} more`
115
107
  : names.join(", ")
116
- return `${group.length} packages at ${first.version} under ${installRoot(first.path)} (${listed})`
108
+ return `${group.length} packages at ${first.version} under ${installRootOf(first.path)} (${listed})`
117
109
  })
118
110
  }
119
111
 
@@ -20,6 +20,7 @@ type FrameworkWebAppOptions = Pick<
20
20
  | "nonce"
21
21
  | "serverComponents"
22
22
  | "i18n"
23
+ | "hostPolicy"
23
24
  >
24
25
 
25
26
  /** `use`, the backend as `api`, and every forwarded framework field the config sets. */