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/cli/discover.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Data } from "effect";
|
|
2
2
|
import { parseSync } from "oxc-parser";
|
|
3
3
|
import { REWRITABLE_RANGE_RE } from "../catalogs.js";
|
|
4
|
+
import { familyMembership } from "../plugin/families.js";
|
|
4
5
|
import { findPluginArg, keyName, prop } from "./ast.js";
|
|
5
6
|
|
|
6
7
|
// src/cli/discover.ts
|
|
@@ -10,6 +11,64 @@ import { findPluginArg, keyName, prop } from "./ast.js";
|
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
13
|
var DiscoverError = class extends Data.TaggedError("DiscoverError") {};
|
|
14
|
+
/**
|
|
15
|
+
* The string literals of an array literal. `complete` is false when the list
|
|
16
|
+
* is not an array literal or holds anything else (a spread, an identifier, a
|
|
17
|
+
* call), since the names behind it cannot be known statically.
|
|
18
|
+
*/
|
|
19
|
+
function stringList(node) {
|
|
20
|
+
if (node === void 0) return {
|
|
21
|
+
values: [],
|
|
22
|
+
complete: true
|
|
23
|
+
};
|
|
24
|
+
if (node.type !== "ArrayExpression") return {
|
|
25
|
+
values: [],
|
|
26
|
+
complete: false
|
|
27
|
+
};
|
|
28
|
+
const elements = node.elements ?? [];
|
|
29
|
+
const values = elements.flatMap((el) => el?.type === "Literal" && typeof el.value === "string" ? [el.value] : []);
|
|
30
|
+
return {
|
|
31
|
+
values,
|
|
32
|
+
complete: values.length === elements.length
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Read one catalog's `families` literal: each family whose `name` is a string
|
|
37
|
+
* literal, with the string literals of its `members` and `exclude`. A family
|
|
38
|
+
* written any other way is not read (the build still checks it), and
|
|
39
|
+
* `complete` is false so a caller can say the list could not be read
|
|
40
|
+
* statically rather than that it declares nothing.
|
|
41
|
+
*/
|
|
42
|
+
function readFamilies(decl) {
|
|
43
|
+
const list = prop(decl, "families");
|
|
44
|
+
if (list === void 0) return {
|
|
45
|
+
families: [],
|
|
46
|
+
complete: true
|
|
47
|
+
};
|
|
48
|
+
if (list.type !== "ArrayExpression") return {
|
|
49
|
+
families: [],
|
|
50
|
+
complete: false
|
|
51
|
+
};
|
|
52
|
+
let complete = true;
|
|
53
|
+
return {
|
|
54
|
+
families: (list.elements ?? []).flatMap((el) => {
|
|
55
|
+
const name = el?.type === "ObjectExpression" ? prop(el, "name") : void 0;
|
|
56
|
+
if (el?.type !== "ObjectExpression" || name?.type !== "Literal" || typeof name.value !== "string") {
|
|
57
|
+
complete = false;
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
const members = stringList(prop(el, "members"));
|
|
61
|
+
const exclude = stringList(prop(el, "exclude"));
|
|
62
|
+
if (!members.complete || !exclude.complete) complete = false;
|
|
63
|
+
return [{
|
|
64
|
+
name: name.value,
|
|
65
|
+
members: members.values,
|
|
66
|
+
exclude: exclude.values
|
|
67
|
+
}];
|
|
68
|
+
}),
|
|
69
|
+
complete
|
|
70
|
+
};
|
|
71
|
+
}
|
|
13
72
|
function operatorOf(range) {
|
|
14
73
|
if (range.startsWith("^")) return "^";
|
|
15
74
|
if (range.startsWith("~")) return "~";
|
|
@@ -17,10 +76,22 @@ function operatorOf(range) {
|
|
|
17
76
|
}
|
|
18
77
|
/**
|
|
19
78
|
* Statically discover the catalog version literals in a config source. Locates
|
|
20
|
-
* the single `PnpmConfigPlugin(...)` call and walks `.catalogs.<name>.packages
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
79
|
+
* the single `PnpmConfigPlugin(...)` call and walks `.catalogs.<name>.packages`
|
|
80
|
+
* plus the `catalog` property (flat, or under `entries`), reported as `default`.
|
|
81
|
+
* Each package whose `dependency` (or bare string) is a simple-operator string
|
|
82
|
+
* literal yields a CatalogEntry with byte-offset spans, reading `peer` as a
|
|
83
|
+
* hand-set string or as `{ value, strategy }` (the span then covers `value`
|
|
84
|
+
* alone) and the entry's `source`; anything else (computed value, complex
|
|
85
|
+
* range, a peer with no string literal, an entry still written with `range`)
|
|
86
|
+
* is reported in `skipped` as
|
|
87
|
+
* `<catalog>.<pkg>` and never throws.
|
|
88
|
+
* Each entry also carries the `family` that locks it, read statically from
|
|
89
|
+
* its catalog's `families` (string literals only) and expanded over the
|
|
90
|
+
* catalog's package names by `familyMembership`; `families` names every
|
|
91
|
+
* family so read, in source order, so `--family` can tell a typo, and
|
|
92
|
+
* `unreadFamilies` names each catalog whose `families` could not be read
|
|
93
|
+
* statically: a non-literal `families`, family or name, or a `members` or
|
|
94
|
+
* `exclude` list with any non-literal element.
|
|
24
95
|
* `catalogs` names every declared catalog in source order, including one
|
|
25
96
|
* that yields no entries, so `--catalog` can tell an empty catalog from a
|
|
26
97
|
* typo. `skippedRefs` carries the same skips as `{ catalog, pkg }` pairs, so
|
|
@@ -36,25 +107,9 @@ function discoverCatalogEntries(source, filename) {
|
|
|
36
107
|
const entries = [];
|
|
37
108
|
const skippedRefs = [];
|
|
38
109
|
const declared = [];
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
skippedRefs,
|
|
43
|
-
catalogs: declared
|
|
44
|
-
});
|
|
45
|
-
const arg = findPluginArg(program);
|
|
46
|
-
if (!arg) return finish();
|
|
47
|
-
const catalogs = prop(arg, "catalogs");
|
|
48
|
-
if (catalogs?.type !== "ObjectExpression") return finish();
|
|
49
|
-
for (const catProp of catalogs.properties ?? []) {
|
|
50
|
-
if (catProp.type !== "Property") continue;
|
|
51
|
-
const catalog = keyName(catProp.key);
|
|
52
|
-
if (catalog === void 0) continue;
|
|
53
|
-
declared.push(catalog);
|
|
54
|
-
const decl = catProp.value;
|
|
55
|
-
if (decl.type !== "ObjectExpression") continue;
|
|
56
|
-
const packages = prop(decl, "packages");
|
|
57
|
-
if (packages?.type !== "ObjectExpression") continue;
|
|
110
|
+
const declaredFamilies = [];
|
|
111
|
+
const unreadFamilies = [];
|
|
112
|
+
const walkPackages = (catalog, packages, membership = /* @__PURE__ */ new Map()) => {
|
|
58
113
|
for (const pkgProp of packages.properties ?? []) {
|
|
59
114
|
if (pkgProp.type !== "Property") continue;
|
|
60
115
|
const pkg = keyName(pkgProp.key);
|
|
@@ -66,14 +121,25 @@ function discoverCatalogEntries(source, filename) {
|
|
|
66
121
|
let source;
|
|
67
122
|
if (value.type === "Literal" && typeof value.value === "string") rangeNode = value;
|
|
68
123
|
else if (value.type === "ObjectExpression") {
|
|
69
|
-
const r = prop(value, "
|
|
124
|
+
const r = prop(value, "dependency");
|
|
70
125
|
if (r?.type === "Literal" && typeof r.value === "string") rangeNode = r;
|
|
71
126
|
const p = prop(value, "peer");
|
|
72
127
|
if (p?.type === "Literal" && typeof p.value === "string") peerNode = p;
|
|
73
|
-
|
|
74
|
-
|
|
128
|
+
else if (p?.type === "ObjectExpression") {
|
|
129
|
+
const v = prop(p, "value");
|
|
130
|
+
if (v?.type === "Literal" && typeof v.value === "string") peerNode = v;
|
|
131
|
+
const s = prop(p, "strategy");
|
|
132
|
+
if (s?.type === "Literal" && (s.value === "lock" || s.value === "lock-minor" || s.value === "interop")) strategy = s.value;
|
|
133
|
+
}
|
|
134
|
+
if (p !== void 0 && peerNode === void 0) {
|
|
135
|
+
skippedRefs.push({
|
|
136
|
+
catalog,
|
|
137
|
+
pkg
|
|
138
|
+
});
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
75
141
|
const src = prop(value, "source");
|
|
76
|
-
if (src?.type === "Literal" && (src.value === "
|
|
142
|
+
if (src?.type === "Literal" && (src.value === "npm" || src.value === "workspace")) source = src.value;
|
|
77
143
|
}
|
|
78
144
|
if (!rangeNode || !REWRITABLE_RANGE_RE.test(rangeNode.value)) {
|
|
79
145
|
skippedRefs.push({
|
|
@@ -83,6 +149,7 @@ function discoverCatalogEntries(source, filename) {
|
|
|
83
149
|
continue;
|
|
84
150
|
}
|
|
85
151
|
const currentRange = rangeNode.value;
|
|
152
|
+
const family = membership.get(pkg);
|
|
86
153
|
entries.push({
|
|
87
154
|
catalog,
|
|
88
155
|
pkg,
|
|
@@ -94,9 +161,48 @@ function discoverCatalogEntries(source, filename) {
|
|
|
94
161
|
span: [peerNode.start, peerNode.end]
|
|
95
162
|
} } : {},
|
|
96
163
|
...strategy ? { strategy } : {},
|
|
97
|
-
...source ? { source } : {}
|
|
164
|
+
...source ? { source } : {},
|
|
165
|
+
...family !== void 0 ? { family } : {}
|
|
98
166
|
});
|
|
99
167
|
}
|
|
168
|
+
};
|
|
169
|
+
const finish = () => ({
|
|
170
|
+
entries,
|
|
171
|
+
skipped: skippedRefs.map((r) => `${r.catalog}.${r.pkg}`),
|
|
172
|
+
skippedRefs,
|
|
173
|
+
catalogs: declared,
|
|
174
|
+
families: declaredFamilies,
|
|
175
|
+
unreadFamilies
|
|
176
|
+
});
|
|
177
|
+
const arg = findPluginArg(program);
|
|
178
|
+
if (!arg) return finish();
|
|
179
|
+
const catalogs = prop(arg, "catalogs");
|
|
180
|
+
if (catalogs?.type === "ObjectExpression") for (const catProp of catalogs.properties ?? []) {
|
|
181
|
+
if (catProp.type !== "Property") continue;
|
|
182
|
+
const catalog = keyName(catProp.key);
|
|
183
|
+
if (catalog === void 0) continue;
|
|
184
|
+
declared.push(catalog);
|
|
185
|
+
const decl = catProp.value;
|
|
186
|
+
if (decl.type !== "ObjectExpression") continue;
|
|
187
|
+
const packages = prop(decl, "packages");
|
|
188
|
+
if (packages?.type !== "ObjectExpression") continue;
|
|
189
|
+
const { families, complete } = readFamilies(decl);
|
|
190
|
+
declaredFamilies.push(...families.map((f) => f.name));
|
|
191
|
+
if (!complete) unreadFamilies.push(catalog);
|
|
192
|
+
const names = (packages.properties ?? []).flatMap((p) => {
|
|
193
|
+
const name = p.type === "Property" ? keyName(p.key) : void 0;
|
|
194
|
+
return name === void 0 ? [] : [name];
|
|
195
|
+
});
|
|
196
|
+
walkPackages(catalog, packages, familyMembership(families, names));
|
|
197
|
+
}
|
|
198
|
+
const defaultCatalog = prop(arg, "catalog");
|
|
199
|
+
if (defaultCatalog?.type === "ObjectExpression") {
|
|
200
|
+
const section = prop(defaultCatalog, "entries");
|
|
201
|
+
const packages = section === void 0 || section.type === "Literal" ? defaultCatalog : section.type === "ObjectExpression" ? section : void 0;
|
|
202
|
+
if (packages !== void 0) {
|
|
203
|
+
if (!declared.includes("default")) declared.push("default");
|
|
204
|
+
walkPackages("default", packages);
|
|
205
|
+
}
|
|
100
206
|
}
|
|
101
207
|
return finish();
|
|
102
208
|
}
|
package/cli/drift.js
CHANGED
|
@@ -12,14 +12,14 @@ import { derivePeerRange } from "./peer-range.js";
|
|
|
12
12
|
* GROUP-WISE by `interop.ts` from the resolved peerDependencies of the whole
|
|
13
13
|
* catalog group. Deriving one per package here would fall through to the
|
|
14
14
|
* lock-minor branch and report a bogus resync target, so interop entries are
|
|
15
|
-
* excluded — parity with
|
|
15
|
+
* excluded — parity with the peer-warning derivation in walk-plan.ts.
|
|
16
16
|
*
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
19
|
function detectPeerDrift(entry) {
|
|
20
20
|
return Effect.gen(function* () {
|
|
21
21
|
if (!entry.peer || !entry.strategy || entry.strategy === "interop") return null;
|
|
22
|
-
const { range: expected } = yield* derivePeerRange(entry.currentRange, entry.strategy);
|
|
22
|
+
const { range: expected } = yield* derivePeerRange(entry.currentRange, entry.strategy, entry.peer.value);
|
|
23
23
|
return expected === entry.peer.value ? null : expected;
|
|
24
24
|
});
|
|
25
25
|
}
|
package/cli/edits.js
CHANGED
|
@@ -4,8 +4,7 @@ import { versionKeyOf } from "./version-key.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* The edit constructors for one entry, each tagged with the entry's package
|
|
6
6
|
* and route-aware version key so `validateEdits` can check it against the
|
|
7
|
-
* registry before it is written. The single place that knows the
|
|
8
|
-
* syntax and the key routing — both the interactive and the `--yes` paths
|
|
7
|
+
* registry before it is written. The single place that knows the key routing — both the interactive and the `--yes` paths
|
|
9
8
|
* build their edits through it.
|
|
10
9
|
*
|
|
11
10
|
* @internal
|
|
@@ -13,7 +12,7 @@ import { versionKeyOf } from "./version-key.js";
|
|
|
13
12
|
function entryEdits(entry) {
|
|
14
13
|
const pkg = entry.pkg;
|
|
15
14
|
const versionKey = versionKeyOf(entry);
|
|
16
|
-
const
|
|
15
|
+
const peer = entry.peer;
|
|
17
16
|
return {
|
|
18
17
|
range: (value) => ({
|
|
19
18
|
span: entry.rangeSpan,
|
|
@@ -23,26 +22,19 @@ function entryEdits(entry) {
|
|
|
23
22
|
kind: "range",
|
|
24
23
|
value
|
|
25
24
|
}),
|
|
26
|
-
setPeer: (value) =>
|
|
27
|
-
span:
|
|
25
|
+
setPeer: peer === void 0 ? void 0 : (value) => ({
|
|
26
|
+
span: peer.span,
|
|
28
27
|
text: JSON.stringify(value),
|
|
29
28
|
pkg,
|
|
30
29
|
versionKey,
|
|
31
30
|
kind: "peer",
|
|
32
31
|
value
|
|
33
|
-
}
|
|
34
|
-
span: [insertAt, insertAt],
|
|
35
|
-
text: `, peer: ${JSON.stringify(value)}`,
|
|
36
|
-
pkg,
|
|
37
|
-
versionKey,
|
|
38
|
-
kind: "peer",
|
|
39
|
-
value
|
|
40
|
-
}
|
|
32
|
+
})
|
|
41
33
|
};
|
|
42
34
|
}
|
|
43
35
|
/**
|
|
44
36
|
* Convert resolved decisions into span edits. A chosen upgrade rewrites the
|
|
45
|
-
*
|
|
37
|
+
* dependency literal (and the existing peer literal when the candidate carries a
|
|
46
38
|
* recomputed peerRange). A keep with peer drift rewrites only the peer literal
|
|
47
39
|
* to the resync target.
|
|
48
40
|
*
|
|
@@ -58,9 +50,8 @@ function buildEdits(decisions) {
|
|
|
58
50
|
const { range, setPeer } = entryEdits(entry);
|
|
59
51
|
if (chosen.kind !== "keep") {
|
|
60
52
|
edits.push(range(chosen.range));
|
|
61
|
-
if (chosen.peerRange &&
|
|
62
|
-
} else if (
|
|
63
|
-
else if (!entry.peer && item.materializePeer) edits.push(setPeer(item.materializePeer));
|
|
53
|
+
if (chosen.peerRange && setPeer) edits.push(setPeer(chosen.peerRange));
|
|
54
|
+
} else if (setPeer && item.driftPeer) edits.push(setPeer(item.driftPeer));
|
|
64
55
|
}
|
|
65
56
|
return edits;
|
|
66
57
|
}
|
package/cli/effective.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Predicate } from "effect";
|
|
2
|
+
import { desugarSecondForms } from "../plugin/second-forms.js";
|
|
1
3
|
import { WORKSPACE_FIELDS } from "../registry.js";
|
|
2
4
|
import { excludeByRepo } from "../runtime/ctx.js";
|
|
3
|
-
import { MAP_EXPORT_FIELDS, UNION_EXPORT_FIELDS, applyLocalDirective } from "./local-merge.js";
|
|
5
|
+
import { MAP_EXPORT_FIELDS, UNION_EXPORT_FIELDS, applyLocalDirective, isLocalDirective } from "./local-merge.js";
|
|
4
6
|
|
|
5
7
|
// src/cli/effective.ts
|
|
6
8
|
/** Apply the manifest's excludeByRepo refine to publicHoistPattern, if present. */
|
|
@@ -9,6 +11,87 @@ function applyExcludeByRepo(out, manifest, rootName) {
|
|
|
9
11
|
const phl = out.publicHoistPattern;
|
|
10
12
|
if (byRepo && typeof byRepo === "object" && Array.isArray(phl)) out.publicHoistPattern = excludeByRepo(phl, { rootName }, byRepo);
|
|
11
13
|
}
|
|
14
|
+
/** `Predicate.isObject` already refuses arrays; this only narrows to a string-keyed record. */
|
|
15
|
+
const isMap = (v) => Predicate.isObject(v);
|
|
16
|
+
/** True when a `local.catalogs` value (a map of catalogs or an array of names) names `default`. */
|
|
17
|
+
function namesDefault(value) {
|
|
18
|
+
return Array.isArray(value) ? value.map(String).includes("default") : isMap(value) && value.default !== void 0;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Desugar `local`'s second forms in the plain-map shape `local.catalogs`
|
|
22
|
+
* already has. A `{ value, strategy, preserve }` directive on `overrides` or
|
|
23
|
+
* `catalogs` is desugared inside its `value`. `local.catalog` (bare or a
|
|
24
|
+
* directive) is desugared on its own and held apart: it acts on the default
|
|
25
|
+
* catalog only, after `local.catalogs` has been applied, so the two compose.
|
|
26
|
+
* Both naming the default catalog is refused.
|
|
27
|
+
*/
|
|
28
|
+
function desugarLocal(local) {
|
|
29
|
+
const directives = {};
|
|
30
|
+
const { catalog: rawCatalog, ...rest } = local;
|
|
31
|
+
const unwrapped = { ...rest };
|
|
32
|
+
for (const field of ["overrides", "catalogs"]) if (isLocalDirective(local[field])) {
|
|
33
|
+
const directive = local[field];
|
|
34
|
+
directives[field] = directive;
|
|
35
|
+
if ("value" in directive) unwrapped[field] = directive.value;
|
|
36
|
+
else delete unwrapped[field];
|
|
37
|
+
}
|
|
38
|
+
let defaultCatalog;
|
|
39
|
+
if (rawCatalog !== void 0 && rawCatalog !== null) {
|
|
40
|
+
const directive = isLocalDirective(rawCatalog) ? { ...rawCatalog } : { value: rawCatalog };
|
|
41
|
+
if (namesDefault(unwrapped.catalogs)) throw new Error("local: catalog and catalogs.default both declare the default catalog; keep one of them.");
|
|
42
|
+
if (directive.value !== void 0 && !Array.isArray(directive.value)) unwrapped.catalog = directive.value;
|
|
43
|
+
defaultCatalog = directive;
|
|
44
|
+
}
|
|
45
|
+
const catalogs = unwrapped.catalogs;
|
|
46
|
+
delete unwrapped.catalogs;
|
|
47
|
+
const fields = desugarSecondForms(unwrapped, "local", { catalogShape: "map" });
|
|
48
|
+
if (defaultCatalog !== void 0 && "catalog" in unwrapped) defaultCatalog.value = isMap(fields.catalogs) ? fields.catalogs.default : {};
|
|
49
|
+
delete fields.catalogs;
|
|
50
|
+
if (catalogs !== void 0) fields.catalogs = catalogs;
|
|
51
|
+
for (const [field, directive] of Object.entries(directives)) fields[field] = fields[field] === void 0 ? directive : {
|
|
52
|
+
...directive,
|
|
53
|
+
value: fields[field]
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
fields,
|
|
57
|
+
defaultCatalog
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The default catalog's packages after `local.catalog`, with the file's own
|
|
62
|
+
* entries kept under the result. Each strategy gives what it gave when
|
|
63
|
+
* `catalog` was a map field merged with the file:
|
|
64
|
+
* - `union` / `merge`: the local packages laid over the managed ones;
|
|
65
|
+
* - `difference`: the listed packages (an array of names, or a map's keys)
|
|
66
|
+
* removed from the managed and file entries together;
|
|
67
|
+
* - `rewrite`: the managed catalog alone, the file's own entries dropped;
|
|
68
|
+
* - a bare value: the managed catalog replaced by it.
|
|
69
|
+
* With no directive, or one with no value, the managed catalog passes through.
|
|
70
|
+
* `undefined` means nothing to write.
|
|
71
|
+
*/
|
|
72
|
+
function defaultCatalogOf(managed, directive, file) {
|
|
73
|
+
const keepFile = (value) => isMap(file) && (value === void 0 || isMap(value)) ? {
|
|
74
|
+
...file,
|
|
75
|
+
...value ?? {}
|
|
76
|
+
} : value;
|
|
77
|
+
const strategy = directive?.strategy === "merge" ? "union" : directive?.strategy;
|
|
78
|
+
const value = directive?.value;
|
|
79
|
+
if (strategy === "rewrite") return managed;
|
|
80
|
+
if (value === void 0) return keepFile(managed);
|
|
81
|
+
if (strategy === "union") return keepFile({
|
|
82
|
+
...isMap(managed) ? managed : {},
|
|
83
|
+
...isMap(value) ? value : {}
|
|
84
|
+
});
|
|
85
|
+
if (strategy === "difference") {
|
|
86
|
+
const base = keepFile(managed);
|
|
87
|
+
if (!isMap(base)) return void 0;
|
|
88
|
+
const out = { ...base };
|
|
89
|
+
const names = Array.isArray(value) ? value.map(String) : isMap(value) ? Object.keys(value) : [];
|
|
90
|
+
for (const name of names) delete out[name];
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
return keepFile(value);
|
|
94
|
+
}
|
|
12
95
|
/**
|
|
13
96
|
* Compute the effective workspace fields for THIS repo: managed base, then
|
|
14
97
|
* excludeByRepo on publicHoistPattern, then per-field local directives.
|
|
@@ -16,24 +99,69 @@ function applyExcludeByRepo(out, manifest, rootName) {
|
|
|
16
99
|
* Union- and map-strategy fields also keep the existing file's entries unless `rewrite`.
|
|
17
100
|
* Only `local` keys that are managed workspace settings apply: a plugin-only
|
|
18
101
|
* key (`localPatchesDir`) or any other non-setting never reaches the yaml.
|
|
102
|
+
* pnpm 12's nested `overrides` and `catalog` forms in `local` and in the file
|
|
103
|
+
* are desugared first, so every merge sees flat maps and the default catalog
|
|
104
|
+
* as `catalogs.default`; `respellForFile` writes them back in the file's form.
|
|
105
|
+
* Every managed catalog is laid over the file's own per package (managed wins
|
|
106
|
+
* on a shared key, a file-only package is kept), as install merges them: the
|
|
107
|
+
* default catalog after `local.catalog` acts on it, a named one after
|
|
108
|
+
* `local.catalogs` does. `local.catalogs: { strategy: "rewrite" }` opts the
|
|
109
|
+
* named catalogs back into replace-by-name.
|
|
110
|
+
*
|
|
111
|
+
* @throws `Error` when `local` sets a nested sub-key beside its twin setting,
|
|
112
|
+
* when `local` or the file sets `catalog` beside `catalogs.default`, or when
|
|
113
|
+
* pnpm would refuse a section option.
|
|
19
114
|
*
|
|
20
115
|
* @internal
|
|
21
116
|
*/
|
|
22
117
|
function effectiveManaged(managed, local, parsed, manifest, rootName) {
|
|
23
118
|
const out = { ...managed };
|
|
24
119
|
applyExcludeByRepo(out, manifest, rootName);
|
|
25
|
-
const
|
|
26
|
-
|
|
120
|
+
const { fields: flatLocal, defaultCatalog } = local === void 0 ? {
|
|
121
|
+
fields: void 0,
|
|
122
|
+
defaultCatalog: void 0
|
|
123
|
+
} : desugarLocal(local);
|
|
124
|
+
const flatParsed = desugarSecondForms(parsed, "pnpm-workspace.yaml", {
|
|
125
|
+
catalogShape: "map",
|
|
126
|
+
twinConflict: "nestedWins"
|
|
127
|
+
});
|
|
128
|
+
const keepFileFields = [...UNION_EXPORT_FIELDS, ...MAP_EXPORT_FIELDS].filter((f) => f in out || f in flatParsed);
|
|
129
|
+
const localFields = Object.keys(flatLocal ?? {}).filter((f) => WORKSPACE_FIELDS.has(f));
|
|
27
130
|
const fields = /* @__PURE__ */ new Set([
|
|
28
131
|
"overrides",
|
|
29
132
|
...keepFileFields,
|
|
30
133
|
...localFields
|
|
31
134
|
]);
|
|
32
135
|
for (const field of fields) {
|
|
33
|
-
const next = applyLocalDirective(out[field],
|
|
136
|
+
const next = applyLocalDirective(out[field], flatLocal?.[field], flatParsed[field], field);
|
|
34
137
|
if (next === void 0) delete out[field];
|
|
35
138
|
else out[field] = next;
|
|
36
139
|
}
|
|
140
|
+
const catalogs = isMap(out.catalogs) ? out.catalogs : {};
|
|
141
|
+
const fileCatalogs = isMap(flatParsed.catalogs) ? flatParsed.catalogs : {};
|
|
142
|
+
if (catalogs.default !== void 0 || defaultCatalog !== void 0) {
|
|
143
|
+
const next = defaultCatalogOf(catalogs.default, defaultCatalog, fileCatalogs.default);
|
|
144
|
+
if (next !== void 0) out.catalogs = {
|
|
145
|
+
...catalogs,
|
|
146
|
+
default: next
|
|
147
|
+
};
|
|
148
|
+
else {
|
|
149
|
+
const { default: _, ...named } = catalogs;
|
|
150
|
+
if (Object.keys(named).length > 0) out.catalogs = named;
|
|
151
|
+
else delete out.catalogs;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!(isLocalDirective(flatLocal?.catalogs) && (flatLocal?.catalogs)?.strategy === "rewrite") && isMap(out.catalogs)) {
|
|
155
|
+
const next = {};
|
|
156
|
+
for (const [name, catalog] of Object.entries(out.catalogs)) {
|
|
157
|
+
const fileCatalog = fileCatalogs[name];
|
|
158
|
+
next[name] = name !== "default" && isMap(catalog) && isMap(fileCatalog) ? {
|
|
159
|
+
...fileCatalog,
|
|
160
|
+
...catalog
|
|
161
|
+
} : catalog;
|
|
162
|
+
}
|
|
163
|
+
out.catalogs = next;
|
|
164
|
+
}
|
|
37
165
|
return out;
|
|
38
166
|
}
|
|
39
167
|
/**
|
package/cli/interop.js
CHANGED
|
@@ -148,6 +148,33 @@ function resolveGroup(members, fetchPeer) {
|
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
|
+
* `resolver`, with each `workspace` member's peers read from its own manifest
|
|
152
|
+
* instead of the registry.
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* A workspace member's next release is usually unpublished, so the registry
|
|
156
|
+
* answers `{}` for it and its peers on the group's npm entries were never
|
|
157
|
+
* seen. The manifest is the next release, whatever version the group holds the
|
|
158
|
+
* member at. Only a peer written as a semver range is a constraint: a
|
|
159
|
+
* `catalog:` or `workspace:` peer follows the catalog or the workspace, so it
|
|
160
|
+
* is dropped rather than read as a range nothing satisfies. A name that is not
|
|
161
|
+
* a workspace package falls back to the registry.
|
|
162
|
+
*
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
function withWorkspacePeers(resolver, workspace, manifestPeers) {
|
|
166
|
+
if (workspace.size === 0) return resolver;
|
|
167
|
+
return { peerDependencies: (pkg, version) => {
|
|
168
|
+
const own = workspace.has(pkg) ? manifestPeers(pkg) : void 0;
|
|
169
|
+
if (own === void 0) return resolver.peerDependencies(pkg, version);
|
|
170
|
+
return Effect.succeed(Object.fromEntries(Object.entries(own).filter(([, range]) => parseRange(range) !== null)));
|
|
171
|
+
} };
|
|
172
|
+
}
|
|
173
|
+
/** The names of the workspace-sourced entries among `entries`. @internal */
|
|
174
|
+
function workspaceMembers(entries) {
|
|
175
|
+
return new Set(entries.filter((e) => e.source === "workspace").map((e) => e.pkg));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
151
178
|
* Fetch the peerDependencies needed to reconcile one catalog interop group,
|
|
152
179
|
* then run the pure resolve + floor derivation. Failures degrade to empty
|
|
153
180
|
* peerDeps (the member resolves at its ceiling).
|
|
@@ -193,13 +220,12 @@ function interopEntryChanged(e, result) {
|
|
|
193
220
|
if (`${e.operator}${version}` !== e.currentRange) return true;
|
|
194
221
|
const peer = result.peers.get(e.pkg);
|
|
195
222
|
if (peer === void 0) return false;
|
|
196
|
-
|
|
197
|
-
return true;
|
|
223
|
+
return e.peer !== void 0 && peer !== e.peer.value;
|
|
198
224
|
}
|
|
199
225
|
/**
|
|
200
226
|
* Build the span edits for one interop catalog group from its resolution: a
|
|
201
|
-
* range edit when the resolved version differs, and a peer edit that rewrites
|
|
202
|
-
* existing
|
|
227
|
+
* range edit when the resolved version differs, and a peer edit that rewrites
|
|
228
|
+
* the existing peer literal. An entry with no peer gets no peer edit.
|
|
203
229
|
*
|
|
204
230
|
* @internal
|
|
205
231
|
*/
|
|
@@ -214,19 +240,12 @@ function buildInteropEdits(entries, result) {
|
|
|
214
240
|
span: e.rangeSpan,
|
|
215
241
|
text: JSON.stringify(newRange)
|
|
216
242
|
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
text: JSON.stringify(peer)
|
|
222
|
-
});
|
|
223
|
-
else if (!e.peer) edits.push({
|
|
224
|
-
span: [at, at],
|
|
225
|
-
text: `, peer: ${JSON.stringify(peer)}`
|
|
226
|
-
});
|
|
227
|
-
}
|
|
243
|
+
if (peer !== void 0 && e.peer && peer !== e.peer.value) edits.push({
|
|
244
|
+
span: e.peer.span,
|
|
245
|
+
text: JSON.stringify(peer)
|
|
246
|
+
});
|
|
228
247
|
}
|
|
229
248
|
return edits;
|
|
230
249
|
}
|
|
231
250
|
|
|
232
|
-
export { buildInteropEdits, deriveFloors, interopEntryChanged, lowestVersion, makePeerFetcher, resolveGroup, runInterop };
|
|
251
|
+
export { buildInteropEdits, deriveFloors, interopEntryChanged, lowestVersion, makePeerFetcher, resolveGroup, runInterop, withWorkspacePeers, workspaceMembers };
|
package/cli/local-merge.js
CHANGED
|
@@ -31,10 +31,13 @@ const MAP_STRATEGIES = {
|
|
|
31
31
|
* round: the file is the base and the managed value is laid on top, so a
|
|
32
32
|
* managed change to a key the file holds is exported (install, where the
|
|
33
33
|
* consumer's value wins, freezes such a key after the first export).
|
|
34
|
+
* `catalog` is left out: it is desugared into `catalogs.default` before the
|
|
35
|
+
* merge, and `effectiveManaged` applies `local.catalog` to that catalog and
|
|
36
|
+
* keeps the file's own entries under it.
|
|
34
37
|
*/
|
|
35
38
|
const MAP_EXPORT_STRATEGIES = new Map(Object.entries(FIELD_REGISTRY).flatMap(([name, p]) => {
|
|
36
39
|
const strategy = MAP_STRATEGIES[p.strategy];
|
|
37
|
-
return strategy === void 0 ? [] : [[name, strategy]];
|
|
40
|
+
return strategy === void 0 || name === "catalog" ? [] : [[name, strategy]];
|
|
38
41
|
}));
|
|
39
42
|
/**
|
|
40
43
|
* Map fields (`mapChildWins` and `sectionMerge` in `FIELD_REGISTRY`) whose
|
package/cli/peer-range.js
CHANGED
|
@@ -14,10 +14,25 @@ const DERIVABLE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
14
14
|
"~",
|
|
15
15
|
""
|
|
16
16
|
]);
|
|
17
|
+
/** The range operator a peer literal already carries: `^`, `~`, or none. */
|
|
18
|
+
function operatorOf(peer) {
|
|
19
|
+
if (peer === void 0) return "";
|
|
20
|
+
const spec = Result.getOrNull(VersionSpecifier.parseResult(peer));
|
|
21
|
+
return spec !== null && (spec.operator === "^" || spec.operator === "~") ? spec.operator : "";
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
24
|
* Recompute a materialized peer range from a package range and a strategy.
|
|
19
25
|
* "lock" pins to the exact version; "lock-minor" floors the patch to .0.
|
|
20
|
-
*
|
|
26
|
+
*
|
|
27
|
+
* The operator comes from the dependency range when it has one (`^`/`~`).
|
|
28
|
+
* An exact dependency has none to give, and every locked-family member is
|
|
29
|
+
* exact, so the peer then keeps the operator `currentPeer` already carries:
|
|
30
|
+
* `4.1.7` beside `~4.1.0` derives `~4.1.0`, never the bare `4.1.0`. When
|
|
31
|
+
* neither carries one, "lock" stays exact (a pin on a pin), and "lock-minor"
|
|
32
|
+
* takes `~`, which holds the minor line on every major (a caret would admit
|
|
33
|
+
* only `0.0.0` on a 0.0.x line). A
|
|
34
|
+
* bare floor version is never a "lock-minor" result: it names one release,
|
|
35
|
+
* usually not the catalogued one, and often one that was never published.
|
|
21
36
|
*
|
|
22
37
|
* "lock" reuses the version text verbatim rather than rebuilding it from
|
|
23
38
|
* major.minor.patch, so prerelease and build identifiers survive intact
|
|
@@ -36,12 +51,13 @@ const DERIVABLE_OPERATORS = /* @__PURE__ */ new Set([
|
|
|
36
51
|
*
|
|
37
52
|
* @internal
|
|
38
53
|
*/
|
|
39
|
-
function derivePeerRange(range, strategy) {
|
|
54
|
+
function derivePeerRange(range, strategy, currentPeer) {
|
|
40
55
|
return Effect.gen(function* () {
|
|
41
56
|
const spec = Result.getOrNull(VersionSpecifier.parseResult(range));
|
|
42
57
|
if (spec === null || !DERIVABLE_OPERATORS.has(spec.operator)) return yield* Effect.fail(new PeerRangeError({ message: `Cannot derive peer range from "${range}"` }));
|
|
43
|
-
const { operator
|
|
44
|
-
const version = range.slice(
|
|
58
|
+
const { operator, version: parsed } = spec;
|
|
59
|
+
const version = range.slice(operator.length);
|
|
60
|
+
const prefix = operator === "" ? operatorOf(currentPeer) : operator;
|
|
45
61
|
if (strategy === "lock") return {
|
|
46
62
|
range: `${prefix}${version}`,
|
|
47
63
|
warning: null
|
|
@@ -54,7 +70,7 @@ function derivePeerRange(range, strategy) {
|
|
|
54
70
|
}
|
|
55
71
|
};
|
|
56
72
|
return {
|
|
57
|
-
range: `${prefix}${parsed.major}.${parsed.minor}.0`,
|
|
73
|
+
range: `${prefix !== "" ? prefix : "~"}${parsed.major}.${parsed.minor}.0`,
|
|
58
74
|
warning: null
|
|
59
75
|
};
|
|
60
76
|
});
|
package/cli/plan.js
CHANGED
|
@@ -15,7 +15,7 @@ import { derivePeerRange } from "./peer-range.js";
|
|
|
15
15
|
*/
|
|
16
16
|
function planEntry(entry, versions) {
|
|
17
17
|
return Effect.gen(function* () {
|
|
18
|
-
const range = parseRange(entry.currentRange);
|
|
18
|
+
const range = parseRange(entry.family !== void 0 && entry.operator === "" ? `^${bareVersion(entry.currentRange)}` : entry.currentRange);
|
|
19
19
|
const current = parseVersion(bareVersion(entry.currentRange));
|
|
20
20
|
const currentMajor = current?.major ?? 0;
|
|
21
21
|
const track = current && current.prerelease.length > 0 ? String(current.prerelease[0]) : null;
|
|
@@ -24,7 +24,7 @@ function planEntry(entry, versions) {
|
|
|
24
24
|
const inRangeMax = range ? Option.getOrNull(Range.maxSatisfying(parsed, range)) : null;
|
|
25
25
|
const sameMajorMax = Option.getOrNull(SemVer.max(parsed.filter((v) => v.major === currentMajor)));
|
|
26
26
|
const overallMax = Option.getOrNull(SemVer.max(parsed));
|
|
27
|
-
const withPeer = (version) => entry.strategy && entry.strategy !== "interop" ? derivePeerRange(`${entry.operator}${version}`, entry.strategy).pipe(Effect.map((d) => d.range)) : Effect.succeed(void 0);
|
|
27
|
+
const withPeer = (version) => entry.strategy && entry.strategy !== "interop" ? derivePeerRange(`${entry.operator}${version}`, entry.strategy, entry.peer?.value).pipe(Effect.map((d) => d.range)) : Effect.succeed(void 0);
|
|
28
28
|
const candidate = (kind, sv) => Effect.map(withPeer(sv.toString()), (peerRange) => ({
|
|
29
29
|
kind,
|
|
30
30
|
range: `${entry.operator}${sv}`,
|
|
@@ -57,7 +57,11 @@ function planEntry(entry, versions) {
|
|
|
57
57
|
* which for a 0.x caret routinely falls OUTSIDE the current range (`^0.2.0`
|
|
58
58
|
* does not contain 0.3.0); the never-cross-a-range rule protects against
|
|
59
59
|
* surprise REGISTRY majors, and the workspace version is this repo's own
|
|
60
|
-
* declared next release.
|
|
60
|
+
* declared next release. An unlocked family member (`upgrade --family`) takes
|
|
61
|
+
* its in-range candidate too, which `planEntry` computes over its breaking
|
|
62
|
+
* line (the major from 1.0, the minor for 0.x), so the tier rules still hold — a stable member never
|
|
63
|
+
* sees a prerelease, and nothing unattended crosses a major. Undefined when
|
|
64
|
+
* nothing but keep is on offer.
|
|
61
65
|
*
|
|
62
66
|
* Shared by `--yes`/`--check` (runUpgrade) and the `--preview` / non-TTY
|
|
63
67
|
* projection (projectDecisions) so the three can never disagree.
|
|
@@ -65,7 +69,8 @@ function planEntry(entry, versions) {
|
|
|
65
69
|
* @internal
|
|
66
70
|
*/
|
|
67
71
|
function defaultPick(entry, candidates) {
|
|
68
|
-
|
|
72
|
+
if (entry.source === "workspace") return candidates.find((c) => c.kind !== "keep");
|
|
73
|
+
return candidates.find((c) => c.kind === "in-range");
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
export { defaultPick, planEntry };
|
package/cli/preview-views.js
CHANGED
|
@@ -3,6 +3,7 @@ import { WORKSPACE_FIELDS } from "../registry.js";
|
|
|
3
3
|
import { buildDiff } from "./diff/build.js";
|
|
4
4
|
import { renderExportDiff } from "./diff/render.js";
|
|
5
5
|
import { effectiveManaged, vanillaManaged } from "./effective.js";
|
|
6
|
+
import { respellForFile } from "./respell.js";
|
|
6
7
|
import { renderSimulated } from "./simulated-view.js";
|
|
7
8
|
import { overlayWorkspace } from "./workspace-overlay.js";
|
|
8
9
|
|
|
@@ -21,7 +22,8 @@ function buildPreviewViews(input) {
|
|
|
21
22
|
managedKeys: WORKSPACE_FIELDS
|
|
22
23
|
};
|
|
23
24
|
const effective = effectiveManaged(input.managed, input.local, input.parsed, input.manifest, input.rootName);
|
|
24
|
-
const
|
|
25
|
+
const { effective: spelled, parsed: fileBase } = respellForFile(effective, input.parsed);
|
|
26
|
+
const merged = overlayWorkspace(spelled, fileBase);
|
|
25
27
|
const vanilla = vanillaManaged(input.managed, input.manifest, input.rootName);
|
|
26
28
|
const before = PnpmWorkspaceFile.canonicalize(input.parsed);
|
|
27
29
|
const changesTree = buildDiff(before, PnpmWorkspaceFile.canonicalize(merged), meta);
|