rolldown-pnpm-config 3.2.1 → 4.1.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 +140 -70
  6. package/cli/commands/upgrade.js +348 -138
  7. package/cli/discover.js +134 -28
  8. package/cli/drift.js +2 -2
  9. package/cli/edits.js +8 -17
  10. package/cli/effective.js +132 -4
  11. package/cli/interop.js +35 -16
  12. package/cli/local-merge.js +4 -1
  13. package/cli/peer-range.js +21 -5
  14. package/cli/plan.js +9 -4
  15. package/cli/preview-views.js +3 -1
  16. package/cli/release-age.js +2 -1
  17. package/cli/respell.js +86 -0
  18. package/cli/select-file.js +5 -2
  19. package/cli/summary.js +44 -10
  20. package/cli/sync/commit-message.js +4 -3
  21. package/cli/sync/config.js +60 -24
  22. package/cli/sync/local-gate.js +19 -9
  23. package/cli/sync/membership.js +93 -31
  24. package/cli/sync/ripples.js +4 -4
  25. package/cli/sync/running-list.js +9 -5
  26. package/cli/ui/walk-screen.js +66 -20
  27. package/cli/validate.js +1 -1
  28. package/cli/version.js +1 -1
  29. package/cli/walk-plan.js +17 -10
  30. package/cli/walk-reducer.js +99 -19
  31. package/cli/workspace-overlay.js +5 -0
  32. package/cli/workspace-resolve.js +17 -1
  33. package/index.d.ts +176 -127
  34. package/package.json +6 -6
  35. package/plugin/allowed-versions.js +3 -3
  36. package/plugin/families.js +185 -0
  37. package/plugin/freeze.js +137 -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 +127 -14
  43. package/skills/rolldown-pnpm-config/references/options.md +131 -47
  44. package/skills/rolldown-pnpm-config/references/sync.md +32 -21
  45. package/skills/rolldown-pnpm-config/references/wiring.md +12 -8
  46. package/plugin/overrides-from-catalogs.js +0 -151
@@ -1,5 +1,6 @@
1
1
  import { Option, Schema } from "effect";
2
- import { isWrappedField } from "../plugin/freeze.js";
2
+ import "../plugin/freeze.js";
3
+ import { isWrappedField } from "../plugin/second-forms.js";
3
4
  import { FIELD_SCHEMAS } from "../registry.js";
4
5
 
5
6
  // src/cli/release-age.ts
package/cli/respell.js ADDED
@@ -0,0 +1,86 @@
1
+ import { SUB_KEYS, secondFormOf } from "../plugin/second-forms.js";
2
+
3
+ // src/cli/respell.ts
4
+ /**
5
+ * Export's last step before the overlay: write the default catalog and the
6
+ * nested `overrides` / `catalog` forms back in the spelling the consumer's
7
+ * `pnpm-workspace.yaml` already uses. Pure.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
12
+ /**
13
+ * The file's nested object with its container replaced by `container` and each
14
+ * sub-key the managed side sets (its twin setting in `effective`) written back
15
+ * in the file's spelling. Each twin written is deleted from `effective`; a
16
+ * sub-key the managed side does not set keeps the file's value.
17
+ */
18
+ function nest(field, effective, file, container) {
19
+ const table = SUB_KEYS[field];
20
+ const out = {
21
+ ...file,
22
+ [table.container]: container
23
+ };
24
+ for (const [sub, spec] of Object.entries(table)) {
25
+ if (sub === "container" || typeof spec !== "object" || !(spec.setting in effective)) continue;
26
+ const value = effective[spec.setting];
27
+ if ("map" in spec) {
28
+ const spelled = Object.entries(spec.map).find(([, v]) => v === value)?.[0];
29
+ if (spelled === void 0) continue;
30
+ out[sub] = spelled;
31
+ } else out[sub] = value;
32
+ delete effective[spec.setting];
33
+ }
34
+ return out;
35
+ }
36
+ /**
37
+ * Respell the effective managed fields for the file they are written into.
38
+ * `parsed` is the raw, un-desugared file; `effectiveManaged` has already laid
39
+ * the managed default catalog over the file's own. When the file declares
40
+ * `catalog`, the managed `catalogs.default` moves to `catalog` (flat, or nested
41
+ * with `mode`/`defaultSaveTarget`/`unused` taken from `catalogMode`,
42
+ * `saveCatalogName` and `catalogPrune`), and `default` is stripped from the
43
+ * returned file's `catalogs` so the overlay never writes the default catalog
44
+ * twice (pnpm refuses a file that sets both). When the file's `overrides` is
45
+ * nested, the managed `overrides` is written as `{ rules, unused }`, with
46
+ * `unused` from `warnUnusedOverrides`. Otherwise the inputs come back as they
47
+ * are. Neither input is mutated.
48
+ *
49
+ * @internal
50
+ */
51
+ function respellForFile(effective, parsed) {
52
+ const fileCatalog = parsed.catalog;
53
+ const fileOverrides = parsed.overrides;
54
+ const catalogForm = secondFormOf(fileCatalog, "catalog");
55
+ const nestedOverrides = secondFormOf(fileOverrides, "overrides") === "nested";
56
+ if (catalogForm === void 0 && !nestedOverrides) return {
57
+ effective,
58
+ parsed
59
+ };
60
+ const out = { ...effective };
61
+ let base = parsed;
62
+ if (isRecord(fileCatalog)) {
63
+ const entries = isRecord(out.catalogs) ? out.catalogs.default : void 0;
64
+ if (isRecord(out.catalogs) && "default" in out.catalogs) {
65
+ const { default: _, ...named } = out.catalogs;
66
+ if (Object.keys(named).length > 0) out.catalogs = named;
67
+ else delete out.catalogs;
68
+ }
69
+ if (catalogForm === "nested") out.catalog = nest("catalog", out, fileCatalog, entries ?? fileCatalog.entries);
70
+ else if (entries !== void 0) out.catalog = entries;
71
+ if (isRecord(parsed.catalogs) && "default" in parsed.catalogs) {
72
+ const { default: _, ...named } = parsed.catalogs;
73
+ base = {
74
+ ...parsed,
75
+ catalogs: named
76
+ };
77
+ }
78
+ }
79
+ if (nestedOverrides && isRecord(fileOverrides) && ("overrides" in out || "warnUnusedOverrides" in out)) out.overrides = nest("overrides", out, fileOverrides, out.overrides ?? fileOverrides.rules);
80
+ return {
81
+ effective: out,
82
+ parsed: base
83
+ };
84
+ }
85
+
86
+ export { respellForFile };
@@ -55,12 +55,15 @@ function pickConfigCandidate(matches) {
55
55
  };
