Skip to content

Commit ff8f9a6

Browse files
cursoragentjherr
andcommitted
feat(ui-react)!: createRoutes(definition, spec) replaces cmsVirtualRoutes(options) (#28)
Chain step 6 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: jherr <jherr@pobox.com>
1 parent 5a366bd commit ff8f9a6

104 files changed

Lines changed: 2212 additions & 585 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/create-routes.md‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
'@tanstack/cms-ui-react': minor
3+
'@tanstack/cms-cli': minor
4+
'@tanstack/cms-core': patch
5+
---
6+
7+
**Breaking:** `createRoutes(definition, spec?)` from
8+
`@tanstack/cms-ui-react/virtual-routes` replaces `cmsVirtualRoutes(options)`,
9+
which is removed. It takes the `defineCmsDefinition` result from
10+
`src/cms.definition.ts`, the only app module `vite.config.ts` imports, and
11+
reads the admin base path and plugin routes from it, so they're no longer
12+
repeated in the Vite config.
13+
14+
The spec names routes by surface. `public`, `admin`, and `api` each take `true`
15+
(every route), `false` (none), a list of route keys (only those), or an object
16+
that drops (`false`) or replaces (a file path) single keys. A surface you leave
17+
out is mounted, so `createRoutes(definition)` mounts everything. `custom`
18+
replaces `children`, and `rootFile` is unchanged. `routesDirectory` and
19+
`generatedDirectory` move to the `tanstackCms()` Vite plugin, which has to
20+
come before `tanstackStart()`. `CreateRoutesSpec` replaces
21+
`CmsVirtualRoutesOptions`, and the route keys (`CmsRouteKey`) are stable public
22+
API. An old option throws with its replacement in the message.
23+
24+
```ts
25+
// before
26+
cmsVirtualRoutes({
27+
adminBasePath: '/admin',
28+
include: { public: false },
29+
routes: { agent: false },
30+
})
31+
// after: admin.basePath is set in defineCmsDefinition()
32+
createRoutes(definition, { public: false, admin: { agent: false } })
33+
```
34+
35+
Migrate with `pnpm codemod create-routes <path-to-your-app>`, run from a
36+
TanStack CMS checkout. It rewrites `vite.config.ts` files and Markdown code
37+
blocks and warns where an `adminBasePath` or `plugins` value has to move into
38+
the definition. `tanstack-cms init` now writes `createRoutes(definition)`.

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ shape of [`examples/blog`](../../../examples/blog) (same as the Payload skill
7070
`@tanstack/router-plugin`, `typescript`, node/react types, `vitest`.
7171
Scripts: `dev`, `build`, `test:types`, `test:lib` (`vitest run`),
7272
`migrate:data`. Pick a free dev port.
73-
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }), nitro(), viteReact()]`
74-
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
75-
from `@tanstack/cms-ui-react/virtual-routes`.
73+
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }), nitro(), viteReact()]`
74+
with `tanstackCms` from `@tanstack/cms-ui-react/vite`, `createRoutes` from
75+
`@tanstack/cms-ui-react/virtual-routes`, and `definition` from
76+
`./src/cms.definition` (the only app module the Vite config imports).
7677
- `vitest.config.ts` — plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
7778
from `vitest/config`.
7879
- `tsconfig.json` — `{ "extends": "../../tsconfig.base.json", "include": ["src/**/*.ts","src/**/*.tsx"] }`.
@@ -84,7 +85,7 @@ shape of [`examples/blog`](../../../examples/blog) (same as the Payload skill
8485
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
8586
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
8687
`redirectsCollection`, …): Vite config and client code load this file, and
87-
`pnpm test:definitions` fails if it reaches React, Start, or server code.
88+
`pnpm test:definitions` fails if it reaches React, Start, server code, or the `@tanstack/cms-core` root.
8889
Then write `cms.config.ts` calling
8990
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
9091
rules that need server code attach there by collection name

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ migration skills' §2):
8080
`@tanstack/router-plugin`, `typescript`, node/react types, `vitest`.
8181
Scripts: `dev`, `build`, `test:types`, `test:lib` (`vitest run`),
8282
`migrate:data`. Pick a free dev port.
83-
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }), nitro(), viteReact()]`
84-
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
85-
from `@tanstack/cms-ui-react/virtual-routes`.
83+
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }), nitro(), viteReact()]`
84+
with `tanstackCms` from `@tanstack/cms-ui-react/vite`, `createRoutes` from
85+
`@tanstack/cms-ui-react/virtual-routes`, and `definition` from
86+
`./src/cms.definition` (the only app module the Vite config imports).
8687
- `vitest.config.ts` — plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
8788
from `vitest/config`.
8889
- `tsconfig.json` — `{ "extends": "../../tsconfig.base.json", "include": ["src/**/*.ts","src/**/*.tsx"] }`.
@@ -98,7 +99,7 @@ npm project with a large dependency tree) — see `examples/emdash-before` and t
9899
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
99100
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
100101
`redirectsCollection`, …): Vite config and client code load this file, and
101-
`pnpm test:definitions` fails if it reaches React, Start, or server code.
102+
`pnpm test:definitions` fails if it reaches React, Start, server code, or the `@tanstack/cms-core` root.
102103
Then write `cms.config.ts` calling
103104
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
104105
rules that need server code attach there by collection name

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ nested docs), and custom React admin components — these drive the gap report.
4949

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

