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.
- package/cli/commands/export.js +1 -1
- package/cli/commands/sync.js +527 -0
- package/cli/effective.js +12 -2
- package/cli/exit-codes.js +9 -2
- package/cli/local-merge.js +66 -1
- package/cli/preview-views.js +1 -1
- package/cli/root.js +3 -1
- package/cli/sync/commit-message.js +19 -0
- package/cli/sync/config.js +83 -0
- package/cli/sync/floors.js +146 -0
- package/cli/sync/local-gate.js +63 -0
- package/cli/sync/membership.js +118 -0
- package/cli/sync/release-plan.js +49 -0
- package/cli/sync/ripples.js +59 -0
- package/cli/sync/running-list.js +153 -0
- package/cli/version.js +1 -1
- package/index.d.ts +76 -9
- package/package.json +1 -1
- package/plugin/freeze.js +2 -1
- package/runtime/strategies/arrays.js +15 -10
- package/skills/rolldown-pnpm-config/SKILL.md +47 -0
- package/skills/rolldown-pnpm-config/assets/catalog-sync.yml +287 -0
- package/skills/rolldown-pnpm-config/assets/pre-push.sh +32 -0
- package/skills/rolldown-pnpm-config/references/catalogs.md +95 -0
- package/skills/rolldown-pnpm-config/references/options.md +314 -0
- package/skills/rolldown-pnpm-config/references/sync.md +138 -0
- package/skills/rolldown-pnpm-config/references/wiring.md +194 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Wiring a rolldown-pnpm-config plugin
|
|
2
|
+
|
|
3
|
+
A config-dependency plugin is one workspace package that builds a
|
|
4
|
+
self-contained `pnpmfile.mjs`. pnpm installs it as a config dependency and
|
|
5
|
+
calls its `updateConfig` hook. The CLI (`rolldown-pnpm-config`) edits the
|
|
6
|
+
plugin's config in place and gates the catalog in CI and on push.
|
|
7
|
+
|
|
8
|
+
The rules for the catalogs themselves are in the catalogs reference; running
|
|
9
|
+
and reading `sync` is in the sync reference.
|
|
10
|
+
|
|
11
|
+
## Package layout
|
|
12
|
+
|
|
13
|
+
Lay the plugin package out like this (built with `effected package build`):
|
|
14
|
+
|
|
15
|
+
| Path | Holds |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `lib/configs/pnpm-config.plugin.ts` | The `PnpmConfigPlugin({...})` call, `export default` |
|
|
18
|
+
| `src/pnpmfile.ts` | `export { hooks } from "rolldown-pnpm-config/virtual/pnpmfile";` |
|
|
19
|
+
| `src/index.ts` | Optional programmatic reads over `rolldown-pnpm-config/virtual/catalogs` |
|
|
20
|
+
| `types/refs.d.ts` | `/// <reference types="rolldown-pnpm-config/virtual" />` |
|
|
21
|
+
| `effected.toml` | The build, below |
|
|
22
|
+
| `package.json` | `private: true`, `publishConfig.access: "public"` |
|
|
23
|
+
|
|
24
|
+
`effected.toml`:
|
|
25
|
+
|
|
26
|
+
```toml
|
|
27
|
+
[package.build]
|
|
28
|
+
# Inline every import: pnpm loads the pnpmfile before anything is installed.
|
|
29
|
+
bundleNodeModules = true
|
|
30
|
+
# Holds the catalog literal at its PnpmConfigPlugin(...) call, which the CLI walks statically.
|
|
31
|
+
plugins = ["./lib/configs/pnpm-config.plugin.ts"]
|
|
32
|
+
|
|
33
|
+
[package.build.looseFiles]
|
|
34
|
+
"pnpmfile.mjs" = "./src/pnpmfile.ts"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`lib/configs/pnpm-config.plugin.ts`:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { PnpmConfigPlugin } from "rolldown-pnpm-config";
|
|
41
|
+
|
|
42
|
+
// The annotation names the return type, which inference would reach through rolldown.
|
|
43
|
+
const plugin: ReturnType<typeof PnpmConfigPlugin> = PnpmConfigPlugin({
|
|
44
|
+
name: "@acme/pnpm-plugin-acme",
|
|
45
|
+
catalogs: {
|
|
46
|
+
acme: {
|
|
47
|
+
packages: {
|
|
48
|
+
"@acme/core": { range: "^1.2.0", peer: "^1.2.0", strategy: "lock-minor", source: "workspace" },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
sync: { catalog: "acme", members: { scope: "@acme/*" } },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export default plugin;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`src/pnpmfile.ts` re-exports the generated hook, nothing more:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
export { hooks } from "rolldown-pnpm-config/virtual/pnpmfile";
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Wrap it only when the package also exports its own typed `hooks` (a
|
|
65
|
+
`PnpmConfig` interface for `catalogs` as a plain record); the wrapper must
|
|
66
|
+
still call the generated `updateConfig` unchanged.
|
|
67
|
+
|
|
68
|
+
Rules:
|
|
69
|
+
|
|
70
|
+
- Keep `private: true` in source. Publishability is
|
|
71
|
+
`publishConfig.access: "public"`; the build sets `private` from it.
|
|
72
|
+
- Add `rolldown-pnpm-config` as a devDependency of the plugin package. That
|
|
73
|
+
is also what links this skill: during install pnpm looks for skills in the
|
|
74
|
+
direct dependencies of every workspace project, counting only the
|
|
75
|
+
dependency groups the install includes, so `pnpm install --prod` skips a
|
|
76
|
+
devDependency's skills. Packages whose skills await approval are listed
|
|
77
|
+
after the install.
|
|
78
|
+
- The build is `dist/prod/npm/pkg/`; the loose `pnpmfile.mjs` lands at
|
|
79
|
+
`dist/prod/npm/pkg/pnpmfile.mjs`, which is the default `sync.local.pnpmfile`.
|
|
80
|
+
- Under plain rolldown or tsdown the `PnpmConfigPlugin(...)` call sits in the
|
|
81
|
+
bundler config's `plugins` instead, and the output must still bundle every
|
|
82
|
+
import.
|
|
83
|
+
|
|
84
|
+
## Scripts and root aliases
|
|
85
|
+
|
|
86
|
+
The CLI's bin belongs to the plugin package, so define the scripts there and
|
|
87
|
+
alias them from the root.
|
|
88
|
+
|
|
89
|
+
Plugin package `package.json`:
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"scripts": {
|
|
94
|
+
"build": "effected package build",
|
|
95
|
+
"pnpm:up": "rolldown-pnpm-config upgrade lib/configs/pnpm-config.plugin.ts",
|
|
96
|
+
"pnpm:preview": "cd lib/configs && rolldown-pnpm-config preview",
|
|
97
|
+
"pnpm:export": "cd lib/configs && rolldown-pnpm-config export",
|
|
98
|
+
"catalog:sync": "rolldown-pnpm-config sync lib/configs/pnpm-config.plugin.ts",
|
|
99
|
+
"catalog:check": "rolldown-pnpm-config sync lib/configs/pnpm-config.plugin.ts --check"
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Root `package.json`, one alias per script:
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"scripts": {
|
|
109
|
+
"pnpm:up": "pnpm --filter '@acme/pnpm-plugin-acme' run pnpm:up",
|
|
110
|
+
"pnpm:preview": "pnpm --filter '@acme/pnpm-plugin-acme' run pnpm:preview",
|
|
111
|
+
"pnpm:export": "pnpm --filter '@acme/pnpm-plugin-acme' run pnpm:export",
|
|
112
|
+
"catalog:sync": "pnpm --filter '@acme/pnpm-plugin-acme' run catalog:sync",
|
|
113
|
+
"catalog:check": "pnpm --filter '@acme/pnpm-plugin-acme' run catalog:check"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- `export` and `preview` autodetect the config in the current directory,
|
|
119
|
+
hence the `cd`. `upgrade` and `sync` take the path.
|
|
120
|
+
- `sync` resolves the workspace root from the config file, so the running
|
|
121
|
+
list, the commit message and the floor changesets land at the root
|
|
122
|
+
whatever the cwd.
|
|
123
|
+
- Never run `pnpm catalog:check --local`: the extra flag reaches
|
|
124
|
+
`sync --check --local`, a usage error (exit 64). Call `sync --local`
|
|
125
|
+
directly.
|
|
126
|
+
- Add `.changeset/catalog-sync.commit.txt` (or `sync.commit.messagePath`) to
|
|
127
|
+
`.gitignore`. The workflow reads it; it is never committed.
|
|
128
|
+
|
|
129
|
+
## The `sync` block
|
|
130
|
+
|
|
131
|
+
Every field the CLI reads. Unknown keys are rejected, and a config with no
|
|
132
|
+
`sync` block is a usage error (exit 64).
|
|
133
|
+
|
|
134
|
+
| Field | Default | Meaning |
|
|
135
|
+
| --- | --- | --- |
|
|
136
|
+
| `catalog` | required | The catalog `sync` owns and rewrites |
|
|
137
|
+
| `members.scope` | required | Package-name glob, e.g. `"@acme/*"`; membership counts these names |
|
|
138
|
+
| `members.packages` | every workspace package | Globs over workspace-relative paths (`"packages/*"`), narrowing discovery |
|
|
139
|
+
| `members.exclude` | `[]` | Package names or name globs left out, e.g. `"@acme/sidecar-*"` |
|
|
140
|
+
| `changeset.path` | `.changeset/catalog-sync.md` | The running-list changeset |
|
|
141
|
+
| `changeset.bump` | `"patch"` | The running list's bump for the plugin, `"patch"` or `"minor"` |
|
|
142
|
+
| `commit.scope` | the `catalog` name | Scope of the headline `chore(<scope>): sync catalog to the next release versions` |
|
|
143
|
+
| `commit.messagePath` | `.changeset/catalog-sync.commit.txt` | Where the commit message is written |
|
|
144
|
+
| `floors` | `false` | Also raise and check breaking-floor changesets (`.changeset/breaking-floor-*.md`) |
|
|
145
|
+
| `local.pnpmfile` | `dist/prod/npm/pkg/pnpmfile.mjs` | The built pnpmfile `--local` imports, relative to the plugin package |
|
|
146
|
+
| `local.catalogs` | every served catalog except `<catalog>` and `<catalog>:peers` | The catalogs `--local` compares with `pnpm-workspace.yaml` |
|
|
147
|
+
|
|
148
|
+
- A member is publishable when its `publishConfig.access` is `"public"`;
|
|
149
|
+
`private` is never read.
|
|
150
|
+
- The plugin package (the nearest `package.json` above the config) is always
|
|
151
|
+
excluded from membership, whatever the block says.
|
|
152
|
+
- `sync` is CLI-only. It never reaches the pnpmfile, and `local.sync` is not
|
|
153
|
+
allowed.
|
|
154
|
+
|
|
155
|
+
## Workflow and hook templates
|
|
156
|
+
|
|
157
|
+
Two templates live in the skill's `assets/` directory. Copy each into the
|
|
158
|
+
repository and replace every placeholder; the comments at the top of each
|
|
159
|
+
file list them.
|
|
160
|
+
|
|
161
|
+
| Template | Copy to | Placeholders |
|
|
162
|
+
| --- | --- | --- |
|
|
163
|
+
| [catalog-sync.yml](../assets/catalog-sync.yml) | `.github/workflows/catalog-sync.yml` | `<PLUGIN_DIR>`, `<CONFIG_PATH>` (relative to the plugin package), `<PLUGIN_PACKAGE>`, `<OWNER>`/`<REPO>`, `<APP_ID_SECRET>` (the variable holding the App's client id), `<APP_KEY_SECRET>` (the secret holding its private key) |
|
|
164
|
+
| [pre-push.sh](../assets/pre-push.sh) | `.husky/pre-push` (or your hook runner's equivalent) | `<PLUGIN_PACKAGE>`, `<PLUGIN_DIR>`, `<CONFIG_PATH>` |
|
|
165
|
+
|
|
166
|
+
- **Catalog Sync workflow.** Runs on the changesets release PR
|
|
167
|
+
(`changeset-release/main`). Order: `sync --check --format json` with
|
|
168
|
+
`continue-on-error` (the gate, before anything mutates), a step that reads
|
|
169
|
+
the JSON `evaluated` field, `sync`, detect changes with
|
|
170
|
+
`git status --porcelain` (not `git diff`, which misses an untracked first
|
|
171
|
+
changeset), build, commit through the GraphQL `createCommitOnBranch`
|
|
172
|
+
mutation with an App token so the commit is signed, then write the
|
|
173
|
+
`Catalog Sync` check run once, in an `if: ${{ !cancelled() }}` step, with its conclusion
|
|
174
|
+
already decided. The workflow branches on the JSON `evaluated` and `drift`
|
|
175
|
+
outputs (drift is any section with status `findings`), not on the check's
|
|
176
|
+
exit: exit 1 means either a finding or a section that could not be
|
|
177
|
+
evaluated, and only an evaluated run with drift runs the sync. A run that
|
|
178
|
+
repaired drift reports failure ("Catalog was out of date, synced"): the
|
|
179
|
+
drift was real at that ref, and a rerun once the sync commit is in the
|
|
180
|
+
branch goes green. The check calls the CLI through `pnpm exec` so stdout is
|
|
181
|
+
exactly the JSON document. If you set `sync.commit.messagePath`, change
|
|
182
|
+
`COMMIT_MESSAGE_PATH` in the commit step to match. The job is triggered by
|
|
183
|
+
the release PR but checks out `main` and commits the sync to `main`. The App
|
|
184
|
+
needs `contents: write` on the repository, and if `main` has branch
|
|
185
|
+
protection or a ruleset the App must be on its bypass list, or
|
|
186
|
+
`createCommitOnBranch` is refused. Both staged-file diffs pass
|
|
187
|
+
`--no-renames`, so a replaced breaking-floor changeset is deleted, not kept; add your own runtime setup and test
|
|
188
|
+
steps where the template marks them.
|
|
189
|
+
- **Pre-push gate.** Skips in CI, builds the plugin through turbo (the gate
|
|
190
|
+
reads the built pnpmfile), then runs
|
|
191
|
+
`pnpm exec rolldown-pnpm-config sync --local <CONFIG_PATH>` in the plugin
|
|
192
|
+
package. It calls the CLI directly, never `catalog:check --local`. Put it
|
|
193
|
+
outside any section a tool manages in `.husky/pre-push` (a block a tool
|
|
194
|
+
regenerates would drop it).
|