rolldown-pnpm-config 3.2.0 → 4.0.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 (46) hide show
  1. package/README.md +1 -1
  2. package/catalogs.js +32 -15
  3. package/cli/commands/export.js +8 -3
  4. package/cli/commands/preview.js +10 -7
  5. package/cli/commands/sync.js +143 -79
  6. package/cli/commands/upgrade.js +333 -135
  7. package/cli/discover.js +134 -28
  8. package/cli/drift.js +1 -1
  9. package/cli/edits.js +8 -17
  10. package/cli/effective.js +119 -4
  11. package/cli/interop.js +7 -15
  12. package/cli/local-merge.js +4 -1
  13. package/cli/plan.js +8 -3
  14. package/cli/preview-views.js +3 -1
  15. package/cli/release-age.js +2 -1
  16. package/cli/render/print.js +2 -5
  17. package/cli/render/report.js +2 -4
  18. package/cli/respell.js +86 -0
  19. package/cli/select-file.js +5 -2
  20. package/cli/summary.js +43 -9
  21. package/cli/sync/commit-message.js +4 -3
  22. package/cli/sync/config.js +60 -24
  23. package/cli/sync/floors.js +6 -3
  24. package/cli/sync/local-gate.js +19 -9
  25. package/cli/sync/membership.js +93 -31
  26. package/cli/sync/ripples.js +4 -4
  27. package/cli/sync/running-list.js +16 -6
  28. package/cli/ui/walk-screen.js +66 -20
  29. package/cli/validate.js +1 -1
  30. package/cli/version.js +1 -1
  31. package/cli/walk-plan.js +17 -10
  32. package/cli/walk-reducer.js +99 -19
  33. package/index.d.ts +176 -127
  34. package/package.json +8 -8
  35. package/plugin/allowed-versions.js +3 -3
  36. package/plugin/families.js +185 -0
  37. package/plugin/freeze.js +122 -32
  38. package/plugin/second-forms.js +155 -0
  39. package/plugin/synced-catalogs.js +32 -0
  40. package/registry.js +13 -1
  41. package/skills/rolldown-pnpm-config/SKILL.md +13 -3
  42. package/skills/rolldown-pnpm-config/references/catalogs.md +109 -12
  43. package/skills/rolldown-pnpm-config/references/options.md +126 -47
  44. package/skills/rolldown-pnpm-config/references/sync.md +32 -21
  45. package/skills/rolldown-pnpm-config/references/wiring.md +10 -8
  46. package/plugin/overrides-from-catalogs.js +0 -151
package/README.md CHANGED
@@ -80,7 +80,7 @@ npx rolldown-pnpm-config upgrade
80
80
  # Applied <n> changes.
