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/plugin/freeze.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { Fmt } from "@effected/cli-kit";
2
2
  import { PnpmSettingsCatalog } from "@effected/pnpm/settings";
3
3
  import { Data, Effect, Predicate, Schema } from "effect";
4
- import { normalizeCatalogs } from "../catalogs.js";
4
+ import { normalizeCatalogs, sourceOf } from "../catalogs.js";
5
5
  import { FIELD_REGISTRY, FIELD_SCHEMAS } from "../registry.js";
6
6
  import { resolvePeerDependencyRules } from "./allowed-versions.js";
7
- import { pinCatalogs, resolveOverrides } from "./overrides-from-catalogs.js";
7
+ import { contradictingOverride, mergeOverrides, resolveFamilies } from "./families.js";
8
+ import { desugarSecondForms, isWrappedField } from "./second-forms.js";
9
+ import { syncedCatalogNames } from "./synced-catalogs.js";
8
10
 
9
11
  // src/plugin/freeze.ts
10
12
  /**
@@ -65,29 +67,103 @@ const PLUGIN_KEYS = /* @__PURE__ */ new Set([
65
67
  "name",
66
68
  "catalogs",
67
69
  "local",
68
- "overridesFromCatalogs",
69
70
  "sync"
70
71
  ]);
71
- /** Keys recognized by the wrapped `{ value, enforcement?, excludeByRepo? }` form. */
72
- const WRAPPED_KEYS = /* @__PURE__ */ new Set([
73
- "value",
74
- "enforcement",
75
- "excludeByRepo"
76
- ]);
77
72
  /**
78
- * True only when `input` is the wrapped `{ value, enforcement?, excludeByRepo? }`
79
- * form: a `value` key and no foreign keys. This disambiguates from a
80
- * record-valued field that happens to contain a `value` key (e.g.
81
- * `overrides: { value: ">=1", lodash: ">=4" }`), which has keys outside the
82
- * recognized set and is therefore treated as a bare value. The single
83
- * definition of "wrapped" — the CLI's static readers use it too.
84
- *
85
- * @internal
73
+ * The first entry key an earlier release read that this one does not, as a
74
+ * message naming what to write instead, or `undefined` when every entry is in
75
+ * the current shape. An entry carrying `range` beside `dependency` is refused
76
+ * too: reading `dependency` alone would ship the half-migrated entry silently.
86
77
  */
