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.
- package/README.md +1 -1
- package/catalogs.js +32 -15
- package/cli/commands/export.js +8 -3
- package/cli/commands/preview.js +10 -7
- package/cli/commands/sync.js +140 -70
- package/cli/commands/upgrade.js +348 -138
- package/cli/discover.js +134 -28
- package/cli/drift.js +2 -2
- package/cli/edits.js +8 -17
- package/cli/effective.js +132 -4
- package/cli/interop.js +35 -16
- package/cli/local-merge.js +4 -1
- package/cli/peer-range.js +21 -5
- package/cli/plan.js +9 -4
- package/cli/preview-views.js +3 -1
- package/cli/release-age.js +2 -1
- package/cli/respell.js +86 -0
- package/cli/select-file.js +5 -2
- package/cli/summary.js +44 -10
- package/cli/sync/commit-message.js +4 -3
- package/cli/sync/config.js +60 -24
- package/cli/sync/local-gate.js +19 -9
- package/cli/sync/membership.js +93 -31
- package/cli/sync/ripples.js +4 -4
- package/cli/sync/running-list.js +9 -5
- package/cli/ui/walk-screen.js +66 -20
- package/cli/validate.js +1 -1
- package/cli/version.js +1 -1
- package/cli/walk-plan.js +17 -10
- package/cli/walk-reducer.js +99 -19
- package/cli/workspace-overlay.js +5 -0
- package/cli/workspace-resolve.js +17 -1
- package/index.d.ts +176 -127
- package/package.json +6 -6
- package/plugin/allowed-versions.js +3 -3
- package/plugin/families.js +185 -0
- package/plugin/freeze.js +137 -32
- package/plugin/second-forms.js +155 -0
- package/plugin/synced-catalogs.js +32 -0
- package/registry.js +13 -1
- package/skills/rolldown-pnpm-config/SKILL.md +13 -3
- package/skills/rolldown-pnpm-config/references/catalogs.md +127 -14
- package/skills/rolldown-pnpm-config/references/options.md +131 -47
- package/skills/rolldown-pnpm-config/references/sync.md +32 -21
- package/skills/rolldown-pnpm-config/references/wiring.md +12 -8
- 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 {
|
|
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,116 @@ 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
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
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
|
|
88
|
-
if (
|
|
89
|
-
const
|
|
90
|
-
|
|
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
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The first catalog entry naming the plugin itself, as a message naming the
|
|
170
|
+
* catalog and the entry, or `undefined` when no catalog holds it. Checking the
|
|
171
|
+
* declarations covers every served catalog: a `:peers` or `:exact` twin holds
|
|
172
|
+
* only names its declaration holds. The entry's `source` does not matter.
|
|
173
|
+
*/
|
|
174
|
+
function selfCataloguedEntry(catalogs, name) {
|
|
175
|
+
for (const [catalog, decl] of Object.entries(catalogs)) {
|
|
176
|
+
if (!Predicate.isObject(decl) || !Predicate.isObject(decl.packages)) continue;
|
|
177
|
+
if (!Object.hasOwn(decl.packages, name)) continue;
|
|
178
|
+
return `catalogs: "${name}" in catalog "${catalog}" is the plugin itself; a plugin must never serve its own name (every catalog rewrite would bump it, a release loop with no end). Remove the entry.`;
|
|
179
|
+
}
|
|
91
180
|
}
|
|
92
181
|
function normalizeField(input) {
|
|
93
182
|
if (isWrappedField(input)) {
|
|
@@ -106,8 +195,17 @@ function normalizeField(input) {
|
|
|
106
195
|
*
|
|
107
196
|
* @internal
|
|
108
197
|
*/
|
|
109
|
-
function freeze(
|
|
198
|
+
function freeze(authored) {
|
|
110
199
|
return Effect.gen(function* () {
|
|
200
|
+
const config = yield* Effect.try({
|
|
201
|
+
try: () => desugarSecondForms(authored, "config"),
|
|
202
|
+
catch: (error) => new ConfigError({ message: Fmt.describe(error) })
|
|
203
|
+
});
|
|
204
|
+
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" }));
|
|
205
|
+
const removed = removedEntryKey(config.catalogs);
|
|
206
|
+
if (removed !== void 0) return yield* Effect.fail(new ConfigError({ message: removed }));
|
|
207
|
+
const unknown = unknownCatalogKey(config.catalogs);
|
|
208
|
+
if (unknown !== void 0) return yield* Effect.fail(new ConfigError({ message: unknown }));
|
|
111
209
|
const base = {};
|
|
112
210
|
const manifest = {};
|
|
113
211
|
const normalized = yield* Effect.try({
|
|
@@ -115,6 +213,18 @@ function freeze(config) {
|
|
|
115
213
|
catch: (error) => new ConfigError({ message: Fmt.describe(error) })
|
|
116
214
|
});
|
|
117
215
|
base.catalogs = yield* validateField("catalogs", CatalogsSchema, normalized);
|
|
216
|
+
const { overrides: generated, members } = yield* Effect.try({
|
|
217
|
+
try: () => resolveFamilies(config.catalogs),
|
|
218
|
+
catch: (error) => new ConfigError({ message: Fmt.describe(error) })
|
|
219
|
+
});
|
|
220
|
+
const authoredOverrides = normalizeField(config.overrides).value;
|
|
221
|
+
if (Predicate.isObject(authoredOverrides) && !Array.isArray(authoredOverrides)) {
|
|
222
|
+
const contradiction = contradictingOverride(authoredOverrides, members);
|
|
223
|
+
if (contradiction !== void 0) return yield* Effect.fail(new ConfigError({ message: contradiction }));
|
|
224
|
+
}
|
|
225
|
+
const orphan = orphanedWorkspaceEntry(config.catalogs, config.sync);
|
|
226
|
+
if (orphan !== void 0) return yield* Effect.fail(new ConfigError({ message: orphan }));
|
|
227
|
+
const hasGenerated = Object.keys(generated).length > 0;
|
|
118
228
|
const exactCatalogs = Object.entries(config.catalogs).flatMap(([name, decl]) => decl?.exact === true && normalized[`${name}:exact`] !== void 0 ? [name] : []);
|
|
119
229
|
manifest.catalogs = {
|
|
120
230
|
strategy: "catalogs",
|
|
@@ -122,6 +232,8 @@ function freeze(config) {
|
|
|
122
232
|
...exactCatalogs.length > 0 ? { options: { exactCatalogs } } : {}
|
|
123
233
|
};
|
|
124
234
|
if (typeof config.name !== "string" || config.name.trim() === "") return yield* Effect.fail(new ConfigError({ message: "Config `name` is required and must be a non-empty string" }));
|
|
235
|
+
const self = selfCataloguedEntry(config.catalogs, config.name);
|
|
236
|
+
if (self !== void 0) return yield* Effect.fail(new ConfigError({ message: self }));
|
|
125
237
|
const declared = config;
|
|
126
238
|
for (const [field, why] of Object.entries(REMOVED_SETTINGS)) if (Object.hasOwn(declared, field) && declared[field] !== void 0) return yield* Effect.fail(new ConfigError({ message: `\`${field}\` is not a pnpm 12 setting: ${why}` }));
|
|
127
239
|
for (const [field, value] of Object.entries(declared)) {
|
|
@@ -130,28 +242,21 @@ function freeze(config) {
|
|
|
130
242
|
}
|
|
131
243
|
const directiveError = (error) => new ConfigError({ message: Fmt.describe(error) });
|
|
132
244
|
for (const [field, reg] of Object.entries(FIELD_REGISTRY)) {
|
|
133
|
-
if (field === "catalogs") continue;
|
|
245
|
+
if (field === "catalogs" || field === "catalog") continue;
|
|
134
246
|
let raw = config[field];
|
|
135
|
-
if (raw === void 0 && field === "overrides" &&
|
|
247
|
+
if (raw === void 0 && field === "overrides" && hasGenerated) raw = {};
|
|
136
248
|
if (raw === void 0) continue;
|
|
137
249
|
const decl = normalizeField(raw);
|
|
138
250
|
base[field] = yield* validateField(field, FIELD_SCHEMAS[field], field === "peerDependencyRules" ? yield* Effect.try({
|
|
139
251
|
try: () => resolvePeerDependencyRules(decl.value, config.catalogs),
|
|
140
252
|
catch: directiveError
|
|
141
|
-
}) : field === "overrides" ?
|
|
142
|
-
try: () => resolveOverrides(decl.value, config.overridesFromCatalogs, config.catalogs),
|
|
143
|
-
catch: directiveError
|
|
144
|
-
}) : decl.value);
|
|
253
|
+
}) : field === "overrides" && hasGenerated && Predicate.isObject(decl.value) && !Array.isArray(decl.value) ? mergeOverrides(decl.value, generated) : decl.value);
|
|
145
254
|
manifest[field] = {
|
|
146
255
|
strategy: reg.strategy,
|
|
147
256
|
enforcement: decl.enforcement ?? reg.enforcement,
|
|
148
257
|
...decl.options ? { options: decl.options } : {}
|
|
149
258
|
};
|
|
150
259
|
}
|
|
151
|
-
base.catalogs = yield* Effect.try({
|
|
152
|
-
try: () => pinCatalogs(base.catalogs, base.overrides, config.overridesFromCatalogs, config.catalogs),
|
|
153
|
-
catch: directiveError
|
|
154
|
-
});
|
|
155
260
|
return {
|
|
156
261
|
base,
|
|
157
262
|
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(
|
|
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
|
-
-
|
|
26
|
-
`
|
|
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,40 +9,141 @@ 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
|
|
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
|
|
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`.
|
|
26
|
-
|
|
27
|
-
and `sync` re-derive
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
The derived peer takes `dependency`'s operator; beside an exact
|
|
65
|
+
`dependency` (every locked family member) it keeps the operator `value`
|
|
66
|
+
already carries, so write the floor as a range (`~4.1.0`, `^0.74.0`). A
|
|
67
|
+
bare floor version (`4.1.0`) under `lock-minor` is drift, and the next run
|
|
68
|
+
that moves the entry rewrites it to `~4.1.0`.
|
|
69
|
+
- An `interop` member with `source: "workspace"` constrains its group
|
|
70
|
+
through the `peerDependencies` in its own `package.json`, not the
|
|
71
|
+
registry's. Only peers written as semver ranges count; `catalog:` and
|
|
72
|
+
`workspace:` peers are ignored.
|
|
73
|
+
- `source: "workspace"` marks a package of this monorepo. `sync` moves it,
|
|
74
|
+
reading the next release version from manifests plus pending changesets.
|
|
75
|
+
`"npm"` (the default) is `upgrade`'s.
|
|
76
|
+
- Never write `range`, an entry-level `strategy` or `source: "registry"`:
|
|
77
|
+
the build fails naming `dependency`, `peer.strategy` and `"npm"`.
|
|
78
|
+
|
|
79
|
+
## Who moves an entry
|
|
80
|
+
|
|
81
|
+
- `upgrade` moves npm entries. It shows a workspace entry read-only and
|
|
82
|
+
never moves it.
|
|
83
|
+
- `sync` moves workspace entries, in every catalog of `sync.catalogs`, and
|
|
84
|
+
leaves npm entries alone, ripples included.
|
|
85
|
+
- Every workspace entry's catalog needs a `sync` pair. A workspace entry in a
|
|
86
|
+
catalog no pair owns, or any workspace entry with no `sync` block, fails the
|
|
87
|
+
build and every install. Add `{ catalog, members: { scope } }` to
|
|
88
|
+
`sync.catalogs`, or set `source: "npm"`.
|
|
89
|
+
- Never edit a workspace entry's `dependency` by hand. `sync` owns it.
|
|
90
|
+
- Add every publishable workspace member in a pair's `members.scope` to that
|
|
91
|
+
pair's catalog with `source: "workspace"`, or leave it out explicitly with
|
|
92
|
+
`members.exclude`. The membership gate fails otherwise, an npm entry for a
|
|
93
|
+
member included, and so does a package two pairs' scopes both match.
|
|
94
|
+
|
|
95
|
+
## Families lock a release line
|
|
96
|
+
|
|
97
|
+
A family locks entries of one catalog that move together, only when asked:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
catalogs: {
|
|
101
|
+
effect: {
|
|
102
|
+
packages: {
|
|
103
|
+
effect: "4.1.7",
|
|
104
|
+
"@effect/platform-node": "4.1.7",
|
|
105
|
+
"@effect/tsgo": "0.6.0",
|
|
106
|
+
},
|
|
107
|
+
families: [
|
|
108
|
+
{ name: "effect", members: ["effect", "@effect/*"], exclude: ["@effect/tsgo"], owners: ["@acme/*"] },
|
|
109
|
+
{ name: "tsgo", members: ["@effect/tsgo"] },
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- `members` and `exclude` are exact names or globs over that catalog's
|
|
116
|
+
entries; `exclude` wins. A name that is no entry, or a glob that matches
|
|
117
|
+
none, fails the build. A new entry matching a glob joins the family.
|
|
118
|
+
- Every member's `dependency` is one exact version (`4.1.7`, not `^4.1.7`),
|
|
119
|
+
and never `source: "workspace"`. Members need not share a version.
|
|
120
|
+
- A package belongs to one family. A family `name` is unique across the
|
|
121
|
+
whole config, not only within its catalog.
|
|
122
|
+
- Each owner glob adds `"<owner>><member>": "<version>"` to `overrides`.
|
|
123
|
+
It pins the owner's regular dependency edges only: pnpm never overrides a
|
|
124
|
+
peer edge, so a member the owner reaches as a peer is fixed by the
|
|
125
|
+
consumer's own `catalog:<name>` dependency. Nothing is pinned graph-wide.
|
|
126
|
+
An authored `overrides` selector wins over a generated one.
|
|
127
|
+
- `upgrade --yes` and `--check` skip members; `--check` lists a newer member
|
|
128
|
+
as informational and still exits 0. A member's peer is skipped with it: a
|
|
129
|
+
family's peers re-derive only on a `--family` run. `upgrade --yes --family <name>`
|
|
130
|
+
(repeatable) moves each member to its newest version in its breaking line
|
|
131
|
+
(the major, or the minor on 0.x). That moves versions, so it is the user's
|
|
132
|
+
to run. A 0.0.x member never moves under `--family` (`^0.0.3` admits only
|
|
133
|
+
`0.0.3`); it moves only when the user picks a version in the interactive
|
|
134
|
+
table.
|
|
135
|
+
- `overridesFromCatalogs` no longer exists and fails the build. Declare a
|
|
136
|
+
family with `owners`, or write `overrides`.
|
|
38
137
|
|
|
39
138
|
## Never put the plugin in its own catalog
|
|
40
139
|
|
|
41
140
|
The plugin package must never appear in any catalog it serves. Every
|
|
42
141
|
catalog rewrite bumps the plugin; a catalogued plugin would then move its
|
|
43
142
|
own catalog, write another changeset and bump again, a release loop that
|
|
44
|
-
never ends.
|
|
45
|
-
|
|
143
|
+
never ends. The build enforces it: an entry under the plugin's own `name`
|
|
144
|
+
in any catalog's `packages`, whatever its `source`, fails with
|
|
145
|
+
`catalogs: "<name>" in catalog "<catalog>" is the plugin itself`. Remove the
|
|
146
|
+
entry, and leave a comment at the catalog saying the omission is deliberate.
|
|
46
147
|
|
|
47
148
|
## Bundle every import; declare none
|
|
48
149
|
|
|
@@ -66,6 +167,18 @@ Read-only forms are fine: `pnpm:preview`, `upgrade --check`,
|
|
|
66
167
|
|
|
67
168
|
## Union and map fields keep unmanaged entries on export
|
|
68
169
|
|
|
170
|
+
`export` writes the default catalog under the key the consumer's
|
|
171
|
+
`pnpm-workspace.yaml` already uses (flat `catalog`, nested `catalog` with
|
|
172
|
+
sub-keys, or `catalogs.default`; neither: `catalogs.default`), never both.
|
|
173
|
+
Nested `overrides` in the file stays nested. The default catalog merges per
|
|
174
|
+
package with the file's own entries: the managed value wins on a shared key,
|
|
175
|
+
and entries only the file holds stay. Named catalogs merge the same way, as
|
|
176
|
+
an install does; `local: { catalogs: { strategy: "rewrite" } }` makes each
|
|
177
|
+
managed named catalog replace the file's by name instead. `export` never
|
|
178
|
+
deletes a catalog only the file holds, and a package the plugin stops
|
|
179
|
+
serving inside a catalog it still serves stays in the file until it is
|
|
180
|
+
removed by hand or by a `rewrite`.
|
|
181
|
+
|
|
69
182
|
For fields whose runtime strategy is a union (`publicHoistPattern`,
|
|
70
183
|
`hoistPattern`, `minimumReleaseAgeExclude`, `trustPolicyExclude`,
|
|
71
184
|
`supportedArchitectures`, `auditConfig`, `ignoredOptionalDependencies`,
|