@vite-hub/codemods 0.4.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 +94 -4
- package/dist/{cli-main-DfzMGFup.js → cli-main-aLhc0Eyq.js} +2419 -758
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -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`, `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 `
|
|
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
|
|
|
@@ -63,7 +63,7 @@ The command runs only the named codemod. Run it with `--help` to list the codemo
|
|
|
63
63
|
| `shell-driver` | The Shell `provider` names to `driver`: `createShellRuntime({ driver })`, `ShellDriver`, and `createJustBashDriver()`. `vitehub migrate` runs it. |
|
|
64
64
|
| `access-spellings` | Realtime `auth: true` to `authorize: true`, and MCP `public: true` to `access: "public"`. `vitehub migrate` runs it. |
|
|
65
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. |
|
|
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
67
|
| `auth-accessors` | Auth `auth` and `getAuth()` to `useAuth()`, and `isGitHubOrgMember()` to `checkGitHubOrgMember()`. `vitehub migrate` runs it. |
|
|
68
68
|
| `workspace-repo` | The GitHub Workspace Store option `repository` to `repo`. `vitehub migrate` runs it. |
|
|
69
69
|
| `kv-list-prefix` | `kv.keys(base)` to `kv.list({ prefix })`, and `kv.clear(base)` to `kv.clear({ prefix })`. `vitehub migrate` runs it. |
|
|
@@ -71,6 +71,9 @@ The command runs only the named codemod. Run it with `--help` to list the codemo
|
|
|
71
71
|
| `cli-url-flag` | `vitehub` calls in scripts and CI: `--server` to `--url`, the app URL. `vitehub migrate` runs it. |
|
|
72
72
|
| `cms-roles` | The `cms` preset option `access: "roles"` to `roles: true`. `vitehub migrate` runs it. |
|
|
73
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. |
|
|
74
77
|
|
|
75
78
|
## `runtime-contracts`
|
|
76
79
|
|
|
@@ -232,6 +235,7 @@ The codemod runs when `package.json` or `modules` lists `@nuxthub/core`, or when
|
|
|
232
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.
|
|
233
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.
|
|
234
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.
|
|
235
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`.
|
|
236
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.
|
|
237
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`.
|
|
@@ -447,9 +451,31 @@ npx @vite-hub/codemods auth-sign-in [dir] [--dry-run]
|
|
|
447
451
|
|
|
448
452
|
## `channels`
|
|
449
453
|
|
|
450
|
-
`
|
|
454
|
+
`vite-hub/agent/channels` is removed, and so is `http()`:
|
|
451
455
|
|
|
452
|
-
|
|
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.
|
|
453
479
|
|
|
454
480
|
It also moves webhook secrets and signatures to the names of Webhooks:
|
|
455
481
|
|
|
@@ -490,8 +516,72 @@ npx @vite-hub/codemods auth-accessors [dir] [--dry-run]
|
|
|
490
516
|
|
|
491
517
|
```sh
|
|
492
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 })
|
|
493
575
|
```
|
|
494
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
|
+
|
|
495
585
|
## Check real apps
|
|
496
586
|
|
|
497
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:
|