@@ -63,11 +63,12 @@ Outside this repo, start from a TanStack Start app and run
6363
`test:types` (`tsc --noEmit`), `test:lib` (`vitest run`), `cms`
6464
(`tanstack-cms`), `migrate:data`. Pick a free dev port.
6565
- `vite.config.ts` — as in `examples/blog`:
66-
`plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }), nitro(), viteReact()]`
67-
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
68-
from `@tanstack/cms-ui-react/virtual-routes`. Payload serves its admin at
69-
`/admin`; keep that URL with `cmsVirtualRoutes({ adminBasePath: '/admin' })`
70-
plus `defineCmsDefinition({ admin: { basePath: '/admin' } })`.
66+
`plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }), nitro(), viteReact()]`
67+
with `tanstackCms` from `@tanstack/cms-ui-react/vite`, `createRoutes` from
68+
`@tanstack/cms-ui-react/virtual-routes`, and `definition` from
69+
`./src/cms.definition`. Payload serves its admin at `/admin`; keep that URL
70+
with `defineCmsDefinition({ admin: { basePath: '/admin' } })`, which
71+
`createRoutes` mounts the admin under (set it once, in the definition).
7172
- `vitest.config.ts` — a plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
7273
from `vitest/config`, so tests don't load the Start/Nitro plugins.
7374
- `tsconfig.json` — `{ "extends": "../../tsconfig.base.json", "include": ["src/**/*.ts","src/**/*.tsx"] }`.
@@ -80,7 +81,7 @@ Outside this repo, start from a TanStack Start app and run
8081
Write `cms.definition.ts` calling `defineCmsDefinition({ collections, admin })`,
8182
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
8283
`redirectsCollection`, …): Vite config and client code load this file, and
83-
`pnpm test:definitions` fails if it reaches React, Start, or server code.
84+
`pnpm test:definitions` fails if it reaches React, Start, server code, or the `@tanstack/cms-core` root.
8485
Then write `cms.config.ts` calling
8586
`defineCms(definition, { blockTypes, auth, seed, collections, … })` and
8687
register the definition's type

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ All store functions from `@tanstack/cms-core/server` are **async** —
2626
## 0. Prerequisites
2727