56
56
  }
57
57
  /**
58
- * Restrict entries to a single catalog by name, or return all when undefined.
58
+ * Restrict entries to a catalog by name, or to any of a list of them; return
59
+ * all when undefined.
59
60
  *
60
61
  * @internal
61
62
  */
62
63
  function filterEntriesByCatalog(entries, catalog) {
63
- return catalog === void 0 ? [...entries] : entries.filter((e) => e.catalog === catalog);
64
+ if (catalog === void 0) return [...entries];
65
+ const scope = typeof catalog === "string" ? [catalog] : catalog;
66
+ return entries.filter((e) => scope.includes(e.catalog));
64
67
  }
65
68
 
66
69
  export { filterEntriesByCatalog, findConfigFiles, pickConfigCandidate };
package/cli/summary.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Doc, Fmt } from "@effected/cli-kit";
2
2
  import { row, tone } from "./render/tone.js";
3
- import { cellTone, displayCandidates, peerFor, tableLayout } from "./walk-reducer.js";
3
+ import { WORKSPACE_ROW_NOTE, cellTone, displayCandidates, familyDetail, peerFor, tableLayout } from "./walk-reducer.js";
4
4
 
5
5
  // src/cli/summary.ts
6
+ const HIDDEN = " (hidden; --full shows them)";
6
7
  /**
7
8
  * Build the pending-decisions summary as a document: one table row per
8
9
  * decision — mirroring the interactive selection table, catalog headers,
@@ -11,20 +12,43 @@ import { cellTone, displayCandidates, peerFor, tableLayout } from "./walk-reduce
11
12
  *
12
13
  * @internal
13
14
  */
