@vite-hub/codemods 0.5.0 → 0.5.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 +18 -8
- package/dist/{cli-main-aLhc0Eyq.js → cli-main-BPr3LL6y.js} +1153 -361
- package/dist/cli.js +2 -3
- package/dist/index.d.ts +14 -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
|
|
|
@@ -33,10 +43,10 @@ vitehub migrate [dir] [--dry-run]
|
|
|
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
|
| --- | --- |
|
|
@@ -228,7 +238,7 @@ npx @vite-hub/codemods queue-durations [dir] [--dry-run]
|
|
|
228
238
|
|
|
229
239
|
## `nuxthub`
|
|
230
240
|
|
|
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/
|
|
241
|
+
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
242
|
|
|
233
243
|
- `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
244
|
- `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.
|
|
@@ -247,7 +257,7 @@ The codemod does not move local data or baseline the database. The follow-ups li
|
|
|
247
257
|
The codemod reads one of the two schema sources of the module:
|
|
248
258
|
|
|
249
259
|
- `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.
|
|
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,
|
|
260
|
+
- `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`.
|
|
251
261
|
|
|
252
262
|
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
263
|
|