@vite-hub/codemods 0.3.0 → 0.4.1

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 CHANGED
@@ -1,12 +1,12 @@
1
1
  # @vite-hub/codemods
2
2
 
3
- [![npm version](https://comark-ui.onmax.me/badge.svg?source=npm-version&package=%40vite-hub%2Fcodemods&icon=npm)](https://npmx.dev/package/@vite-hub/codemods)
4
- [![license](https://comark-ui.onmax.me/badge.svg?label=license&value=Apache-2.0)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
5
- [![docs](https://comark-ui.onmax.me/badge.svg?label=docs&value=vitehub.dev)](https://vitehub.dev/docs)
3
+ [![npm version](https://img.shields.io/npm/v/@vite-hub/codemods)](https://npmx.dev/package/@vite-hub/codemods)
4
+ [![license](https://img.shields.io/static/v1?label=license&message=Apache-2.0&color=blue)](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
5
+ [![docs](https://img.shields.io/static/v1?label=docs&message=vitehub.dev&color=blue)](https://vitehub.dev/docs)
6
6
 
7
7
  `@vite-hub/codemods` moves an application to ViteHub. Each codemod edits the source files that it can change safely and ends with a report: the files it changed and a numbered list of manual follow-ups, with `file:line` where it applies.
8
8
 
9
- The package requires Node.js 22.18 or newer. Read the [Codemods docs](https://vitehub.dev/docs/codemods) for a tutorial and what each codemod changes.
9
+ The package requires Node.js 24.15 or newer. Read the [Codemods docs](https://vitehub.dev/docs/codemods) for a tutorial and what each codemod changes.
10
10
 
11
11
  ## Migrate an app
12
12
 
@@ -28,7 +28,7 @@ The command exits with `0` when every codemod completes, also when they report f
28
28
  vitehub migrate [dir] [--dry-run]
29
29
  ```
30
30
 
31
- `vitehub migrate` runs the upgrade codemods, the ones that move an app from an older ViteHub API, in this order: `vitehub-options`, `define-forms`, `runtime-contracts`, `root-accessors`, `one-entry-imports`, `queue-workflow-verbs`, `agent-surface`, `driver-key`, `renamed-apis`, `tsconfig-paths`, and `shell-driver`. Each one sees the edits of the ones before it, and the report is the same as above. Install `@vite-hub/codemods` as a development dependency first. The codemods that move an app from another module, such as `nuxthub`, do not run. The report ends with a reminder to run Vite Doctor: rule `VHUB0003` finds Result calls, such as `await email.send(...)`, whose error the code drops.
31
+ `vitehub migrate` runs the upgrade codemods, the ones that move an app from an older ViteHub API, in this order: `vitehub-options`, `define-forms`, `runtime-contracts`, `root-accessors`, `one-entry-imports`, `queue-workflow-verbs`, `queue-durations`, `result-tuples`, `agent-surface`, `driver-key`, `renamed-apis`, `tsconfig-paths`, `shell-driver`, `access-spellings`, `auth-sign-in`, `channels`, `auth-accessors`, `workspace-repo`, `kv-list-prefix`, `cli-url-flag`, `cli-yes-flag`, `cms-roles`, and `choices-package`. Each one sees the edits of the ones before it, and the report is the same as above. Install `@vite-hub/codemods` as a development dependency first. The codemods that move an app from another module, such as `nuxthub`, do not run. The report ends with a reminder to run Vite Doctor: rule `VHUB0003` finds Result calls, such as `await email.send(...)`, whose error the code drops.
32
32
 
33
33
  ## Run one codemod
34
34
 
@@ -46,16 +46,31 @@ The command runs only the named codemod. Run it with `--help` to list the codemo
46
46
  | `t3-env` | A Nuxt app from `@t3-oss/env-nuxt` `createEnv()` to ViteHub Env through `vite-hub/nuxt` |
47
47
  | `resend` | `nuxt-resend` and Resend SDK `emails.send()` calls to ViteHub Email through `vite-hub/nuxt` |
48
48
  | `queue-workflow-verbs` | The old Queue and Workflow verbs to `sendQueue`, `useQueue`, `startWorkflow`, and `resumeWorkflow` |
49
+ | `queue-durations` | Queue `delaySeconds` to `delay` with a duration such as `"60s"`, and `retentionSeconds` to `retention`. `vitehub migrate` runs it. |
50
+ | `result-tuples` | `startWorkflow()`, `getWorkflowRun()`, `cancelWorkflow()`, `resumeWorkflow()`, the Workflow handle methods, `runSchedule()`, `listAuthEvents()`, `aggregateAuthEvents()`, `runBrowser()`, `runBrowserContent()`, `runSandboxTask()`, and gateway `ask()` to `[error, data]` reads. `vitehub migrate` runs it. |
49
51
  | `nuxt-cron` | `nuxt-cron` jobs to ViteHub Schedule Definitions through `vite-hub/nuxt` |
52
+ | `nuxt-better-auth` | A Nuxt app from `@nuxtjs/better-auth` to ViteHub Auth through `vite-hub/nuxt`: `server/auth.ts`, `app/auth.client.ts`, and `definePageMeta({ auth })` |
53
+ | `docus` | A Docus site to `@vite-hub/docs`: the module, the site options, and the page frontmatter |
54
+ | `nuxt-content` | Nuxt Content collections in `content.config.ts` to ViteHub Content Sources through `vite-hub/nuxt` |
50
55
  | `runtime-contracts` | `vite-hub/runtime/h3` and `vite-hub/runtime/node` imports, Evlog names from `vite-hub/logs`, and `checkRateLimit()` calls to the new contracts |
51
56
  | `root-accessors` | `db`, `schema`, `useDatabase`, `email`, `runSchedule`, and the Env accessors to the root of their primitive |
52
57
  | `agent-surface` | A ViteHub app from the old Agent names to `invoker`, `loadAgent()`, `agentWorkflow()`, `extends`, and the merged Agent entries |
53
58
  | `renamed-apis` | An app from the ViteHub names that this release renamed, such as `hubDb` and `kv.del()` |
54
- | `define-forms` | The former define forms of Schedule, Sandbox Task, Content, and Database to the one form of each |
59
+ | `define-forms` | The former define forms of Queue, Schedule, Sandbox Task, Workflow, Content, and Database to the one form of each |
55
60
  | `one-entry-imports` | Imports of subpaths that moved into one entry per concept, and `vite-hub/task` to `nitro/task` |
56
- | `vitehub-options` | The options that moved in `vitehub()`: `preset` to `host`, `logs` into `observability`, Env declarations into `vitehub({ env })`, and `devtools` and `contentImportBase` removed |
61
+ | `vitehub-options` | The options that moved in `vitehub()`: `preset` to `host`, `observability.logs` to `logs`, Env declarations into `vitehub({ env })`, and `devtools` and `contentImportBase` removed |
57
62
  | `tsconfig-paths` | `#vitehub/*` entries of tsconfig `paths` that point into `.vitehub/` or `.nuxt/`, which ViteHub now types itself |
58
63
  | `shell-driver` | The Shell `provider` names to `driver`: `createShellRuntime({ driver })`, `ShellDriver`, and `createJustBashDriver()`. `vitehub migrate` runs it. |
64
+ | `access-spellings` | Realtime `auth: true` to `authorize: true`, and MCP `public: true` to `access: "public"`. `vitehub migrate` runs it. |
65
+ | `auth-sign-in` | `vitehub({ auth: { redirects } })` and `access.signIn.callbackURL` to `access: { signIn, afterSignIn }` in `server/auth.ts`. `vitehub migrate` runs it. |
66
+ | `channels` | Agent `http()` calls to `channelAdapter("http", options)` where safe, and webhook secrets and signatures to the names of Webhooks. `vitehub migrate` runs it. |
67
+ | `auth-accessors` | Auth `auth` and `getAuth()` to `useAuth()`, and `isGitHubOrgMember()` to `checkGitHubOrgMember()`. `vitehub migrate` runs it. |
68
+ | `workspace-repo` | The GitHub Workspace Store option `repository` to `repo`. `vitehub migrate` runs it. |
69
+ | `kv-list-prefix` | `kv.keys(base)` to `kv.list({ prefix })`, and `kv.clear(base)` to `kv.clear({ prefix })`. `vitehub migrate` runs it. |
70
+ | `cli-yes-flag` | Replace old CLI prompt flags in scripts and CI, or report a manual migration. `vitehub migrate` runs it. |
71
+ | `cli-url-flag` | `vitehub` calls in scripts and CI: `--server` to `--url`, the app URL. `vitehub migrate` runs it. |
72
+ | `cms-roles` | The `cms` preset option `access: "roles"` to `roles: true`. `vitehub migrate` runs it. |
73
+ | `choices-package` | `@vite-hub/decisions` and `vite-hub/decisions` imports and the `vitehub decisions` command to `choices`. `vitehub migrate` runs it. |
59
74
 
60
75
  ## `runtime-contracts`
61
76
 
@@ -83,6 +98,7 @@ ViteHub renamed some APIs. `renamed-apis` rewrites the code of an app that uses
83
98
  | `hubDb` from `@vite-hub/database/vite` or `@vite-hub/database/nuxt` | `hubDatabase` |
84
99
  | `hubKv` from `@vite-hub/kv/vite` | `hubKV` |
85
100
  | `createWorkspaceDriver` from `@vite-hub/workspace/mountx` | `createMountxDriver` |
101
+ | `fetch` from `vite-hub/workspace` or `@vite-hub/workspace`, the URL Source | `url` |
86
102
  | `console` from `vite-hub/console/server` | `agentConsole` |
87
103
  | `kv.del()`, `blob.del()`, `kv.store(name).del()` | `.delete()` |
88
104
  | `deriveSecret(purpose, event)` | `deriveSecret(purpose, { event })` |
@@ -122,8 +138,11 @@ ViteHub keeps one define form for each primitive. `define-forms` rewrites the fo
122
138
 
123
139
  | Former form | New form |
124
140
  | --- | --- |
141
+ | `defineQueue(handler, { concurrency: 5 })` | `defineQueue({ handler, concurrency: 5 })` |
125
142
  | `defineSchedule("0 9 * * *", handler, { manual: true })` | `defineSchedule({ cron: "0 9 * * *", manual: true, handler })` |
126
143
  | `defineSandboxTask({ run })` | `defineSandboxTask({ handler })` |
144
+ | `defineWorkflow("onboard-user", async (payload: Payload, { steps }) => {}, { native })` | `defineWorkflow<Payload>({ handler: async ({ payload, steps }) => {}, native })`. The file path is the name. |
145
+ | `createWorkflow("welcome", async (payload: Payload) => {})` | `createWorkflow<Payload>("welcome", async ({ payload }) => {})` |
127
146
  | `export const content = defineContent({ ... })` in `server/content.ts` | `export default defineContent({ ... })`, and `import content from` in the files that import it |
128
147
  | `server/databases/config.ts` and the files beside it | `server/databases/default/index.ts` and the same files in `server/databases/default/` |
129
148
  | `server/databases/migrations/` | `server/databases/default/migrations/` |
@@ -131,7 +150,11 @@ ViteHub keeps one define form for each primitive. `define-forms` rewrites the fo
131
150
 
132
151
  The codemod updates the import paths of moved files, also through the `~~`, `@@`, and `#server` aliases, and path strings such as `out: "./server/databases/migrations"` in `drizzle.config.ts`. It works in Nuxt layers too.
133
152
 
134
- The report lists what it cannot change: Schedule options that are not an object literal, which it spreads into the object, Sandbox Task options that are not an object literal, dynamic imports of `server/content.ts`, helper files left in `server/databases/` that the new discovery reads as Databases, and lines in `package.json` and host config files that name the former Database paths.
153
+ The codemod leaves Queue handlers unchanged. They still receive the same job object, so destructuring it (for example, `({ payload }) => payload.email`) is optional. A one-argument call whose argument could be a definition object is left alone unless the codemod can identify a handler.
154
+
155
+ The report lists what needs review: Queue calls with spread arguments or options the codemod cannot safely flatten, Schedule options that are not an object literal (which it spreads into the object), Sandbox Task options that are not an object literal, dynamic imports of `server/content.ts`, helper files left in `server/databases/` that the new discovery reads as Databases, and lines in `package.json` and host config files that name the former Database paths.
156
+
157
+ It also reports Workflow option expressions, spreads, and ambiguous handlers, as well as local Workflow handlers that it wraps to keep their positional arguments.
135
158
 
136
159
  ```sh
137
160
  npx @vite-hub/codemods define-forms [dir] [--dry-run]
@@ -139,21 +162,21 @@ npx @vite-hub/codemods define-forms [dir] [--dry-run]
139
162
 
140
163
  ## `vitehub-options`
141
164
 
142
- `vitehub()` is the only config place, and `logs` is part of `observability`. `vitehub-options` edits every `vite.config.*` and `nuxt.config.*` in the app:
165
+ `vitehub()` is the only config place, and `logs` is its own key. `vitehub-options` edits every `vite.config.*` and `nuxt.config.*` in the app:
143
166
 
144
167
  | Old | New |
145
168
  | --- | --- |
146
169
  | `vitehub({ preset })`, `vitehub: { preset }` in `nuxt.config.ts` | `host` |
147
170
  | `sandbox: true` | `sandboxTask: true` |
148
- | `vitehub({ logs: true })` | `vitehub({ observability: { logs: true } })` |
149
- | `logs: { evlog, source }` | `observability: { evlog, logs: { source } }` |
171
+ | `vitehub({ observability: { logs: true } })` | `vitehub({ logs: true })` |
172
+ | `logs: { evlog, source }` | `observability: { evlog }, logs: { source }` |
150
173
  | `defineConfig({ env: { server }, plugins: [vitehub()] })` | `vitehub({ env: { server } })` |
151
174
  | `defineConfig({ env, plugins: [hubEnv()] })` | `hubEnv({ ...declarations })` |
152
175
  | `vite: { env }` in `nuxt.config.ts` | `env` in the `vite-hub/nuxt` options |
153
176
  | A top-level Vite key such as `kv` or `blob` | `vitehub({ kv })`, or the argument of `hubKV()` |
154
177
  | `devtools`, `contentImportBase` | removed |
155
178
 
156
- The report lists what the codemod cannot move: `preset` next to `host`, `sandbox` options that are not a boolean, `cloudflare.secretsFile`, a `logs` or `env` value that is an expression, `env` set in two places, `vitehub({ env: false })` next to Env declarations, and source lines that name a renamed option type, such as `KVModuleOptions`, which is now `KVOptions`.
179
+ The report lists what the codemod cannot move: `preset` next to `host`, `sandbox` options that are not a boolean, `cloudflare.secretsFile`, an `observability` or `env` value that is an expression, `env` set in two places, `vitehub({ env: false })` next to Env declarations, and source lines that name a renamed option type, such as `KVModuleOptions`, which is now `KVOptions`.
157
180
 
158
181
  Sandbox Task option objects belong in `hubSandboxTask()`. The codemod passes them to an existing standalone plugin call without arguments. When the config uses `vitehub()` or `vite-hub/nuxt`, it keeps the options in place and reports a manual follow-up because the framework accepts only boolean Sandbox Task enablement.
159
182
 
@@ -183,6 +206,23 @@ The codemod reads imports from `vite-hub/queue`, `vite-hub/workflow`, and their
183
206
  npx @vite-hub/codemods queue-workflow-verbs [dir] [--dry-run]
184
207
  ```
185
208
 
209
+ ## `queue-durations`
210
+
211
+ Queue `delaySeconds` is now `delay`, and `retentionSeconds` is now `retention`. `delay` takes a duration string, such as `"60s"`. `retention` takes a duration or a number of seconds. `queue-durations` rewrites the app:
212
+
213
+ | Old | New |
214
+ | --- | --- |
215
+ | `{ delaySeconds: 60 }` | `{ delay: "60s" }` |
216
+ | `{ delaySeconds: 24 * 60 * 60 }` | `{ delay: "86400s" }` |
217
+ | `{ retentionSeconds: 3600 }` | `{ retention: 3600 }` |
218
+ | `onError` returns `{ retry: { delaySeconds: 30 } }` | `{ retry: { delay: "30s" } }` |
219
+
220
+ It reads the options of `sendQueue()`, `deferQueue()`, `dynamicQueue.send()`, `dynamicQueue.defer()`, and `send()` and `sendBatch()` of a `useQueue()` client, also without an import in Nuxt server code, and of the old verbs `runQueue()` and `getQueue()`. Cloudflare's native `message.retry()` and `batch.retryAll()` keep `delaySeconds`. The report lists a `delay` value that is not a number in the code and old names that are left, such as options in a variable.
221
+
222
+ ```sh
223
+ npx @vite-hub/codemods queue-durations [dir] [--dry-run]
224
+ ```
225
+
186
226
  ## `nuxthub`
187
227
 
188
228
  The codemod runs when `package.json` or `modules` lists `@nuxthub/core`, or when `nuxt.config` sets `hub`. It follows [Migrate from NuxtHub](https://vitehub.dev/docs/getting-started/migrate-from-nuxthub) and makes only the edits that keep the same behavior:
@@ -264,6 +304,52 @@ Jobs with six-field crons, computed times or time zones, or a shape the codemod
264
304
 
265
305
  Jobs that map to the same Schedule name all stay unchanged, including names from existing files with another source extension or an `index` file. Configuration and module options must be object literals with explicit, unique property names. Opaque option objects, spreads, dynamic keys, or accessors stop the migration without edits; jobs with such options stay with `nuxt-cron`. Inline `vite-hub/nuxt` options take precedence over root `vitehub` options. Existing root or inline Schedule options require a manual migration; the codemod stops without edits. It also stops when the effective host or jobs directory is computed, or the host is `deno`, whose Nuxt integration cannot provide Schedule. On Node it enables KV when absent, and stops if KV is explicitly disabled: configure a default KV store before retrying.
266
306
 
307
+ ## `nuxt-better-auth`
308
+
309
+ The codemod moves a Nuxt app from `@nuxtjs/better-auth` to ViteHub Auth. It reads the app and its local layers (`layers/*` and relative `extends` paths):
310
+
311
+ - `server/auth.config.ts` becomes `server/auth.ts`, and `defineServerAuth()` becomes `defineAuth()` from `vite-hub/auth`. The Better Auth options stay. In a callback, `requestOrigin` stays and `runtimeConfig` becomes `useRuntimeConfig()` from `nitro/runtime-config`. When the app has a Database, or a NuxtHub one, the codemod adds `database: authDatabase()`.
312
+ - `app/auth.config.ts` becomes `app/auth.client.ts`, and `defineClientAuth()` becomes `defineAuthClient()` from `vite-hub/auth/vue`. A config without options goes away.
313
+ - A supported route rule with `auth` becomes `definePageMeta({ auth })` on each page it matches. A page that sets supported `auth` meta keeps it. Signed-in API rules become `access.routes` entries. Exact public exceptions and the Auth endpoints stay outside the generated API guard.
314
+ - `auth.redirects.login` and `auth.redirects.guest` become `access.signIn` and `access.afterSignIn` in `server/auth.ts`.
315
+ - In server code, `serverAuth(event)` becomes `useAuth(event)` and `requireUserSession(event)` becomes `requireAuth(event)`. Optional session reads use Better Auth's `getSession()` and forward its session cookies.
316
+ - `package.json` loses `@nuxtjs/better-auth` and gets `vite-hub`, `@vite-hub/auth`, and `better-auth` `^1.7.15`.
317
+
318
+ The codemod stops without editing Auth when it cannot preserve the source policy. For example, it stops on user-field checks, overlapping page rules, path-dependent page rules, guest-only API rules, and computed route redirects. It checks nested local layers. It stops for Nuxt environment overrides such as `$production` or `$env`, `extends` overrides, and `extends` entries it cannot inspect. It also stops when ViteHub Auth is disabled or the source configs cannot move to Definitions that ViteHub can load.
319
+
320
+ The report lists manual changes for `requireUserSession()` with options, client composables such as `useSignIn()` and `fetchSession()`, unsupported module options and helpers, `#nuxt-better-auth` types, and `NUXT_BETTER_AUTH_SECRET` in env files.
321
+
322
+ ```sh
323
+ npx @vite-hub/codemods nuxt-better-auth [dir] [--dry-run]
324
+ ```
325
+
326
+ ## `docus`
327
+
328
+ The codemod moves a site that extends the `docus` layer to `@vite-hub/docs`:
329
+
330
+ - `extends: ['docus']` goes, and `@vite-hub/docs/nuxt` joins `modules`. `site.name`, `site.url`, `llms.domain`, and the app config `seo`, `github`, and `socials` become `docs.site`, `docs.github`, and `docs.socials`.
331
+ - Files in `content/` lose the `1.` order prefix of Nuxt Content, and the order goes to `navigation.order`, or `order` in the folder's `.navigation.yml`. Page URLs stay the same.
332
+ - Frontmatter keeps only the fields that `@vite-hub/docs` reads, because another field fails its build. `seo.ogImage` becomes `seo.image`, `navigation.icon` becomes `icon`, and a page without `title` takes its first `# Heading`. `::callout` becomes `::note`.
333
+ - `package.json` loses `docus`, `@nuxt/content`, and `better-sqlite3`, and gets `@vite-hub/docs` and its peers.
334
+
335
+ The report lists what it does not move: Nuxt UI page components in Markdown, such as `::u-page-hero`, Vue components in `components/content/`, frontmatter fields such as `links`, and the app config keys and Docus module options without an equivalent.
336
+
337
+ The codemod stops without changing files if a destination is occupied, custom collections or extra Markdown could change the published pages, or it cannot preserve routes, local Markdown file links, or computed settings. Resolve the reported issue before migrating.
338
+
339
+ ```sh
340
+ npx @vite-hub/codemods docus [dir] [--dry-run]
341
+ ```
342
+
343
+ ## `nuxt-content`
344
+
345
+ The codemod moves the collections of `content.config.ts` to `server/content.ts`. Each collection becomes a `glob()` Source with the same files and paths, and a `schema` goes through `contentSource()`. `source.prefix` and `source.exclude` keep their paths. `z` from `@nuxt/content` becomes `z` from `zod`. Content serves the Sources with `access: 'public'`, as Nuxt Content did. `@nuxt/content` becomes `vite-hub/nuxt`, and `package.json` gets `vite-hub` and `@vite-hub/content`.
346
+
347
+ The report lists `queryCollection()` reads and `<ContentRenderer>`, because ViteHub Content reads with `content.get(path)` and `content.list()`. It also flags data collections, which need the `json()` or `yaml()` plugin, and the `content` options of `nuxt.config`. The codemod stops without changing files if any collection has a Source or schema it cannot translate safely, such as a remote `source.repository`, an exclusion it cannot rebase, or a schema that refers to a local declaration. A Docus site moves with `docus` instead.
348
+
349
+ ```sh
350
+ npx @vite-hub/codemods nuxt-content [dir] [--dry-run]
351
+ ```
352
+
267
353
  ## `agent-surface`
268
354
 
269
355
  ```sh
@@ -326,6 +412,86 @@ The same renames apply to the `@vite-hub/*` paths, to namespace imports, and to
326
412
  npx @vite-hub/codemods shell-driver [dir] [--dry-run]
327
413
  ```
328
414
 
415
+ ## `access-spellings`
416
+
417
+ Public access has one spelling, `access: "public"`, and sign-in has one, `authorize`:
418
+
419
+ | Old | New |
420
+ | --- | --- |
421
+ | `defineRealtime({ auth: true })` | `defineRealtime({ authorize: true })` |
422
+ | `defineRealtime({ auth: false, authorize })` | `defineRealtime({ authorize })` |
423
+ | `public: true` on `defineMcpTool()`, `defineMcpPrompt()`, and `defineMcpResource()` | `access: "public"` |
424
+ | `public: false` on an MCP definition | removed |
425
+
426
+ The codemod also changes default-export objects in `server/realtime/` and `server/mcp/`, and `defineRealtime()` without an import, as Nuxt auto-imports it. A Realtime definition with both `auth: true` and `authorize()` stays, and the report lists it: `authorize()` now also runs for signed-out callers, with `user: null`, so remove `auth` and return `false` when `user` is `null`.
427
+
428
+ ```sh
429
+ npx @vite-hub/codemods access-spellings [dir] [--dry-run]
430
+ ```
431
+
432
+ ## `auth-sign-in`
433
+
434
+ The sign-in pages of Auth are in one place, `access` of `server/auth.ts`:
435
+
436
+ | Old | New |
437
+ | --- | --- |
438
+ | `vitehub({ auth: { redirects: { login: '/login' } } })` | `defineAuth({ access: { signIn: '/login' } })` |
439
+ | `vitehub({ auth: { redirects: { guest: '/app' } } })` | `defineAuth({ access: { afterSignIn: '/app' } })` |
440
+ | `access: { signIn: { provider: 'github', callbackURL: '/app' } }` | `access: { signIn: { provider: 'github' }, afterSignIn: '/app' }` |
441
+
442
+ If a redirect cannot be migrated safely, the codemod leaves the files unchanged and reports what to move by hand. This covers conflicting overrides, destinations that are not literal app paths, dynamic Definition options, and a `redirects.login` page next to a provider in `access.signIn`.
443
+
444
+ ```sh
445
+ npx @vite-hub/codemods auth-sign-in [dir] [--dry-run]
446
+ ```
447
+
448
+ ## `channels`
449
+
450
+ `http()` is removed. Use `webhook()` from `vite-hub/channels` for an HTTP sender. Use `channelAdapter("http", options)` from `vite-hub/agent/channels` to keep the Channel kind and State.
451
+
452
+ The codemod rewrites direct calls without options or with a literal Boolean `route` option. Import paths stay the same. The report flags references, typed or complex calls, namespace imports, dynamic loads, re-exports of `http`, and mocks for manual review. To preserve the kind on a typed route, use `channelAdapter("http", options)` and type callback parameters explicitly. Use `webChat()` only if changing the kind is acceptable.
453
+
454
+ It also moves webhook secrets and signatures to the names of Webhooks:
455
+
456
+ | Old | New |
457
+ | --- | --- |
458
+ | `secretToken: process.env.X` in a `webhooks` registration | `secret: "X"` |
459
+ | `secretToken: () => …` in a `webhooks` registration | `secret: () => …` |
460
+ | `secret: process.env.X` in `webhook()` or `stripe()` | `secret: "X"` |
461
+ | `signature: "github-sha256"` or `"stripe-sha256"` | `signature: "github"` or `"stripe"` |
462
+ | `signature: { preset: "hmac-sha256", … }` | `signature: { type: "hmac-sha256", … }` |
463
+ | `{ preset: "stripe-sha256", toleranceSeconds: 600 }`, `stripe({ toleranceSeconds: 600 })` | `{ type: "stripe", tolerance: "600s" }`, `stripe({ tolerance: "600s" })` |
464
+
465
+ A string `secret` is the name of the server variable that holds the secret, in `webhook()`, `stripe()`, and every `webhooks` registration of `channelAdapter()`, `defineChannelTrigger()`, and the chat adapters. A direct read like `useServerEnv().github.webhookSecret` moves into a function. Existing resolvers stay intact. The report lists expressions the codemod cannot classify, `secretToken` strings, and possible hard-coded secrets on `stripe()` or with an old signature. Move hard-coded secrets to server variables and set `secret` to the variable name.
466
+
467
+ ```sh
468
+ npx @vite-hub/codemods channels [dir] [--dry-run]
469
+ ```
470
+
471
+ ## `auth-accessors`
472
+
473
+ Auth has one server accessor, `useAuth(event?)`:
474
+
475
+ | Old | New |
476
+ | --- | --- |
477
+ | `auth` from `vite-hub/auth/server` | `useAuth()` |
478
+ | `getAuth()` from `vite-hub/auth/server` | `useAuth()` |
479
+ | `await isGitHubOrgMember(token, 'acme')` from `vite-hub/auth` | `(!(await checkGitHubOrgMember(token, 'acme'))[0])` |
480
+
481
+ The codemod also changes named imports from `#vitehub/auth/server`. It reports possible `auth` and `getAuth()` auto-imports in `server/` without editing them, because those names can come from your app. `useAuth()` without an event reads the app's Auth Definition, as before. In a route, pass the event yourself: `useAuth(event)`. The report lists `useSession()` imports and possible app auto-imports, because `useUserSession()` names its refs differently. The codemod leaves membership imports unchanged if a call is not awaited or the organization may be empty.
482
+
483
+ ```sh
484
+ npx @vite-hub/codemods auth-accessors [dir] [--dry-run]
485
+ ```
486
+
487
+ ## `cli-url-flag`
488
+
489
+ `--url` is the app URL in every `vitehub` command. The codemod changes `--server <url>` to `--url <url>` in the `vitehub` calls of `package.json` scripts, `.github/workflows/*.yml`, and `*.sh` files. A `--url` that names the Console, such as `http://localhost:3000/_vitehub`, now fails: pass the app URL without `/_vitehub`.
490
+
491
+ ```sh
492
+ npx @vite-hub/codemods cli-url-flag [dir] [--dry-run]
493
+ ```
494
+
329
495
  ## Check real apps
330
496
 
331
497
  `test/real-world/projects.json` pins open source Nuxt apps that use the supported modules. The runner clones each app outside the repository, installs it when its codemod loads app code, runs the migration, and checks which codemods ran and what the report says:
@@ -345,6 +511,44 @@ ViteHub types the `#vitehub/*` aliases itself, in `.vitehub/types/`. Older apps
345
511
  npx @vite-hub/codemods tsconfig-paths [dir] [--dry-run]
346
512
  ```
347
513
 
514
+ ## `workspace-repo`
515
+
516
+ `workspace-repo` renames the `repository` option of a GitHub Workspace Store to `repo`, the one spelling that the Store reads:
517
+
518
+ ```sh
519
+ npx @vite-hub/codemods workspace-repo [dir] [--dry-run]
520
+ ```
521
+
522
+ ```diff [server/workspaces/handbook.ts]
523
+ export default defineWorkspace({
524
+ store: {
525
+ driver: 'github',
526
+ - repository: 'acme/handbook',
527
+ + repo: 'acme/handbook',
528
+ },
529
+ })
530
+ ```
531
+
532
+ The codemod changes inline GitHub Stores in `defineWorkspace()` and `vitehub()` calls. If a Store sets both keys or uses spreads or computed keys, the report asks you to move the previously effective repository to `repo` by hand. Migrate separately declared Store options by hand as well. The Workspace `fetch()` Source is now `url()`; `renamed-apis` updates imports while keeping their local names.
533
+
534
+ ## `cms-roles`
535
+
536
+ `cms-roles` renames the option of the `cms` Content preset that turns on the CMS role policy:
537
+
538
+ ```sh
539
+ npx @vite-hub/codemods cms-roles [dir] [--dry-run]
540
+ ```
541
+
542
+ ```diff [server/content.ts]
543
+ export default defineContent({
544
+ - extends: [cms, { access: 'roles' }],
545
+ + extends: [cms, { roles: true }],
546
+ collections,
547
+ })
548
+ ```
549
+
550
+ The `access` option of `defineContent()` itself, such as `access: 'public'`, stays. The report lists a preset `access` value that is not the literal `'roles'`.
551
+
348
552
  ## Add a codemod
349
553
 
350
554
  A codemod is a `Codemod` object with a `name`, a one-line `description`, a `detect()` function that tells whether the app uses what it migrates, and a `run()` function that returns planned edits and follow-ups. `run()` must not write files; the runner writes them, or prints them in a dry run. Add the codemod to `src/registry.ts`; the order there is the order in which the migration runs codemods. A codemod that moves an app from an older ViteHub API also goes in `upgradeCodemods`, so `vitehub migrate` runs it. Shared `nuxt.config` and `package.json` helpers live in `src/shared`.