rolldown-pnpm-config 3.0.7 → 3.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.
@@ -0,0 +1,153 @@
1
+ // src/cli/sync/running-list.ts
2
+ /**
3
+ * The config's catalog entries by catalog name, then package: the
4
+ * {@link CurrentCatalog} that {@link mergeMoves} and {@link staleMoves} read.
5
+ *
6
+ * @internal
7
+ */
8
+ function currentCatalogs(entries) {
9
+ const byCatalog = /* @__PURE__ */ new Map();
10
+ for (const entry of entries) {
11
+ const group = byCatalog.get(entry.catalog) ?? /* @__PURE__ */ new Map();
12
+ group.set(entry.pkg, entry);
13
+ byCatalog.set(entry.catalog, group);
14
+ }
15
+ return (catalog) => byCatalog.get(catalog) ?? /* @__PURE__ */ new Map();
16
+ }
17
+ const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
18
+ /** `4 catalog:effected versions`, pluralized. */
19
+ function moveSummary(catalog, count) {
20
+ return `${count} catalog:${catalog} version${count === 1 ? "" : "s"}`;
21
+ }
22
+ /** Moves grouped by catalog, each group sorted by package name. */
23
+ function byCatalog(moves) {
24
+ const groups = /* @__PURE__ */ new Map();
25
+ for (const move of moves) {
26
+ const group = groups.get(move.catalog) ?? [];
27
+ group.push(move);
28
+ groups.set(move.catalog, group);
29
+ }
30
+ return [...groups.entries()].sort(([a], [b]) => compare(a, b)).map(([catalog, group]) => [catalog, group.sort((a, b) => compare(a.pkg, b.pkg))]);
31
+ }
32
+ /** `^0.13.0 -> ^0.13.1 (peer ^0.13.0)`; the peer parenthetical is dropped when unknown. */
33
+ function moveText(move) {
34
+ const peer = move.peer === void 0 ? "" : ` (peer ${move.peer})`;
35
+ return `${move.from} -> ${move.to}${peer}`;
36
+ }
37
+ /**
38
+ * The running-list changeset for a set of moves.
39
+ *
40
+ * @remarks
41
+ * 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. With no
43
+ * moves the body falls back to a one-line statement naming `catalog`. The text
44
+ * format is byte-compatible with the scripts this ports.
45
+ *
46
+ * @internal
47
+ */
48
+ function renderChangeset(pluginName, bump, moves, catalog) {
49
+ return `---\n"${pluginName}": ${bump}\n---\n\n## Maintenance\n\n${moves.length === 0 ? `- Synced the \`${catalog}\` catalog to the current release versions` : byCatalog(moves).map(([name, group]) => {
50
+ const lines = group.map((move) => `- \`${move.pkg}\` ${moveText(move)}`);
51
+ return `### Updates ${moveSummary(name, group.length)}\n\n${lines.join("\n")}`;
52
+ }).join("\n\n")}\n`;
53
+ }
54
+ /** One `### Updates … catalog:<catalog> …` heading, capturing the catalog. */
55
+ const SECTION = /^### Updates \d+ catalog:(\S+) versions?$/;
56
+ /**
57
+ * One move line as {@link renderChangeset} writes it.
58
+ *
59
+ * @remarks
60
+ * Ranges may hold spaces (`^0.33.0 || ^0.34.0`), so none is matched as `\S+`: a
61
+ * skipped line would drop that move on the next sync with no warning. The
62
+ * ` -> ` and ` (peer ` separators split them; a semver range holds neither.
63
+ */
64
+ const MOVE_LINE = /^- `([^`]+)` (.+?) -> (.+?)(?: \(peer (.+)\))?$/;
65
+ /**
66
+ * The moves an existing running-list changeset records, read back from its body.
67
+ *
68
+ * @remarks
69
+ * The inverse of {@link renderChangeset}. The fallback body, and any line that
70
+ * is not a move under an `### Updates` heading, contributes nothing.
71
+ *
72
+ * @internal
73
+ */
74
+ function parseChangeset(text) {
75
+ const moves = [];
76
+ let catalog;
77
+ for (const line of text.split(/\r?\n/)) {
78
+ const section = SECTION.exec(line);
79
+ if (section !== null) {
80
+ catalog = section[1];
81
+ continue;
82
+ }
83
+ const move = MOVE_LINE.exec(line);
84
+ if (move === null || catalog === void 0) continue;
85
+ const [, pkg, from, to, peer] = move;
86
+ if (pkg === void 0 || from === void 0 || to === void 0) continue;
87
+ moves.push({
88
+ catalog,
89
+ pkg,
90
+ from,
91
+ to,
92
+ peer
93
+ });
94
+ }
95
+ return moves;
96
+ }
97
+ /**
98
+ * The moves the pending changeset should list once `fresh` lands on top of `pending`.
99
+ *
100
+ * @remarks
101
+ * The changeset is the release's running list: a sync before the release adds to
102
+ * it, never replaces it. A package already listed keeps its first `from`, the
103
+ * range the last release published. Every listed package takes its `to` and peer
104
+ * from `current`, so the list can never disagree with what ships. A move that
105
+ * `current` has returned to its `from` drops out, and so does one whose package
106
+ * left the catalog.
107
+ *
108
+ * @internal
109
+ */
110
+ function mergeMoves(pending, fresh, current) {
111
+ const merged = /* @__PURE__ */ new Map();
112
+ for (const move of [...pending, ...fresh]) {
113
+ const key = `${move.catalog}\0${move.pkg}`;
114
+ const first = merged.get(key);
115
+ merged.set(key, first === void 0 ? move : {
116
+ ...move,
117
+ from: first.from
118
+ });
119
+ }
120
+ const out = [];
121
+ for (const move of merged.values()) {
122
+ const entry = current(move.catalog).get(move.pkg);
123
+ if (entry === void 0) continue;
124
+ if (entry.currentRange === move.from) continue;
125
+ out.push({
126
+ ...move,
127
+ to: entry.currentRange,
128
+ peer: entry.peer?.value
129
+ });
130
+ }
131
+ return out;
132
+ }
133
+ /**
134
+ * The listed moves whose `to` or peer no longer match the config, one line each.
135
+ *
136
+ * @remarks
137
+ * A stale list fails the gate the way a stale config does: a changeset whose
138
+ * ranges disagree with the config it ships beside describes a different release.
139
+ *
140
+ * @internal
141
+ */
142
+ function staleMoves(pending, current) {
143
+ const stale = [];
144
+ for (const move of pending) {
145
+ const entry = current(move.catalog).get(move.pkg);
146
+ const range = entry?.currentRange;
147
+ const peer = entry?.peer?.value;
148
+ if (range !== move.to || peer !== move.peer) stale.push(` ${move.catalog}.${move.pkg} listed ${moveText(move)}, config ${range ?? "(absent)"}${peer === void 0 ? "" : ` (peer ${peer})`}`);
149
+ }
150
+ return stale;
151
+ }
152
+
153
+ export { byCatalog, currentCatalogs, mergeMoves, parseChangeset, renderChangeset, staleMoves };
package/cli/version.js CHANGED
@@ -6,6 +6,6 @@
6
6
  *
