@vite-hub/codemods 0.5.0 → 0.6.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 +68 -13
- package/dist/{cli-main-aLhc0Eyq.js → cli-main-ICe6yfP7.js} +2447 -581
- package/dist/cli.js +2 -3
- package/dist/index.d.ts +16 -18
- package/dist/index.js +1 -2
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -6,21 +6,31 @@
|
|
|
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 24.15 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 22.12 or newer. The migrated app needs Node.js 24.15 or newer for `vite-hub`, and the report says so when the shell runs an older Node.js. 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
|
|
|
13
13
|
```sh
|
|
14
|
-
npx @vite-hub/codemods [dir] [--dry-run]
|
|
14
|
+
npx @vite-hub/codemods [dir] [--dry-run] [--nuxt-nightly]
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
The command finds every module in the app that a codemod supports and runs those codemods one after another, so each one sees the edits of the ones before it. `dir` is the application directory. It defaults to the current directory. `--dry-run` prints the combined edits as diffs and the report, and writes nothing.
|
|
18
18
|
|
|
19
|
-
The report lists, for each codemod, why it ran and what it did, then the files it changed, a numbered list of manual follow-ups with `file:line`, notes, and the commands to run next. A codemod that cannot migrate the app changes nothing and says why; the others still run.
|
|
19
|
+
The report lists, for each codemod, why it ran and what it did, then the files it changed, a numbered list of manual follow-ups with `file:line`, notes, and the commands to run next. A codemod that cannot migrate the app changes nothing and says why; the others still run.
|
|
20
|
+
|
|
21
|
+
The codemods that add `vite-hub/nuxt`, such as `nuxt-safe-runtime-config` and `nuxthub`, need Nitro 3, which runs on Nuxt 4.7 with the `nitro` package, or on Nuxt 5. The command reads the `nuxt` range in `package.json`, directly or through a pnpm `catalog:` in `pnpm-workspace.yaml`:
|
|
22
|
+
|
|
23
|
+
- Only Nuxt 5, such as `npm:nuxt-nightly@5x`: no change.
|
|
24
|
+
- Nuxt 4.7 and no earlier version, such as `^4.7.0` or `>=4.7.0 <6`: it adds `"nitro": "^3.0.261103-rc"` to `dependencies` when `package.json` does not list `nitro`, or replaces a `nitro` range outside it, such as `2.2.28`. The report notes the change.
|
|
25
|
+
- A range that allows a version before 4.7, such as `^4.2.0`: it stops before it writes anything, also with `--dry-run`, and exits with `1`. Upgrade with `pnpm add nuxt@^4.7.0 nitro`, or add `--nuxt-nightly` to set `"nuxt": "npm:nuxt-nightly@5x"` in `package.json` and migrate in the same run.
|
|
26
|
+
|
|
27
|
+
Each codemod also adds `vite-hub` and the packages of each ViteHub feature that it turns on to `package.json`, such as `@vite-hub/email` for `resend`, and `@vite-hub/schedule` and `@vite-hub/kv` for `nuxt-cron` on Node. Without them, the build stops with `VITE_HUB_R0136`. Run the install command that the report lists. The codemods do not change the Nuxt version without `--nuxt-nightly`, and do not install packages. Nuxt 5 stops auto-importing Nitro helpers such as `defineEventHandler` in server code. Set `experimental: { nitroAutoImports: true }` to keep them, or import them as the Nuxt 5 build error lists.
|
|
28
|
+
|
|
29
|
+
New feature packages use the app's existing `vite-hub` version, range, or matching ViteHub preview. If the codemod cannot match that dependency, it stops before writing the migration and asks you to update the `vite-hub` entry.
|
|
20
30
|
|
|
21
31
|
The migration uses a unique scratch directory and preserves existing `.vitehub-migrate` directories. If a codemod would edit a symbolic link or a file inside a linked directory, it stops without applying that codemod's edits. Running one codemod does the same. Replace the link with a local file or directory before retrying.
|
|
22
32
|
|
|
23
|
-
The command exits with `0` when every codemod completes, also when they report follow-ups, and when no codemod applies. A plain Vite or Node app needs no `nuxt.config`. It exits with `1` when a codemod could not migrate, when the folder has neither `package.json` nor `nuxt.config`, or when `nuxt.config` does not parse.
|
|
33
|
+
The command exits with `0` when every codemod completes, also when they report follow-ups, and when no codemod applies. A plain Vite or Node app needs no `nuxt.config`. It exits with `1` when a codemod could not migrate, when a codemod that adds `vite-hub/nuxt` finds a Nuxt version before 4.7 without `--nuxt-nightly`, when the folder has neither `package.json` nor `nuxt.config`, or when `nuxt.config` does not parse.
|
|
24
34
|
|
|
25
35
|
## Upgrade ViteHub
|
|
26
36
|
|
|
@@ -28,15 +38,15 @@ The command exits with `0` when every codemod completes, also when they report f
|
|
|
28
38
|
vitehub migrate [dir] [--dry-run]
|
|
29
39
|
```
|
|
30
40
|
|
|
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.
|
|
41
|
+
`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`, `console-out-of-app`, `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
42
|
|
|
33
43
|
## Run one codemod
|
|
34
44
|
|
|
35
45
|
```sh
|
|
36
|
-
npx @vite-hub/codemods nuxt-safe-runtime-config [dir] [--dry-run]
|
|
46
|
+
npx @vite-hub/codemods nuxt-safe-runtime-config [dir] [--dry-run] [--nuxt-nightly]
|
|
37
47
|
```
|
|
38
48
|
|
|
39
|
-
The command runs only the named codemod. Run it with `--help` to list the codemods. It exits with `1` when the codemod cannot migrate, for example when it cannot find or parse `nuxt.config`.
|
|
49
|
+
The command runs only the named codemod. Run it with `--help` to list the codemods. It exits with `1` when the codemod cannot migrate, for example when it cannot find or parse `nuxt.config`. It checks the Nuxt version the same way as the full migration, and `--nuxt-nightly` works the same way.
|
|
40
50
|
|
|
41
51
|
| Codemod | Moves |
|
|
42
52
|
| --- | --- |
|
|
@@ -58,7 +68,7 @@ The command runs only the named codemod. Run it with `--help` to list the codemo
|
|
|
58
68
|
| `renamed-apis` | An app from the ViteHub names that this release renamed, such as `hubDb` and `kv.del()` |
|
|
59
69
|
| `define-forms` | The former define forms of Queue, Schedule, Sandbox Task, Workflow, Content, and Database to the one form of each |
|
|
60
70
|
| `one-entry-imports` | Imports of subpaths that moved into one entry per concept, and `vite-hub/task` to `nitro/task` |
|
|
61
|
-
| `vitehub-options` | The options that moved in `vitehub()`: `preset` to `host`, `observability.logs` to `logs`, Env declarations into `vitehub({ env })`,
|
|
71
|
+
| `vitehub-options` | The options that moved in `vitehub()`: `preset` to `host`, `observability.logs` to `logs`, Env declarations into `vitehub({ env })`, the Console journal options into `agent.invocations`, and `devtools`, `contentImportBase` and the Console options that left the app removed |
|
|
62
72
|
| `tsconfig-paths` | `#vitehub/*` entries of tsconfig `paths` that point into `.vitehub/` or `.nuxt/`, which ViteHub now types itself |
|
|
63
73
|
| `shell-driver` | The Shell `provider` names to `driver`: `createShellRuntime({ driver })`, `ShellDriver`, and `createJustBashDriver()`. `vitehub migrate` runs it. |
|
|
64
74
|
| `access-spellings` | Realtime `auth: true` to `authorize: true`, and MCP `public: true` to `access: "public"`. `vitehub migrate` runs it. |
|
|
@@ -70,6 +80,7 @@ The command runs only the named codemod. Run it with `--help` to list the codemo
|
|
|
70
80
|
| `cli-yes-flag` | Replace old CLI prompt flags in scripts and CI, or report a manual migration. `vitehub migrate` runs it. |
|
|
71
81
|
| `cli-url-flag` | `vitehub` calls in scripts and CI: `--server` to `--url`, the app URL. `vitehub migrate` runs it. |
|
|
72
82
|
| `cms-roles` | The `cms` preset option `access: "roles"` to `roles: true`. `vitehub migrate` runs it. |
|
|
83
|
+
| `console-out-of-app` | The `via: "page"` branch of `console.authorize` and `ConsolePageAuthorizeContext` removed, and `VITEHUB_CONSOLE_MCP_KEY` lines reported. `vitehub migrate` runs it. |
|
|
73
84
|
| `choices-package` | `@vite-hub/decisions` and `vite-hub/decisions` imports and the `vitehub decisions` command to `choices`. `vitehub migrate` runs it. |
|
|
74
85
|
| `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
86
|
| `cli-agent-tree` | `vitehub` Agent calls in scripts and CI: `agents …`, `invocations …`, and `conversations export` move under `vitehub agent`. `vitehub migrate` runs it. |
|
|
@@ -178,8 +189,10 @@ npx @vite-hub/codemods define-forms [dir] [--dry-run]
|
|
|
178
189
|
| `vite: { env }` in `nuxt.config.ts` | `env` in the `vite-hub/nuxt` options |
|
|
179
190
|
| A top-level Vite key such as `kv` or `blob` | `vitehub({ kv })`, or the argument of `hubKV()` |
|
|
180
191
|
| `devtools`, `contentImportBase` | removed |
|
|
192
|
+
| `console: { pill }`, `console.mcpClient`, `console.embed`, `console.mcp`, `console.origins`, `console.signInPage`, `console.auth: 'token'` | removed. `console: true` when no option stays |
|
|
193
|
+
| `console: { databaseUrl, observations, retention }` | `agent: { invocations: { databaseUrl, observations, retention } }` |
|
|
181
194
|
|
|
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`.
|
|
195
|
+
The report lists what the codemod cannot move: `preset` next to `host`, `sandbox` options that are not a boolean, `cloudflare.secretsFile`, `console.auth: 'app'` and `console.auth: { ... }`, 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`. The codemod leaves a Console journal option in place and reports it when the move could change the effective journal, would overwrite an existing option, or would put `databaseUrl` on an explicit store where it has no effect.
|
|
183
196
|
|
|
184
197
|
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.
|
|
185
198
|
|
|
@@ -228,7 +241,7 @@ npx @vite-hub/codemods queue-durations [dir] [--dry-run]
|
|
|
228
241
|
|
|
229
242
|
## `nuxthub`
|
|
230
243
|
|
|
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/
|
|
244
|
+
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/compare/nuxthub#migrate-from-nuxthub) and makes only the edits that keep the same behavior:
|
|
232
245
|
|
|
233
246
|
- `nuxt.config`: `'@nuxthub/core'` becomes `'vite-hub/nuxt'`, and `hub` becomes `vitehub` in place. `db: 'sqlite'` becomes `database: true`, and `kv`, `blob`, and `cache` stay `true`. The host comes from `nitro.preset`, then `cloudflare` when the app has a Wrangler config, then `node`. Driver options and other `hub` keys become follow-ups. MySQL stops the codemod, because ViteHub does not support it.
|
|
234
247
|
- `package.json`: removes `@nuxthub/core` and adds `vite-hub`. With a database, it adds `@vite-hub/database` and brings `drizzle-orm` and `drizzle-kit` to at least `^1.0.0-rc.5`, the lowest version that `@vite-hub/database` accepts.
|
|
@@ -244,10 +257,30 @@ The codemod does not move local data or baseline the database. The follow-ups li
|
|
|
244
257
|
|
|
245
258
|
## `nuxt-safe-runtime-config`
|
|
246
259
|
|
|
260
|
+
The `.env.example` migration requires `vite-hub` in the range `>=0.5.1 <1`. The codemod reads a `catalog:` version from `pnpm-workspace.yaml` and an `npm:vite-hub@` alias. If the declared range allows an unsupported release, it stops without writing files. Update the range in `package.json`, then run the codemod again. If the codemod cannot read the declaration, such as `workspace:*`, `link:`, `file:`, a pkg.pr.new URL, or `latest`, it keeps it and lists a follow-up.
|
|
261
|
+
|
|
247
262
|
The codemod reads one of the two schema sources of the module:
|
|
248
263
|
|
|
249
|
-
- `safeRuntimeConfig.envSchema` points at a `.env.example` with `@env-spec` annotations. The codemod replaces it with `envSchema(new URL("./.env.example", import.meta.url), { prefix: "NUXT_" })` from
|
|
250
|
-
- `safeRuntimeConfig.$schema` is a Valibot, Zod 3, Zod 4, or ArkType schema, inline or in a module. For Zod 4 before 4.2, the codemod calls `toJSONSchema()` from the app's own Zod. The codemod converts it to JSON Schema and writes `env()`, `env.number()`, `env.boolean()`, and `env.enum()` declarations under `vitehub.env`. Each declaration reads its `NUXT_*` variable with `env.source()`. A `process.env.NAME || fallback` value reads `NAME` with `env.source()` and keeps `fallback` as the default. Env treats an empty variable as unset, as `||` did. Literal `runtimeConfig` values, including empty strings, become defaults,
|
|
264
|
+
- `safeRuntimeConfig.envSchema` points at a `.env.example` with `@env-spec` annotations. The codemod replaces it with `envSchema(new URL("./.env.example", import.meta.url), { prefix: "NUXT_" })` from `vite-hub/env/vite`. With the `NUXT_` prefix, `NUXT_PUBLIC_*` keys become Public Env and other `NUXT_*` keys become Server Env, with the same names and variables. Server `paths` stay the same. Public Env is flat, so a nested public path falls back to its flat name.
|
|
265
|
+
- `safeRuntimeConfig.$schema` is a Valibot, Zod 3, Zod 4, or ArkType schema, inline or in a module. For Zod 4 before 4.2, the codemod calls `toJSONSchema()` from the app's own Zod. The codemod converts it to JSON Schema and writes `env()`, `env.number()`, `env.boolean()`, and `env.enum()` declarations under `vitehub.env`. Each declaration reads its `NUXT_*` variable with `env.source()`. A `process.env.NAME || fallback` value reads `NAME` with `env.source()` and keeps `fallback` as the default. Env treats an empty variable as unset, as `||` did. Literal `runtimeConfig` values, including empty strings, become defaults. The codemod checks each default against its field schema, applying the source module’s input coercion for runtime validation. A rejected value, such as `""` for `v.minLength(16)`, is dropped when validation is fatal, so Env requires its variable. Nonfatal `onError` modes do not drop a default solely because validation rejects it. The checks follow the installed module version. Before 0.4.0, the module checked only at build unless `validateAtRuntime: true`. From 0.4.0, it also checks when the server starts unless `validateAtRuntime: false`, so `validateAtBuild: false` alone still rejects. When the codemod cannot read the version, it uses the 0.4.0 rules. Keys under `runtimeConfig.public` become Public Env with `mode: "build"`. Credential-like server names become `secret: true`.
|
|
266
|
+
|
|
267
|
+
Env options cannot hold every schema rule, such as `v.minLength(16)`, `z.url()`, or `v.transform()`, or the shape of a JSON array. For these fields the codemod writes `server/env.schema.ts`, or `server/runtime-config.schema.ts` when the first file exists. The module exports the schema of each field: `.entries.x` for Valibot, `.shape.x` for Zod, and `.get("x")` for ArkType. It imports a `$schema` module. It moves an inline `$schema` and its imports into the module, unless the schema uses other `nuxt.config` bindings. The codemod runs each export on the loaded schema before it writes it. A server field reads its export with `env.schemaFrom()`: `env({ schema })` when the schema takes a string, and `env.json(schema)` when it takes a number, boolean, or array. A public field imports its export into `nuxt.config`, and Env runs it during the build. The codemod lists public ArkType rules as follow-ups. Env stops the app when a schema fails, so the codemod writes the module only when `nuxt-safe-runtime-config` did the same: `onError: 'throw'` with build or runtime validation on. With `onError: 'warn'` or `'ignore'`, the rules become follow-ups. Keep the `$schema` file and its schema library.
|
|
268
|
+
|
|
269
|
+
Whole-object fields such as records stay in `runtimeConfig`: one Env declaration cannot preserve nested Nuxt overrides such as `NUXT_LABELS_COLOR`. The report names the affected fields without printing credential defaults, expressions, or schema rejection details.
|
|
270
|
+
|
|
271
|
+
```diff [nuxt.config.ts]
|
|
272
|
+
- runtimeConfig: { apiSecret: '', allowedOrigins: 'a,b', port: '3000' },
|
|
273
|
+
- safeRuntimeConfig: { $schema: './schema' },
|
|
274
|
+
+ vitehub: {
|
|
275
|
+
+ env: {
|
|
276
|
+
+ server: {
|
|
277
|
+
+ apiSecret: env({ schema: env.schemaFrom('./server/env.schema.ts', 'apiSecret'), secret: true, source: env.source('NUXT_API_SECRET') }),
|
|
278
|
+
+ allowedOrigins: env({ default: 'a,b', schema: env.schemaFrom('./server/env.schema.ts', 'allowedOrigins'), source: env.source('NUXT_ALLOWED_ORIGINS') }),
|
|
279
|
+
+ port: env({ default: '3000', schema: env.schemaFrom('./server/env.schema.ts', 'port'), source: env.source('NUXT_PORT') }),
|
|
280
|
+
+ },
|
|
281
|
+
+ },
|
|
282
|
+
+ },
|
|
283
|
+
```
|
|
251
284
|
|
|
252
285
|
When `safeRuntimeConfig` declares neither and the app has no layers, the module validates nothing, so the codemod removes it from `modules`, `nuxt.config`, and `package.json`. It stops instead when code still calls `useSafeRuntimeConfig()`. Schema-free removal also stops when the config extends layers, uses a root spread, or has automatic `layers/` directories: inherited schemas and composable calls are unknown. Review those layers and remove the module by hand, or declare the schema in the app config before retrying.
|
|
253
286
|
|
|
@@ -255,7 +288,9 @@ In both cases the codemod replaces `'nuxt-safe-runtime-config'` with `'vite-hub/
|
|
|
255
288
|
|
|
256
289
|
An existing `modules` property must be an array literal. If it is an expression such as `buildModules()`, or a root spread could supply an inherited list, the codemod stops without writing files; make the list explicit before retrying. A dynamic `nitro.preset` also stops the codemod unless a ViteHub host is already explicit; use a string literal or set `vitehub.host` before retrying. Consumed local layers inside the app are included in call-site migration. Local layers outside the app directory are left unchanged and named in the report for manual migration before using the migrated app.
|
|
257
290
|
|
|
258
|
-
|
|
291
|
+
A Nitro app without `nuxt.config` that declares `nitropack`, directly or through an npm alias, stops this codemod with `CODEMODS_NITRO_UNSUPPORTED`. Keep `nuxt-safe-runtime-config/nitro` until the app runs on Nitro 3. If the app declares both `nitro` and `nitropack`, keep only the package it uses before retrying.
|
|
292
|
+
|
|
293
|
+
The report lists what Env cannot express and what the codemod could not rewrite: rules that no schema module keeps, unions of input types, unsupported defaults, non-empty secret defaults omitted from Env declarations, secret reads that need `.unseal()`, reads that pass the config object on, `useRuntimeConfig()` reads of migrated keys, template reads, and ESLint rules of the module. Zod 3 input coercion is reported because Env accepts different inputs. Unsupported Zod 3 wrappers, including `.catch()` fallbacks, stay in `runtimeConfig` for manual migration. Public Env values are fixed when you build, while Nuxt applied `NUXT_PUBLIC_*` overrides when the server started.
|
|
259
294
|
|
|
260
295
|
[`examples/nuxt-safe-runtime-config`](./examples/nuxt-safe-runtime-config) is a Nuxt app that uses the module. The end-to-end test builds and starts it, migrates a copy, type-checks and builds the copy with `vite-hub/nuxt`, and compares the typed values that one server route returns:
|
|
261
296
|
|
|
@@ -639,6 +674,26 @@ npx @vite-hub/codemods cms-roles [dir] [--dry-run]
|
|
|
639
674
|
|
|
640
675
|
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
676
|
|
|
677
|
+
## `console-out-of-app`
|
|
678
|
+
|
|
679
|
+
The Console runs outside the app, so `console.authorize` no longer gets `via: "page"`. `console-out-of-app` removes the code that handled it:
|
|
680
|
+
|
|
681
|
+
```sh
|
|
682
|
+
npx @vite-hub/codemods console-out-of-app [dir] [--dry-run]
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
```diff [server/console-authorize.ts]
|
|
686
|
+
import { defineConsoleAuthorize } from 'vite-hub/console/auth'
|
|
687
|
+
-import type { ConsolePageAuthorizeContext } from 'vite-hub/console/auth'
|
|
688
|
+
|
|
689
|
+
export default defineConsoleAuthorize(({ via, user }) => {
|
|
690
|
+
- if (via === 'page') return user?.role === 'admin'
|
|
691
|
+
return true
|
|
692
|
+
})
|
|
693
|
+
```
|
|
694
|
+
|
|
695
|
+
It edits the function passed to `defineConsoleAuthorize()` from `vite-hub/console/auth`, and the function that `server/console-authorize.ts` default-exports. It removes an `if` on `via === 'page'` without an `else`, and the `ConsolePageAuthorizeContext` import when nothing else names it. The report lists other `'page'` checks, `ConsolePageAuthorizeContext` when the file still uses it, and each env or Wrangler line that sets `VITEHUB_CONSOLE_MCP_KEY`, without its value. The SQL that removes the old Console tables and Site access users is on [Move the Console from earlier releases](https://vitehub.dev/docs/console/migrate).
|
|
696
|
+
|
|
642
697
|
## Add a codemod
|
|
643
698
|
|
|
644
699
|
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`.
|