Skip to content

Commit 5a366bd

Browse files
jherrcursoragent
andauthored
feat(core)!: split plugins and app configs into a definition and a runtime (#25) (#25)
Chain step 5 of the linear merge chain onto main 3b4a112: this PR's own changes, resolved against the PRs before it in the merge order. Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent 02582ea commit 5a366bd

150 files changed

Lines changed: 4075 additions & 1574 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.changeset/definition-split.md‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
'@tanstack/cms-core': minor
3+
'@tanstack/cms-cli': minor
4+
'@tanstack/cms-skills': minor
5+
'@tanstack/cms-connect-atproto': minor
6+
---
7+
8+
Split plugins into a definition and a runtime, and attach a collection's
9+
server-bound hooks, access, and storage in the runtime config.
10+
11+
**Breaking: `definePlugin({ definition, runtime })`.** A plugin's `name`,
12+
`collections`, `adminNav`, `routes`, and `adminRoutes` go in
13+
`definition: definePluginDefinition({ … })`; its `blockTypes`, `fieldTypes`,
14+
`ops`, `eventHandlers`, and `onEvent` go in `runtime`. The flat
15+
`definePlugin({ name, … })` form throws, and so does a key on the wrong side.
16+
`@tanstack/cms-core/definition` exports `definePluginDefinition` (and the
17+
`CmsPluginDefinition` type) in place of `definePlugin`, which is now
18+
root-only. To migrate, run this from a TanStack CMS checkout:
19+
20+
```bash
21+
pnpm codemod definition-split <path-to-your-app>
22+
```
23+
24+
```ts
25+
// before
26+
definePlugin({ name: 'analytics', collections: [pageview], ops: [topPages] })
27+
// after
28+
definePlugin({
29+
definition: definePluginDefinition({
30+
name: 'analytics',
31+
collections: [pageview],
32+
}),
33+
runtime: { ops: [topPages] },
34+
})
35+
```
36+
37+
List the plugin's definition in `defineCmsDefinition({ plugins })` and the
38+
plugin in the runtime config's `plugins`; the runtime entry replaces the
39+
definition entry of the same name. A plugin with no collections or routes,
40+
like the AT Protocol connector, can sit in the runtime config alone. One-file
41+
apps list the plugin once in `defineCms({ plugins })`, as before.
42+
43+
**Breaking: the runtime config's `collections` is an object keyed by
44+
collection name.** `defineCms(definition, { collections: { post: { hooks,
45+
access, storage } } })` attaches the server-bound half of a collection the
46+
definition declares. Hooks are typed from the collection's fields. An unknown
47+
name, any other key, or a hook or rule the definition already sets throws.
48+
Before, the runtime config couldn't name `collections` at all.
49+
50+
- The same codemod writes `cms.definition.ts` next to each `cms.config.ts`
51+
(collections, `admin`, plugin definitions, and what they depend on) and
52+
rewrites the config to `defineCms(definition, runtime)` with
53+
`Register { cms: typeof definition }`. Hooks and access that import server
54+
code have to be moved to the runtime `collections` by hand.
55+
- `defineInterfaceCollection` is exported from `@tanstack/cms-core/definition`.
56+
- `@tanstack/cms-cli`: `tanstack-cms init` writes `src/cms.definition.ts` and a
57+
`src/cms.config.ts` that calls `defineCms(definition, { … })`. If either file
58+
exists, both are kept unless `--force` is passed.
59+
- `@tanstack/cms-skills`: code-mode `applySkillToCode` adds a skill's
60+
collections to `cms.definition.ts`, creating it and a `cms.config.ts` in a
61+
new app. A one-file app still gets them appended to `cms.config.ts`.
62+
- `@tanstack/cms-connect-atproto`: `createAtprotoConnector()` returns a
63+
runtime-only plugin; add it to the runtime config's `plugins`.

‎.claude/skills/astro-starlight-to-tanstack-cms/SKILL.md‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ description: Migrate an Astro Starlight docs site to TanStack CMS 1.0 (@tanstack
77

88
Port an [Astro Starlight](https://starlight.astro.build) docs site onto
99
TanStack CMS: the target is a TanStack Start app whose app-specific code is a
10-
`cms.config.ts` (the mapped schema and theme) plus the migrated content. The
10+
`cms.definition.ts` (the mapped schema) and a `cms.config.ts` (blocks, seed,
11+
theme) plus the migrated content. The
1112
admin UI, docs layout with sidebar, block editor, drafts and review queue,
1213
redirects, sitemap, HTTP API, and MCP come from `@tanstack/cms-core`,
1314
`@tanstack/cms-api`, and `@tanstack/cms-ui-react`.
@@ -78,7 +79,17 @@ shape of [`examples/blog`](../../../examples/blog) (same as the Payload skill
7879
- `src/router.tsx` — `import './cms.config'` then build the router from
7980
`./routeTree.gen` (generated on first `dev`/`build`).
8081

81-
## 3. Map the schema → `src/cms.config.ts`
82+
## 3. Map the schema → `src/cms.definition.ts`
83+
84+
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
85+
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
86+
`redirectsCollection`, …): Vite config and client code load this file, and
87+
`pnpm test:definitions` fails if it reaches React, Start, or server code.
88+
Then write `cms.config.ts` calling
89+
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
90+
rules that need server code attach there by collection name
91+
(`collections: { post: { hooks, access } }`). A small app may keep one file
92+
(`defineCms({ collections, … })`).
8293

8394
One Starlight `docs` collection → one core collection. **Name it `page`** with
8495
a `blocks` field: the public renderer (`/p/$id`), the docs layout, and the

‎.claude/skills/astro-starlight-to-tanstack-cms/scripts/migrate-starlight.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* block — there is no Lexical step. With `--export <file>` it also writes a
1717
* CMS export (`tanstack-cms-export` v1) to load with `tanstack-cms import`.
1818
*
19-
* This is the data half. The schema half is the hand-written src/cms.config.ts
19+
* This is the data half. The schema half is the hand-written src/cms.definition.ts
2020
* (see SKILL.md's frontmatter → field mapping table).
2121
*/
2222
import { readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs'

‎.claude/skills/emdash-to-tanstack-cms/SKILL.md‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ description: Migrate an EmDash CMS site to TanStack CMS 1.0 (@tanstack/cms-core
66
# EmDash → TanStack CMS migration
77

88
Port an [EmDash](https://emdashcms.com) site onto TanStack CMS: the target is a
9-
TanStack Start app whose app-specific code is a `cms.config.ts` (the mapped
10-
schema) plus the migrated content. The admin UI, block editor, public renderer,
9+
TanStack Start app whose app-specific code is a `cms.definition.ts` (the
10+
mapped schema) and a `cms.config.ts` (blocks, seed, theme) plus the migrated
11+
content. The admin UI, block editor, public renderer,
1112
drafts, revisions, scheduling, review queue, search, HTTP API, and MCP/WebMCP
1213
come from `@tanstack/cms-core`, `@tanstack/cms-api`, and
1314
`@tanstack/cms-ui-react`.
@@ -92,9 +93,17 @@ Keep the real EmDash source app **out of the pnpm workspace** (it's an external
9293
npm project with a large dependency tree) — see `examples/emdash-before` and the
9394
`!examples/emdash-before` line in the root `pnpm-workspace.yaml`.
9495

95-
## 3. Map the schema → `src/cms.config.ts`
96-
97-
Write `cms.config.ts` calling `defineCms({ collections, blockTypes, … })`.
96+
## 3. Map the schema → `src/cms.definition.ts`
97+
98+
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
99+
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
100+
`redirectsCollection`, …): Vite config and client code load this file, and
101+
`pnpm test:definitions` fails if it reaches React, Start, or server code.
102+
Then write `cms.config.ts` calling
103+
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
104+
rules that need server code attach there by collection name
105+
(`collections: { post: { hooks, access } }`). A small app may keep one file
106+
(`defineCms({ collections, … })`).
98107

99108
**Collections.** Each EmDash collection → a core `Collection`. Name the
100109
public page collection **`page` with a `blocks` field** and the blog

‎.claude/skills/emdash-to-tanstack-cms/scripts/migrate-emdash.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* seed. With `--export <file>` it also writes a CMS export
1717
* (`tanstack-cms-export` v1) to load with `tanstack-cms import <file>`.
1818
*
19-
* This is the data half. The schema half is the hand-written src/cms.config.ts
19+
* This is the data half. The schema half is the hand-written src/cms.definition.ts
2020
* (see SKILL.md's field/collection mapping tables).
2121
*/
2222
import { readFileSync, writeFileSync } from 'node:fs'
@@ -183,7 +183,7 @@ function main() {
183183
)
184184
}
185185

186-
// multiselect options for cms.config.ts: every taxonomy's terms
186+
// multiselect options for cms.definition.ts: every taxonomy's terms
187187
for (const tax of seed.taxonomies ?? []) {
188188
const terms = (tax.terms ?? []).map((t) => `${t.slug} (${t.label})`)
189189
console.log(` taxonomy ${tax.name} options: ${terms.join(', ')}`)

‎.claude/skills/payload-to-tanstack-cms/SKILL.md‎

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ description: Migrate a Payload CMS (v3) project to TanStack CMS 1.0 (@tanstack/c
66
# Payload → TanStack CMS migration
77

88
Port a [Payload v3](https://payloadcms.com) project onto TanStack CMS: the
9-
target is a TanStack Start app whose app-specific code is a `cms.config.ts`
10-
(the mapped schema, access rules, and hooks) plus the migrated content.
9+
target is a TanStack Start app whose app-specific code is a
10+
`cms.definition.ts` (the mapped schema) and a `cms.config.ts` (the runtime:
11+
blocks, auth, server-bound access rules and hooks) plus the migrated content.
1112
The admin UI, block editor, public renderer, drafts and review queue, media
1213
library, HTTP API, and MCP come from `@tanstack/cms-core`,
1314
`@tanstack/cms-api`, and `@tanstack/cms-ui-react`.
@@ -48,7 +49,7 @@ nested docs), and custom React admin components — these drive the gap report.
4849

4950
Outside this repo, start from a TanStack Start app and run
5051
`npx tanstack-cms init` (from `@tanstack/cms-cli`): it creates
51-
`src/cms.config.ts`, adds `tanstackCms()` and `cmsVirtualRoutes()` to
52+
`src/cms.definition.ts` and `src/cms.config.ts`, adds `tanstackCms()` and `cmsVirtualRoutes()` to
5253
`vite.config.ts`, imports the config from `src/router.tsx`, and ignores
5354
`.data/`. In this repo, copy the shape of [`examples/blog`](../../../examples/blog):
5455

@@ -66,18 +67,30 @@ Outside this repo, start from a TanStack Start app and run
6667
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
6768
from `@tanstack/cms-ui-react/virtual-routes`. Payload serves its admin at
6869
`/admin`; keep that URL with `cmsVirtualRoutes({ adminBasePath: '/admin' })`
69-
plus `defineCms({ admin: { basePath: '/admin' } })`.
70+
plus `defineCmsDefinition({ admin: { basePath: '/admin' } })`.
7071
- `vitest.config.ts` — a plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
7172
from `vitest/config`, so tests don't load the Start/Nitro plugins.
7273
- `tsconfig.json` — `{ "extends": "../../tsconfig.base.json", "include": ["src/**/*.ts","src/**/*.tsx"] }`.
7374
- `src/router.tsx` — `import './cms.config'` (side effect: registers the
7475
model) then build the router from `./routeTree.gen` (generated on first
7576
`dev`/`build`).
7677

77-
## 3. Map the schema → `src/cms.config.ts`
78-
79-
Write `cms.config.ts` calling `defineCms({ collections, blockTypes, … })` and
80-
register its type (`declare module '@tanstack/cms-core' { interface Register { cms: typeof cms } }`).
78+
## 3. Map the schema → `src/cms.definition.ts`
79+
80+
Write `cms.definition.ts` calling `defineCmsDefinition({ collections, admin })`,
81+
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
82+
`redirectsCollection`, …): Vite config and client code load this file, and
83+
`pnpm test:definitions` fails if it reaches React, Start, or server code.
84+
Then write `cms.config.ts` calling
85+
`defineCms(definition, { blockTypes, auth, seed, collections, … })` and
86+
register the definition's type
87+
(`declare module '@tanstack/cms-core' { interface Register { cms: typeof definition } }`).
88+
The runtime `collections` is an object keyed by collection name that attaches
89+
`hooks`, `access`, and `storage` to the definition's collections:
90+
`collections: { post: { hooks: { afterChange }, access: { read } } }`. Put a
91+
hook or access predicate there when it needs server code (store reads,
92+
a database, secrets); role arrays and pure predicates can stay on the
93+
collection. A small app may keep one file (`defineCms({ collections, … })`).
8194
`cms.config.ts` is imported on the client too: read secrets lazily inside
8295
functions (AI adapter factories, `webhooks[].secret: () => process.env.X`).
8396

@@ -162,7 +175,9 @@ Payload `{ data, originalDoc, req, operation }` → core
162175
`{ doc, id }` (`postRead`), `{ id, actor }` (`preDelete`). Return the
163176
transformed doc from `preValidate` / `postValidate` / `postRead`; throw to
164177
abort a write. Keep hooks under about 50ms. Replace `req.payload.find(…)` with
165-
`queryDocuments`/`readDocument` from `@tanstack/cms-core/server`. Hooks that
178+
`queryDocuments`/`readDocument` from `@tanstack/cms-core/server`, and attach
179+
those hooks in the runtime config
180+
(`defineCms(definition, { collections: { post: { hooks } } })`). Hooks that
166181
only fan out to other systems (cache purges, search indexing) usually become
167182
`defineCms({ webhooks })` instead. No equivalent: `beforeOperation`,
168183
`afterOperation`, `beforeRead`, `afterError`, auth hooks.
@@ -288,7 +303,9 @@ judgment. Check at least:
288303
- **Richer Lexical** — node types not converted.
289304
- **Custom admin components** — Payload React field/view overrides don't
290305
carry over automatically; rebuild custom field inputs with `field.input` or
291-
`defineFieldType()`, and custom views or hooks with routes or `definePlugin()`.
306+
`defineFieldType()`, and custom views or hooks with routes or
307+
`definePlugin({ definition, runtime })` (collections and routes in
308+
`definition`, ops and event handlers in `runtime`).
292309
- **Databases** — Postgres/MongoDB adapters have no built-in equivalent
293310
(SQLite and libSQL/Turso ship; custom `StorageAdapter`s are possible).
294311

‎.claude/skills/payload-to-tanstack-cms/scripts/migrate-data.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* `--export <file>` it also writes a CMS export (`tanstack-cms-export` v1) to
1616
* load with `tanstack-cms import <file>`.
1717
*
18-
* This is the data half. The schema half is the hand-written src/cms.config.ts
18+
* This is the data half. The schema half is the hand-written src/cms.definition.ts
1919
* (see SKILL.md's field/block mapping tables).
2020
*/
2121
import { writeFileSync } from 'node:fs'
@@ -54,7 +54,7 @@ const OUT = join(here, '..', 'src', 'seed-data.ts')
5454
const CONFIG = [
5555
{
5656
source: 'pages', // Payload collection slug
57-
target: 'page', // core collection name (must match cms.config.ts)
57+
target: 'page', // core collection name (must match cms.definition.ts)
5858
id: (doc) => (doc.slug ?? '').replace(/^\//, '') || 'home',
5959
fields: [
6060
{ name: 'title', kind: 'scalar' },

‎.claude/skills/voting/SKILL.md‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description: Build a native upvote/downvote (voting) feature on a TanStack CMS 1
88
Add Reddit/HN-style upvote/downvote voting to a TanStack CMS app. The worked
99
reference for everything below is
1010
[`examples/blog-voting`](../../../examples/blog-voting): the blog example plus
11-
`src/cms.config.ts` (the `vote` collection + count fields), `src/voting/`
11+
`src/cms.definition.ts` (the `vote` collection + count fields), `src/voting/`
1212
(the write/read paths, component, and tests), and `src/routes/top.tsx`. When
1313
in doubt, read that.
1414

@@ -25,7 +25,8 @@ All store functions from `@tanstack/cms-core/server` are **async** —
2525

2626
## 0. Prerequisites
2727

28-
- A TanStack CMS app (`cms.config.ts` + `cmsVirtualRoutes()`), e.g. a copy of
28+
- A TanStack CMS app (`cms.definition.ts` + `cms.config.ts` +
29+
`cmsVirtualRoutes()`), e.g. a copy of
2930
[`examples/blog`](../../../examples/blog).
3031
- An `auth` config (`createMockAuth()` from `@tanstack/cms-ui-react` for
3132
demos, `auth: { getUser }` in production) so votes have a voter.
@@ -44,9 +45,11 @@ All store functions from `@tanstack/cms-core/server` are **async** —
4445
| Review queue? | **No.** Votes commit directly | The review queue is for _content_ awaiting human approval. Votes are user interactions; the vote documents themselves are the audit trail (revisions give you who-voted-what-when) |
4546
| Anonymous votes | Not by default | Anonymous voting invites brigading and can't do one-vote-per-user. If the product needs it, say so explicitly and accept the tradeoffs (§4) |
4647

47-
## 2. Model the schema → `src/cms.config.ts`
48+
## 2. Model the schema → `src/cms.definition.ts`
4849

49-
Add a `vote` collection to the `collections` array and count fields on the votable collection:
50+
Add a `vote` collection to the definition's `collections` array (in a one-file
51+
app, `defineCms({ collections })` in `cms.config.ts`) and count fields on the
52+
votable collection:
5053

5154
```ts
5255
defineCollection({
@@ -267,7 +270,7 @@ A small component: up arrow, score, down arrow. Requirements:
267270
Agents can read `post` scores through the standard tools, and you can expose
268271
voting as a first-class operation and MCP/WebMCP/content-agent tool with
269272
`defineOp({ name: 'cast_vote', access: 'content.write', agent: { kind: 'write' }, input, run })`
270-
in `defineCms({ ops })` (where `ctx.session.user?.id` provides the authenticated
273+
in `defineCms(definition, { ops })` (where `ctx.session.user?.id` provides the authenticated
271274
voter id). Alternatively, keep `castVote` as a Start server function for the UI
272275
only, or serve a custom MCP endpoint that checks `verifyMcpAccess(request)` from
273276
`@tanstack/cms-core/server` and calls `castVoteForVoter` with the resolved

‎.claude/skills/wordpress-to-tanstack-cms/SKILL.md‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ description: Migrate a WordPress site to TanStack CMS 1.0 (@tanstack/cms-core +
66
# WordPress → TanStack CMS migration
77

88
Port a [WordPress](https://wordpress.org) site onto TanStack CMS: the target is
9-
a TanStack Start app whose app-specific code is a `cms.config.ts` (the mapped
10-
schema) plus the migrated content. The admin UI, block editor, public renderer,
9+
a TanStack Start app whose app-specific code is a `cms.definition.ts` (the
10+
mapped schema) and a `cms.config.ts` (blocks, seed, theme) plus the migrated
11+
content. The admin UI, block editor, public renderer,
1112
drafts, revisions, review queue, redirects, sitemap, HTTP API, and MCP/WebMCP
1213
come from `@tanstack/cms-core`, `@tanstack/cms-api`, and
1314
`@tanstack/cms-ui-react`.
@@ -85,9 +86,17 @@ migration skills' §2):
8586
The WXR source (`<name>-before`) is just the export file + a README — not a
8687
workspace app.
8788

88-
## 3. Map the schema → `src/cms.config.ts`
89-
90-
Write `cms.config.ts` calling `defineCms({ collections, blockTypes, … })`.
89+
## 3. Map the schema → `src/cms.definition.ts`
90+
91+
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
92+
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
93+
`redirectsCollection`, …): Vite config and client code load this file, and
94+
`pnpm test:definitions` fails if it reaches React, Start, or server code.
95+
Then write `cms.config.ts` calling
96+
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
97+
rules that need server code attach there by collection name
98+
(`collections: { post: { hooks, access } }`). A small app may keep one file
99+
(`defineCms({ collections, … })`).
91100

92101
**Post types → collections.** Map the `page` post type to a core collection
93102
**named `page` with a `blocks` field** and `post` to a core **`post`**

‎.claude/skills/wordpress-to-tanstack-cms/scripts/migrate-wordpress.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* `--export <file>` it also writes a CMS export (`tanstack-cms-export` v1) to
1717
* load with `tanstack-cms import <file>`.
1818
*
19-
* This is the data half. The schema half is the hand-written src/cms.config.ts
19+
* This is the data half. The schema half is the hand-written src/cms.definition.ts
2020
* (see SKILL.md's field/collection mapping tables).
2121
*/
2222
import { readFileSync, writeFileSync } from 'node:fs'
@@ -71,7 +71,7 @@ const CONFIG = {
7171
}),
7272
},
7373
}
74-
const REDIRECTS = 'redirect' // the redirectsCollection() name in cms.config.ts
74+
const REDIRECTS = 'redirect' // the redirectsCollection() name in cms.definition.ts
7575
// ===========================================================================
7676

7777
/** Path of a WordPress permalink (`https://site/a-post/` → `/a-post/`), or null. */

0 commit comments

Comments
 (0)