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