81
81
  ```
82
82
 
83
- The command shows an interactive table by default — every catalog package at once, one row per package, `●`/`○` bubbles, modeled on `pnpm up -i`. `--yes` takes the latest in-range version for every package without prompting and fails hard on any warning or unresolvable package name; `--dry-run` runs the identical table and skips only the write; `--catalog <name>` scopes every mode — the table, `--preview`, `--check`, `--yes` and `--dry-run` — to one catalog, and fails on a name the config does not declare. Pass `--preview` for a non-interactive projection of what an upgrade would do, with `--full` to show up-to-date entries too. The output is colorized in a supporting terminal. For packages that declare a `strategy`, the command also resyncs their materialized peer range, preserving any prerelease identifier rather than rebuilding it from parsed version parts. See [upgrading catalogs](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/05-upgrading-catalogs.md) for the full surface.
83
+ The command shows an interactive table by default — every catalog package at once, one row per package, `●`/`○` bubbles, modeled on `pnpm up -i`. `--yes` takes the latest in-range version for every npm entry without prompting and fails hard on any warning or unresolvable package name; workspace entries (`source: "workspace"`) are `rolldown-pnpm-config sync`'s and show read-only, and the members of a locked catalog family move only under `--family <name>`; `--dry-run` runs the identical table and skips only the write; `--catalog <name>` scopes every mode — the table, `--preview`, `--check`, `--yes` and `--dry-run` — to one catalog, and fails on a name the config does not declare. Pass `--preview` for a non-interactive projection of what an upgrade would do, with `--full` to show up-to-date entries too. The output is colorized in a supporting terminal. For entries whose peer is `{ value, strategy }`, the command also re-derives the peer value, preserving any prerelease identifier rather than rebuilding it from parsed version parts. See [upgrading catalogs](https://github.com/spencerbeggs/rolldown-pnpm-config/blob/main/docs/05-upgrading-catalogs.md) for the full surface.
84
84
 
85
85
  ## Exporting to pnpm-workspace.yaml
86
86
 
package/catalogs.js CHANGED
@@ -3,11 +3,27 @@ import { Result } from "effect";
3
3
 
4
4
  // src/catalogs.ts
5
5
  /**
6
- * The install range of a catalog spec (bare string or `{ range }` object).
6
+ * The dependency specifier of a catalog spec (bare string or `{ dependency }` object).
7
7
  *
8
8
  * @internal
9
9
  */
10
- const rangeOf = (spec) => typeof spec === "string" ? spec : spec.range;
10
+ const dependencyOf = (spec) => typeof spec === "string" ? spec : spec.dependency;
11
+ /**
12
+ * The peer of a catalog spec as `{ value, strategy }`, `strategy` absent for
13
+ * a hand-set string peer, or `undefined` when the entry has no peer.
14
+ *
15
+ * @internal
16
+ */
17
+ function peerOf(spec) {
18
+ if (typeof spec === "string" || spec.peer === void 0) return void 0;
19
+ return typeof spec.peer === "string" ? { value: spec.peer } : spec.peer;
20
+ }
21
+ /**
22
+ * Where a catalog spec's next dependency comes from: its `source`, or `"npm"`.
23
+ *
24
+ * @internal
25
+ */
26
+ const sourceOf = (spec) => typeof spec === "string" ? "npm" : spec.source ?? "npm";
11
27
  /**
12
28
  * Matches a range the `upgrade` CLI discovers and rewrites: a simple operator
13
29
  * (`^`, `~` or none) on a version, partials like `^1.2` and `1.x` included.
@@ -33,30 +49,30 @@ function singleVersionOf(range) {
33
49
  }
34
50
  /** The `<name>:exact` value of one entry, `undefined` to leave it out; throws on an entry with no single version. */
35
51
  function exactEntry(catalog, pkg, spec) {
36
- const range = rangeOf(spec);
52
+ const range = dependencyOf(spec);
37
53
  const derived = singleVersionOf(range);
38
54
  const explicit = typeof spec === "object" ? spec.exact : void 0;
39
55
  if (explicit === false) return void 0;
40
56
  const rewritable = REWRITABLE_RANGE_RE.test(range);
41
57
  if (explicit !== void 0) {
42
58
  if (derived !== null) throw new Error(`catalogs: "${pkg}" in catalog "${catalog}" derives its exact version ${derived} from "${range}"; remove its exact value, which upgrade would leave stale`);
43
- if (rewritable) throw new Error(`catalogs: "${pkg}" in catalog "${catalog}" has range "${range}", which upgrade rewrites; an exact value would go stale, so write the range as a full version, or set exact: false`);
59
+ if (rewritable) throw new Error(`catalogs: "${pkg}" in catalog "${catalog}" has dependency "${range}", which upgrade rewrites; an exact value would go stale, so write the dependency as a full version, or set exact: false`);
44
60
  const parsed = Result.getOrNull(VersionSpecifier.parseResult(explicit));
45
61
  if (parsed === null || parsed.operator !== "") throw new Error(`catalogs: exact value "${explicit}" for "${pkg}" in catalog "${catalog}" is not a plain version`);
46
62
  return explicit;
47
63
  }
48
- if (derived === null && rewritable) throw new Error(`catalogs: catalog "${catalog}" sets exact: true, but "${pkg}" has range "${range}", which names no single version; write the range as a full version, or set exact: false to leave it out`);
49
- if (derived === null) throw new Error(`catalogs: catalog "${catalog}" sets exact: true, but "${pkg}" has range "${range}", which names no single version; set exact to a version, or exact: false to leave it out`);
64
+ if (derived === null && rewritable) throw new Error(`catalogs: catalog "${catalog}" sets exact: true, but "${pkg}" has dependency "${range}", which names no single version; write the dependency as a full version, or set exact: false to leave it out`);
65
+ if (derived === null) throw new Error(`catalogs: catalog "${catalog}" sets exact: true, but "${pkg}" has dependency "${range}", which names no single version; set exact to a version, or exact: false to leave it out`);
50
66
  return derived;
51
67
  }
52
68
  /**
53
- * Normalize declarative catalog input into the resolved `{ catalog → pkg → range }`
69
+ * Normalize declarative catalog input into the resolved `{ catalog → pkg → specifier }`
54
70
  * map consumed by the runtime. Pure: the base catalog uses each package's
55
- * `range` (or bare string); a peers catalog is emitted only for packages
56
- * carrying a materialized `peer`, using that value verbatim, under the
57
- * `<name>:peers` colon-delimited name. A declaration with `exact: true` also
58
- * emits `<name>:exact`, each range with its operator stripped. `strategy` is
59
- * CLI-only and ignored here. Throws when an exact-opted entry names no single
71
+ * `dependency` (or bare string); a peers catalog is emitted only for packages
72
+ * carrying a `peer`, using its value verbatim, under the `<name>:peers`
73
+ * colon-delimited name. A declaration with `exact: true` also emits
74
+ * `<name>:exact`, each dependency with its operator stripped. A peer's
75
+ * `strategy` and the entry's `source` are CLI-only and ignored here. Throws when an exact-opted entry names no single
60
76
  * version, or when an entry sets `exact` in a catalog that has not opted in.
61
77
  *
62
78
  * @internal
@@ -69,8 +85,9 @@ function normalizeCatalogs(input) {
69
85
  const peers = {};
70
86
  const exact = {};
71
87
  for (const [pkg, spec] of Object.entries(decl.packages)) {
72
- base[pkg] = typeof spec === "string" ? spec : spec.range;
73
- if (typeof spec === "object" && spec.peer !== void 0) peers[pkg] = spec.peer;
88
+ base[pkg] = dependencyOf(spec);
89
+ const peer = peerOf(spec);
90
+ if (peer !== void 0) peers[pkg] = peer.value;
74
91
  if (decl.exact === true) {
75
92
  const value = exactEntry(name, pkg, spec);
76
93
  if (value !== void 0) exact[pkg] = value;
@@ -83,4 +100,4 @@ function normalizeCatalogs(input) {
83
100
  return out;
84
101
  }
85
102
 
86
- export { REWRITABLE_RANGE_RE, normalizeCatalogs, rangeOf };
103
+ export { REWRITABLE_RANGE_RE, dependencyOf, normalizeCatalogs, peerOf, sourceOf };
@@ -1,6 +1,6 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { dirname, relative } from "node:path";
3
- import { CliDoc, CliMessage } from "@effected/cli-kit";
3
+ import { CliDoc, CliMessage, Fmt } from "@effected/cli-kit";
4
4
  import { AtomicFile } from "@effected/files";
5
5
  import { PnpmWorkspaceFile } from "@effected/pnpm";
6
6
  import { Data, Effect, Option, Predicate } from "effect";
@@ -18,6 +18,7 @@ import { loadConfigAndWorkspace } from "../load-config.js";
18
18
  import { legend } from "../render/legend.js";
19
19
  import { printView } from "../render/print.js";
20
20
  import { failureDoc } from "../render/report.js";
21
+ import { respellForFile } from "../respell.js";
21
22
  import { findConfigFiles, pickConfigCandidate } from "../select-file.js";
22
23
  import { overlayWorkspace } from "../workspace-overlay.js";
23
24
 
@@ -51,7 +52,10 @@ function runExport(opts) {
51
52
  const managed = {};
52
53
  for (const [k, v] of Object.entries(base)) if (WORKSPACE_FIELDS.has(k)) managed[k] = v;
53
54
  const rootName = resolveRootName({ dir: dirname(path) });
54
- const effective = effectiveManaged(managed, localCfg, parsed, manifest, rootName);
55
+ const effective = yield* Effect.try({
56
+ try: () => effectiveManaged(managed, localCfg, parsed, manifest, rootName),
57
+ catch: (e) => new ExportError({ message: Fmt.errorText(e) })
58
+ });
55
59
  const explicitPatchMap = owned === void 0;
56
60
  const contributed = {};
57
61
  if (explicitPatchMap) {
@@ -69,7 +73,8 @@ function runExport(opts) {
69
73
  root: dirname(path),
70
74
  exists: existsSync
71
75
  });
72
- const merged = overlayWorkspace(effective, parsed);
76
+ const { effective: spelled, parsed: fileBase } = respellForFile(effective, parsed);
77
+ const merged = overlayWorkspace(spelled, fileBase);
73
78
  const rendered = yield* Effect.fromResult(file.writeResult(merged)).pipe(Effect.mapError((e) => new ExportError({ message: e.message })));
74
79
  const localKeys = new Set(Object.keys(localCfg ?? {}).filter((k) => WORKSPACE_FIELDS.has(k)));
75
80
  const tree = buildDiff(PnpmWorkspaceFile.canonicalize(parsed), PnpmWorkspaceFile.canonicalize(merged), {
@@ -1,5 +1,5 @@
1
1
  import { dirname } from "node:path";
2
- import { CliDoc, CliInteractive } from "@effected/cli-kit";
2
+ import { CliDoc, CliInteractive, Fmt } from "@effected/cli-kit";
3
3
  import { CliUi } from "@effected/cli-kit/ui";
4
4
  import { Data, Effect, Option } from "effect";
5
5
  import { Argument, Command } from "effect/cli";
@@ -35,12 +35,15 @@ function runPreviewViews(opts) {
35
35
  const { base, manifest } = yield* freeze(config).pipe(Effect.mapError((e) => new PreviewError({ message: e.message })));
36
36
  const managed = {};
37
37
  for (const [k, v] of Object.entries(base)) if (WORKSPACE_FIELDS.has(k)) managed[k] = v;
38
- return buildPreviewViews({
39
- managed,
40
- ...localCfg ? { local: localCfg } : {},
41
- parsed,
42
- manifest,
43
- rootName: resolveRootName({ dir: dirname(path) })
38
+ return yield* Effect.try({
39
+ try: () => buildPreviewViews({
40
+ managed,
41
+ ...localCfg ? { local: localCfg } : {},
42
+ parsed,
43
+ manifest,
44
+ rootName: resolveRootName({ dir: dirname(path) })
45
+ }),
46
+ catch: (e) => new PreviewError({ message: Fmt.errorText(e) })
44
47
  });
45
48
  });
46
49
  }
@@ -12,8 +12,8 @@ import { applyEdits } from "../rewrite.js";
12
12
  import { renderCommitMessage } from "../sync/commit-message.js";
13
13
  import { SyncConfigError, resolveEvaluatedSync } from "../sync/config.js";
14
14
  import { applyFloorEdits, describeFloorEdits, planFloorEdits } from "../sync/floors.js";
15
- import { exportDrift, exportedCatalogNames, readServedCatalogs } from "../sync/local-gate.js";
16
- import { MEMBERSHIP_REMEDY, checkMembership, membershipMessage, pluginManifest, pluginPackageName } from "../sync/membership.js";
15
+ import { LocalGateError, exportDrift, exportedCatalogNames, readServedCatalogs } from "../sync/local-gate.js";
16
+ import { checkSyncMembership, hasMembershipGap, membershipRemedies, notWorkspaceRow, pairsMembershipMessage, pluginManifest, pluginPackageName } from "../sync/membership.js";
17
17
  import { readReleasePlan } from "../sync/release-plan.js";
18
18
  import { rippleEdits, rippleMismatches } from "../sync/ripples.js";
19
19
  import { currentCatalogs, mergeMoves, parseChangeset, renderChangeset, staleMoves } from "../sync/running-list.js";
@@ -34,18 +34,44 @@ var SyncUsageError = class extends Data.TaggedError("SyncUsageError") {
34
34
  }
35
35
  };
36
36
  /**
37
- * Publishable workspace packages the sync catalog does not name. Raised before
37
+ * Publishable workspace packages the sync catalog does not name, or names
38
+ * without `source: "workspace"`, so sync would never move them. Raised before
38
39
  * any write: a sync that upgraded versions while a member was missing would
39
40
  * report "synced" for a catalog that is still incomplete. A finding, exit 1.
40
41
  *
41
42
  * @internal
42
43
  */
43
44
  var MembershipError = class extends Data.TaggedError("MembershipError") {
44
- /** The failure report: the `membershipMessage` text. */
45
+ /** The failure report: the `pairsMembershipMessage` text. */
45
46
  [CliDoc]() {
46
47
  return failureDoc(this.message);
47
48
  }
48
49
  };
50
+ /** Every synced catalog, in pair order: what the upgrade, ripple and running-list steps act on. */
51
+ function syncedCatalogs(sync) {
52
+ return sync.pairs.map((pair) => pair.catalog);
53
+ }
54
+ /**
55
+ * The entries `sync` owns: workspace-sourced ones. An npm entry in a synced
56
+ * catalog is `upgrade`'s, so a ripple never moves it, even when it names a
57
+ * workspace package the release plan bumps.
58
+ */
59
+ function workspaceEntries(entries) {
60
+ return entries.filter((entry) => entry.source === "workspace");
61
+ }
62
+ /**
63
+ * Every pair's membership as one comparison, in pair order: the write-mode
64
+ * result and its JSON document. The failure message and `--check` keep the
65
+ * pairs apart.
66
+ */
67
+ function mergeMembership(pairs) {
68
+ return {
69
+ missing: pairs.flatMap((p) => p.result.missing),
70
+ notWorkspace: pairs.flatMap((p) => p.result.notWorkspace),
71
+ publishable: pairs.flatMap((p) => p.result.publishable),
72
+ catalogued: pairs.flatMap((p) => p.result.catalogued)
73
+ };
74
+ }
49
75
  /** Read and decode the `sync` block of the config at `configFile`. */
50
76
  function readSyncConfig(configFile) {
51
77
  return Effect.gen(function* () {
@@ -76,19 +102,20 @@ function readRunningList(file) {
76
102
  function writeListAndMessage(rootDir, sync, pluginName, moves) {
77
103
  return Effect.gen(function* () {
78
104
  const path = yield* Path.Path;
79
- yield* writeFile(path.join(rootDir, sync.changesetPath), renderChangeset(pluginName, sync.bump, moves, sync.catalog));
80
- yield* writeFile(path.join(rootDir, sync.messagePath), renderCommitMessage(sync.commitScope, moves));
105
+ const file = path.join(rootDir, sync.changesetPath);
106
+ yield* writeFile(file, yield* Effect.fromResult(renderChangeset(pluginName, sync.bump, moves, syncedCatalogs(sync))).pipe(Effect.mapError((error) => new UpgradeError({ message: `Cannot render ${file}: ${error.message}` }))));
107
+ yield* writeFile(path.join(rootDir, sync.messagePath), renderCommitMessage(sync.commitScope, moves, sync.pairs.length));
81
108
  });
82
109
  }
83
110
  /**
84
- * Bring the sync catalog in the config at `configFile` to the next release
85
- * versions, and record the moves in the running-list changeset.
111
+ * Bring every sync pair's catalog in the config at `configFile` to the next
112
+ * release versions, and record the moves in one running-list changeset.
86
113
  *
87
114
  * @remarks
88
115
  * The order is the scripts' and each step has its reason:
89
116
  *
90
- * 1. Membership, before any write: a sync that upgrades versions while a
91
- * member is missing would report success for an incomplete catalog.
117
+ * 1. Membership, per pair, before any write: a sync that upgrades versions
118
+ * while a member is missing would report success for an incomplete catalog.
92
119
  * 2. Floors, when `sync.floors` is on, before the plan is read: a raised
93
120
  * package releases at a new minor, and the catalog must name that version.
94
121
  * 3. The release plan, read before the config is rewritten, so a plan that
@@ -96,9 +123,11 @@ function writeListAndMessage(rootDir, sync, pluginName, moves) {
96
123
  * commit message unchanged (step 2 may already have written floors).
97
124
  * 4. A snapshot of the config, which decides whether the catalog moved: the
98
125
  * file cannot disagree with itself.
99
- * 5. The upgrade (`--yes`), scoped to the sync catalog.
126
+ * 5. The upgrade (`--yes`), one run over every pair's catalog, moving only
127
+ * workspace entries: npm entries in a synced catalog are `upgrade`'s.
100
128
  * 6. Ripples, read from the config the upgrade just wrote: a package bumped
101
129
  * only as a dependency ripple has no changeset, so the upgrade cannot see it.
130
+ * Only workspace entries ripple.
102
131
  * 7. If the config did not move, the running list is rewritten only when it is
103
132
  * stale (hand-edited, or carried over a merge), so a sync repairs it.
104
133
  * Otherwise this run's moves are merged into it: it lists every move since
@@ -112,11 +141,16 @@ const runSyncWrite = Effect.fn("Sync.runSyncWrite")(function* (opts) {
112
141
  const file = opts.configFile;
113
142
  const sync = yield* readSyncConfig(file);
114
143
  const rootDir = findWorkspaceRoot(dirname(path.resolve(file)));
115
- const membership = yield* checkMembership(file, rootDir, sync);
116
- if (membership.missing.length > 0) return yield* new MembershipError({
117
- message: membershipMessage(membership.missing, file),
118
- missing: membership.missing
119
- });
144
+ const pairs = yield* checkSyncMembership(file, rootDir, sync);
145
+ const membership = mergeMembership(pairs);
146
+ if (hasMembershipGap(membership)) {
147
+ const gaps = pairs.filter((pair) => hasMembershipGap(pair.result));
148
+ return yield* new MembershipError({
149
+ message: pairsMembershipMessage(gaps, file, sync.pairs.length > 1),
150
+ missing: membership.missing,
151
+ notWorkspace: membership.notWorkspace
152
+ });
153
+ }
120
154
  const pluginName = yield* pluginPackageName(file);
121
155
  let floors = 0;
122
156
  if (sync.floors) {
@@ -126,14 +160,16 @@ const runSyncWrite = Effect.fn("Sync.runSyncWrite")(function* (opts) {
126
160
  }
127
161
  const plan = yield* readReleasePlan(rootDir);
128
162
  const before = (yield* readCatalogSource(file)).source;
163
+ const catalogs = syncedCatalogs(sync);
129
164
  const upgraded = yield* runUpgrade({
130
165
  file,
131
166
  resolver: opts.resolver,
132
167
  workspaceResolver: opts.workspaceResolver,
133
- catalog: sync.catalog
168
+ catalog: catalogs,
169
+ owns: "workspace"
134
170
  });
135
- const { source: afterUpgrade, entries } = yield* readCatalogSource(file, sync.catalog);
136
- const ripples = yield* rippleMismatches(entries, plan);
171
+ const { source: afterUpgrade, entries } = yield* readCatalogSource(file, catalogs);
172
+ const ripples = yield* rippleMismatches(workspaceEntries(entries), plan);
137
173
  if (ripples.length > 0) yield* writeFile(file, applyEdits(afterUpgrade, rippleEdits(entries, ripples)));
138
174
  const after = yield* readCatalogSource(file);
139
175
  const current = currentCatalogs(after.entries);
@@ -186,29 +222,41 @@ const runSyncWrite = Effect.fn("Sync.runSyncWrite")(function* (opts) {
186
222
  const syncRemedy = (displayFile) => `Run \`rolldown-pnpm-config sync ${displayFile}\`.`;