2828
- A TanStack CMS app (`cms.definition.ts` + `cms.config.ts` +
29-
`cmsVirtualRoutes()`), e.g. a copy of
29+
`createRoutes(definition)`), e.g. a copy of
3030
[`examples/blog`](../../../examples/blog).
3131
- An `auth` config (`createMockAuth()` from `@tanstack/cms-ui-react` for
3232
demos, `auth: { getUser }` in production) so votes have a voter.
@@ -251,10 +251,10 @@ A small component: up arrow, score, down arrow. Requirements:
251251
silently); `useCmsAuth()` from `@tanstack/cms-ui-react` says who's signed in.
252252
- Wiring, in order of preference:
253253
1. Render `VoteButtons` in app-owned pages (list cards, a top-posts page)
254-
added with `cmsVirtualRoutes({ children: [route('/top', './top.tsx')] })`
254+
added with `createRoutes(definition, { custom: [route('/top', './top.tsx')] })`
255255
— child paths are relative to `src/routes`. This is what the worked
256256
example does.
257-
2. **Replace the built-in post page**: `cmsVirtualRoutes({ routes: { post: './post.$id.tsx' } })`
257+
2. **Replace the built-in post page**: `createRoutes(definition, { public: { post: './post.$id.tsx' } })`
258258
swaps in your own file (relative to `src/routes`); it must call
259259
`createFileRoute('/post/$id')`. Start from the package's
260260
`routes/post.$id.tsx` and add the buttons.

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ migration skills' §2):
7575
`@tanstack/router-plugin`, `typescript`, node/react types, `vitest`.
7676
Scripts: `dev`, `build`, `test:types`, `test:lib` (`vitest run`),
7777
`migrate:data`. Pick a free dev port.
78-
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }), nitro(), viteReact()]`
79-
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
80-
from `@tanstack/cms-ui-react/virtual-routes`.
78+
- `vite.config.ts` — `plugins: [tanstackCms(), tailwindcss(), tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }), nitro(), viteReact()]`
79+
with `tanstackCms` from `@tanstack/cms-ui-react/vite`, `createRoutes` from
80+
`@tanstack/cms-ui-react/virtual-routes`, and `definition` from
81+
`./src/cms.definition` (the only app module the Vite config imports).
8182
- `vitest.config.ts` — plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
8283
from `vitest/config`.
8384
- `tsconfig.json` — extends `../../tsconfig.base.json`; `src/router.tsx` —
@@ -91,7 +92,7 @@ workspace app.
9192
Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
9293
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
9394
`redirectsCollection`, …): Vite config and client code load this file, and
94-
`pnpm test:definitions` fails if it reaches React, Start, or server code.
95+
`pnpm test:definitions` fails if it reaches React, Start, server code, or the `@tanstack/cms-core` root.
9596
Then write `cms.config.ts` calling
9697
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
9798
rules that need server code attach there by collection name

‎README.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TanStack Start app, and your UI reads its content through TanStack DB.
3333

3434
- **TanStack Start is the runtime.** The admin, the public pages, and every API
3535
endpoint are Start routes shipped in a package and mounted with
36-
`cmsVirtualRoutes()`. Each CMS operation is a Start server function
36+
`createRoutes(definition)`. Each CMS operation is a Start server function
3737
(`@tanstack/cms-api/start`), so the admin and your own loaders call the
3838
engine in-process, with no HTTP hop. The same operations are served over
3939
HTTP, MCP, and WebMCP for everything outside the app.
@@ -106,8 +106,8 @@ for your app's own routes and components. See
106106
- **SEO built in.** Sitemap, robots.txt, redirects, OpenGraph and JSON-LD
107107
helpers, and signed webhooks on publish, unpublish, and delete.
108108
- **Routes from a package.** The admin, public pages, and API endpoints mount
109-
into your Start app with `cmsVirtualRoutes()`. Move the admin under a base
110-
path, override any route with your own file, or drop it.
109+
into your Start app with `createRoutes(definition)`. Mount only some, move
110+
the admin under a base path, or replace or drop any route by its key.
111111
- **A CLI.** `tanstack-cms init`, `migrate`, `seed`, `export`, `import`, and
112112
`backup`.
113113

@@ -163,7 +163,9 @@ declare module '@tanstack/cms-core' {
163163
}
164164
```
165165

166-
A small app can keep both halves in one `defineCms({ collections, … })` call.
166+
A small app can keep both halves in one `defineCms({ collections, … })` call,
167+
but `vite.config.ts` mounts the routes from the definition, so keep at least
168+
`defineCmsDefinition({})` in `src/cms.definition.ts`.
167169

