@vite-hub/codemods 0.3.1 → 0.5.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/README.md +306 -12
- package/dist/{cli-main-N5ZWa_hM.js → cli-main-aLhc0Eyq.js} +12252 -5311
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @vite-hub/codemods
|
|
2
2
|
|
|
3
|
-
[](https://npmx.dev/package/@vite-hub/codemods)
|
|
4
|
+
[](https://github.com/vite-hub/vitehub/blob/main/LICENSE)
|
|
5
|
+
[](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
|
|
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 `
|
|
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`, `choices-package`, `cli-get-list`, `cli-agent-tree`, and `nuxt-server-imports`. 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,34 @@ 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`
|
|
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` | Imports of `vite-hub/agent/channels` to `vite-hub/channels/adapters` and `vite-hub/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. |
|
|
74
|
+
| `cli-get-list` | `vitehub` read commands in scripts and CI: `show` and `info` to `get`, `env inspect` and `env status` to `env list`, `schedule runs` to `runs list`. `vitehub migrate` runs it. |
|
|
75
|
+
| `cli-agent-tree` | `vitehub` Agent calls in scripts and CI: `agents …`, `invocations …`, and `conversations export` move under `vitehub agent`. `vitehub migrate` runs it. |
|
|
76
|
+
| `nuxt-server-imports` | ViteHub server helpers, such as `kv` and `sendQueue`, that Nuxt server files used as auto-imports, to explicit imports from `vite-hub/*`. `vitehub migrate` runs it last. |
|
|
59
77
|
|
|
60
78
|
## `runtime-contracts`
|
|
61
79
|
|
|
@@ -83,6 +101,7 @@ ViteHub renamed some APIs. `renamed-apis` rewrites the code of an app that uses
|
|
|
83
101
|
| `hubDb` from `@vite-hub/database/vite` or `@vite-hub/database/nuxt` | `hubDatabase` |
|
|
84
102
|
| `hubKv` from `@vite-hub/kv/vite` | `hubKV` |
|
|
85
103
|
| `createWorkspaceDriver` from `@vite-hub/workspace/mountx` | `createMountxDriver` |
|
|
104
|
+
| `fetch` from `vite-hub/workspace` or `@vite-hub/workspace`, the URL Source | `url` |
|
|
86
105
|
| `console` from `vite-hub/console/server` | `agentConsole` |
|
|
87
106
|
| `kv.del()`, `blob.del()`, `kv.store(name).del()` | `.delete()` |
|
|
88
107
|
| `deriveSecret(purpose, event)` | `deriveSecret(purpose, { event })` |
|
|
@@ -122,8 +141,11 @@ ViteHub keeps one define form for each primitive. `define-forms` rewrites the fo
|
|
|
122
141
|
|
|
123
142
|
| Former form | New form |
|
|
124
143
|
| --- | --- |
|
|
144
|
+
| `defineQueue(handler, { concurrency: 5 })` | `defineQueue({ handler, concurrency: 5 })` |
|
|
125
145
|
| `defineSchedule("0 9 * * *", handler, { manual: true })` | `defineSchedule({ cron: "0 9 * * *", manual: true, handler })` |
|
|
126
146
|
| `defineSandboxTask({ run })` | `defineSandboxTask({ handler })` |
|
|
147
|
+
| `defineWorkflow("onboard-user", async (payload: Payload, { steps }) => {}, { native })` | `defineWorkflow<Payload>({ handler: async ({ payload, steps }) => {}, native })`. The file path is the name. |
|
|
148
|
+
| `createWorkflow("welcome", async (payload: Payload) => {})` | `createWorkflow<Payload>("welcome", async ({ payload }) => {})` |
|
|
127
149
|
| `export const content = defineContent({ ... })` in `server/content.ts` | `export default defineContent({ ... })`, and `import content from` in the files that import it |
|
|
128
150
|
| `server/databases/config.ts` and the files beside it | `server/databases/default/index.ts` and the same files in `server/databases/default/` |
|
|
129
151
|
| `server/databases/migrations/` | `server/databases/default/migrations/` |
|
|
@@ -131,7 +153,11 @@ ViteHub keeps one define form for each primitive. `define-forms` rewrites the fo
|
|
|
131
153
|
|
|
132
154
|
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
155
|
|
|
134
|
-
The
|
|
156
|
+
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.
|
|
157
|
+
|
|
158
|
+
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.
|
|
159
|
+
|
|
160
|
+
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
161
|
|
|
136
162
|
```sh
|
|
137
163
|
npx @vite-hub/codemods define-forms [dir] [--dry-run]
|
|
@@ -139,21 +165,21 @@ npx @vite-hub/codemods define-forms [dir] [--dry-run]
|
|
|
139
165
|
|
|
140
166
|
## `vitehub-options`
|
|
141
167
|
|
|
142
|
-
`vitehub()` is the only config place, and `logs` is
|
|
168
|
+
`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
169
|
|
|
144
170
|
| Old | New |
|
|
145
171
|
| --- | --- |
|
|
146
172
|
| `vitehub({ preset })`, `vitehub: { preset }` in `nuxt.config.ts` | `host` |
|
|
147
173
|
| `sandbox: true` | `sandboxTask: true` |
|
|
148
|
-
| `vitehub({ logs: true })` | `vitehub({
|
|
149
|
-
| `logs: { evlog, source }` | `observability: { evlog, logs: { source }
|
|
174
|
+
| `vitehub({ observability: { logs: true } })` | `vitehub({ logs: true })` |
|
|
175
|
+
| `logs: { evlog, source }` | `observability: { evlog }, logs: { source }` |
|
|
150
176
|
| `defineConfig({ env: { server }, plugins: [vitehub()] })` | `vitehub({ env: { server } })` |
|
|
151
177
|
| `defineConfig({ env, plugins: [hubEnv()] })` | `hubEnv({ ...declarations })` |
|
|
152
178
|
| `vite: { env }` in `nuxt.config.ts` | `env` in the `vite-hub/nuxt` options |
|
|
153
179
|
| A top-level Vite key such as `kv` or `blob` | `vitehub({ kv })`, or the argument of `hubKV()` |
|
|
154
180
|
| `devtools`, `contentImportBase` | removed |
|
|
155
181
|
|
|
156
|
-
The report lists what the codemod cannot move: `preset` next to `host`, `sandbox` options that are not a boolean, `cloudflare.secretsFile`,
|
|
182
|
+
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
183
|
|
|
158
184
|
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
185
|
|
|
@@ -183,6 +209,23 @@ The codemod reads imports from `vite-hub/queue`, `vite-hub/workflow`, and their
|
|
|
183
209
|
npx @vite-hub/codemods queue-workflow-verbs [dir] [--dry-run]
|
|
184
210
|
```
|
|
185
211
|
|
|
212
|
+
## `queue-durations`
|
|
213
|
+
|
|
214
|
+
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:
|
|
215
|
+
|
|
216
|
+
| Old | New |
|
|
217
|
+
| --- | --- |
|
|
218
|
+
| `{ delaySeconds: 60 }` | `{ delay: "60s" }` |
|
|
219
|
+
| `{ delaySeconds: 24 * 60 * 60 }` | `{ delay: "86400s" }` |
|
|
220
|
+
| `{ retentionSeconds: 3600 }` | `{ retention: 3600 }` |
|
|
221
|
+
| `onError` returns `{ retry: { delaySeconds: 30 } }` | `{ retry: { delay: "30s" } }` |
|
|
222
|
+
|
|
223
|
+
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.
|
|
224
|
+
|
|
225
|
+
```sh
|
|
226
|
+
npx @vite-hub/codemods queue-durations [dir] [--dry-run]
|
|
227
|
+
```
|
|
228
|
+
|
|
186
229
|
## `nuxthub`
|
|
187
230
|
|
|
188
231
|
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:
|
|
@@ -192,6 +235,7 @@ The codemod runs when `package.json` or `modules` lists `@nuxthub/core`, or when
|
|
|
192
235
|
- Schema: moves `server/db/schema.ts`, `server/db/schema.<dialect>.ts`, or the `server/db/schema/` folder to `server/databases/default/`, and writes `server/databases/default/index.ts` with `defineDatabase({ schema })`. Like NuxtHub, it reads only the top-level files of the folder, and skips files for another dialect, such as `users.sqlite.ts` in a Postgres app. Static, dynamic, CommonJS, and type imports follow the moved files. An aggregate exports every schema file, including an existing index; the report asks you to check conflicting exports. Legacy `relations()` declarations and each `db.query` use become follow-ups: rewrite them with Drizzle 1.0's `defineRelations()`, pass them to the Database Definition, and update relational filters before running the app. A query with a `where` function gets its own follow-up, because Drizzle 1.0 reads `where` as an object.
|
|
193
236
|
- Database options: for Postgres, the Definition reads `POSTGRES_URL`, then `POSTGRESQL_URL`, then `DATABASE_URL`, as NuxtHub did. `connection.hyperdriveId` becomes `cloudflare.hyperdriveId`. `driver: 'd1-http'` becomes `cloudflare: { databaseId, http: true }`, and the report lists the `NUXT_HUB_CLOUDFLARE_*` variables to rename. `casing` becomes a follow-up, because Drizzle 1.0 sets casing per table. Schema files in local layers (`layers/*` and relative `extends`) become follow-ups too.
|
|
194
237
|
- Imports: `hub:db` and `@nuxthub/db` become `vite-hub/database`, which exports `db` and `schema`. `hub:kv` and `hub:blob` become `vite-hub/kv` and `vite-hub/blob`. `hub:db:schema` becomes a relative import of the moved schema.
|
|
238
|
+
- Auto-imports: NuxtHub auto-imported `kv`, `blob`, `db`, and `schema` in server code, and Nuxt 5 does not. Each server file that uses one of them without an import gets an import from `vite-hub/*`. A name that the app gives from `server/utils/` stays as it is.
|
|
195
239
|
- KV and Blob calls: tuple-returning methods such as `const x = await kv.get(k)` and `await blob.del(p)` get a tuple and `if (error) throw error`, also for returns in async functions. `blob.delete()` becomes `blob.del()`. `blob.serve()` returns a Response unchanged; in an H3 handler the event argument becomes `event.req`. An unknown event or an unsupported use of a tuple becomes a follow-up with `file:line`.
|
|
196
240
|
- Wrangler config: the D1 `migrations_table: "_hub_migrations"` goes, because ViteHub must not reuse it. On Cloudflare, KV, cache, and Blob options keep the resource that matches the original binding or its `KV`, `CACHE`, or `BLOB` default. R2 options keep the bucket's jurisdiction too. Unrelated bindings stay in place. The report lists the matched entries to remove after checking the generated options, and the D1 options to set by hand.
|
|
197
241
|
- Modules that expect NuxtHub: ViteHub does not emulate NuxtHub's module APIs, so the codemod reports them as follow-ups and changes nothing. It finds the `hub:db:schema:extend`, `hub:db:migrations:dirs`, and `hub:db:queries:paths` hooks in `nuxt.config`, in the `modules/` folder, and in local layers (`layers/*` and relative `extends` paths), and points to `vitehub.databases` contributions or a custom migration. It also reports `studio.media.external` of nuxt-studio, and each installed dependency whose `package.json` lists `@nuxthub/core` in `peerDependencies` or `dependencies`, such as `@evlog/nuxthub`.
|
|
@@ -264,6 +308,52 @@ Jobs with six-field crons, computed times or time zones, or a shape the codemod
|
|
|
264
308
|
|
|
265
309
|
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
310
|
|
|
311
|
+
## `nuxt-better-auth`
|
|
312
|
+
|
|
313
|
+
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):
|
|
314
|
+
|
|
315
|
+
- `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()`.
|
|
316
|
+
- `app/auth.config.ts` becomes `app/auth.client.ts`, and `defineClientAuth()` becomes `defineAuthClient()` from `vite-hub/auth/vue`. A config without options goes away.
|
|
317
|
+
- 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.
|
|
318
|
+
- `auth.redirects.login` and `auth.redirects.guest` become `access.signIn` and `access.afterSignIn` in `server/auth.ts`.
|
|
319
|
+
- 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.
|
|
320
|
+
- `package.json` loses `@nuxtjs/better-auth` and gets `vite-hub`, `@vite-hub/auth`, and `better-auth` `^1.7.15`.
|
|
321
|
+
|
|
322
|
+
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.
|
|
323
|
+
|
|
324
|
+
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.
|
|
325
|
+
|
|
326
|
+
```sh
|
|
327
|
+
npx @vite-hub/codemods nuxt-better-auth [dir] [--dry-run]
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## `docus`
|
|
331
|
+
|
|
332
|
+
The codemod moves a site that extends the `docus` layer to `@vite-hub/docs`:
|
|
333
|
+
|
|
334
|
+
- `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`.
|
|
335
|
+
- 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.
|
|
336
|
+
- 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`.
|
|
337
|
+
- `package.json` loses `docus`, `@nuxt/content`, and `better-sqlite3`, and gets `@vite-hub/docs` and its peers.
|
|
338
|
+
|
|
339
|
+
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.
|
|
340
|
+
|
|
341
|
+
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.
|
|
342
|
+
|
|
343
|
+
```sh
|
|
344
|
+
npx @vite-hub/codemods docus [dir] [--dry-run]
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
## `nuxt-content`
|
|
348
|
+
|
|
349
|
+
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`.
|
|
350
|
+
|
|
351
|
+
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.
|
|
352
|
+
|
|
353
|
+
```sh
|
|
354
|
+
npx @vite-hub/codemods nuxt-content [dir] [--dry-run]
|
|
355
|
+
```
|
|
356
|
+
|
|
267
357
|
## `agent-surface`
|
|
268
358
|
|
|
269
359
|
```sh
|
|
@@ -326,6 +416,172 @@ The same renames apply to the `@vite-hub/*` paths, to namespace imports, and to
|
|
|
326
416
|
npx @vite-hub/codemods shell-driver [dir] [--dry-run]
|
|
327
417
|
```
|
|
328
418
|
|
|
419
|
+
## `access-spellings`
|
|
420
|
+
|
|
421
|
+
Public access has one spelling, `access: "public"`, and sign-in has one, `authorize`:
|
|
422
|
+
|
|
423
|
+
| Old | New |
|
|
424
|
+
| --- | --- |
|
|
425
|
+
| `defineRealtime({ auth: true })` | `defineRealtime({ authorize: true })` |
|
|
426
|
+
| `defineRealtime({ auth: false, authorize })` | `defineRealtime({ authorize })` |
|
|
427
|
+
| `public: true` on `defineMcpTool()`, `defineMcpPrompt()`, and `defineMcpResource()` | `access: "public"` |
|
|
428
|
+
| `public: false` on an MCP definition | removed |
|
|
429
|
+
|
|
430
|
+
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`.
|
|
431
|
+
|
|
432
|
+
```sh
|
|
433
|
+
npx @vite-hub/codemods access-spellings [dir] [--dry-run]
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
## `auth-sign-in`
|
|
437
|
+
|
|
438
|
+
The sign-in pages of Auth are in one place, `access` of `server/auth.ts`:
|
|
439
|
+
|
|
440
|
+
| Old | New |
|
|
441
|
+
| --- | --- |
|
|
442
|
+
| `vitehub({ auth: { redirects: { login: '/login' } } })` | `defineAuth({ access: { signIn: '/login' } })` |
|
|
443
|
+
| `vitehub({ auth: { redirects: { guest: '/app' } } })` | `defineAuth({ access: { afterSignIn: '/app' } })` |
|
|
444
|
+
| `access: { signIn: { provider: 'github', callbackURL: '/app' } }` | `access: { signIn: { provider: 'github' }, afterSignIn: '/app' }` |
|
|
445
|
+
|
|
446
|
+
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`.
|
|
447
|
+
|
|
448
|
+
```sh
|
|
449
|
+
npx @vite-hub/codemods auth-sign-in [dir] [--dry-run]
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
## `channels`
|
|
453
|
+
|
|
454
|
+
`vite-hub/agent/channels` is removed, and so is `http()`:
|
|
455
|
+
|
|
456
|
+
| Old | New |
|
|
457
|
+
| --- | --- |
|
|
458
|
+
| `import { slack, webChat } from "vite-hub/agent/channels"` | `import { slack, webChat } from "vite-hub/channels/adapters"` |
|
|
459
|
+
| `import { defineChannelTrigger, ignored } from "vite-hub/agent/channels"` | `import { defineChannelTrigger, ignored } from "vite-hub/channels"` |
|
|
460
|
+
| `import { webhook } from "vite-hub/channels"` | `import { webhook } from "vite-hub/channels/adapters"` |
|
|
461
|
+
| `http(options)` | `channelAdapter("http", options)` |
|
|
462
|
+
|
|
463
|
+
`vite-hub/channels` has `defineChannel()`, `defineChannelTrigger()`, `ignored()`, `retryLater()`, and `rejected()`, and needs no `@vite-hub/agent`. Every adapter, also `webhook()` and `stripe()`, comes from `vite-hub/channels/adapters`. A namespace import, a re-export, an `import()` call, and a `vi.mock()` path move to `vite-hub/channels/adapters`, and the report lists each mock. The owner path `@vite-hub/agent/channels` stays.
|
|
464
|
+
|
|
465
|
+
The codemod rewrites `http()` calls without options or with a literal Boolean `route` option. 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.
|
|
466
|
+
|
|
467
|
+
It also moves webhook secrets and signatures to the names of Webhooks:
|
|
468
|
+
|
|
469
|
+
| Old | New |
|
|
470
|
+
| --- | --- |
|
|
471
|
+
| `secretToken: process.env.X` in a `webhooks` registration | `secret: "X"` |
|
|
472
|
+
| `secretToken: () => …` in a `webhooks` registration | `secret: () => …` |
|
|
473
|
+
| `secret: process.env.X` in `webhook()` or `stripe()` | `secret: "X"` |
|
|
474
|
+
| `signature: "github-sha256"` or `"stripe-sha256"` | `signature: "github"` or `"stripe"` |
|
|
475
|
+
| `signature: { preset: "hmac-sha256", … }` | `signature: { type: "hmac-sha256", … }` |
|
|
476
|
+
| `{ preset: "stripe-sha256", toleranceSeconds: 600 }`, `stripe({ toleranceSeconds: 600 })` | `{ type: "stripe", tolerance: "600s" }`, `stripe({ tolerance: "600s" })` |
|
|
477
|
+
|
|
478
|
+
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.
|
|
479
|
+
|
|
480
|
+
It also moves webhook secrets and signatures to the names of Webhooks:
|
|
481
|
+
|
|
482
|
+
| Old | New |
|
|
483
|
+
| --- | --- |
|
|
484
|
+
| `secretToken: process.env.X` in a `webhooks` registration | `secret: "X"` |
|
|
485
|
+
| `secretToken: () => …` in a `webhooks` registration | `secret: () => …` |
|
|
486
|
+
| `secret: process.env.X` in `webhook()` or `stripe()` | `secret: "X"` |
|
|
487
|
+
| `signature: "github-sha256"` or `"stripe-sha256"` | `signature: "github"` or `"stripe"` |
|
|
488
|
+
| `signature: { preset: "hmac-sha256", … }` | `signature: { type: "hmac-sha256", … }` |
|
|
489
|
+
| `{ preset: "stripe-sha256", toleranceSeconds: 600 }`, `stripe({ toleranceSeconds: 600 })` | `{ type: "stripe", tolerance: "600s" }`, `stripe({ tolerance: "600s" })` |
|
|
490
|
+
|
|
491
|
+
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.
|
|
492
|
+
|
|
493
|
+
```sh
|
|
494
|
+
npx @vite-hub/codemods channels [dir] [--dry-run]
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
## `auth-accessors`
|
|
498
|
+
|
|
499
|
+
Auth has one server accessor, `useAuth(event?)`:
|
|
500
|
+
|
|
501
|
+
| Old | New |
|
|
502
|
+
| --- | --- |
|
|
503
|
+
| `auth` from `vite-hub/auth/server` | `useAuth()` |
|
|
504
|
+
| `getAuth()` from `vite-hub/auth/server` | `useAuth()` |
|
|
505
|
+
| `await isGitHubOrgMember(token, 'acme')` from `vite-hub/auth` | `(!(await checkGitHubOrgMember(token, 'acme'))[0])` |
|
|
506
|
+
|
|
507
|
+
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.
|
|
508
|
+
|
|
509
|
+
```sh
|
|
510
|
+
npx @vite-hub/codemods auth-accessors [dir] [--dry-run]
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
## `cli-url-flag`
|
|
514
|
+
|
|
515
|
+
`--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`.
|
|
516
|
+
|
|
517
|
+
```sh
|
|
518
|
+
npx @vite-hub/codemods cli-url-flag [dir] [--dry-run]
|
|
519
|
+
## `cli-get-list`
|
|
520
|
+
|
|
521
|
+
`get` reads one record and `list` reads many. The codemod renames the `vitehub` calls in `package.json` scripts, `.github/workflows/*.yml`, and `*.sh` files:
|
|
522
|
+
|
|
523
|
+
| Old | New |
|
|
524
|
+
| --- | --- |
|
|
525
|
+
| `vitehub agent info` | `vitehub agent get` |
|
|
526
|
+
| `vitehub agent invocations show` | `vitehub agent invocations get` |
|
|
527
|
+
| `vitehub content show`, `vitehub workspace show` | `get` |
|
|
528
|
+
| `vitehub email outbox show`, `vitehub queue jobs show` | `outbox get`, `jobs get` |
|
|
529
|
+
| `vitehub workflow get` | `vitehub workflow runs get --json` |
|
|
530
|
+
| `vitehub workflow runs show` | `vitehub workflow runs get` (use `--run-id` for `--id`) |
|
|
531
|
+
| `vitehub schedule runs <schedule>` | `vitehub schedule runs list <schedule>` |
|
|
532
|
+
| `vitehub schedule attempts <run>` | `vitehub schedule runs get <run>` |
|
|
533
|
+
| `vitehub env inspect` | `vitehub env list` |
|
|
534
|
+
| `vitehub env status --url <app>` | `vitehub env list --url <app> --json` |
|
|
535
|
+
| `vitehub project info` | `vitehub project get` |
|
|
536
|
+
| `vitehub definitions list` | `vitehub inspect definitions --kind <kind>` for local definitions; use the Console for runtime records |
|
|
537
|
+
|
|
538
|
+
The codemod updates simple shell invocations. It skips scripts and steps with complex shell syntax, such as command substitutions or parameter defaults, to avoid editing text that is not a command. It reports recognized calls that need a manual change. `env status` without `--url` asked the dev server; pass that URL explicitly rather than reading the local stage. Review old `env status` calls using `--timeout` or `--input`, which `env list` does not accept. For `workflow runs show --input`, rename `id` to `runId` in the JSON. Review `definitions list` calls to choose between local inspection and the Console.
|
|
539
|
+
|
|
540
|
+
```sh
|
|
541
|
+
npx @vite-hub/codemods cli-get-list [dir] [--dry-run]
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
## `cli-agent-tree`
|
|
545
|
+
|
|
546
|
+
Every Agent command is under `vitehub agent`. The codemod moves the `vitehub` calls in `package.json` scripts, `.github/workflows/*.yml`, and `*.sh` files:
|
|
547
|
+
|
|
548
|
+
| Old | New |
|
|
549
|
+
| --- | --- |
|
|
550
|
+
| `vitehub agents list`, `vitehub agents invoke <agent>` | `vitehub agent list`, `vitehub agent invoke <agent>` |
|
|
551
|
+
| `vitehub agents status --agent <name>`, `vitehub agent get --agent <name>` | `vitehub agent get <name>` |
|
|
552
|
+
| `vitehub invocations list\|get\|cancel\|undo\|delete\|capabilities\|workspace` | `vitehub agent invocations …` |
|
|
553
|
+
| `vitehub conversations export` | `vitehub agent conversations export` |
|
|
554
|
+
|
|
555
|
+
The codemod leaves old Console deletes untouched. Migrate them by hand to `vitehub agent invocations delete <id> --url <app>` with the same app, and use `--yes` in scripts. Without `--url` the new command deletes from the journal file.
|
|
556
|
+
|
|
557
|
+
Migrate old `invocations list` and `get` calls by hand. Check the new command's `--help` for supported inputs. The CLI list output no longer includes the Console cursor, and get emits a flat record with `--json` and does not accept observation paging options. The Console RPC still supports the old contracts. For Agent inspection, `--url` selects the Console unless you add `--dev` to select the Dev Loop.
|
|
558
|
+
|
|
559
|
+
```sh
|
|
560
|
+
npx @vite-hub/codemods cli-agent-tree [dir] [--dry-run]
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
## `nuxt-server-imports`
|
|
564
|
+
|
|
565
|
+
On Nuxt 5, `vite-hub/nuxt` auto-imports its server helpers only when the app sets `experimental.nitroAutoImports: true` or `nitroLegacy`. This codemod adds an explicit import to each Nuxt server file that uses a helper without one:
|
|
566
|
+
|
|
567
|
+
```diff [server/api/welcome.post.ts]
|
|
568
|
+
import { defineEventHandler, readBody } from "nitro/h3"
|
|
569
|
+
+import { kv } from "vite-hub/kv"
|
|
570
|
+
+import { sendQueue } from "vite-hub/queue"
|
|
571
|
+
|
|
572
|
+
export default defineEventHandler(async (event) => {
|
|
573
|
+
const { email } = await readBody<{ email: string }>(event)
|
|
574
|
+
const [error] = await sendQueue("welcome", { email })
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
- It reads the server directory (`serverDir`) of the app and of each local layer, and the helper list of `vite-hub/nuxt`.
|
|
578
|
+
- It joins a name with an existing value import of the same `vite-hub/*` entry. It leaves a name that the file declares or imports.
|
|
579
|
+
- It preserves app-owned server auto-imports, including utility re-exports and names set in `nitro.imports`. The report lists the preserved names.
|
|
580
|
+
- It leaves files alone when Nuxt still injects the ViteHub helpers. If it cannot resolve the effective config or an auto-import source statically, it reports what to check instead of guessing.
|
|
581
|
+
- The report names the files that still use Nitro and H3 helpers, such as `defineEventHandler`, without an import. The Nuxt 5 build error lists their import paths.
|
|
582
|
+
|
|
583
|
+
`vitehub migrate` runs it last, so it imports the names that the other codemods write, such as `useAuth` and `sendQueue`.
|
|
584
|
+
|
|
329
585
|
## Check real apps
|
|
330
586
|
|
|
331
587
|
`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 +601,44 @@ ViteHub types the `#vitehub/*` aliases itself, in `.vitehub/types/`. Older apps
|
|
|
345
601
|
npx @vite-hub/codemods tsconfig-paths [dir] [--dry-run]
|
|
346
602
|
```
|
|
347
603
|
|
|
604
|
+
## `workspace-repo`
|
|
605
|
+
|
|
606
|
+
`workspace-repo` renames the `repository` option of a GitHub Workspace Store to `repo`, the one spelling that the Store reads:
|
|
607
|
+
|
|
608
|
+
```sh
|
|
609
|
+
npx @vite-hub/codemods workspace-repo [dir] [--dry-run]
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
```diff [server/workspaces/handbook.ts]
|
|
613
|
+
export default defineWorkspace({
|
|
614
|
+
store: {
|
|
615
|
+
driver: 'github',
|
|
616
|
+
- repository: 'acme/handbook',
|
|
617
|
+
+ repo: 'acme/handbook',
|
|
618
|
+
},
|
|
619
|
+
})
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
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.
|
|
623
|
+
|
|
624
|
+
## `cms-roles`
|
|
625
|
+
|
|
626
|
+
`cms-roles` renames the option of the `cms` Content preset that turns on the CMS role policy:
|
|
627
|
+
|
|
628
|
+
```sh
|
|
629
|
+
npx @vite-hub/codemods cms-roles [dir] [--dry-run]
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
```diff [server/content.ts]
|
|
633
|
+
export default defineContent({
|
|
634
|
+
- extends: [cms, { access: 'roles' }],
|
|
635
|
+
+ extends: [cms, { roles: true }],
|
|
636
|
+
collections,
|
|
637
|
+
})
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
The `access` option of `defineContent()` itself, such as `access: 'public'`, stays. The report lists a preset `access` value that is not the literal `'roles'`.
|
|
641
|
+
|
|
348
642
|
## Add a codemod
|
|
349
643
|
|
|
350
644
|
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`.
|