7
7
  * @internal
8
8
  */
9
- const CLI_VERSION = "3.0.7";
9
+ const CLI_VERSION = "3.1.0";
10
10
 
11
11
  export { CLI_VERSION };
package/index.d.ts CHANGED
@@ -165,10 +165,13 @@ type FieldInput<T> = T | {
165
165
  readonly enforcement?: Enforcement;
166
166
  };
167
167
  /**
168
- * Per-field local merge directive applied only by `rolldown-pnpm-config export`.
169
- * All keys optional: `value` alone overwrites; `strategy` unions/differences
170
- * `value` with the managed value; `preserve` (overrides only) keeps existing
171
- * file entries whose value starts with a listed protocol.
168
+ * Per-field local merge directive applied only by `rolldown-pnpm-config export`
169
+ * (and shown by `preview`). All keys optional: `value` alone overwrites the
170
+ * managed value; `strategy` `union` or `merge` adds `value` to it and
171
+ * `difference` removes `value` from it; `rewrite` carries no value, keeps the
172
+ * managed value and stops a union field keeping the file's own entries;
173
+ * `preserve` (`overrides` only) lists the protocols whose existing file entries
174
+ * are kept (default `file`, `link`, `workspace`, `portal`).
172
175
  *
173
176
  * @public
174
177
  */