14
- function summaryDoc(decisions, interop, rejected) {
15
+ function summaryDoc(decisions, interop, rejected, scope) {
15
16
  const lines = [];
16
17
  let toUpdate = 0;
17
18
  let major = 0;
18
19
  let resync = 0;
19
- let materialize = 0;
20
20
  let upToDate = 0;
21
+ let workspace = 0;
22
+ const hidden = scope?.hidden ?? {
23
+ upToDate: 0,
24
+ workspace: 0,
25
+ families: 0,
26
+ members: 0
27
+ };
28
+ const lockedRows = [...scope?.locked ?? []];
29
+ const slots = scope?.order ?? [...decisions.keys(), ...lockedRows];
21
30
  const { pkgWidth, maxCells, blankCell, cellText } = tableLayout(decisions.map((d) => d.item));
22
31
  let lastCatalog = null;
23
- for (const { item, chosen } of decisions) {
32
+ const header = (catalog) => {
33
+ if (catalog === lastCatalog) return;
34
+ lastCatalog = catalog;
35
+ lines.push(row(" ", 0, [tone(`── catalog: ${catalog} ──`, "unchanged")]));
36
+ };
37
+ for (const slot of slots) {
38
+ if (typeof slot !== "number") {
39
+ header(slot.catalog);
40
+ lines.push(row(" ", 0, [tone(`▸ family: ${slot.family}`, "plain"), tone(` (${familyDetail(slot.members, slot.newer)})`, "unchanged")]));
41
+ continue;
42
+ }
43
+ const decision = decisions[slot];
44
+ if (decision === void 0) continue;
45
+ const { item, chosen } = decision;
24
46
  const { entry } = item;
25
- if (entry.catalog !== lastCatalog) {
26
- lastCatalog = entry.catalog;
27
- lines.push(row(" ", 0, [tone(`── catalog: ${entry.catalog} ──`, "unchanged")]));
47
+ header(entry.catalog);
48
+ if (item.readOnly === true) {
49
+ workspace++;
50
+ lines.push(row(" ", 0, [tone(`${Fmt.pad(entry.pkg, pkgWidth + 2)}${entry.currentRange} ${WORKSPACE_ROW_NOTE}`, "unchanged")]));
51
+ continue;
28
52
  }
29
53
  const cells = displayCandidates(item);
30
54
  const content = [tone(Fmt.pad(entry.pkg, pkgWidth + 2), "plain")];
@@ -39,12 +63,22 @@ function summaryDoc(decisions, interop, rejected) {
39
63
  if (chosen.kind !== "keep") {
40
64
  toUpdate++;
41
65
  if (chosen.isMajor) major++;
42
- if (!entry.peer && entry.strategy && chosen.peerRange) materialize++;
43
66
  } else if (entry.peer && item.driftPeer) resync++;
44
- else if (!entry.peer && item.materializePeer) materialize++;
45
67
  else upToDate++;
46
68
  }
47
- lines.push(row(" ", 0, [tone(`${toUpdate} to update · ${major} major · ${resync} resync · ${materialize} new peer · ${upToDate} up to date`, "unchanged")]));
69
+ const tally = [
70
+ `${toUpdate} to update`,
71
+ `${major} major`,
72
+ `${resync} resync`,
73
+ `${upToDate + hidden.upToDate} up to date${hidden.upToDate > 0 ? HIDDEN : ""}`
74
+ ];
75
+ if (workspace + hidden.workspace > 0) tally.push(`${workspace + hidden.workspace} workspace${hidden.workspace > 0 ? HIDDEN : ""}`);
76
+ const families = lockedRows.length + hidden.families;
77
+ if (families > 0) {
78
+ const members = lockedRows.reduce((n, r) => n + r.members, 0) + hidden.members;
79
+ tally.push(`${families} locked ${families === 1 ? "family" : "families"} (${Fmt.plural(members, "member")})${hidden.families > 0 ? HIDDEN : ""}`);
80
+ }
81
+ lines.push(row(" ", 0, [tone(tally.join(" · "), "unchanged")]));
48
82
  if (interop) for (const c of interop.conflicts) lines.push(row("⚠", 0, [tone(`${c.pkg} (kept ${c.ceiling}) blocked by ${c.blockedBy}`, "warn")]));
49
83
  return Doc.concat(Doc.lines(lines, { wrap: false }), rejected !== void 0 && rejected.length > 0 && [Doc.line(""), Doc.lines([row("⚠", 0, [tone("Rejected (no published version satisfies these):", "warn")]), ...rejected.map((r) => row("⚠", 1, [tone(`${r.pkg} ${r.kind} ${r.value} — ${r.reason}`, "warn")]))], { wrap: false })]);
50
84
  }
@@ -6,15 +6,16 @@ import { byCatalog } from "./running-list.js";
6
6
  * blank line, then one bullet per package.
7
7
  *
8
8
  * @remarks
9
- * With no moves the message is the headline alone. Package names are written
9
+ * With no moves the message is the headline alone, which names `catalogs` in
10
+ * the plural when the sync owns more than one. Package names are written
10
11
  * bare, never as inline code: commitlint presets such as
11
12
  * `@savvy-web/commitlint`'s `silk/body-no-markdown` reject a body with more
12
13
  * than a couple of code spans, and a sync can move dozens of packages.
13
14
  *
14
15
  * @internal
15
16
  */
16
- function renderCommitMessage(scope, moves) {
17
- const headline = `chore(${scope}): sync catalog to the next release versions`;
17
+ function renderCommitMessage(scope, moves, catalogCount = 1) {
18
+ const headline = `chore(${scope}): sync ${catalogCount > 1 ? "catalogs" : "catalog"} to the next release versions`;
18
19
  if (moves.length === 0) return `${headline}\n`;
19
20
  return `${headline}\n\n${byCatalog(moves).flatMap(([, group]) => group.map((move) => `- ${move.pkg} ${move.from} -> ${move.to}`)).join("\n")}\n`;
20
21
  }
@@ -1,5 +1,6 @@
1
1
  import { CliDoc } from "@effected/cli-kit";
2
- import { Data, Effect, Schema } from "effect";
2
+ import { Data, Effect, Result, Schema } from "effect";
3
+ import { syncedCatalogNames } from "../../plugin/synced-catalogs.js";
3
4
  import { failureDoc } from "../render/report.js";
4
5
 
5
6
  // src/cli/sync/config.ts
@@ -16,13 +17,18 @@ var SyncConfigError = class extends Data.TaggedError("SyncConfigError") {
16
17
  }
17
18
  };
18
19
  const Names = Schema.Array(Schema.String);
20
+ const Members = Schema.Struct({
21
+ scope: Schema.NonEmptyString,
22
+ packages: Schema.optionalKey(Names),
23
+ exclude: Schema.optionalKey(Names)
24
+ });
19
25
  const SyncSchema = Schema.Struct({
20
- catalog: Schema.String,
21
- members: Schema.Struct({
22
- scope: Schema.NonEmptyString,
23
- packages: Schema.optionalKey(Names),
24
- exclude: Schema.optionalKey(Names)
25
- }),
26
+ catalogs: Schema.optionalKey(Schema.NonEmptyArray(Schema.Struct({
27
+ catalog: Schema.String,
28
+ members: Members
29
+ }))),
30
+ catalog: Schema.optionalKey(Schema.String),
31
+ members: Schema.optionalKey(Members),
26
32
  changeset: Schema.optionalKey(Schema.Struct({
27
33
  path: Schema.optionalKey(Schema.String),
28
34
  bump: Schema.optionalKey(Schema.Literals(["patch", "minor"]))
@@ -38,31 +44,61 @@ const SyncSchema = Schema.Struct({
38
44
  }))
39
45
  });
40
46
  const decodeSync = Schema.decodeUnknownEffect(SyncSchema);
47
+ const NO_SYNC = "add `sync: { catalogs: [{ catalog, members: { scope } }] }` to the PnpmConfigPlugin config";
48
+ /** The pairs of either authored form, or the message naming why there are none. */
49
+ function pairsOf(sync) {
50
+ const shorthand = sync.catalog !== void 0 || sync.members !== void 0;
51
+ if (sync.catalogs !== void 0 && shorthand) return Result.fail("`sync` sets both sync.catalogs and the sync.catalog/sync.members shorthand: keep one of them, moving the shorthand pair into sync.catalogs");
52
+ const authored = sync.catalogs ?? (sync.catalog !== void 0 && sync.members !== void 0 ? [{
53
+ catalog: sync.catalog,
54
+ members: sync.members
55
+ }] : void 0);
56
+ if (authored === void 0) return Result.fail(sync.catalog === void 0 ? `\`sync\` names no catalog: ${NO_SYNC}` : "`sync.catalog` needs `members: { scope }` beside it");
57
+ return Result.succeed(authored.map((pair) => ({
58
+ catalog: pair.catalog,
59
+ scope: pair.members.scope,
60
+ packages: pair.members.packages,
61
+ exclude: pair.members.exclude ?? []
62
+ })));
63
+ }
41
64
  /**
42
65
  * Decode the statically evaluated `sync` block of a plugin config and apply
43
66
  * its defaults. Unknown keys are rejected so a typo cannot pass for an absent
44
67
  * setting.
45
68
  *
69
+ * @remarks
70
+ * `sync.catalogs` and the one-pair `sync.catalog` + `sync.members` shorthand
71
+ * both resolve to `pairs`; setting both fails. Two pairs naming one catalog
72
+ * fail, and with more than one pair `commit.scope` is required, since the
73
+ * single-pair default (the catalog name) no longer names one thing.
74
+ *
46
75
  * @internal
47
76
  */
48
77
  function resolveSyncConfig(config) {
49
- if (config.sync === void 0) return Effect.fail(new SyncConfigError({ message: "no `sync` block: add `sync: { catalog, members: { scope } }` to the PnpmConfigPlugin config" }));
50
- return decodeSync(config.sync, {
51
- onExcessProperty: "error",
52
- errors: "all"
53
- }).pipe(Effect.mapError((error) => new SyncConfigError({ message: `invalid \`sync\` block: ${error.message}` })), Effect.map((sync) => ({
54
- catalog: sync.catalog,
55
- scope: sync.members.scope,
56
- packages: sync.members.packages,
57
- exclude: sync.members.exclude ?? [],
58
- changesetPath: sync.changeset?.path ?? ".changeset/catalog-sync.md",
59
- bump: sync.changeset?.bump ?? "patch",
60
- commitScope: sync.commit?.scope ?? sync.catalog,
61
- messagePath: sync.commit?.messagePath ?? ".changeset/catalog-sync.commit.txt",
62
- floors: sync.floors ?? false,
63
- pnpmfile: sync.local?.pnpmfile ?? "dist/prod/npm/pkg/pnpmfile.mjs",
64
- localCatalogs: sync.local?.catalogs
65
- })));
78
+ if (config.sync === void 0) return Effect.fail(new SyncConfigError({ message: `no \`sync\` block: ${NO_SYNC}` }));
79
+ return Effect.gen(function* () {
80
+ const sync = yield* decodeSync(config.sync, {
81
+ onExcessProperty: "error",
82
+ errors: "all"
83
+ }).pipe(Effect.mapError((error) => new SyncConfigError({ message: `invalid \`sync\` block: ${error.message}` })));
84
+ const pairs = yield* Effect.fromResult(pairsOf(sync)).pipe(Effect.mapError((message) => new SyncConfigError({ message })));
85
+ const names = syncedCatalogNames(config.sync) ?? [];
86
+ const twice = names.find((name, i) => names.indexOf(name) !== i);
87
+ if (twice !== void 0) return yield* new SyncConfigError({ message: `two sync pairs name the catalog "${twice}": merge their members into one pair` });
88
+ const [first] = pairs;
89
+ const commitScope = sync.commit?.scope ?? (pairs.length === 1 ? first?.catalog : void 0);
90
+ if (commitScope === void 0) return yield* new SyncConfigError({ message: `\`sync\` has ${pairs.length} pairs, so commit.scope is required: no one catalog names the commit` });
91
+ return {
92
+ pairs,
93
+ changesetPath: sync.changeset?.path ?? ".changeset/catalog-sync.md",
94
+ bump: sync.changeset?.bump ?? "patch",
95
+ commitScope,
96
+ messagePath: sync.commit?.messagePath ?? ".changeset/catalog-sync.commit.txt",
97
+ floors: sync.floors ?? false,
98
+ pnpmfile: sync.local?.pnpmfile ?? "dist/prod/npm/pkg/pnpmfile.mjs",
99
+ localCatalogs: sync.local?.catalogs
100
+ };
101
+ });
66
102
  }
67
103
  /**
68
104
  * Decode the `sync` block from what `evaluatePluginConfig` read out of
@@ -2,6 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { pathToFileURL } from "node:url";
3
3
  import { Fmt } from "@effected/cli-kit";
4
4
  import { Data, Effect, Predicate } from "effect";
5
+ import { desugarSecondForms } from "../../plugin/second-forms.js";
5
6
 
6
7
  // src/cli/sync/local-gate.ts
7
8
  /**
@@ -28,30 +29,39 @@ function readServedCatalogs(pnpmfilePath) {
28
29
  }
29
30
  /**
30
31
  * The catalogs the export writes into this repo's own workspace file: an
31
- * explicit `local.catalogs` wins, otherwise every served catalog except the
32
- * sync catalog and its derived `:peers` and `:exact` siblings, which lag it
32
+ * explicit `local.catalogs` wins, otherwise every served catalog except each
33
+ * pair's catalog and its derived `:peers` and `:exact` siblings, which lag it
33
34
  * between releases in exactly the same way.
34
35
  *
35
36
  * @internal
36
37
  */
37
38
  function exportedCatalogNames(served, sync) {
38
39
  if (sync.localCatalogs !== void 0) return sync.localCatalogs;
39
- const managed = /* @__PURE__ */ new Set([
40
- sync.catalog,
41
- `${sync.catalog}:peers`,
42
- `${sync.catalog}:exact`
43
- ]);
40
+ const managed = new Set(sync.pairs.flatMap(({ catalog }) => [
41
+ catalog,
42
+ `${catalog}:peers`,
43
+ `${catalog}:exact`
44
+ ]));
44
45
  return Object.keys(served).filter((name) => !managed.has(name));
45
46
  }
46
47
  /**
47
48
  * Per exported catalog, the packages whose served range differs from the
48
49
  * parsed `pnpm-workspace.yaml` mapping (its `catalogs` key holds the named
49
- * catalogs). Rows are human-readable; empty means in sync.
50
+ * catalogs, and a `catalog` key, flat or nested, is the default catalog).
51
+ * Rows are human-readable; empty means in sync.
52
+ *
53
+ * @throws `Error` when the workspace file declares the default catalog twice
54
+ * or pnpm would refuse a section option. A nested sub-key beside its twin
55
+ * setting is accepted, the sub-key winning, as pnpm reads it.
50
56
  *
51
57
  * @internal
52
58
  */
53
59
  function exportDrift(served, names, workspace) {
54
- const catalogs = Predicate.isObject(workspace.catalogs) ? workspace.catalogs : {};
60
+ const flat = desugarSecondForms(workspace, "pnpm-workspace.yaml", {
61
+ catalogShape: "map",
62
+ twinConflict: "nestedWins"
63
+ });
64
+ const catalogs = Predicate.isObject(flat.catalogs) ? flat.catalogs : {};
55
65
  const rows = [];
56
66
  for (const name of names) {
57
67
  const want = served[name] ?? {};
@@ -52,67 +52,129 @@ function compile(source) {
52
52
  return Result.mapError(GlobPattern.compileResult(source), (error) => new SyncWorkspaceError({ message: `invalid glob "${source}": ${error.message}` }));
53
53
  }
54
54
  /**
55
- * Publishable workspace packages in `sync.scope`, sorted: `publishConfig.access`
55
+ * Publishable workspace packages in a pair's `scope`, sorted: `publishConfig.access`
56
56
  * is `"public"`, the name is not excluded and is not the plugin itself. A scope
57
57
  * that matches no workspace package name at all, whatever its access, fails.
58
- * `sync.packages`, when set, limits discovery to members whose workspace-relative
58
+ * The pair's `packages`, when set, limits discovery to members whose workspace-relative
59
59
  * path matches one of its globs. Unlike the upgrade resolver, an unreadable
60
60
  * workspace fails rather than reading as empty: an empty list would pass the
61
61
  * gate for the wrong reason.
62
62
  *
63
63
  * @internal
64
64
  */
65
- function publishableMembers(rootDir, sync, pluginName) {
65
+ function publishableMembers(rootDir, pair, pluginName) {
66
66
  return Effect.gen(function* () {
67
67
  if (!existsSync(join(rootDir, "pnpm-workspace.yaml"))) return yield* new SyncWorkspaceError({ message: `no pnpm-workspace.yaml found in ${rootDir}` });
68
- const scope = yield* Effect.fromResult(compile(sync.scope));
69
- const excludes = yield* Effect.fromResult(Result.all(sync.exclude.map(compile)));
70
- const paths = yield* Effect.fromResult(Result.all((sync.packages ?? []).map(compile)));
68
+ const scope = yield* Effect.fromResult(compile(pair.scope));
69
+ const excludes = yield* Effect.fromResult(Result.all(pair.exclude.map(compile)));
70
+ const paths = yield* Effect.fromResult(Result.all((pair.packages ?? []).map(compile)));
71
71
  const packages = yield* Effect.try({
72
72
  try: () => getWorkspacePackagesSync(rootDir, nodeSyncOps),
73
73
  catch: (error) => new SyncWorkspaceError({ message: `cannot discover workspace packages in ${rootDir}: ${error instanceof Error ? error.message : String(error)}` })
74
74
  });
75
- if (!packages.some((pkg) => scope.matches(pkg.name))) return yield* new SyncWorkspaceError({ message: `members.scope "${sync.scope}" matches no workspace package in ${rootDir}: check it for a typo` });
76
- return packages.filter((pkg) => pkg.publishConfig?.access === "public" && pkg.name !== pluginName && scope.matches(pkg.name) && !excludes.some((glob) => glob.matches(pkg.name)) && (sync.packages === void 0 || paths.some((glob) => glob.matches(pkg.relativePath)))).map((pkg) => pkg.name).sort();
75
+ if (!packages.some((pkg) => scope.matches(pkg.name))) return yield* new SyncWorkspaceError({ message: `members.scope "${pair.scope}" matches no workspace package in ${rootDir}: check it for a typo` });
76
+ return packages.filter((pkg) => pkg.publishConfig?.access === "public" && pkg.name !== pluginName && scope.matches(pkg.name) && !excludes.some((glob) => glob.matches(pkg.name)) && (pair.packages === void 0 || paths.some((glob) => glob.matches(pkg.relativePath)))).map((pkg) => pkg.name).sort();
77
77
  });
78
78
  }
79
79
  /**
80
- * Compare the workspace's publishable members with the packages the sync
80
+ * Compare a pair's publishable members, already discovered, with the packages
81
+ * its catalog names in the config at `configFile`. The span is the caller's.
82
+ */
83
+ function compareMembership(configFile, pair, publishable) {
84
+ return Effect.gen(function* () {
85
+ const { entries } = yield* readCatalogSource(configFile, pair.catalog);
86
+ const catalogued = entries.map((entry) => entry.pkg);
87
+ const scope = yield* Effect.fromResult(compile(pair.scope));
88
+ const inScope = catalogued.filter((name) => scope.matches(name));
89
+ if (publishable.length === 0 && inScope.length > 0) return yield* new SyncWorkspaceError({ message: `no publishable package matches ${pair.scope}, yet the \`${pair.catalog}\` catalog names ${inScope.length}: a member that is \`private\` without \`publishConfig.access: "public"\` is not publishable` });
90
+ const named = new Set(catalogued);
91
+ const workspace = new Set(entries.filter((entry) => entry.source === "workspace").map((entry) => entry.pkg));
92
+ return {
93
+ missing: publishable.filter((name) => !named.has(name)),
94
+ notWorkspace: publishable.filter((name) => named.has(name) && !workspace.has(name)),
95
+ publishable,
96
+ catalogued
97
+ };
98
+ });
99
+ }
100
+ /**
101
+ * Compare one pair's publishable workspace members with the packages its
81
102
  * catalog names in the config at `configFile`.
82
103
  *
83
104
  * @internal
84
105
  */
85
- const checkMembership = Effect.fn("Sync.checkMembership")(function* (configFile, rootDir, sync) {
86
- const publishable = yield* publishableMembers(rootDir, sync, yield* pluginPackageName(configFile));
87
- const { entries } = yield* readCatalogSource(configFile, sync.catalog);
88
- const catalogued = entries.map((entry) => entry.pkg);
89
- const scope = yield* Effect.fromResult(compile(sync.scope));
90
- const inScope = catalogued.filter((name) => scope.matches(name));
91
- if (publishable.length === 0 && inScope.length > 0) return yield* new SyncWorkspaceError({ message: `no publishable package matches ${sync.scope}, yet the \`${sync.catalog}\` catalog names ${inScope.length}: a member that is \`private\` without \`publishConfig.access: "public"\` is not publishable` });
92
- const named = new Set(catalogued);
93
- return {
94
- missing: publishable.filter((name) => !named.has(name)),
95
- publishable,
96
- catalogued
97
- };
106
+ const checkMembership = Effect.fn("Sync.checkMembership")(function* (configFile, rootDir, pair) {
107
+ return yield* compareMembership(configFile, pair, yield* publishableMembers(rootDir, pair, yield* pluginPackageName(configFile)));
108
+ });
109
+ /**
110
+ * Run the membership gate for every sync pair, in pair order. A publishable
111
+ * package two pairs both own fails before any catalog is compared: `sync`
112
+ * would otherwise write it into two catalogs.
113
+ *
114
+ * @internal
115
+ */
116
+ const checkSyncMembership = Effect.fn("Sync.checkSyncMembership")(function* (configFile, rootDir, sync) {
117
+ const pluginName = yield* pluginPackageName(configFile);
118
+ const owned = yield* Effect.forEach(sync.pairs, (pair) => publishableMembers(rootDir, pair, pluginName));
119
+ const ownerOf = /* @__PURE__ */ new Map();
120
+ for (const [i, pair] of sync.pairs.entries()) for (const name of owned[i] ?? []) {
121
+ const other = ownerOf.get(name);
122
+ if (other !== void 0) return yield* new SyncWorkspaceError({ message: `${name} matches the members of two sync pairs, catalogs "${other}" and "${pair.catalog}": narrow one pair's scope or exclude it there` });
123
+ ownerOf.set(name, pair.catalog);
124
+ }
125
+ return yield* Effect.forEach(sync.pairs, (pair, i) => compareMembership(configFile, pair, owned[i] ?? []).pipe(Effect.map((result) => ({
126
+ catalog: pair.catalog,
127
+ result
128
+ }))));
98
129
  });
99
130
  /**
100
- * What to do about a membership gap: the last line of {@link membershipMessage}.
131
+ * What to do about a membership gap: the last line of {@link pairsMembershipMessage}.
101
132
  *
102
133
  * @internal
103
134
  */
104
135
  const MEMBERSHIP_REMEDY = "Add an entry for each at the PnpmConfigPlugin(...) call site with `source: \"workspace\"`.";
105
136
  /**
106
- * The failure text for publishable packages the catalog does not name.
137
+ * What to do about a member catalogued without `source: "workspace"`: the
138
+ * last line of {@link pairsMembershipMessage} when any pair has one.
139
+ *
140
+ * @internal
141
+ */
142
+ const NOT_WORKSPACE_REMEDY = "Set `source: \"workspace\"` on each of these entries: only sync moves a member, and sync moves only workspace entries.";
143
+ /**
144
+ * The `--check` / `--local` row for a member catalogued without
145
+ * `source: "workspace"`, beside the bare ` - <name>` row of a missing one.
146
+ *
147
+ * @internal
148
+ */
149
+ const notWorkspaceRow = (name) => ` - ${name} (set source: "workspace")`;
150
+ /**
151
+ * The failure text for the pairs with a membership gap: per pair, a block of
152
+ * the publishable packages its catalog does not name, and a block of those it
153
+ * names without `source: "workspace"`, each naming its catalog when `named`
154
+ * (the sync owns more than one) — the second always names it — then each
155
+ * remedy once.
156
+ *
157
+ * @internal
158
+ */
159
+ function pairsMembershipMessage(gaps, configFile, named) {
160
+ return [...gaps.flatMap((gap) => [...gap.result.missing.length === 0 ? [] : [`Publishable packages missing from ${named ? `catalog "${gap.catalog}"` : "the catalog"} in ${configFile}:`, ...gap.result.missing.map((name) => ` - ${name}`)], ...gap.result.notWorkspace.length === 0 ? [] : [`Publishable packages catalog "${gap.catalog}" names without \`source: "workspace"\` in ${configFile}:`, ...gap.result.notWorkspace.map((name) => ` - ${name}`)]]), ...membershipRemedies(gaps.map((gap) => gap.result))].join("\n");
161
+ }
162
+ /**
163
+ * The remedies for the gaps in `results`, each once: {@link MEMBERSHIP_REMEDY}
164
+ * for a missing member, {@link NOT_WORKSPACE_REMEDY} for one catalogued
165
+ * without `source: "workspace"`.
107
166
  *
108
167
  * @internal
109
168
  */
110
- function membershipMessage(missing, configFile) {
111
- return [
112
- `Publishable packages missing from the catalog in ${configFile}:`,
113
- ...missing.map((name) => ` - ${name}`),
114
- MEMBERSHIP_REMEDY
115
- ].join("\n");
169
+ function membershipRemedies(results) {
170
+ return [...results.some((result) => result.missing.length > 0) ? [MEMBERSHIP_REMEDY] : [], ...results.some((result) => result.notWorkspace.length > 0) ? [NOT_WORKSPACE_REMEDY] : []];
116
171
  }
172
+ /**
173
+ * Whether a pair's membership has any gap: a member its catalog does not
174
+ * name, or one it names without `source: "workspace"`.
175
+ *
176
+ * @internal
177
+ */
178
+ const hasMembershipGap = (result) => result.missing.length > 0 || result.notWorkspace.length > 0;
117
179
 
118
- export { MEMBERSHIP_REMEDY, SyncWorkspaceError, checkMembership, membershipMessage, pluginManifest, pluginPackageName, publishableMembers };
180
+ export { MEMBERSHIP_REMEDY, NOT_WORKSPACE_REMEDY, SyncWorkspaceError, checkSyncMembership, hasMembershipGap, membershipRemedies, notWorkspaceRow, pairsMembershipMessage, pluginManifest, pluginPackageName, publishableMembers };
@@ -7,9 +7,9 @@ import { derivePeerRange } from "../peer-range.js";
7
7
  *
8
8
  * @remarks
9
9
  * The peer follows the entry's strategy through `derivePeerRange`, so `lock`
10
- * pins it and `lock-minor` floors it. An entry with no peer literal keeps none.
11
- * A peer literal with no declared strategy floors as `lock-minor`, matching the
12
- * scripts this ports.
10
+ * pins it and `lock-minor` floors it. Only `peer: { value, strategy }` is
11
+ * derived: a bare-string peer is hand-set, so it keeps its value, and an
12
+ * entry with no peer keeps none.
13
13
  *
14
14
  * @internal
15
15
  */
@@ -20,7 +20,7 @@ const rippleMismatches = Effect.fn("Sync.rippleMismatches")(function* (entries,
20
20
  if (planned === void 0) continue;
21
21
  const to = `${entry.operator}${planned}`;
22
22
  if (entry.currentRange === to) continue;
23
- const derived = entry.peer === void 0 ? void 0 : yield* Effect.orDie(derivePeerRange(to, entry.strategy ?? "lock-minor"));
23
+ const derived = entry.peer === void 0 || entry.strategy === void 0 ? void 0 : yield* Effect.orDie(derivePeerRange(to, entry.strategy, entry.peer.value));
24
24
  const warning = derived?.warning?.message;
25
25
  ripples.push({
26
26
  catalog: entry.catalog,
@@ -41,14 +41,18 @@ function moveText(move) {
41
41
  *
42
42
  * @remarks
43
43
  * Names every package and both of its ranges: consumers take their ranges from
44
- * the catalog, so which packages moved and to what IS the release note. With no
45
- * moves the body falls back to a one-line statement naming `catalog`. The text
46
- * format is byte-compatible with the scripts this ports.
44
+ * the catalog, so which packages moved and to what IS the release note. Moves
45
+ * are grouped under one heading per catalog, so a catalog with no moves has
46
+ * none. With no moves at all the body falls back to a one-line statement naming
47
+ * every synced catalog in `catalogs`. The text format is byte-compatible with
48
+ * the scripts this ports.
47
49
  *
48
50
  * @internal
49
51
  */
50
- function renderChangeset(pluginName, bump, moves, catalog) {
51
- const body = moves.length === 0 ? `- Synced the \`${catalog}\` catalog to the current release versions` : byCatalog(moves).map(([name, group]) => {
52
+ function renderChangeset(pluginName, bump, moves, catalogs) {
53
+ const names = catalogs.map((name) => `\`${name}\``);
54
+ const synced = names.length > 1 ? `${names.slice(0, -1).join(", ")} and ${names.at(-1)} catalogs` : `${names[0] ?? ""} catalog`;
55
+ const body = moves.length === 0 ? `- Synced the ${synced} to the current release versions` : byCatalog(moves).map(([name, group]) => {
52
56
  const lines = group.map((move) => `- \`${move.pkg}\` ${moveText(move)}`);
53
57
  return `### Updates ${moveSummary(name, group.length)}\n\n${lines.join("\n")}`;
54
58
  }).join("\n\n");