87
- function isWrappedField(input) {
88
- if (!Predicate.isObject(input)) return false;
89
- const keys = Object.keys(input);
90
- return keys.includes("value") && keys.every((k) => WRAPPED_KEYS.has(k));
78
+ function removedEntryKey(catalogs) {
79
+ if (typeof catalogs !== "object" || catalogs === null) return void 0;
80
+ for (const [catalog, decl] of Object.entries(catalogs)) {
81
+ if (typeof decl !== "object" || decl === null || typeof decl.packages !== "object" || decl.packages === null) continue;
82
+ for (const [pkg, spec] of Object.entries(decl.packages)) {
83
+ if (typeof spec !== "object" || spec === null) continue;
84
+ const entry = spec;
85
+ const at = `catalogs: "${pkg}" in catalog "${catalog}"`;
86
+ if (Object.hasOwn(entry, "range")) return `${at} sets range, which is now dependency; rename range to dependency`;
87
+ if (Object.hasOwn(entry, "strategy")) return `${at} sets strategy on the entry, which is now peer.strategy; write peer: { value, strategy }`;
88
+ if (entry.source === "registry") return `${at} sets source: "registry", which is now "npm"; write source: "npm", or omit it`;
89
+ }
90
+ }
91
+ }
92
+ /** The keys each level of a catalog declaration reads; any other key fails the build. */
93
+ const DECLARATION_KEYS = [
94
+ "packages",
95
+ "exact",
96
+ "families"
97
+ ];
98
+ const ENTRY_KEYS = [
99
+ "dependency",
100
+ "peer",
101
+ "source",
102
+ "exact"
103
+ ];
104
+ const PEER_KEYS = ["value", "strategy"];
105
+ const FAMILY_KEYS = [
106
+ "name",
107
+ "members",
108
+ "exclude",
109
+ "owners"
110
+ ];
111
+ /** The first own key of `value` outside `known`, as a message naming it, where it sits and the keys to write instead. */
112
+ function unknownKeyIn(value, known, at) {
113
+ const key = Object.keys(value).find((name) => !known.includes(name));
114
+ if (key === void 0) return void 0;
115
+ const near = Fmt.suggest(key, known);
116
+ return `${at} sets unknown key "${key}": ${near.length > 0 ? `did you mean ${near.map((name) => `"${name}"`).join(" or ")}? ` : ""}(valid keys: ${known.join(", ")})`;
117
+ }
118
+ /**
119
+ * The first key a catalog declaration, entry, object peer or family does not
120
+ * read, as a message naming the key, where it sits and the nearest valid key,
121
+ * or `undefined` when every key is known. Runs after {@link removedEntryKey},
122
+ * so a key an earlier release read keeps its own message. A key the build
123
+ * ignored would ship an entry the author did not write: `soruce: "workspace"`
124
+ * would serve an npm entry, and a peer's `stratgy` a hand-set value.
125
+ */
126
+ function unknownCatalogKey(catalogs) {
127
+ if (!Predicate.isObject(catalogs)) return void 0;
128
+ for (const [catalog, decl] of Object.entries(catalogs)) {
129
+ if (!Predicate.isObject(decl) || !Predicate.isObject(decl.packages)) continue;
130
+ const inDecl = unknownKeyIn(decl, DECLARATION_KEYS, `catalogs: catalog "${catalog}"`);
131
+ if (inDecl !== void 0) return inDecl;
132
+ for (const [pkg, spec] of Object.entries(decl.packages)) {
133
+ if (!Predicate.isObject(spec)) continue;
134
+ const at = `catalogs: "${pkg}" in catalog "${catalog}"`;
135
+ const inEntry = unknownKeyIn(spec, ENTRY_KEYS, at);
136
+ if (inEntry !== void 0) return inEntry;
137
+ const { peer } = spec;
138
+ const inPeer = Predicate.isObject(peer) ? unknownKeyIn(peer, PEER_KEYS, `${at}, in its peer,`) : void 0;
139
+ if (inPeer !== void 0) return inPeer;
140
+ }
141
+ if (!Array.isArray(decl.families)) continue;
142
+ for (const family of decl.families) {
143
+ if (!Predicate.isObject(family)) continue;
144
+ const { name } = family;
145
+ const inFamily = unknownKeyIn(family, FAMILY_KEYS, `catalogs: family "${String(name)}" in catalog "${catalog}"`);
146
+ if (inFamily !== void 0) return inFamily;
147
+ }
148
+ }
149
+ }
150
+ /**
151
+ * The first `source: "workspace"` entry in a catalog no sync pair owns, as a
152
+ * message naming the entry, its catalog and the pair to add, or `undefined`
153
+ * when every workspace entry is owned. Only `sync` moves a workspace entry, so
154
+ * an orphan would never move at all.
155
+ */
156
+ function orphanedWorkspaceEntry(catalogs, sync) {
157
+ const owned = syncedCatalogNames(sync);
158
+ for (const [catalog, decl] of Object.entries(catalogs)) {
159
+ if (owned?.includes(catalog) || !Predicate.isObject(decl) || !Predicate.isObject(decl.packages)) continue;
160
+ for (const [pkg, spec] of Object.entries(decl.packages)) {
161
+ if (sourceOf(spec) !== "workspace") continue;
162
+ const at = `catalogs: "${pkg}" in catalog "${catalog}" sets source: "workspace"`;
163
+ const pair = `{ catalog: "${catalog}", members: { scope } }`;
164
+ return owned === void 0 ? `${at}, but the config has no \`sync\` block, and only sync moves a workspace entry: add sync: { catalogs: [${pair}] }, or set source: "npm"` : `${at}, but no sync pair owns that catalog (sync owns ${owned.length > 0 ? owned.map((name) => `"${name}"`).join(", ") : "none"}): add ${pair} to sync.catalogs, or set source: "npm"`;
165
+ }
166
+ }
91
167
  }
92
168
  function normalizeField(input) {
93
169
  if (isWrappedField(input)) {
@@ -106,8 +182,17 @@ function normalizeField(input) {
106
182
  *
107
183
  * @internal
108
184
  */
109
- function freeze(config) {
185
+ function freeze(authored) {
110
186
  return Effect.gen(function* () {
187
+ const config = yield* Effect.try({
188
+ try: () => desugarSecondForms(authored, "config"),
189
+ catch: (error) => new ConfigError({ message: Fmt.describe(error) })
190
+ });
191
+ if (Object.hasOwn(config, "overridesFromCatalogs")) return yield* Effect.fail(new ConfigError({ message: "`overridesFromCatalogs` is removed: declare a family with `owners` on the catalog (`catalogs.<name>.families`), or write `overrides`, instead" }));
192
+ const removed = removedEntryKey(config.catalogs);
193
+ if (removed !== void 0) return yield* Effect.fail(new ConfigError({ message: removed }));
194
+ const unknown = unknownCatalogKey(config.catalogs);
195
+ if (unknown !== void 0) return yield* Effect.fail(new ConfigError({ message: unknown }));
111
196
  const base = {};
112
197
  const manifest = {};
113
198
  const normalized = yield* Effect.try({
@@ -115,6 +200,18 @@ function freeze(config) {
115
200
  catch: (error) => new ConfigError({ message: Fmt.describe(error) })
116
201
  });
117
202
  base.catalogs = yield* validateField("catalogs", CatalogsSchema, normalized);
203
+ const { overrides: generated, members } = yield* Effect.try({
204
+ try: () => resolveFamilies(config.catalogs),
205
+ catch: (error) => new ConfigError({ message: Fmt.describe(error) })
206
+ });
207
+ const authoredOverrides = normalizeField(config.overrides).value;
208
+ if (Predicate.isObject(authoredOverrides) && !Array.isArray(authoredOverrides)) {
209
+ const contradiction = contradictingOverride(authoredOverrides, members);
210
+ if (contradiction !== void 0) return yield* Effect.fail(new ConfigError({ message: contradiction }));
211
+ }
212
+ const orphan = orphanedWorkspaceEntry(config.catalogs, config.sync);
213
+ if (orphan !== void 0) return yield* Effect.fail(new ConfigError({ message: orphan }));
214
+ const hasGenerated = Object.keys(generated).length > 0;
118
215
  const exactCatalogs = Object.entries(config.catalogs).flatMap(([name, decl]) => decl?.exact === true && normalized[`${name}:exact`] !== void 0 ? [name] : []);
119
216
  manifest.catalogs = {
120
217
  strategy: "catalogs",
@@ -130,28 +227,21 @@ function freeze(config) {
130
227
  }
131
228
  const directiveError = (error) => new ConfigError({ message: Fmt.describe(error) });
132
229
  for (const [field, reg] of Object.entries(FIELD_REGISTRY)) {
133
- if (field === "catalogs") continue;
230
+ if (field === "catalogs" || field === "catalog") continue;
134
231
  let raw = config[field];
135
- if (raw === void 0 && field === "overrides" && config.overridesFromCatalogs !== void 0) raw = {};
232
+ if (raw === void 0 && field === "overrides" && hasGenerated) raw = {};
136
233
  if (raw === void 0) continue;
137
234
  const decl = normalizeField(raw);
138
235
  base[field] = yield* validateField(field, FIELD_SCHEMAS[field], field === "peerDependencyRules" ? yield* Effect.try({
139
236
  try: () => resolvePeerDependencyRules(decl.value, config.catalogs),
140
237
  catch: directiveError
141
- }) : field === "overrides" ? yield* Effect.try({
142
- try: () => resolveOverrides(decl.value, config.overridesFromCatalogs, config.catalogs),
143
- catch: directiveError
144
- }) : decl.value);
238
+ }) : field === "overrides" && hasGenerated && Predicate.isObject(decl.value) && !Array.isArray(decl.value) ? mergeOverrides(decl.value, generated) : decl.value);
145
239
  manifest[field] = {
146
240
  strategy: reg.strategy,
147
241
  enforcement: decl.enforcement ?? reg.enforcement,
148
242
  ...decl.options ? { options: decl.options } : {}
149
243
  };
150
244
  }
151
- base.catalogs = yield* Effect.try({
152
- try: () => pinCatalogs(base.catalogs, base.overrides, config.overridesFromCatalogs, config.catalogs),
153
- catch: directiveError
154
- });
155
245
  return {
156
246
  base,
157
247
  manifest,
@@ -0,0 +1,155 @@
1
+ import { PnpmPackageMap } from "@effected/pnpm";
2
+ import { Result } from "effect";
3
+
4
+ // src/plugin/second-forms.ts
5
+ /** Keys recognized by the wrapped `{ value, enforcement?, excludeByRepo? }` form. */
6
+ const WRAPPED_KEYS = /* @__PURE__ */ new Set([
7
+ "value",
8
+ "enforcement",
9
+ "excludeByRepo"
10
+ ]);
11
+ const isRecord = (input) => typeof input === "object" && input !== null && !Array.isArray(input);
12
+ /**
13
+ * True only when `input` is the wrapped `{ value, enforcement?, excludeByRepo? }`
14
+ * form: a `value` key and no foreign keys. This disambiguates from a
15
+ * record-valued field that happens to contain a `value` key (e.g.
16
+ * `overrides: { value: ">=1", lodash: ">=4" }`), which has keys outside the
17
+ * recognized set and is therefore treated as a bare value. The single
18
+ * definition of "wrapped" — the CLI's static readers use it too.
19
+ *
20
+ * @internal
21
+ */
22
+ function isWrappedField(input) {
23
+ if (!isRecord(input)) return false;
24
+ const keys = Object.keys(input);
25
+ return keys.includes("value") && keys.every((k) => WRAPPED_KEYS.has(k));
26
+ }
27
+ /**
28
+ * The nested sub-key to managed-setting table, the one source for the desugar
29
+ * and for export's respelling back into the file's nested form.
30
+ *
31
+ * @internal
32
+ */
33
+ const SUB_KEYS = {
34
+ overrides: {
35
+ container: "rules",
36
+ unused: {
37
+ setting: "warnUnusedOverrides",
38
+ map: {
39
+ warn: true,
40
+ ignore: false
41
+ }
42
+ }
43
+ },
44
+ catalog: {
45
+ container: "entries",
46
+ mode: { setting: "catalogMode" },
47
+ defaultSaveTarget: { setting: "saveCatalogName" },
48
+ unused: {
49
+ setting: "catalogPrune",
50
+ map: {
51
+ prune: true,
52
+ ignore: false
53
+ }
54
+ }
55
+ }
56
+ };
57
+ /**
58
+ * Split a `catalog` or `overrides` value into its package map and section
59
+ * options through the kit's `PnpmPackageMap.readResult`: the value is the
60
+ * section exactly when `entries` / `rules` holds a mapping, so a key holding a
61
+ * specifier string is a package of the plain map. A refused option (a key
62
+ * beside the map that is not an option, or an option outside its values) is
63
+ * thrown with the `where` prefix.
64
+ */
65
+ function readSection(where, field, value) {
66
+ const read = PnpmPackageMap.readResult(value, field);
67
+ if (Result.isFailure(read)) throw new Error(`${where}: ${read.failure.message}`);
68
+ return read.success;
69
+ }
70
+ /**
71
+ * Classify an `overrides` or `catalog` value by the kit's rule: `"nested"`
72
+ * when its `rules` / `entries` key holds a mapping, `"flat"` for a plain
73
+ * package map, and `undefined` when it is not an object.
74
+ *
75
+ * @internal
76
+ */
77
+ function secondFormOf(value, field) {
78
+ if (!isRecord(value)) return void 0;
79
+ return PnpmPackageMap.read(value, field).section ? "nested" : "flat";
80
+ }
81
+ function setTwin(twins, field, sub, setting, value) {
82
+ if (twins.conflict === "error" && twins.input[setting] !== void 0) throw new Error(`${twins.where}: ${field}.${sub} and ${setting} both set ${setting}; keep one of them.`);
83
+ twins.out[setting] = value;
84
+ }
85
+ /** Set every twin a section's options name; the kit already checked their values. */
86
+ function setTwins(twins, field, options) {
87
+ for (const [sub, spec] of Object.entries(SUB_KEYS[field])) {
88
+ if (sub === "container" || typeof spec !== "object" || options[sub] === void 0) continue;
89
+ const value = options[sub];
90
+ setTwin(twins, field, sub, spec.setting, "map" in spec ? spec.map[value] : value);
91
+ }
92
+ }
93
+ function flattenOverrides(value, twins) {
94
+ const read = readSection(twins.where, "overrides", value);
95
+ if (!read.section) return value;
96
+ setTwins(twins, "overrides", read.options);
97
+ return read.map;
98
+ }
99
+ /**
100
+ * Rewrite pnpm 12's nested `overrides: { rules, unused }` and
101
+ * `catalog: { entries, mode, defaultSaveTarget, unused }` forms into the
102
+ * settings the plugin manages: `overrides` becomes its flat map, `catalog` folds
103
+ * into `catalogs.default` (shaped by `catalogShape`), and the sub-keys set
104
+ * `warnUnusedOverrides`, `catalogMode`, `saveCatalogName` and `catalogPrune`.
105
+ * Which form a value is, and which section options pnpm accepts, is the kit's
106
+ * `PnpmPackageMap.readResult`; the twin table, the conflict checks, the fold and
107
+ * the wrapper are this module's. Returns a new object; the input is untouched.
108
+ *
109
+ * @param input - The authored config or parsed workspace settings.
110
+ * @param where - Error prefix: `"config"`, `"local"` or `"pnpm-workspace.yaml"`.
111
+ * @param options - See {@link DesugarOptions}.
112
+ * @throws `Error` when a sub-key and its twin setting are both authored (under
113
+ * `twinConflict: "error"`), when `catalog` and `catalogs.default` both are, when
114
+ * `catalog` carries a wrapper option, or when the kit refuses a section option.
115
+ *
116
+ * @internal
117
+ */
118
+ function desugarSecondForms(input, where, options = {}) {
119
+ const catalogShape = options.catalogShape ?? "declaration";
120
+ const out = { ...input };
121
+ const twins = {
122
+ input,
123
+ where,
124
+ conflict: options.twinConflict ?? "error",
125
+ out: {}
126
+ };
127
+ if (out.overrides !== void 0) {
128
+ const raw = out.overrides;
129
+ out.overrides = isWrappedField(raw) ? {
130
+ ...raw,
131
+ value: flattenOverrides(raw.value, twins)
132
+ } : flattenOverrides(raw, twins);
133
+ }
134
+ if ("catalog" in out) {
135
+ const raw = out.catalog;
136
+ delete out.catalog;
137
+ if (!(raw === void 0 || raw === null && catalogShape === "map")) {
138
+ if (!isRecord(raw)) throw new Error(`${where}: catalog must be an object of package ranges.`);
139
+ if (isWrappedField(raw)) throw new Error(`${where}: catalog does not take value, enforcement or excludeByRepo; declare the entries under catalogs.default to use them.`);
140
+ const existing = out.catalogs;
141
+ if (isRecord(existing) && existing.default !== void 0) throw new Error(`${where}: catalog and catalogs.default both declare the default catalog; keep one of them.`);
142
+ const read = readSection(where, "catalog", raw);
143
+ setTwins(twins, "catalog", read.options);
144
+ const entries = read.map;
145
+ if (isRecord(entries) && Object.keys(entries).length > 0) out.catalogs = {
146
+ ...isRecord(existing) ? existing : {},
147
+ default: catalogShape === "map" ? entries : { packages: entries }
148
+ };
149
+ }
150
+ }
151
+ Object.assign(out, twins.out);
152
+ return out;
153
+ }
154
+
155
+ export { SUB_KEYS, desugarSecondForms, isWrappedField, secondFormOf };
@@ -0,0 +1,32 @@
1
+ // src/plugin/synced-catalogs.ts
2
+ /**
3
+ * The catalogs a raw `sync` block owns. Pure and free of Effect, so the build
4
+ * (`freeze`, for the orphan rule) and the CLI (`sync`'s config) read the block
5
+ * the same way.
6
+ */
7
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
8
+ /**
9
+ * The catalog of every sync pair in `sync`, in source order: each
10
+ * `sync.catalogs[].catalog`, after the shorthand `sync.catalog` when it is
11
+ * set. `undefined` when there is no `sync` block at all.
12
+ *
13
+ * @remarks
14
+ * Total over any input. A block it cannot read owns nothing (`[]`), so the
15
+ * build refuses its workspace entries rather than trusting a typo; the CLI's
16
+ * decode names the malformed key. Both forms set at once read as their
17
+ * union here, and the CLI refuses them.
18
+ *
19
+ * @internal
20
+ */
21
+ function syncedCatalogNames(sync) {
22
+ if (sync === void 0) return void 0;
23
+ if (!isRecord(sync)) return [];
24
+ const names = [];
25
+ if (typeof sync.catalog === "string") names.push(sync.catalog);
26
+ if (Array.isArray(sync.catalogs)) {
27
+ for (const pair of sync.catalogs) if (isRecord(pair) && typeof pair.catalog === "string") names.push(pair.catalog);
28
+ }
29
+ return names;
30
+ }
31
+
32
+ export { syncedCatalogNames };
package/registry.js CHANGED
@@ -318,6 +318,18 @@ const FIELD_REGISTRY = {
318
318
  strategy: "scalar",
319
319
  enforcement: "absent"
320
320
  },
321
+ catalogPrune: {
322
+ strategy: "scalar",
323
+ enforcement: "absent"
324
+ },
325
+ saveCatalogName: {
326
+ strategy: "scalar",
327
+ enforcement: "absent"
328
+ },
329
+ warnUnusedOverrides: {
330
+ strategy: "scalar",
331
+ enforcement: "absent"
332
+ },
321
333
  cleanupUnusedCatalogs: {
322
334
  strategy: "scalar",
323
335
  enforcement: "absent"
@@ -469,6 +481,6 @@ const FIELD_SCHEMAS = Object.fromEntries(MANAGED_FIELDS.map((field) => [field, P
469
481
  *
470
482
  * @internal
471
483
  */
472
- const WORKSPACE_FIELDS = new Set(MANAGED_FIELDS.filter((field) => PnpmSettingsCatalog.entries[field].locations.includes("workspace")));
484
+ const WORKSPACE_FIELDS = new Set(MANAGED_FIELDS.filter(PnpmSettingsCatalog.isWorkspaceFileSetting));
473
485
 
474
486
  export { FIELD_REGISTRY, FIELD_SCHEMAS, MANAGED_FIELDS, WORKSPACE_FIELDS };
@@ -16,14 +16,24 @@ plugin's config in place (`upgrade`, `sync`), writes the repository's own
16
16
 
17
17
  - Keep the `catalogs` literal inline in the `PnpmConfigPlugin({...})` call.
18
18
  The CLI reads and rewrites it statically; never hoist, spread or compute it.
19
+ - The default catalog is `catalogs.default` or the nested/flat `catalog`
20
+ setting, never both; `overrides` also has a nested `{ rules, unused }` form.
21
+ See [references/options.md](references/options.md).
19
22
  - Dependencies use `catalog:<name>`; peers use `catalog:<name>:peers`.
20
23
  - Never run `pnpm:up` or `pnpm:export` (or `upgrade` / `export` without
21
24
  `--dry-run`). They are the user's; tell the user which to run.
22
25
  - Never put the plugin package in any catalog it serves.
23
26
  - A config dependency installs without its dependencies. Bundle every
24
27
  import of the pnpmfile and never declare one as a dependency.
25
- - Never edit a `sync.catalog` range or `.changeset/catalog-sync.md` by hand.
26
- `sync` owns both.
28
+ - Write each catalog entry as `{ dependency, peer?, source? }`, never the
29
+ old `range`, entry-level `strategy` or `source: "registry"`, which fail the
30
+ build.
31
+ - `sync` moves `source: "workspace"` entries and `upgrade` moves npm
32
+ entries. Every workspace entry's catalog needs a pair in `sync.catalogs`,
33
+ or the build fails. Never edit a workspace entry's `dependency` or
34
+ `.changeset/catalog-sync.md` by hand.
35
+ - A family member (`catalogs.<name>.families`) is locked: an exact version,
36
+ moved only by `upgrade --family <name>`, which is the user's to run.
27
37
  - Keep `private: true` in source; publishability is
28
38
  `publishConfig.access: "public"`.
29
39
  - A gate's exit 1 is not proof of drift. Read `evaluated` and each
@@ -36,7 +46,7 @@ Load the reference that matches the task. Each stands alone.
36
46
  | Reference | Load when |
37
47
  | --- | --- |
38
48
  | [references/wiring.md](references/wiring.md) | Adding the plugin to a repository: package layout, `effected.toml`, scripts and root aliases, every `sync` block field and default, the workflow and pre-push shapes |
39
- | [references/catalogs.md](references/catalogs.md) | Adding or editing catalog entries, choosing a specifier, adding imports to the plugin, or entries `export` keeps in `pnpm-workspace.yaml` (union and map fields) |
49
+ | [references/catalogs.md](references/catalogs.md) | Adding or editing catalog entries or families, choosing a specifier, adding imports to the plugin, or entries `export` keeps in `pnpm-workspace.yaml` (union and map fields) |
40
50
  | [references/options.md](references/options.md) | Writing or editing a plugin config, or looking up what a top-level key, `sync` field, value form, strategy or managed pnpm setting does |
41
51
  | [references/sync.md](references/sync.md) | Running `sync`, `sync --check` or `sync --local`, reading their text or JSON report, applying a remedy, or a red Catalog Sync check |
42
52
 
@@ -9,32 +9,121 @@ Write the `catalogs` object literally inside the `PnpmConfigPlugin({...})`
9
9
  call. `upgrade` and `sync` read and rewrite it statically through the AST.
10
10
 
11
11
  - Never hoist it into a variable, a spread, a helper or another module.
12
- - Never compute a range. Write a string literal.
12
+ - Never compute a version. Write a string literal, and keep `families`,
13
+ `members` and `exclude` literal lists: `upgrade --family` refuses a
14
+ spread, an identifier or a call there.
13
15
  - Quoted keys (`"@acme/core"`) are fine.
14
16
 
17
+ ## The default catalog
18
+
19
+ The default catalog is declared as `catalogs.default` or as the top-level
20
+ `catalog` setting, in a flat or nested form (see "`overrides` and `catalog`:
21
+ two forms each" in [options.md](options.md)); never both, which fails the
22
+ build. Either spelling ships as `catalogs.default`, and divergence warnings,
23
+ `upgrade` discovery and a `sync` pair naming `default` apply to it. The
24
+ `:exact` and `:peers` variants and `families` need `catalogs.default`: the
25
+ `catalog` setting takes plain dependency strings, with no `exact`, `peer`
26
+ or `families`. A consumer writes `catalog:` or `catalog:default`.
27
+
15
28
  ## Specifiers
16
29
 
17
30
  | Field | Write | Why |
18
31
  | --- | --- | --- |
19
- | `dependencies`, `devDependencies` | `catalog:<name>` | The catalog's `range` |
32
+ | `dependencies`, `devDependencies` | `catalog:<name>` | The entry's `dependency` |
20
33
  | `peerDependencies` | `catalog:<name>:peers` | The entry's `peer` floor |
21
34
  | An exact pin | `catalog:<name>:exact` | Only when the declaration sets `exact: true` |
22
35
 
23
36
  `pnpm pack` writes a `catalog:` specifier as the catalog's value, so a peer
24
37
  spelled `catalog:<name>` publishes the dependency range instead of the peer
25
- floor. The `:peers` twin holds only entries that declare a `peer`. Give such
26
- an entry a `strategy` (`"lock"`, `"lock-minor"` or `"interop"`) so `upgrade`
27
- and `sync` re-derive `peer` whenever they move `range`.
38
+ floor. The `:peers` twin holds only entries that declare a `peer`. Write such
39
+ a peer as `{ value, strategy }` (`"lock"`, `"lock-minor"` or `"interop"`) so
40
+ `upgrade` and `sync` re-derive it whenever they move `dependency`.
28
41
 
29
42
  ## Entries
30
43
 
31
- - An entry for a workspace package sets `source: "workspace"`, so `upgrade`
32
- and `sync` read the next release version from the workspace (manifests plus
33
- pending changesets) instead of the registry.
34
- - Never edit the `range` of a `sync.catalog` entry by hand. `sync` owns it.
35
- - Add every publishable workspace member in `sync.members.scope` to the sync
36
- catalog, or leave it out explicitly with `sync.members.exclude`. The
37
- membership gate fails otherwise.
44
+ An entry is a bare dependency string (an npm entry with no peer), or an
45
+ object naming what it writes:
46
+
47
+ ```ts
48
+ catalogs: {
49
+ acme: {
50
+ packages: {
51
+ typescript: "^5.9.0",
52
+ effect: { dependency: "^4.1.7", peer: { value: "^4.1.0", strategy: "lock-minor" } },
53
+ "@acme/core": { dependency: "^1.2.0", peer: { value: "^1.2.0", strategy: "lock-minor" }, source: "workspace" },
54
+ "left-pad": { dependency: "^1.3.0", peer: "*" },
55
+ },
56
+ },
57
+ },
58
+ ```
59
+
60
+ - `dependency` is any specifier, served under `catalog:<name>`. A move keeps
61
+ its operator.
62
+ - `peer` is served under `catalog:<name>:peers`. `{ value, strategy }` is
63
+ re-derived on every move; a bare string is hand-set and never touched.
64
+ - `source: "workspace"` marks a package of this monorepo. `sync` moves it,
65
+ reading the next release version from manifests plus pending changesets.
66
+ `"npm"` (the default) is `upgrade`'s.
67
+ - Never write `range`, an entry-level `strategy` or `source: "registry"`:
68
+ the build fails naming `dependency`, `peer.strategy` and `"npm"`.
69
+
70
+ ## Who moves an entry
71
+
72
+ - `upgrade` moves npm entries. It shows a workspace entry read-only and
73
+ never moves it.
74
+ - `sync` moves workspace entries, in every catalog of `sync.catalogs`, and
75
+ leaves npm entries alone, ripples included.
76
+ - Every workspace entry's catalog needs a `sync` pair. A workspace entry in a
77
+ catalog no pair owns, or any workspace entry with no `sync` block, fails the
78
+ build and every install. Add `{ catalog, members: { scope } }` to
79
+ `sync.catalogs`, or set `source: "npm"`.
80
+ - Never edit a workspace entry's `dependency` by hand. `sync` owns it.
81
+ - Add every publishable workspace member in a pair's `members.scope` to that
82
+ pair's catalog with `source: "workspace"`, or leave it out explicitly with
83
+ `members.exclude`. The membership gate fails otherwise, an npm entry for a
84
+ member included, and so does a package two pairs' scopes both match.
85
+
86
+ ## Families lock a release line
87
+
88
+ A family locks entries of one catalog that move together, only when asked:
89
+
90
+ ```ts
91
+ catalogs: {
92
+ effect: {
93
+ packages: {
94
+ effect: "4.1.7",
95
+ "@effect/platform-node": "4.1.7",
96
+ "@effect/tsgo": "0.6.0",
97
+ },
98
+ families: [
99
+ { name: "effect", members: ["effect", "@effect/*"], exclude: ["@effect/tsgo"], owners: ["@acme/*"] },
100
+ { name: "tsgo", members: ["@effect/tsgo"] },
101
+ ],
102
+ },
103
+ },
104
+ ```
105
+
106
+ - `members` and `exclude` are exact names or globs over that catalog's
107
+ entries; `exclude` wins. A name that is no entry, or a glob that matches
108
+ none, fails the build. A new entry matching a glob joins the family.
109
+ - Every member's `dependency` is one exact version (`4.1.7`, not `^4.1.7`),
110
+ and never `source: "workspace"`. Members need not share a version.
111
+ - A package belongs to one family. A family `name` is unique across the
112
+ whole config, not only within its catalog.
113
+ - Each owner glob adds `"<owner>><member>": "<version>"` to `overrides`.
114
+ It pins the owner's regular dependency edges only: pnpm never overrides a
115
+ peer edge, so a member the owner reaches as a peer is fixed by the
116
+ consumer's own `catalog:<name>` dependency. Nothing is pinned graph-wide.
117
+ An authored `overrides` selector wins over a generated one.
118
+ - `upgrade --yes` and `--check` skip members; `--check` lists a newer member
119
+ as informational and still exits 0. `upgrade --yes --family <name>`
120
+ (repeatable) moves each member to its newest version in its breaking line
121
+ (the major, or the minor on 0.x). That moves versions, so it is the user's
122
+ to run. A 0.0.x member never moves under `--family` (`^0.0.3` admits only
123
+ `0.0.3`); it moves only when the user picks a version in the interactive
124
+ table.
125
+ - `overridesFromCatalogs` no longer exists and fails the build. Declare a
126
+ family with `owners`, or write `overrides`.
38
127
 
39
128
  ## Never put the plugin in its own catalog
40
129
 
@@ -66,6 +155,14 @@ Read-only forms are fine: `pnpm:preview`, `upgrade --check`,
66
155
 
67
156
  ## Union and map fields keep unmanaged entries on export
68
157
 
158
+ `export` writes the default catalog under the key the consumer's
159
+ `pnpm-workspace.yaml` already uses (flat `catalog`, nested `catalog` with
160
+ sub-keys, or `catalogs.default`; neither: `catalogs.default`), never both.
161
+ Nested `overrides` in the file stays nested. The default catalog merges per
162
+ package with the file's own entries: the managed value wins on a shared key,
163
+ and entries only the file holds stay. Named catalogs still replace by name on
164
+ export, while an install keeps the consumer's entries; that gap is open.
165
+
69
166
  For fields whose runtime strategy is a union (`publicHoistPattern`,
70
167
  `hoistPattern`, `minimumReleaseAgeExclude`, `trustPolicyExclude`,
71
168
  `supportedArchitectures`, `auditConfig`, `ignoredOptionalDependencies`,