@@ -177,6 +180,62 @@ interface LocalDirective<T> {
177
180
  readonly value?: T;
178
181
  readonly strategy?: "union" | "difference" | "merge" | "rewrite";
179
182
  }
183
+ /**
184
+ * The `sync` block: how `rolldown-pnpm-config sync` keeps one of the plugin's
185
+ * own catalogs in step with the workspace packages it ships beside (the
186
+ * members), moving each member's catalog entry to the version that member's
187
+ * next release will publish. Read statically by the CLI; the build and the
188
+ * shipped pnpmfile ignore it.
189
+ *
190
+ * @public
191
+ */
192
+ interface SyncConfig {
193
+ /** The catalog that names the members; sync moves its entries to the members' next release versions. */
194
+ readonly catalog: string;
195
+ /** Which workspace packages are synced. */
196
+ readonly members: {
197
+ /**
198
+ * Glob over package names selecting the members, e.g. `"@effected/*"`.
199
+ * Must be non-empty and match at least one workspace package, or the
200
+ * membership check fails rather than passing on an empty set.
201
+ */
202
+ readonly scope: string;
203
+ /**
204
+ * Globs over workspace-relative package paths (e.g. `"packages/*"`), not
205
+ * package names, narrowing which workspace packages are discovered. Omitted,
206
+ * every workspace package in the scope is considered.
207
+ */
208
+ readonly packages?: readonly string[];
209
+ /** Package names or globs over package names left out of the scope. */
210
+ readonly exclude?: readonly string[];
211
+ };
212
+ /** The running-list changeset (default `.changeset/catalog-sync.md`, bump `patch`). */
213
+ readonly changeset?: {
214
+ readonly path?: string;
215
+ readonly bump?: "patch" | "minor";
216
+ };
217
+ /** The commit message (scope defaults to the catalog name; file `.changeset/catalog-sync.commit.txt`). */
218
+ readonly commit?: {
219
+ readonly scope?: string;
220
+ readonly messagePath?: string;
221
+ };
222
+ /**
223
+ * Manage the breaking-floor changesets (`.changeset/breaking-floor-*.md`)
224
+ * (default `false`). `sync --check` only reports a floor section when those
225
+ * files differ from the ones the release plan derives; a write-mode `sync`
226
+ * raises them, writing or deleting the files, before it reads the plan.
227
+ */
228
+ readonly floors?: boolean;
229
+ /**
230
+ * The `--local` check: the built pnpmfile (default `dist/prod/npm/pkg/pnpmfile.mjs`)
231
+ * and the catalogs to compare with `pnpm-workspace.yaml` (default: every
232
+ * served catalog except the sync catalog and its `:peers` twin).
233
+ */
234
+ readonly local?: {
235
+ readonly pnpmfile?: string;
236
+ readonly catalogs?: readonly string[];
237
+ };
238
+ }
180
239
  /**
181
240
  * The declarative plugin configuration.
182
241
  *
@@ -194,9 +253,17 @@ interface PluginConfig {
194
253
  /** The catalogs to inject into pnpm config, keyed by catalog name. */
195
254
  readonly catalogs: Record<string, CatalogDeclaration>;
196
255
  /**
197
- * Export-only overrides. Each field set here replaces the corresponding
198
- * generated field when running `rolldown-pnpm-config export`. Ignored by the
199
- * build and the shipped pnpmfile.
256
+ * Configuration for `rolldown-pnpm-config sync`. Read statically by the CLI;
257
+ * not a pnpm setting, so it never reaches the base or the pnpmfile.
258
+ */
259
+ readonly sync?: SyncConfig;
260
+ /**
261
+ * Export-only overrides. Each field set here replaces, or with a
262
+ * {@link LocalDirective} merges into, the corresponding generated field when
263
+ * running `rolldown-pnpm-config export` or `preview`. Ignored by the build
264
+ * and the shipped pnpmfile. Only managed pnpm settings reach
265
+ * `pnpm-workspace.yaml`; `localPatchesDir` is read by patch discovery and
266
+ * never written.
200
267
  */