168170
```ts
169171
// vite.config.ts
@@ -172,14 +174,15 @@ import { tanstackStart } from '@tanstack/react-start/plugin/vite'
172174
import { nitro } from 'nitro/vite'
173175
import viteReact from '@vitejs/plugin-react'
174176
import tailwindcss from '@tailwindcss/vite'
175-
import { cmsVirtualRoutes } from '@tanstack/cms-ui-react/virtual-routes'
177+
import { createRoutes } from '@tanstack/cms-ui-react/virtual-routes'
176178
import { tanstackCms } from '@tanstack/cms-ui-react/vite'
179+
import { definition } from './src/cms.definition'
177180

178181
export default defineConfig({
179182
plugins: [
180183
tanstackCms(),
181184
tailwindcss(),
182-
tanstackStart({ router: { virtualRouteConfig: cmsVirtualRoutes() } }),
185+
tanstackStart({ router: { virtualRouteConfig: createRoutes(definition) } }),
183186
nitro(),
184187
viteReact(),
185188
],

‎app/base/vite.config.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import { nitro } from 'nitro/vite'
44
import viteReact from '@vitejs/plugin-react'
55
import tailwindcss from '@tailwindcss/vite'
66
import { index, route } from '@tanstack/virtual-file-routes'
7-
import { cmsVirtualRoutes } from '@tanstack/cms-ui-react/virtual-routes'
7+
import { createRoutes } from '@tanstack/cms-ui-react/virtual-routes'
88
import { tanstackCms } from '@tanstack/cms-ui-react/vite'
9+
import { definition } from './src/cms.definition'
910

1011
const quickjsPackages = [
1112
'quickjs-emscripten',
@@ -22,11 +23,11 @@ export default defineConfig({
2223
tailwindcss(),
2324
tanstackStart({
2425
router: {
25-
virtualRouteConfig: cmsVirtualRoutes({
26+
virtualRouteConfig: createRoutes(definition, {
2627
rootFile: './__root.tsx',
27-
include: { public: false },
28-
routes: { agent: './agent.tsx' },
29-
children: [
28+
public: false,
29+
admin: { agent: './agent.tsx' },
30+
custom: [
3031
index('./home.tsx'),
3132
route('/setup', './setup.tsx'),
3233
route('/collections', './collections.tsx'),

‎app/prm/src/collections.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* and priority (`high` | `medium` | `low` | `unranked`).
1515
* - `personSource` stores per-field provenance (`high` | `medium` | `low`).
1616
*/
17-
import { defineCollection } from '@tanstack/cms-core'
18-
import type { AccessRule } from '@tanstack/cms-core'
17+
import { defineCollection } from '@tanstack/cms-core/definition'
18+
import type { AccessRule } from '@tanstack/cms-core/definition'
1919

2020
export const INTEREST_OPTIONS = [
2121
'agent-harness',

‎app/prm/vite.config.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ import { nitro } from 'nitro/vite'
44
import viteReact from '@vitejs/plugin-react'
55
import tailwindcss from '@tailwindcss/vite'
66
import { route } from '@tanstack/virtual-file-routes'
7-
import { cmsVirtualRoutes } from '@tanstack/cms-ui-react/virtual-routes'
7+
import { createRoutes } from '@tanstack/cms-ui-react/virtual-routes'
88
import { tanstackCms } from '@tanstack/cms-ui-react/vite'
9+
import { definition } from './src/cms.definition'
910

1011
export default defineConfig({
1112
plugins: [
1213
tanstackCms(),
1314
tailwindcss(),
1415
tanstackStart({
1516
router: {
16-
virtualRouteConfig: cmsVirtualRoutes({
17+
virtualRouteConfig: createRoutes(definition, {
1718
rootFile: './__root.tsx',
18-
include: { public: false, admin: true, api: true },
19-
children: [
19+
public: false,
20+
custom: [
2021
route('/', './index.tsx'),
2122
route('/setup', './setup.tsx'),
2223
route('/login', './login.tsx'),

0 commit comments

Comments
 (0)