rolldown-pnpm-config 3.2.1 → 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.
- 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 +333 -135
- package/cli/discover.js +134 -28
- package/cli/drift.js +1 -1
- package/cli/edits.js +8 -17
- package/cli/effective.js +119 -4
- package/cli/interop.js +7 -15
- package/cli/local-merge.js +4 -1
- package/cli/plan.js +8 -3
- 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 +42 -6
- 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/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 +122 -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 +109 -12
- package/skills/rolldown-pnpm-config/references/options.md +126 -47
- package/skills/rolldown-pnpm-config/references/sync.md +32 -21
- package/skills/rolldown-pnpm-config/references/wiring.md +10 -8
- package/plugin/overrides-from-catalogs.js +0 -151
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rolldown-pnpm-config",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A dogfooding example of our plugin",
|
|
6
6
|
"repository": {
|
|
@@ -36,20 +36,20 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@effect/platform-node": "4.1.7",
|
|
39
|
-
"@effected/changesets": "0.
|
|
39
|
+
"@effected/changesets": "0.12.0",
|
|
40
40
|
"@effected/cli-kit": "0.34.0",
|
|
41
41
|
"@effected/env": "0.12.0",
|
|
42
|
-
"@effected/files": "0.
|
|
42
|
+
"@effected/files": "0.7.0",
|
|
43
43
|
"@effected/glob": "0.23.1",
|
|
44
44
|
"@effected/npm": "0.35.1",
|
|
45
|
-
"@effected/pnpm": "0.
|
|
45
|
+
"@effected/pnpm": "0.2.0",
|
|
46
46
|
"@effected/semver": "0.24.0",
|
|
47
47
|
"@effected/walker": "0.33.0",
|
|
48
|
-
"@effected/workspaces": "0.49.
|
|
48
|
+
"@effected/workspaces": "0.49.6",
|
|
49
49
|
"@effected/yaml": "0.31.0",
|
|
50
50
|
"effect": "4.1.7",
|
|
51
51
|
"ink": "^8.0.0",
|
|
52
|
-
"oxc-parser": "^0.
|
|
52
|
+
"oxc-parser": "^0.161.0",
|
|
53
53
|
"react": "^19.3.1"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VersionSpecifier } from "@effected/semver";
|
|
2
2
|
import { Predicate, Result } from "effect";
|
|
3
|
-
import {
|
|
3
|
+
import { dependencyOf } from "../catalogs.js";
|
|
4
4
|
import { bareVersion } from "../semver-util.js";
|
|
5
5
|
|
|
6
6
|
// src/plugin/allowed-versions.ts
|
|
@@ -21,11 +21,11 @@ function deriveOne(catalogs, { catalog, peer, prefix }) {
|
|
|
21
21
|
if (decl === void 0) throw new Error(`allowedVersionsFromCatalogs: catalog "${catalog}" is not declared`);
|
|
22
22
|
const peerSpec = decl.packages[peer];
|
|
23
23
|
if (peerSpec === void 0) throw new Error(`allowedVersionsFromCatalogs: peer "${peer}" is not in catalog "${catalog}"`);
|
|
24
|
-
const value = applyPrefix(
|
|
24
|
+
const value = applyPrefix(dependencyOf(peerSpec), prefix);
|
|
25
25
|
const table = {};
|
|
26
26
|
for (const [name, spec] of Object.entries(decl.packages)) {
|
|
27
27
|
if (name === peer) continue;
|
|
28
|
-
const range =
|
|
28
|
+
const range = dependencyOf(spec);
|
|
29
29
|
if (!isExactVersion(range)) continue;
|
|
30
30
|
table[`${name}@${range}>${peer}`] = value;
|
|
31
31
|
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { GlobPattern } from "@effected/glob";
|
|
2
|
+
import { OverrideKey } from "@effected/pnpm";
|
|
3
|
+
import { Range, SemVer, VersionSpecifier } from "@effected/semver";
|
|
4
|
+
import { Option, Result } from "effect";
|
|
5
|
+
import { dependencyOf, sourceOf } from "../catalogs.js";
|
|
6
|
+
|
|
7
|
+
// src/plugin/families.ts
|
|
8
|
+
/**
|
|
9
|
+
* The entries one `members` or `exclude` list selects. Each problem (an
|
|
10
|
+
* invalid glob, an exact name that is no entry, a glob that matches none) is
|
|
11
|
+
* handed to `problem`: the build throws on it, so a typo fails instead of
|
|
12
|
+
* silently shrinking the family, while the CLI's static reading skips it.
|
|
13
|
+
*/
|
|
14
|
+
function select(patterns, entries, catalog, problem, list) {
|
|
15
|
+
const selected = /* @__PURE__ */ new Set();
|
|
16
|
+
for (const pattern of patterns) {
|
|
17
|
+
const compiled = GlobPattern.compileResult(pattern);
|
|
18
|
+
if (Result.isFailure(compiled)) {
|
|
19
|
+
problem(`${list} "${pattern}" is not a valid glob: ${compiled.failure.message}`);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const glob = compiled.success;
|
|
23
|
+
if (!glob.hasMagic) {
|
|
24
|
+
if (entries.includes(pattern)) selected.add(pattern);
|
|
25
|
+
else problem(`${list} "${pattern}" is not an entry of catalog "${catalog}"`);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const matched = entries.filter((name) => glob.matches(name));
|
|
29
|
+
if (matched.length === 0) problem(`${list} glob "${pattern}" matches no entry of catalog "${catalog}"`);
|
|
30
|
+
for (const name of matched) selected.add(name);
|
|
31
|
+
}
|
|
32
|
+
return selected;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The package names of one catalog that each family claims, keyed by package:
|
|
36
|
+
* `members` expanded over `entries`, less `exclude`. Tolerant by design: an
|
|
37
|
+
* invalid glob or a name that is no entry selects nothing, because the CLI
|
|
38
|
+
* reads `families` statically and the build, not the CLI, reports the
|
|
39
|
+
* mistake. A package claimed twice keeps the first family; the build refuses
|
|
40
|
+
* that config anyway.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
function familyMembership(families, entries) {
|
|
45
|
+
const out = /* @__PURE__ */ new Map();
|
|
46
|
+
const ignore = () => {};
|
|
47
|
+
for (const family of families) {
|
|
48
|
+
const excluded = select(family.exclude ?? [], entries, "", ignore, "exclude");
|
|
49
|
+
for (const name of select(family.members, entries, "", ignore, "member")) if (!excluded.has(name) && !out.has(name)) out.set(name, family.name);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** The plain version an exact dependency names, or `null` for any range, tag or operator. */
|
|
54
|
+
function exactVersionOf(dependency) {
|
|
55
|
+
const parsed = Result.getOrNull(VersionSpecifier.parseResult(dependency));
|
|
56
|
+
return parsed === null || parsed.operator !== "" ? null : parsed.version.toString();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolve every catalog's `families`: expand `members` and `exclude` over the
|
|
60
|
+
* catalog's entries, check each member is locked (exact, not a workspace
|
|
61
|
+
* entry, in one family only), and generate one owner-scoped override per
|
|
62
|
+
* owner glob and member. Pure; throws an `Error` naming the catalog and
|
|
63
|
+
* family on any violation, which freeze reports as a `ConfigError`.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* Owners are emitted as pnpm parent selectors written as authored, globs
|
|
67
|
+
* included: pnpm 12.24 matches `own-*>is-number` against a parent named
|
|
68
|
+
* `own-a` (measured), so no expansion is needed. The override pins regular
|
|
69
|
+
* dependency edges only; pnpm never applies one to a peer edge.
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
function resolveFamilies(catalogs) {
|
|
74
|
+
const members = /* @__PURE__ */ new Map();
|
|
75
|
+
const overrides = {};
|
|
76
|
+
const names = /* @__PURE__ */ new Map();
|
|
77
|
+
for (const [catalog, decl] of Object.entries(catalogs)) {
|
|
78
|
+
if (typeof decl !== "object" || decl === null || typeof decl.packages !== "object" || decl.packages === null) continue;
|
|
79
|
+
if (decl.families === void 0) continue;
|
|
80
|
+
if (!Array.isArray(decl.families)) throw new Error(`catalogs: families of catalog "${catalog}" is not a list`);
|
|
81
|
+
const entries = Object.keys(decl.packages);
|
|
82
|
+
for (const family of decl.families) {
|
|
83
|
+
const at = `catalogs: family "${family?.name}" in catalog "${catalog}"`;
|
|
84
|
+
if (typeof family?.name !== "string" || family.name === "") throw new Error(`catalogs: a family in catalog "${catalog}" has no name`);
|
|
85
|
+
const declaredIn = names.get(family.name);
|
|
86
|
+
if (declaredIn === catalog) throw new Error(`${at}: family "${family.name}" is declared twice`);
|
|
87
|
+
if (declaredIn !== void 0) throw new Error(`catalogs: family "${family.name}" is declared in catalog "${declaredIn}" and catalog "${catalog}"; a family name is unique across the config`);
|
|
88
|
+
names.set(family.name, catalog);
|
|
89
|
+
for (const key of [
|
|
90
|
+
"members",
|
|
91
|
+
"exclude",
|
|
92
|
+
"owners"
|
|
93
|
+
]) {
|
|
94
|
+
if (key !== "members" && family[key] === void 0) continue;
|
|
95
|
+
if (!Array.isArray(family[key])) throw new Error(`${at}: ${key} is not a list`);
|
|
96
|
+
}
|
|
97
|
+
const fail = (message) => {
|
|
98
|
+
throw new Error(`${at}: ${message}`);
|
|
99
|
+
};
|
|
100
|
+
const excluded = select(family.exclude ?? [], entries, catalog, fail, "exclude");
|
|
101
|
+
const chosen = [...select(family.members, entries, catalog, fail, "member")].filter((name) => !excluded.has(name));
|
|
102
|
+
if (chosen.length === 0) throw new Error(`${at}: the family has no members once exclude applies`);
|
|
103
|
+
const locked = [];
|
|
104
|
+
for (const name of chosen) {
|
|
105
|
+
const spec = decl.packages[name];
|
|
106
|
+
const prior = members.get(name);
|
|
107
|
+
if (prior !== void 0) throw new Error(`catalogs: "${name}" is in family "${prior.family}" (catalog "${prior.catalog}") and family "${family.name}" (catalog "${catalog}"); a package belongs to one family`);
|
|
108
|
+
if (sourceOf(spec) === "workspace") throw new Error(`${at}: member "${name}" in catalog "${catalog}" has source "workspace", which sync moves; a locked family member cannot be a workspace entry`);
|
|
109
|
+
const dependency = dependencyOf(spec);
|
|
110
|
+
const version = exactVersionOf(dependency);
|
|
111
|
+
if (version === null) throw new Error(`${at}: member "${name}" has dependency "${dependency}", which is not an exact version; a family member must be exact`);
|
|
112
|
+
members.set(name, {
|
|
113
|
+
catalog,
|
|
114
|
+
family: family.name,
|
|
115
|
+
version
|
|
116
|
+
});
|
|
117
|
+
locked.push([name, version]);
|
|
118
|
+
}
|
|
119
|
+
for (const owner of family.owners ?? []) for (const [name, version] of locked) overrides[`${owner}>${name}`] = version;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
members,
|
|
124
|
+
overrides
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The canonical spelling of an `overrides` key, so `" own>effect"` and
|
|
129
|
+
* `"own>effect"` are recognised as one selector; a key pnpm cannot parse is
|
|
130
|
+
* kept as written (the settings schema refuses it later).
|
|
131
|
+
*/
|
|
132
|
+
function canonicalSelector(key) {
|
|
133
|
+
const parsed = OverrideKey.parseResult(key);
|
|
134
|
+
return Result.isSuccess(parsed) ? parsed.success.format() : key;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Merge the family-generated overrides under the authored ones. An authored
|
|
138
|
+
* selector wins even when it spells a generated one differently: the
|
|
139
|
+
* generated entry is dropped, so pnpm never sees one selector twice.
|
|
140
|
+
*
|
|
141
|
+
* @internal
|
|
142
|
+
*/
|
|
143
|
+
function mergeOverrides(authored, generated) {
|
|
144
|
+
const authoredSelectors = new Set(Object.keys(authored).map(canonicalSelector));
|
|
145
|
+
const kept = Object.entries(generated).filter(([key]) => !authoredSelectors.has(canonicalSelector(key)));
|
|
146
|
+
return {
|
|
147
|
+
...Object.fromEntries(kept),
|
|
148
|
+
...authored
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/** Whether a selector's range admits the version; a range or version that does not parse is assumed to. */
|
|
152
|
+
function reaches(range, version) {
|
|
153
|
+
const parsedRange = Range.parseResult(range);
|
|
154
|
+
const parsedVersion = SemVer.parseResult(version);
|
|
155
|
+
if (Result.isFailure(parsedRange) || Result.isFailure(parsedVersion)) return true;
|
|
156
|
+
return Range.satisfies(parsedVersion.success, parsedRange.success);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The first authored `overrides` entry that contradicts a family: a global
|
|
160
|
+
* selector (no parent) whose target is a family member and whose value is not
|
|
161
|
+
* that member's exact version, as a message naming the selector, the family
|
|
162
|
+
* and the version, or `undefined` when there is none. A global override
|
|
163
|
+
* applies to every edge, the consumer's own `catalog:` dependency included, so
|
|
164
|
+
* it would serve a version the family does not lock. A parent-scoped selector
|
|
165
|
+
* (`@effect/platform-node@4.0.0-rc.118>@effect/platform-node-shared`) is the
|
|
166
|
+
* author's deliberate exception for one parent and is never refused; a key
|
|
167
|
+
* pnpm cannot parse is left to the settings schema. A target whose version
|
|
168
|
+
* range excludes the member's locked version (`effect@3` over 4.1.7) can never
|
|
169
|
+
* reach the locked copy and is not refused.
|
|
170
|
+
*
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
function contradictingOverride(authored, members) {
|
|
174
|
+
for (const [key, value] of Object.entries(authored)) {
|
|
175
|
+
const parsed = OverrideKey.parseResult(key);
|
|
176
|
+
if (Result.isFailure(parsed) || Option.isSome(parsed.success.parent)) continue;
|
|
177
|
+
const member = members.get(parsed.success.target.name);
|
|
178
|
+
if (member === void 0 || value === member.version) continue;
|
|
179
|
+
const range = Option.getOrUndefined(parsed.success.target.range);
|
|
180
|
+
if (range !== void 0 && !reaches(range, member.version)) continue;
|
|
181
|
+
return `overrides: "${key}": "${value}" pins family member "${parsed.success.target.name}" on every edge, but family "${member.family}" (catalog "${member.catalog}") locks it at ${member.version}: write "${member.version}", or scope the override to a parent (\`<parent>>${parsed.success.target.name}\`)`;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export { contradictingOverride, familyMembership, mergeOverrides, resolveFamilies };
|
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,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
|
-
*
|
|
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
|
+
}
|
|
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(
|
|
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" &&
|
|
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" ?
|
|
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(
|
|
484
|
+
const WORKSPACE_FIELDS = new Set(MANAGED_FIELDS.filter(PnpmSettingsCatalog.isWorkspaceFileSetting));
|
|
473
485
|
|
|
474
486
|
export { FIELD_REGISTRY, FIELD_SCHEMAS, MANAGED_FIELDS, WORKSPACE_FIELDS };
|