201
268
  readonly local?: {
202
269
  /**
@@ -205,7 +272,7 @@ interface PluginConfig {
205
272
  * folder detection is independent and unaffected.
206
273
  */
207
274
  readonly localPatchesDir?: string;
208
- } & { readonly [K in Exclude<keyof PluginConfig, "overridesFromCatalogs">]?: PluginConfig[K] | LocalDirective<PluginConfig[K]>; };
275
+ } & { readonly [K in Exclude<keyof PluginConfig, "name" | "local" | "overridesFromCatalogs" | "sync">]?: PluginConfig[K] | LocalDirective<PluginConfig[K]>; };
209
276
  /** Per-package manifest overrides merged into the dependency graph. */
210
277
  readonly packageExtensions?: FieldInput<PnpmSettingType<"packageExtensions">>;
211
278
  /** Deprecated versions explicitly allowed, keyed by package. */
@@ -486,5 +553,5 @@ interface PluginConfig {
486
553
  * @public
487
554
  */
488
555
  export declare function PnpmConfigPlugin(config: PluginConfig): Plugin;
489
- export type { AllowedVersionsFromCatalogs, CatalogDeclaration, CatalogPackageSpec, Enforcement, FieldInput, LocalDirective, OverridesFromCatalogs, PeerStrategy, PluginConfig, VersionSource };
556
+ export type { AllowedVersionsFromCatalogs, CatalogDeclaration, CatalogPackageSpec, Enforcement, FieldInput, LocalDirective, OverridesFromCatalogs, PeerStrategy, PluginConfig, SyncConfig, VersionSource };
490
557
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rolldown-pnpm-config",
3
- "version": "3.0.7",
3
+ "version": "3.1.0",
4
4
  "private": false,
5
5
  "description": "A dogfooding example of our plugin",
6
6
  "repository": {
package/plugin/freeze.js CHANGED
@@ -65,7 +65,8 @@ const PLUGIN_KEYS = /* @__PURE__ */ new Set([
65
65
  "name",
66
66
  "catalogs",
67
67
  "local",
68
- "overridesFromCatalogs"
68
+ "overridesFromCatalogs",
69
+ "sync"
69
70
  ]);
70
71
  /** Keys recognized by the wrapped `{ value, enforcement?, excludeByRepo? }` form. */
71
72
  const WRAPPED_KEYS = /* @__PURE__ */ new Set([
@@ -17,24 +17,29 @@ const arrayUnion = (base, local) => ({
17
17
  divergences: []
18
18
  });
19
19
  /**
20
- * Per-axis union of a record of string arrays; drops empty axes. Quiet.
20
+ * Per-axis union of two records of string arrays, sorted by key; drops empty
21
+ * axes. Shared by the strategy and by `export`'s keep-the-file merge.
21
22
  *
22
23
  * @internal
23
24
  */
24
- const arrayRecordUnion = (base, local) => {
25
- const managed = base ?? {};
26
- const child = local ?? {};
25
+ function unionRecord(managed, child) {
27
26
  const keys = /* @__PURE__ */ new Set([...Object.keys(managed), ...Object.keys(child)]);
28
27
  const result = {};
29
28
  for (const key of [...keys].sort(byCodeUnit)) {
30
29
  const merged = unionSort(managed[key] ?? [], child[key]);
31
30
  if (merged.length > 0) result[key] = merged;
32
31
  }
33
- return {
34
- merged: result,
35
- divergences: []
36
- };
37
- };
32
+ return result;
33
+ }
34
+ /**
35
+ * Per-axis union of a record of string arrays; drops empty axes. Quiet.
36
+ *
37
+ * @internal
38
+ */
39
+ const arrayRecordUnion = (base, local) => ({
40
+ merged: unionRecord(base ?? {}, local ?? {}),
41
+ divergences: []
42
+ });
38
43
  /**
39
44
  * A settings section with list and scalar keys (`audit`, `update`): a key whose
40
45
  * managed or local value is a string list is unioned like `arrayUnion`, so a
@@ -62,4 +67,4 @@ const sectionMerge = (base, local) => {
62
67
  };
63
68
  };
64
69
 
65
- export { arrayRecordUnion, arrayUnion, sectionMerge, unionSort };
70
+ export { arrayRecordUnion, arrayUnion, sectionMerge, unionRecord, unionSort };
@@ -0,0 +1,47 @@
1
+ ---
2
+ name: rolldown-pnpm-config
3
+ description: Use when working on a pnpm config-dependency plugin built with rolldown-pnpm-config, including adding one to a repository, laying out its package, writing the PnpmConfigPlugin call or its sync block, adding the pnpm:up, pnpm:preview, pnpm:export, catalog:sync and catalog:check aliases, wiring the Catalog Sync workflow or the pre-push gate, adding or editing a served catalog, writing catalog specifiers in a package.json, adding imports to the plugin, explaining entries pnpm:export keeps in pnpm-workspace.yaml, running or reading rolldown-pnpm-config sync, sync --check or sync --local, a pre-push catalog gate that blocks a push, or a red Catalog Sync check on a release PR.
4
+ ---
5
+
6
+ # rolldown-pnpm-config
7
+
8
+ A config-dependency plugin is one workspace package whose build emits a
9
+ self-contained `pnpmfile.mjs`. pnpm installs it as a config dependency and
10
+ calls its `updateConfig` hook. The `rolldown-pnpm-config` CLI edits the
11
+ plugin's config in place (`upgrade`, `sync`), writes the repository's own
12
+ `pnpm-workspace.yaml` (`export`), and gates the catalog in CI and on push
13
+ (`sync --check`, `sync --local`).
14
+
15
+ ## Rules for every task
16
+
17
+ - Keep the `catalogs` literal inline in the `PnpmConfigPlugin({...})` call.
18
+ The CLI reads and rewrites it statically; never hoist, spread or compute it.
19
+ - Dependencies use `catalog:<name>`; peers use `catalog:<name>:peers`.
20
+ - Never run `pnpm:up` or `pnpm:export` (or `upgrade` / `export` without
21
+ `--dry-run`). They are the user's; tell the user which to run.
22
+ - Never put the plugin package in any catalog it serves.
23
+ - A config dependency installs without its dependencies. Bundle every
24
+ import of the pnpmfile and never declare one as a dependency.
25
+ - Never edit a `sync.catalog` range or `.changeset/catalog-sync.md` by hand.
26
+ `sync` owns both.
27
+ - Keep `private: true` in source; publishability is
28
+ `publishConfig.access: "public"`.
29
+ - A gate's exit 1 is not proof of drift. Read `evaluated` and each
30
+ section's `status` before acting.
31
+
32
+ ## References
33
+
34
+ Load the reference that matches the task. Each stands alone.
35
+
36
+ | Reference | Load when |
37
+ | --- | --- |
38
+ | [references/wiring.md](references/wiring.md) | Adding the plugin to a repository: package layout, `effected.toml`, scripts and root aliases, every `sync` block field and default, the workflow and pre-push shapes |
39
+ | [references/catalogs.md](references/catalogs.md) | Adding or editing catalog entries, choosing a specifier, adding imports to the plugin, or entries `export` keeps in `pnpm-workspace.yaml` (union and map fields) |
40
+ | [references/options.md](references/options.md) | Writing or editing a plugin config, or looking up what a top-level key, `sync` field, value form, strategy or managed pnpm setting does |
41
+ | [references/sync.md](references/sync.md) | Running `sync`, `sync --check` or `sync --local`, reading their text or JSON report, applying a remedy, or a red Catalog Sync check |
42
+
43
+ ## Assets
44
+
45
+ The skill's `assets/` directory holds the Catalog Sync workflow
46
+ (`catalog-sync.yml`) and the pre-push gate (`pre-push.sh`) to copy into a
47
+ repository. The wiring reference says how to adapt them.