187
223
  /** The remedy for export drift: the export writes the yaml, the rebuild serves what it wrote. */
188
224
  const EXPORT_REMEDY = "Run `pnpm pnpm:export`, then rebuild the plugin.";
189
- /** A section with nothing to report. */
190
- const ok = (section) => ({
225
+ /** A section with nothing to report; `catalog` names the pair a per-catalog section covers. */
226
+ const ok = (section, catalog) => ({
191
227
  section,
228
+ ...catalog === void 0 ? {} : { catalog },
192
229
  status: "ok"
193
230
  });
194
231
  /** `rows` as findings, or ok when there are none. */
195
- const findings = (section, rows, remedy) => rows.length === 0 ? ok(section) : {
232
+ const findings = (section, rows, remedy, catalog) => rows.length === 0 ? ok(section, catalog) : {
196
233
  section,
234
+ ...catalog === void 0 ? {} : { catalog },
197
235
  status: "findings",
198
236
  rows,
199
237
  remedy
200
238
  };
239
+ /** A typed failure as a section's `error` status. */
240
+ const errorSection = (section, error) => ({
241
+ section,
242
+ status: "error",
243
+ kind: error._tag,
244
+ message: error.message
245
+ });
201
246
  /**
202
247
  * Evaluate one section. A typed failure becomes its `error` status, so one
203
248
  * section that cannot be read never hides the verdict of the next.
204
249
  */
205
250
  function evaluate(section, effect) {
206
- return effect.pipe(Effect.catch((error) => Effect.succeed({
207
- section,
208
- status: "error",
209
- kind: error._tag,
210
- message: error.message
211
- })));
251
+ return effect.pipe(Effect.catch((error) => Effect.succeed(errorSection(section, error))));
252
+ }
253
+ /**
254
+ * Evaluate a section reported per catalog. A failure that no one pair owns
255
+ * (an unreadable workspace or release plan) is one `error` section with no
256
+ * catalog, since it says nothing about any pair in particular.
257
+ */
258
+ function evaluatePerCatalog(section, effect) {
259
+ return effect.pipe(Effect.catch((error) => Effect.succeed([errorSection(section, error)])));
212
260
  }
213
261
  /** One drift row: `catalog.pkg from -> to (source)`; a peer-only resync keeps its range. */
214
262
  function driftRow(row) {
@@ -216,22 +264,25 @@ function driftRow(row) {
216
264
  return ` ${row.catalog}.${row.pkg} ${move} (${row.source})`;
217
265
  }
218
266
  /**
219
- * Versions: the upgrade's own check, a dry run scoped to the sync catalog.
220
- * Also returns the rows the upgrade would move (none when it errored), which
221
- * the ripples section lays over the config.
267
+ * Versions: the upgrade's own check, a dry run per sync pair, so a resolver
268
+ * failure is reported against the catalog it belongs to. Also returns the rows
269
+ * the upgrades would move (none from a pair that errored), which the ripples
270
+ * section lays over the config.
222
271
  */
223
- function versionsSection(opts, sync, remedy) {
224
- return runUpgrade({
272
+ function versionsSections(opts, sync, remedy) {
273
+ return Effect.forEach(syncedCatalogs(sync), (catalog) => runUpgrade({
225
274
  file: opts.configFile,
226
275
  resolver: opts.resolver,
227
276
  workspaceResolver: opts.workspaceResolver,
228
- catalog: sync.catalog,
277
+ catalog,
278
+ owns: "workspace",
229
279
  dryRun: true
230
280
  }).pipe(Effect.result, Effect.map((result) => {
231
281
  const { failure } = checkJsonOutcome(result);
232
282
  if (failure !== void 0) return {
233
283
  section: {
234
284
  section: "versions",
285
+ catalog,
235
286
  status: "error",
236
287
  kind: failure.kind ?? "resolution",
237
288
  message: failure.message
@@ -240,14 +291,17 @@ function versionsSection(opts, sync, remedy) {
240
291
  };
241
292
  const changed = Result.isSuccess(result) ? result.success.changed : [];
242
293
  return {
243
- section: findings("versions", changed.map(driftRow), remedy),
294
+ section: findings("versions", changed.map(driftRow), remedy, catalog),
244
295
  changed
245
296
  };
246
- }));
297
+ }))).pipe(Effect.map((pairs) => ({
298
+ sections: pairs.map((p) => p.section),
299
+ changed: pairs.flatMap((p) => p.changed)
300
+ })));
247
301
  }
248
- /** Membership: publishable workspace members the sync catalog does not name. */
249
- function membershipSection(configFile, rootDir, sync) {
250
- return evaluate("membership", checkMembership(configFile, rootDir, sync).pipe(Effect.map((m) => findings("membership", m.missing.map((name) => ` - ${name}`), MEMBERSHIP_REMEDY))));
302
+ /** Membership, per pair: publishable workspace members the pair's catalog does not name, or names without `source: "workspace"`. */
303
+ function membershipSections(configFile, rootDir, sync) {
304
+ return evaluatePerCatalog("membership", checkSyncMembership(configFile, rootDir, sync).pipe(Effect.map((pairs) => pairs.map((pair) => findings("membership", [...pair.result.missing.map((name) => ` - ${name}`), ...pair.result.notWorkspace.map(notWorkspaceRow)], membershipRemedies([pair.result]).join(" "), pair.catalog)))));
251
305
  }
252
306
  /** Floors: the breaking-floor changesets on disk differ from the ones the plan derives. */
253
307
  function floorsSection(rootDir, remedy) {
@@ -264,31 +318,33 @@ function runningListSection(configFile, rootDir, sync, remedy) {
264
318
  }));
265
319
  }
266
320
  /**
267
- * Ripples: entries behind the version the release plan would release, which
268
- * the upgrade cannot see.
321
+ * Ripples, per pair: workspace entries behind the version the release plan
322
+ * would release, which the upgrade cannot see.
269
323
  *
270
324
  * @remarks
271
325
  * Write mode looks for ripples after the upgrade has run, so `upgraded` (the
272
- * versions section's drift rows) is laid over the config first: a package the
273
- * upgrade moves is a versions row, never a ripple too. When versions errored,
274
- * `upgraded` is empty and the list is unfiltered. With `floors: true`, the
275
- * targets come from the plan before any floor is raised (write mode raises
276
- * floors first), so a row can differ from what a sync would write.
326
+ * versions sections' drift rows) is laid over the config first: a package the
327
+ * upgrade moves is a versions row, never a ripple too. A pair whose versions
328
+ * errored contributes no rows, so its ripples are unfiltered. With
329
+ * `floors: true`, the targets come from the plan before any floor is raised
330
+ * (write mode raises floors first), so a row can differ from what a sync would
331
+ * write.
277
332
  */
278
- function ripplesSection(configFile, rootDir, sync, upgraded, remedy) {
279
- return evaluate("ripples", Effect.gen(function* () {
333
+ function ripplesSections(configFile, rootDir, sync, upgraded, remedy) {
334
+ return evaluatePerCatalog("ripples", Effect.gen(function* () {
280
335
  const plan = yield* readReleasePlan(rootDir);
281
- const { entries } = yield* readCatalogSource(configFile, sync.catalog);
336
+ const catalogs = syncedCatalogs(sync);
337
+ const { entries } = yield* readCatalogSource(configFile, catalogs);
282
338
  const moved = new Map(upgraded.map((row) => [`${row.catalog}\0${row.pkg}`, row.to]));
283
- const afterUpgrade = entries.map((entry) => {
339
+ const afterUpgrade = workspaceEntries(entries).map((entry) => {
284
340
  const to = moved.get(`${entry.catalog}\0${entry.pkg}`);
285
341
  return to === void 0 ? entry : {
286
342
  ...entry,
287
343
  currentRange: to
288
344
  };
289
345
  });
290
- const rows = (yield* rippleMismatches(afterUpgrade, plan)).map((r) => ` ${r.catalog}.${r.pkg} ${r.from} -> ${r.to}`);
291
- return findings("ripples", rows, remedy);
346
+ const ripples = yield* rippleMismatches(afterUpgrade, plan);
347
+ return catalogs.map((catalog) => findings("ripples", ripples.filter((r) => r.catalog === catalog).map((r) => ` ${r.catalog}.${r.pkg} ${r.from} -> ${r.to}`), remedy, catalog));
292
348
  }));
293
349
  }
294
350
  /**
@@ -309,7 +365,11 @@ function exportSection(configFile, rootDir, sync) {
309
365
  const source = yield* fs.readFileString(path.join(rootDir, "pnpm-workspace.yaml"));
310
366
  const workspace = yield* PnpmWorkspaceFile.parse(source);
311
367
  const names = exportedCatalogNames(served.success, sync);
312
- return findings("export", exportDrift(served.success, names, { ...workspace.value }), EXPORT_REMEDY);
368
+ const rows = yield* Effect.try({
369
+ try: () => exportDrift(served.success, names, { ...workspace.value }),
370
+ catch: (cause) => new LocalGateError({ message: Fmt.errorText(cause) })
371
+ });
372
+ return findings("export", rows, EXPORT_REMEDY);
313
373
  }));
314
374
  }
315
375
  /** What both gates start from: the decoded `sync` block and the workspace root. */
@@ -336,9 +396,10 @@ function checkDoc(mode, sections) {
336
396
  *
337
397
  * @remarks
338
398
  * Every section is evaluated, in the order versions, membership, floors (when
339
- * `sync.floors` is on), running-list, ripples, and none short-circuits: the
340
- * scripts this ports stop at the first failure, but a red check that lists
341
- * everything saves a round trip. Only an unreadable or invalid config fails
399
+ * `sync.floors` is on), running-list, ripples, and none short-circuits.
400
+ * Versions, membership and ripples come once per sync pair, in pair order,
401
+ * each naming its `catalog`. The scripts this ports stop at the first
402
+ * failure, but a red check that lists everything saves a round trip. Only an unreadable or invalid config fails
342
403
  * the run; a section that cannot be evaluated is an `error` section.
343
404
  *
344
405
  * @internal
@@ -347,14 +408,16 @@ const runSyncCheck = Effect.fn("Sync.runSyncCheck")(function* (opts) {
347
408
  const file = opts.configFile;
348
409
  const remedy = syncRemedy(opts.displayFile ?? file);
349
410
  const { sync, rootDir } = yield* gateContext(file);
350
- const versions = yield* versionsSection(opts, sync, remedy);
351
- const rest = yield* Effect.all([
352
- membershipSection(file, rootDir, sync),
353
- ...sync.floors ? [floorsSection(rootDir, remedy)] : [],
354
- runningListSection(file, rootDir, sync, remedy),
355
- ripplesSection(file, rootDir, sync, versions.changed, remedy)
411
+ const versions = yield* versionsSections(opts, sync, remedy);
412
+ const membership = yield* membershipSections(file, rootDir, sync);
413
+ const shared = yield* Effect.all([...sync.floors ? [floorsSection(rootDir, remedy)] : [], runningListSection(file, rootDir, sync, remedy)]);
414
+ const ripples = yield* ripplesSections(file, rootDir, sync, versions.changed, remedy);
415
+ return checkDoc("check", [
416
+ ...versions.sections,
417
+ ...membership,
418
+ ...shared,
419
+ ...ripples
356
420
  ]);
357
- return checkDoc("check", [versions.section, ...rest]);
358
421
  });
359
422
  /**
360
423
  * The offline push-time gate: membership, and that the exported catalogs in
@@ -362,8 +425,8 @@ const runSyncCheck = Effect.fn("Sync.runSyncCheck")(function* (opts) {
362
425
  * release plan, no version drift; writes nothing.
363
426
  *
364
427
  * @remarks
365
- * The sync catalog and its `:peers` sibling are not exported by default, so a
366
- * lagging sync catalog in the yaml is not reported: that is `--check`'s
428
+ * The synced catalogs and their `:peers` and `:exact` twins are not exported by
429
+ * default, so a lagging synced catalog in the yaml is not reported: that is `--check`'s
367
430
  * versions question, and it needs the network.
368
431
  *
369
432
  * @internal
@@ -371,7 +434,9 @@ const runSyncCheck = Effect.fn("Sync.runSyncCheck")(function* (opts) {
371
434
  const runSyncLocal = Effect.fn("Sync.runSyncLocal")(function* (opts) {
372
435
  const file = opts.configFile;
373
436
  const { sync, rootDir } = yield* gateContext(file);
374
- return checkDoc("local", yield* Effect.all([membershipSection(file, rootDir, sync), exportSection(file, rootDir, sync)]));
437
+ const membership = yield* membershipSections(file, rootDir, sync);
438
+ const exported = yield* exportSection(file, rootDir, sync);
439
+ return checkDoc("local", [...membership, exported]);
375
440
  });
376
441
  /**
377
442
  * Fail unless the `sync` block manages breaking floors: `--floors-only` on a
@@ -434,15 +499,21 @@ function findingsHeading(section, count) {
434
499
  function syncCheckView(doc) {
435
500
  const failing = doc.sections.filter((s) => s.status !== "ok");
436
501
  if (failing.length === 0) return [Doc.line(doc.mode === "check" ? "Catalogs are in sync." : "Catalog membership and the exported catalogs are in sync.")];
437
- return failing.map((s) => {
502
+ const catalogs = new Set(doc.sections.flatMap((s) => s.catalog === void 0 ? [] : [s.catalog]));
503
+ const named = (heading, catalog) => catalogs.size > 1 && catalog !== void 0 ? heading.replace(/:$/, ` (catalog ${catalog}):`) : heading;
504
+ const remedyAtEnd = catalogs.size > 1;
505
+ const blocks = failing.map((s) => {
438
506
  if (s.status === "findings") return Doc.section(void 0, [
439
- Doc.line(findingsHeading(s.section, s.rows.length)),
507
+ Doc.line(named(findingsHeading(s.section, s.rows.length), s.catalog)),
440
508
  Doc.lines(s.rows, { wrap: false }),
441
- Doc.line(s.remedy)
509
+ ...remedyAtEnd ? [] : [Doc.line(s.remedy)]
442
510
  ]);
443
511
  const heading = s.section === "versions" ? CHECK_FAILED_LABEL : `The ${s.section} section could not be evaluated (${s.kind}, not a finding):`;
444
- return Doc.section(void 0, [Doc.line(heading), Doc.lines(s.message.split("\n").map((line) => ` ${line}`), { wrap: false })]);
512
+ return Doc.section(void 0, [Doc.line(named(heading, s.catalog)), Doc.lines(s.message.split("\n").map((line) => ` ${line}`), { wrap: false })]);
445
513
  });
514
+ if (!remedyAtEnd) return blocks;
515
+ const remedies = [...new Set(failing.flatMap((s) => s.status === "findings" ? [s.remedy] : []))];
516
+ return [Doc.section(void 0, [...blocks, ...remedies.map((r) => Doc.line(r))])];
446
517
  }
447
518
  /** One move as a report line: `catalog.pkg from -> to`. */
448
519
  function moveLine(move, note = "") {
@@ -452,14 +523,7 @@ function moveLine(move, note = "") {
452
523
  function syncWriteDoc(result) {
453
524
  if (!result.wrote) return [Doc.line("The sync catalog is current; nothing written.")];
454
525
  const rippled = new Set(result.ripples.map((r) => `${r.catalog}\0${r.pkg}`));
455
- const blocks = [];
456
- if (result.moves.length > 0) {
457
- blocks.push(Doc.line(`Synced ${Fmt.plural(result.moves.length, "catalog entry", "catalog entries")}:`));
458
- blocks.push(Doc.lines(result.moves.map((m) => moveLine(m, rippled.has(`${m.catalog}\0${m.pkg}`) ? " (ripple)" : "")), { wrap: false }));
459
- } else if (result.listWritten) blocks.push(Doc.line("The catalog was current; rewrote the stale running list."));
460
- else blocks.push(Doc.line("The catalog was current; the running list was left as it was."));
461
- if (result.floors > 0) blocks.push(Doc.line(`Updated ${Fmt.plural(result.floors, "breaking-floor changeset")}.`));
462
- return blocks;
526
+ return Doc.concat(result.moves.length > 0 ? [Doc.line(`Synced ${Fmt.plural(result.moves.length, "catalog entry", "catalog entries")}:`), Doc.lines(result.moves.map((m) => moveLine(m, rippled.has(`${m.catalog}\0${m.pkg}`) ? " (ripple)" : "")), { wrap: false })] : Doc.line(result.listWritten ? "The catalog was current; rewrote the stale running list." : "The catalog was current; the running list was left as it was."), result.floors > 0 && Doc.line(`Updated ${Fmt.plural(result.floors, "breaking-floor changeset")}.`));
463
527
  }
464
528
  /**
465
529
  * The `--format json` document of a write-mode run.
@@ -596,7 +660,7 @@ const syncCommand = Command.make("sync", {
596
660
  return yield* Effect.fail(result.failure);
597
661
  }
598
662
  const doc = result.success;
599
- yield* CliFormat.print(format === "json" ? "json" : "auto", {
663
+ yield* CliFormat.print(format, {
600
664
  doc: () => syncCheckView(doc),
601
665
  json: () => doc
602
666
  }, ONE_LINE);